Function: c-font-lock-fontify-region

c-font-lock-fontify-region is a byte-compiled function defined in cc-mode.el.gz.

Signature

(c-font-lock-fontify-region BEG END &optional VERBOSE)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-mode.el.gz
(defun c-font-lock-fontify-region (beg end &optional verbose)
  ;; Effectively advice around `font-lock-fontify-region' which extends the
  ;; region (BEG END), for example, to avoid context fontification chopping
  ;; off the start of the context.  Do not extend the region if it's already
  ;; been done (i.e. from an after-change fontification.  An example (C++)
  ;; where the chopping off used to happen is this:
  ;;
  ;;     template <typename T>
  ;;
  ;;
  ;;     void myfunc(T* p) {}
  ;;
  ;; Type a space in the first blank line, and the fontification of the next
  ;; line was fouled up by context fontification.
  (save-restriction
    (widen)
    (let (new-beg new-end new-region case-fold-search)
      (c-save-buffer-state nil
	;; Temporarily reapply the string fence syntax-table properties.
	(unwind-protect
	    (progn
	      (c-restore-string-fences)
	      (if (and c-in-after-change-fontification
		       (< beg c-new-END) (> end c-new-BEG))
		  ;; Region and the latest after-change fontification region overlap.
		  ;; Determine the upper and lower bounds of our adjusted region
		  ;; separately.
		  (progn
		    (if (<= beg c-new-BEG)
			(setq c-in-after-change-fontification nil))
		    (setq new-beg
			  (if (and (>= beg (c-point 'bol c-new-BEG))
				   (<= beg c-new-BEG))
			      ;; Either jit-lock has accepted `c-new-BEG', or has
			      ;; (probably) extended the change region spuriously
			      ;; to BOL, which position likely has a
			      ;; syntactically different position.  To ensure
			      ;; correct fontification, we start at `c-new-BEG',
			      ;; assuming any characters to the left of
			      ;; `c-new-BEG' on the line do not require
			      ;; fontification.
			      c-new-BEG
			    (setq new-region (c-before-context-fl-expand-region beg end)
				  new-end (cdr new-region))
			    (car new-region)))
		    (setq new-end
			  (if (and (>= end (c-point 'bol c-new-END))
				   (<= end c-new-END))
			      c-new-END
			    (or new-end
				(cdr (c-before-context-fl-expand-region beg end))))))
		;; Context (etc.) fontification.
		(setq new-region (c-before-context-fl-expand-region beg end)
		      new-beg (car new-region)  new-end (cdr new-region)))
	      ;; Finally invoke font lock's functionality.
	      (funcall (default-value 'font-lock-fontify-region-function)
		       new-beg new-end verbose))
	  (c-clear-string-fences))))))