emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

jit-lock refontifies too much


From: martin rudalics
Subject: jit-lock refontifies too much
Date: Mon, 12 Sep 2005 08:25:34 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

`jit-lock-fontify-now' contains the line

    (setq next (line-beginning-position 2))

`font-lock-default-fontify-region' contains the line

    (setq end (line-beginning-position 2))

In practice this means that when jit-lock is turned on, every time you
type a character jit-lock refontifies the current _and_ the following
line.  Chunks fontified stealthily always overlap by one line.

One might argue that `font-lock-after-change-function' contains

         (progn (goto-char end) (forward-line 1) (point)))))))

but there the adjustment might be useful - albeit undocumented - since
it allows to correct the syntactic context for the following line.
jit-lock mode has `jit-lock-context-fontify' handle syntactic context
and unconditionally refontifying the second line is plain overkill.

In `font-lock-default-fontify-region' I'd therefore replace the lines:

          (when font-lock-multiline
            (setq end (or (text-property-any end (point-max)
                                             'font-lock-multiline nil)
                          (point-max))))
          (goto-char end)
          (setq end (line-beginning-position 2))
          ;; Now do the fontification.

either by

          (cond
           (font-lock-multiline
            (setq end (or (text-property-any end (point-max)
                                             'font-lock-multiline nil)
                          (point-max)))
            (goto-char end) (setq end (line-beginning-position 2)))
           ;; don't modify end in jit-lock-mode
           ((and (boundp 'jit-lock-mode) jit-lock-mode))
           (t (goto-char end) (setq end (line-beginning-position 2))))
          ;; Now do the fontification.

or - but this might disturb people accustomed to the current behavior of
plain font-lock -

          (when font-lock-multiline
            (setq end (or (text-property-any end (point-max)
                                             'font-lock-multiline nil)
                          (point-max)))
            (goto-char end)
            (setq end (line-beginning-position 2)))
          ;; Now do the fontification.

Finally one could introduce a variable `font-lock-lines-after'

(defcustom font-lock-lines-after 0
  "*Number of lines after the changed text to include in refontification."
  :type 'integer
  :group 'font-lock
  :version "22.1")

and use

          (goto-char end)
          (setq end (line-beginning-position (1+ font-lock-lines-after)))
          (when font-lock-multiline
            (setq end (or (text-property-any end (point-max)
                                             'font-lock-multiline nil)
                          (point-max)))
            (goto-char end)
            (setq end (line-beginning-position 2)))
          ;; Now do the fontification.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]