From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#22316: font-lock corrupts `end' position in jit-lock after-change function. Date: Tue, 5 Jan 2016 21:47:28 +0000 Message-ID: <20160105214728.GA3602@acm.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1452030388 3101 80.91.229.3 (5 Jan 2016 21:46:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Jan 2016 21:46:28 +0000 (UTC) To: 22316@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 05 22:46:16 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aGZQl-0006p5-Al for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Jan 2016 22:46:15 +0100 Original-Received: from localhost ([::1]:51560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGZQk-0006tl-JX for geb-bug-gnu-emacs@m.gmane.org; Tue, 05 Jan 2016 16:46:14 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGZQd-0006tf-GE for bug-gnu-emacs@gnu.org; Tue, 05 Jan 2016 16:46:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGZQY-0004x6-B7 for bug-gnu-emacs@gnu.org; Tue, 05 Jan 2016 16:46:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51015) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGZQY-0004x1-7I for bug-gnu-emacs@gnu.org; Tue, 05 Jan 2016 16:46:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aGZQY-0003Gh-0O for bug-gnu-emacs@gnu.org; Tue, 05 Jan 2016 16:46:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 05 Jan 2016 21:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 22316 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.145203032812513 (code B ref -1); Tue, 05 Jan 2016 21:46:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 5 Jan 2016 21:45:28 +0000 Original-Received: from localhost ([127.0.0.1]:39235 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGZQ0-0003Fl-2d for submit@debbugs.gnu.org; Tue, 05 Jan 2016 16:45:28 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:41576) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aGZPz-0003FZ-D9 for submit@debbugs.gnu.org; Tue, 05 Jan 2016 16:45:27 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGZPt-0004dX-0J for submit@debbugs.gnu.org; Tue, 05 Jan 2016 16:45:22 -0500 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:47691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGZPs-0004dR-US for submit@debbugs.gnu.org; Tue, 05 Jan 2016 16:45:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGZPr-0006nJ-Qy for bug-gnu-emacs@gnu.org; Tue, 05 Jan 2016 16:45:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGZPm-0004cb-Q7 for bug-gnu-emacs@gnu.org; Tue, 05 Jan 2016 16:45:19 -0500 Original-Received: from mail.muc.de ([193.149.48.3]:31095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGZPm-0004cK-Gt for bug-gnu-emacs@gnu.org; Tue, 05 Jan 2016 16:45:14 -0500 Original-Received: (qmail 81152 invoked by uid 3782); 5 Jan 2016 21:45:11 -0000 Original-Received: from acm.muc.de (p548A4948.dip0.t-ipconnect.de [84.138.73.72]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 05 Jan 2016 22:45:10 +0100 Original-Received: (qmail 5180 invoked by uid 1000); 5 Jan 2016 21:47:28 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:111275 Archived-At: 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).