emacs-bug-tracker
[Top][All Lists]
Advanced

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

[debbugs-tracker] bug#22316: closed (font-lock corrupts `end' position i


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#22316: closed (font-lock corrupts `end' position in jit-lock after-change function.)
Date: Fri, 08 Jan 2016 14:45:01 +0000

Your message dated 8 Jan 2016 14:44:05 -0000
with message-id <address@hidden>
and subject line Re: bug#22316: font-lock corrupts `end' position in jit-lock 
after-change      function.
has caused the debbugs.gnu.org bug report #22316,
regarding font-lock corrupts `end' position in jit-lock after-change function.
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
22316: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=22316
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: font-lock corrupts `end' position in jit-lock after-change function. Date: Tue, 5 Jan 2016 21:47:28 +0000 User-agent: Mutt/1.5.23 (2014-03-12)
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).



--- End Message ---
--- Begin Message --- Subject: Re: bug#22316: font-lock corrupts `end' position in jit-lock after-change function. Date: 8 Jan 2016 14:44:05 -0000 User-agent: tin/2.3.1-20141224 ("Tallant") (UNIX) (FreeBSD/10.2-RELEASE-p7 (amd64))
Bug fixed.

-- 
Alan Mackenzie (Nuremberg, Germany).



--- End Message ---

reply via email to

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