Function: font-lock-extend-jit-lock-region-after-change

font-lock-extend-jit-lock-region-after-change is a byte-compiled function defined in font-lock.el.gz.

Signature

(font-lock-extend-jit-lock-region-after-change BEG END OLD-LEN)

Documentation

Function meant for jit-lock-after-change-extend-region-functions.

This function does 2 things:
- extend the region so that it not only includes the part that was modified
  but also the surrounding text whose highlighting may change as a consequence.
- anticipate (part of) the region extension that will happen later in
  font-lock-default-fontify-region, in order to avoid the need for
  double-redisplay in jit-lock-fontify-now.

Source Code

;; Defined in /usr/src/emacs/lisp/font-lock.el.gz
(defun font-lock-extend-jit-lock-region-after-change (beg end old-len)
  "Function meant for `jit-lock-after-change-extend-region-functions'.
This function does 2 things:
- extend the region so that it not only includes the part that was modified
  but also the surrounding text whose highlighting may change as a consequence.
- anticipate (part of) the region extension that will happen later in
  `font-lock-default-fontify-region', in order to avoid the need for
  double-redisplay in `jit-lock-fontify-now'."
  (save-excursion
    ;; First extend the region as font-lock-after-change-function would.
    (let ((region (if font-lock-extend-after-change-region-function
                      (funcall font-lock-extend-after-change-region-function
                               beg end old-len))))
      (if region
          (setq beg (min jit-lock-start (car region))
                end (max jit-lock-end (cdr region))))
      ;; Then extend the region obeying font-lock-multiline properties,
      ;; indicating which part of the buffer needs to be refontified.
      ;; !!! This is the *main* user of font-lock-multiline property !!!
      ;; font-lock-after-change-function could/should also do that, but it
      ;; doesn't need to because font-lock-default-fontify-region does
      ;; it anyway.  Here OTOH we have no guarantee that
      ;; font-lock-default-fontify-region will be executed on this region
      ;; any time soon.
      ;; Note: contrary to font-lock-default-fontify-region, we do not do
      ;; any loop here because we are not looking for a safe spot: we just
      ;; mark the text whose appearance may need to change as a result of
      ;; the buffer modification.
      (when (and (> beg (point-min))
                 (get-text-property (1- beg) 'font-lock-multiline))
        (setq beg (or (previous-single-property-change
                       beg 'font-lock-multiline)
                      (point-min))))
      (when (< end (point-max))
        (setq end
              (cond
               ((get-text-property end 'font-lock-multiline)
                (or (text-property-any end (point-max)
                                       'font-lock-multiline nil)
                    (point-max)))
               ;; If `end' has been set by the function above, don't corrupt it.
               (font-lock-extend-after-change-region-function end)
                ;; Rounding up to a whole number of lines should include the
                ;; line right after `end'.  Typical case: the first char of
                ;; the line was deleted.  Or a \n was inserted in the middle
                ;; of a line.
               (t (1+ end)))))
      ;; Finally, pre-enlarge the region to a whole number of lines, to try
      ;; and anticipate what font-lock-default-fontify-region will do, so as to
      ;; avoid double-redisplay.
      ;; We could just run `font-lock-extend-region-functions', but since
      ;; the only purpose is to avoid the double-redisplay, we prefer to
      ;; do here only the part that is cheap and most likely to be useful.
      (when (memq 'font-lock-extend-region-wholelines
                  font-lock-extend-region-functions)
        (goto-char beg)
        (setq beg (min jit-lock-start (line-beginning-position)))
        (goto-char end)
        (setq end
              (max jit-lock-end
                   (if (bolp) (point) (line-beginning-position 2)))))
      (setq jit-lock-start beg
	    jit-lock-end end))))