emacs-devel
[Top][All Lists]
Advanced

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

Re: jit-lock doesn't honor font-lock-lines-before


From: Stefan Monnier
Subject: Re: jit-lock doesn't honor font-lock-lines-before
Date: Thu, 01 Sep 2005 09:49:44 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>>> Suppose not: Wouldn't that mean `font-lock-lines-before' is useless?
>> Not at all.
> Then you mean that `font-lock-lines-before' is useless with jit-lock?

....fumbling about...

Hmm.... now I see what you mean.  I simply assumed that the code for
font-lock-lines-before had been added at the same place as the code for
font-lock-multiline, so it would work just as well for jit-lock as for
lazy-lock or anything else.
As it currently stands, it indeed is broken.  Sorry for being so stubborn.

I suggest the patch below, which also sets the default value to 0: except
for some special modes which rely on font-lock-lines-before (and which
should thus set it explicitly to an appropriate value), setting it to
something more than 0 will just waste CPU.

> I don't know about font-lock-fontification-face-function.
> `font-lock-multiline' is not a hack, at least not a priori.  It simply
> has not been developed yet.  `font-lock-lines-before' is a brute hack.
> However, until `font-lock-multiline' is implemented correctly, it might
> be better than nothing.

I designed and implemented font-lock-multiline.  It's a hack.  It can't be
fixed.  If you want reliable and efficient multiline keywords, you have to
specify them differently (read: change/extend the format of
font-lock-keywords).  Although you are right that you could get it to work
more or less right for the special case of anchored keywords.


        Stefan


--- font-lock.el        22 aoĆ» 2005 10:22:15 -0400      1.271
+++ font-lock.el        01 sep 2005 09:43:30 -0400      
@@ -293,7 +282,7 @@
                 (integer :tag "size"))
   :group 'font-lock)
 
-(defcustom font-lock-lines-before 1
+(defcustom font-lock-lines-before 0
   "*Number of lines before the changed text to include in refontification."
   :type 'integer
   :group 'font-lock
@@ -1049,6 +1038,8 @@
          ;; Use the fontification syntax table, if any.
          (when font-lock-syntax-table
            (set-syntax-table font-lock-syntax-table))
+          (goto-char beg)
+          (setq beg (line-beginning-position (- 1 font-lock-lines-before)))
          ;; check to see if we should expand the beg/end area for
          ;; proper multiline matches
          (when (and font-lock-multiline
@@ -1105,8 +1096,7 @@
       (save-match-data
        ;; Rescan between start of lines enclosing the region.
        (font-lock-fontify-region
-        (progn (goto-char beg)
-               (forward-line (- font-lock-lines-before)) (point))
+        (progn (goto-char beg) (forward-line 0) (point))
         (progn (goto-char end) (forward-line 1) (point)))))))
 
 (defun font-lock-fontify-block (&optional arg)




reply via email to

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