GNU bug report logs - #22316
font-lock corrupts `end' position in jit-lock after-change function.

Previous Next

Package: emacs;

Reported by: Alan Mackenzie <acm <at> muc.de>

Date: Tue, 5 Jan 2016 21:46:01 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Alan Mackenzie <acm <at> muc.de>
Subject: bug#22316: closed (Re: bug#22316: font-lock corrupts `end'
 position in jit-lock after-change	function.)
Date: Fri, 08 Jan 2016 14:45:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#22316: font-lock corrupts `end' position in jit-lock after-change function.

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 22316 <at> debbugs.gnu.org.

-- 
22316: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22316
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Alan Mackenzie <acm <at> muc.de>
To: 22316-done <at> debbugs.gnu.org
Subject: Re: bug#22316: font-lock corrupts `end' position in jit-lock
 after-change	function.
Date: 8 Jan 2016 14:44:05 -0000
Bug fixed.

-- 
Alan Mackenzie (Nuremberg, Germany).


[Message part 3 (message/rfc822, inline)]
From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Subject: font-lock corrupts `end' position in jit-lock after-change function.
Date: Tue, 5 Jan 2016 21:47:28 +0000
Hello, Emacs.

With the latest emacs-25 branch (committed 2016-01-05, ~21:15 +0000),
do emacs -Q, and load (or type in) the follow AWK Mode file (M-x
awk-mode, if required):

########################################################################
#!/usr/bin/gawk -f
BEGIN {
    x = 4
}
#########################################################################

Notice the fontification of "BEGIN".  Type a space anywhere on the first
line.  The following happens:
(i) The fontification on the "B" of "BEGIN" is erased instantly.
(ii) Half a second (jit-lock-context-time) later, the fontification on
  "EGIN" is erased.

The cause of the problem is in
font-lock-extend-jit-lock-region-after-change.  The sequence is as
follows:
(i) In AWK Mode, font-lock-extend-after-change-region-function is
  non-nil, and this function is called to set `beg' and `end', the
  bounds of the region to fontify.  In the above case, this region is
  exactly line 1.
(ii) f-l-extend-j-l-r-a-change adds 1 to end.  The region (beg end) now
  covers line 1 and the "B" at the beginning of line 2.
(iii) After-change fontification fontifies this spurious region, (beg
  end).  Since "B" is "on its own", it appears to be an ordinary
  variable use, hence is fontified without a face.
(iv) Half a second later, context fontification starts from `end', finds
  "EGIN" and fontifies this as an ordinary variable, without a face.

The solution I propose is that should the region have been set by
font-lock-extend-after-change-region-function, the `end' position
should be accepted as is.

Here is a patch to implement this.  I will commit it soon to emacs-25 if
I hear no objections.



diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 4a92069..3c1f01d 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -1302,15 +1302,18 @@ font-lock-extend-jit-lock-region-after-change
                       (point-min))))
       (when (< end (point-max))
         (setq end
-              (if (get-text-property end 'font-lock-multiline)
-                  (or (text-property-any end (point-max)
-                                         'font-lock-multiline nil)
-                      (point-max))
+              (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.
-                (1+ end))))
+               (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.


-- 
Alan Mackenzie (Nuremberg, Germany).



This bug report was last modified 9 years and 194 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.