GNU bug report logs - #56841
Emacs-28 C Mode: Fontification errors when arglist closing ) is on next line

Previous Next

Package: emacs;

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

Date: Sat, 30 Jul 2022 13:06:01 UTC

Severity: minor

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

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 56841 in the body.
You can then email your comments to 56841 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Sat, 30 Jul 2022 13:06:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Alan Mackenzie <acm <at> muc.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 30 Jul 2022 13:06:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: bug-gnu-emacs <at> gnu.org
Cc: Bill Sacks <sacks <at> ucar.edu>
Subject: Emacs-28 C Mode: Fontification errors when arglist closing ) is on
 next line
Date: Sat, 30 Jul 2022 13:05:24 +0000
Hello, Emacs.

This is (a version of) a bug reported by Bill Sacks <sacks <at> ucar.edu> in
the correspondence for bug #56818.  I am separating it from that bug,
since it is a distinct bug, despite having similar symptoms.  In
Emacs-28:

1. Start emacs -Q.
2. Insert the following file in C Mode:

void myfunc(

  ) {

}

3. In line 2 (the first blank line) type "<TAB>int somevar".
4. Note that somevar is not fontified.  This is a bug, given that the
  arglist to myfunc is terminated with a ) on line 3.
5. Do something (e.g. typing M-x) to cause a redisplay.  somevar gets
  its correct face.
6. Note that any insertion or deletion in L2 causes somevar to lose its
  fontification.  This is a bug.
7. (After 6).  Move point onto somevar and do C-u C-x =.  This shows
  that the face text property is set on the character despite the face
  not appearing on the screen.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Sat, 30 Jul 2022 14:16:01 GMT) Full text and rfc822 format available.

Message #8 received at 56841 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 56841 <at> debbugs.gnu.org, sacks <at> ucar.edu
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Sat, 30 Jul 2022 17:14:43 +0300
> Cc: Bill Sacks <sacks <at> ucar.edu>
> Date: Sat, 30 Jul 2022 13:05:24 +0000
> From: Alan Mackenzie <acm <at> muc.de>
> 
> 1. Start emacs -Q.
> 2. Insert the following file in C Mode:
> 
> void myfunc(
> 
>   ) {
> 
> }
> 
> 3. In line 2 (the first blank line) type "<TAB>int somevar".
> 4. Note that somevar is not fontified.  This is a bug, given that the
>   arglist to myfunc is terminated with a ) on line 3.
> 5. Do something (e.g. typing M-x) to cause a redisplay.  somevar gets
>   its correct face.
> 6. Note that any insertion or deletion in L2 causes somevar to lose its
>   fontification.  This is a bug.
> 7. (After 6).  Move point onto somevar and do C-u C-x =.  This shows
>   that the face text property is set on the character despite the face
>   not appearing on the screen.

Are you saying this is not a bug in CC mode but somewhere else?  Or
are you saying that you don't yet know what is the culprit and will
investigate?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Sat, 30 Jul 2022 14:29:02 GMT) Full text and rfc822 format available.

Message #11 received at 56841 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 56841 <at> debbugs.gnu.org, sacks <at> ucar.edu, acm <at> muc.de
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Sat, 30 Jul 2022 14:27:53 +0000
Hello, Eli.

On Sat, Jul 30, 2022 at 17:14:43 +0300, Eli Zaretskii wrote:
> > Cc: Bill Sacks <sacks <at> ucar.edu>
> > Date: Sat, 30 Jul 2022 13:05:24 +0000
> > From: Alan Mackenzie <acm <at> muc.de>

> > 1. Start emacs -Q.
> > 2. Insert the following file in C Mode:

> > void myfunc(

> >   ) {

> > }

> > 3. In line 2 (the first blank line) type "<TAB>int somevar".
> > 4. Note that somevar is not fontified.  This is a bug, given that the
> >   arglist to myfunc is terminated with a ) on line 3.
> > 5. Do something (e.g. typing M-x) to cause a redisplay.  somevar gets
> >   its correct face.
> > 6. Note that any insertion or deletion in L2 causes somevar to lose its
> >   fontification.  This is a bug.
> > 7. (After 6).  Move point onto somevar and do C-u C-x =.  This shows
> >   that the face text property is set on the character despite the face
> >   not appearing on the screen.

> Are you saying this is not a bug in CC mode but somewhere else?  Or
> are you saying that you don't yet know what is the culprit and will
> investigate?

It is most definitely a bug in CC Mode, and I'm looking at it at the
moment.

My feeling right now is that the fix will be too involved to go into the
release branch.

-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Sat, 30 Jul 2022 15:11:01 GMT) Full text and rfc822 format available.

Message #14 received at 56841 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 56841 <at> debbugs.gnu.org, sacks <at> ucar.edu
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Sat, 30 Jul 2022 18:10:12 +0300
> Date: Sat, 30 Jul 2022 14:27:53 +0000
> Cc: 56841 <at> debbugs.gnu.org, sacks <at> ucar.edu, acm <at> muc.de
> From: Alan Mackenzie <acm <at> muc.de>
> 
> > Are you saying this is not a bug in CC mode but somewhere else?  Or
> > are you saying that you don't yet know what is the culprit and will
> > investigate?
> 
> It is most definitely a bug in CC Mode, and I'm looking at it at the
> moment.

Thanks.

> My feeling right now is that the fix will be too involved to go into the
> release branch.

Let's talk when you have a fix.  But generally, this doesn't sound
like a too grave problem to me, especially since there's an easy way
of asking Emacs to fontify correctly.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Sun, 31 Jul 2022 15:50:02 GMT) Full text and rfc822 format available.

Message #17 received at 56841 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Eli Zaretskii <eliz <at> gnu.org>, sacks <at> ucar.edu
Cc: 56841 <at> debbugs.gnu.org, acm <at> muc.de
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Sun, 31 Jul 2022 15:48:56 +0000
Hello, Eli and Bill.

On Sat, Jul 30, 2022 at 18:10:12 +0300, Eli Zaretskii wrote:
> > Date: Sat, 30 Jul 2022 14:27:53 +0000
> > Cc: 56841 <at> debbugs.gnu.org, sacks <at> ucar.edu, acm <at> muc.de
> > From: Alan Mackenzie <acm <at> muc.de>

> > > Are you saying this is not a bug in CC mode but somewhere else?  Or
> > > are you saying that you don't yet know what is the culprit and will
> > > investigate?

> > It is most definitely a bug in CC Mode, and I'm looking at it at the
> > moment.

> Thanks.

> > My feeling right now is that the fix will be too involved to go into the
> > release branch.

> Let's talk when you have a fix.  But generally, this doesn't sound
> like a too grave problem to me, especially since there's an easy way
> of asking Emacs to fontify correctly.

Here's a proposed version of the fix, which seems to work.  The diff is
probably best perused with diff -b.  The patch will apply to both the master
branch and Emacs-28.1.


CC Mode: Fontify args correctly when arglist closing ) is not on the same line

This should fix bug #56841.

* lisp/progmodes/cc-engine.el (c-forward-declarator): Fix an off-by-one
comparing the position after a c-forward-name with a limit.

* lisp/progmodes/cc-mode.el (c-fl-decl-end): Handle correctly point starting
inside a literal.  Insert a missing c-backward-syntactic-ws in the handling of
C++ attributes.  Better handle point starting inside a [ or (.  Tidy up the
handling of syntactic whitespace at the end of the buffer.



diff -r e4e62074b8a6 cc-engine.el
--- a/cc-engine.el	Sat Jul 30 09:15:53 2022 +0000
+++ b/cc-engine.el	Sun Jul 31 15:39:26 2022 +0000
@@ -9576,7 +9576,7 @@
 	 (or (= paren-depth 0)
 	     (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
 
-	 (<= (point) limit)
+	 (< (point) limit)
 
 	 ;; Skip over any trailing bit, such as "__attribute__".
 	 (progn
diff -r e4e62074b8a6 cc-mode.el
--- a/cc-mode.el	Sat Jul 30 09:15:53 2022 +0000
+++ b/cc-mode.el	Sun Jul 31 15:39:26 2022 +0000
@@ -2412,49 +2412,59 @@
       (and (/= new-pos pos) new-pos))))
 
 (defun c-fl-decl-end (pos)
-  ;; If POS is inside a declarator, return the end of the token that follows
-  ;; the declarator, otherwise return nil.  POS being in a literal does not
-  ;; count as being in a declarator (on pragmatic grounds).  POINT is not
-  ;; preserved.
+  ;; If POS is inside a declarator, return the end of the paren pair that
+  ;; terminates it, or the token that follows the declarator, otherwise return
+  ;; nil.  If there is no such token, the end of the last token in the buffer
+  ;; is used.  POS being in a literal is now (2022-07) handled correctly.
+  ;; POINT is not preserved.
   (goto-char pos)
   (let ((lit-start (c-literal-start))
 	(lim (c-determine-limit 1000))
 	enclosing-attribute pos1)
-    (unless lit-start
-      (c-backward-syntactic-ws
-       lim)
-      (when (setq enclosing-attribute (c-enclosing-c++-attribute))
-	(goto-char (car enclosing-attribute))) ; Only happens in C++ Mode.
-      (when (setq pos1 (c-on-identifier))
-	(goto-char pos1)
-	(let ((lim (save-excursion
-		     (and (c-beginning-of-macro)
-			  (progn (c-end-of-macro) (point))))))
-	  (and (c-forward-declarator lim)
-	       (if (eq (char-after) ?\()
-		   (and
-		    (c-go-list-forward nil lim)
-		    (progn (c-forward-syntactic-ws lim)
-			   (not (eobp)))
-		    (progn
-		      (if (looking-at c-symbol-char-key)
-			  ;; Deal with baz (foo((bar)) type var), where
-			  ;; foo((bar)) is not semantically valid.  The result
-			  ;; must be after var).
-			  (and
-			   (goto-char pos)
-			   (setq pos1 (c-on-identifier))
-			   (goto-char pos1)
-			   (progn
-			     (c-backward-syntactic-ws lim)
-			     (eq (char-before) ?\())
-			   (c-fl-decl-end (1- (point))))
-			(c-backward-syntactic-ws lim)
-			(point))))
-		 (and (progn (c-forward-syntactic-ws lim)
-			     (not (eobp)))
+    (if lit-start
+	(goto-char lit-start))
+    (c-backward-syntactic-ws lim)
+    (when (setq enclosing-attribute (c-enclosing-c++-attribute))
+      (goto-char (car enclosing-attribute)) ; Only happens in C++ Mode.
+      (c-backward-syntactic-ws lim))
+    (while (and (> (point) lim)
+		(memq (char-before) '(?\[ ?\()))
+      (backward-char)
+      (c-backward-syntactic-ws lim))
+    (when (setq pos1 (c-on-identifier))
+      (goto-char pos1)
+      (let ((lim (save-excursion
+		   (and (c-beginning-of-macro)
+			(progn (c-end-of-macro) (point))))))
+	(and (c-forward-declarator lim)
+	     (if (eq (char-after) ?\()
+		 (and
+		  (c-go-list-forward nil lim)
+		  (progn (c-forward-syntactic-ws lim)
+			 (not (eobp)))
+		  (progn
+		    (if (looking-at c-symbol-char-key)
+			;; Deal with baz (foo((bar)) type var), where
+			;; foo((bar)) is not semantically valid.  The result
+			;; must be after var).
+			(and
+			 (goto-char pos)
+			 (setq pos1 (c-on-identifier))
+			 (goto-char pos1)
+			 (progn
+			   (c-backward-syntactic-ws lim)
+			   (eq (char-before) ?\())
+			 (c-fl-decl-end (1- (point))))
 		      (c-backward-syntactic-ws lim)
-		      (point)))))))))
+		      (point))))
+	       (if (progn (c-forward-syntactic-ws lim)
+			  (not (eobp)))
+		   (c-forward-over-token)
+		 (let ((lit-start (c-literal-start)))
+		   (when lit-start
+		       (goto-char lit-start))
+		   (c-backward-syntactic-ws)))
+	       (and (>= (point) pos) (point))))))))
 
 (defun c-change-expand-fl-region (_beg _end _old-len)
   ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock


-- 
Alan Mackenzie (Nuremberg, Germany).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Sun, 31 Jul 2022 15:55:02 GMT) Full text and rfc822 format available.

Message #20 received at 56841 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 56841 <at> debbugs.gnu.org, sacks <at> ucar.edu, acm <at> muc.de
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Sun, 31 Jul 2022 18:53:58 +0300
> Date: Sun, 31 Jul 2022 15:48:56 +0000
> Cc: 56841 <at> debbugs.gnu.org, acm <at> muc.de
> From: Alan Mackenzie <acm <at> muc.de>
> 
> > Let's talk when you have a fix.  But generally, this doesn't sound
> > like a too grave problem to me, especially since there's an easy way
> > of asking Emacs to fontify correctly.
> 
> Here's a proposed version of the fix, which seems to work.  The diff is
> probably best perused with diff -b.  The patch will apply to both the master
> branch and Emacs-28.1.

Thanks.  I guess this should go to master.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Tue, 02 Aug 2022 19:31:02 GMT) Full text and rfc822 format available.

Message #23 received at 56841 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: sacks <at> ucar.edu
Cc: 56841 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Tue, 2 Aug 2022 19:30:43 +0000
Hello again, Bill.

On Sat, Jul 30, 2022 at 17:14:43 +0300, Eli Zaretskii wrote:
> > Cc: Bill Sacks <sacks <at> ucar.edu>
> > Date: Sat, 30 Jul 2022 13:05:24 +0000
> > From: Alan Mackenzie <acm <at> muc.de>

> > 1. Start emacs -Q.
> > 2. Insert the following file in C Mode:

> > void myfunc(

> >   ) {

> > }

> > 3. In line 2 (the first blank line) type "<TAB>int somevar".
> > 4. Note that somevar is not fontified.  This is a bug, given that the
> >   arglist to myfunc is terminated with a ) on line 3.
> > 5. Do something (e.g. typing M-x) to cause a redisplay.  somevar gets
> >   its correct face.
> > 6. Note that any insertion or deletion in L2 causes somevar to lose its
> >   fontification.  This is a bug.
> > 7. (After 6).  Move point onto somevar and do C-u C-x =.  This shows
> >   that the face text property is set on the character despite the face
> >   not appearing on the screen.

This bug, although the symptoms were similar to the other bug you
reported, was an entirely different bug, more difficult to fix.

I now have a patch for it, and would ask you to apply the patch to your
Emacs 28.1 and byte compile the files in it, as before.  (As before,
help is available from me by private email.)  Then please test it on
your actual C code and let us know how it went.  Thanks!



diff -r e4e62074b8a6 cc-engine.el
--- a/cc-engine.el	Sat Jul 30 09:15:53 2022 +0000
+++ b/cc-engine.el	Tue Aug 02 19:14:15 2022 +0000
@@ -9576,7 +9576,7 @@
 	 (or (= paren-depth 0)
 	     (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
 
-	 (<= (point) limit)
+	 (< (point) limit)
 
 	 ;; Skip over any trailing bit, such as "__attribute__".
 	 (progn
diff -r e4e62074b8a6 cc-mode.el
--- a/cc-mode.el	Sat Jul 30 09:15:53 2022 +0000
+++ b/cc-mode.el	Tue Aug 02 19:14:15 2022 +0000
@@ -2412,49 +2412,59 @@
       (and (/= new-pos pos) new-pos))))
 
 (defun c-fl-decl-end (pos)
-  ;; If POS is inside a declarator, return the end of the token that follows
-  ;; the declarator, otherwise return nil.  POS being in a literal does not
-  ;; count as being in a declarator (on pragmatic grounds).  POINT is not
-  ;; preserved.
+  ;; If POS is inside a declarator, return the position of the end of the
+  ;; paren pair that terminates it, or of the end of the token that follows
+  ;; the declarator, otherwise return nil.  If there is no such token, the end
+  ;; of the last token in the buffer is used.  POS being in a literal is now
+  ;; (2022-07) handled correctly.  POINT is not preserved.
   (goto-char pos)
   (let ((lit-start (c-literal-start))
 	(lim (c-determine-limit 1000))
 	enclosing-attribute pos1)
-    (unless lit-start
-      (c-backward-syntactic-ws
-       lim)
-      (when (setq enclosing-attribute (c-enclosing-c++-attribute))
-	(goto-char (car enclosing-attribute))) ; Only happens in C++ Mode.
-      (when (setq pos1 (c-on-identifier))
-	(goto-char pos1)
-	(let ((lim (save-excursion
-		     (and (c-beginning-of-macro)
-			  (progn (c-end-of-macro) (point))))))
-	  (and (c-forward-declarator lim)
-	       (if (eq (char-after) ?\()
-		   (and
-		    (c-go-list-forward nil lim)
-		    (progn (c-forward-syntactic-ws lim)
-			   (not (eobp)))
-		    (progn
-		      (if (looking-at c-symbol-char-key)
-			  ;; Deal with baz (foo((bar)) type var), where
-			  ;; foo((bar)) is not semantically valid.  The result
-			  ;; must be after var).
-			  (and
-			   (goto-char pos)
-			   (setq pos1 (c-on-identifier))
-			   (goto-char pos1)
-			   (progn
-			     (c-backward-syntactic-ws lim)
-			     (eq (char-before) ?\())
-			   (c-fl-decl-end (1- (point))))
-			(c-backward-syntactic-ws lim)
-			(point))))
-		 (and (progn (c-forward-syntactic-ws lim)
-			     (not (eobp)))
+    (if lit-start
+	(goto-char lit-start))
+    (c-backward-syntactic-ws lim)
+    (when (setq enclosing-attribute (c-enclosing-c++-attribute))
+      (goto-char (car enclosing-attribute)) ; Only happens in C++ Mode.
+      (c-backward-syntactic-ws lim))
+    (while (and (> (point) lim)
+		(memq (char-before) '(?\[ ?\()))
+      (backward-char)
+      (c-backward-syntactic-ws lim))
+    (when (setq pos1 (c-on-identifier))
+      (goto-char pos1)
+      (let ((lim (save-excursion
+		   (and (c-beginning-of-macro)
+			(progn (c-end-of-macro) (point))))))
+	(and (c-forward-declarator lim)
+	     (if (and (eq (char-after) ?\()
+		      (c-go-list-forward nil lim))
+		 (and
+		  (progn (c-forward-syntactic-ws lim)
+			 (not (eobp)))
+		  (progn
+		    (if (looking-at c-symbol-char-key)
+			;; Deal with baz (foo((bar)) type var), where
+			;; foo((bar)) is not semantically valid.  The result
+			;; must be after var).
+			(and
+			 (goto-char pos)
+			 (setq pos1 (c-on-identifier))
+			 (goto-char pos1)
+			 (progn
+			   (c-backward-syntactic-ws lim)
+			   (eq (char-before) ?\())
+			 (c-fl-decl-end (1- (point))))
 		      (c-backward-syntactic-ws lim)
-		      (point)))))))))
+		      (point))))
+	       (if (progn (c-forward-syntactic-ws lim)
+			  (not (eobp)))
+		   (c-forward-over-token)
+		 (let ((lit-start (c-literal-start)))
+		   (when lit-start
+		       (goto-char lit-start))
+		   (c-backward-syntactic-ws)))
+	       (and (>= (point) pos) (point))))))))
 
 (defun c-change-expand-fl-region (_beg _end _old-len)
   ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock


-- 
Alan Mackenzie (Nuremberg, Germany).




Severity set to 'minor' from 'normal' Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Thu, 04 Aug 2022 13:59:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56841; Package emacs. (Mon, 22 Aug 2022 16:09:02 GMT) Full text and rfc822 format available.

Message #28 received at 56841 <at> debbugs.gnu.org (full text, mbox):

From: Bill Sacks <sacks <at> ucar.edu>
To: Alan Mackenzie <acm <at> muc.de>
Cc: 56841 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Mon, 22 Aug 2022 10:08:48 -0600
[Message part 1 (text/plain, inline)]
Thank you very much for this fix, Alan. I have now tested it both with 
my test case and in more realistic code, and it seems to fix the issues 
I was encountering – thank you!

Sorry for the delay on getting back to you about this.

Bill

Alan Mackenzie wrote on 8/2/22 1:30 PM:
> Hello again, Bill.
>
> On Sat, Jul 30, 2022 at 17:14:43 +0300, Eli Zaretskii wrote:
>>> Cc: Bill Sacks <sacks <at> ucar.edu>
>>> Date: Sat, 30 Jul 2022 13:05:24 +0000
>>> From: Alan Mackenzie <acm <at> muc.de>
>>> 1. Start emacs -Q.
>>> 2. Insert the following file in C Mode:
>>> void myfunc(
>>>    ) {
>>> }
>>> 3. In line 2 (the first blank line) type "<TAB>int somevar".
>>> 4. Note that somevar is not fontified.  This is a bug, given that the
>>>    arglist to myfunc is terminated with a ) on line 3.
>>> 5. Do something (e.g. typing M-x) to cause a redisplay.  somevar gets
>>>    its correct face.
>>> 6. Note that any insertion or deletion in L2 causes somevar to lose its
>>>    fontification.  This is a bug.
>>> 7. (After 6).  Move point onto somevar and do C-u C-x =.  This shows
>>>    that the face text property is set on the character despite the face
>>>    not appearing on the screen.
> This bug, although the symptoms were similar to the other bug you
> reported, was an entirely different bug, more difficult to fix.
>
> I now have a patch for it, and would ask you to apply the patch to your
> Emacs 28.1 and byte compile the files in it, as before.  (As before,
> help is available from me by private email.)  Then please test it on
> your actual C code and let us know how it went.  Thanks!
>
>
>
> diff -r e4e62074b8a6 cc-engine.el
> --- a/cc-engine.el	Sat Jul 30 09:15:53 2022 +0000
> +++ b/cc-engine.el	Tue Aug 02 19:14:15 2022 +0000
> @@ -9576,7 +9576,7 @@
>   	 (or (= paren-depth 0)
>   	     (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
>   
> -	 (<= (point) limit)
> +	 (< (point) limit)
>   
>   	 ;; Skip over any trailing bit, such as "__attribute__".
>   	 (progn
> diff -r e4e62074b8a6 cc-mode.el
> --- a/cc-mode.el	Sat Jul 30 09:15:53 2022 +0000
> +++ b/cc-mode.el	Tue Aug 02 19:14:15 2022 +0000
> @@ -2412,49 +2412,59 @@
>         (and (/= new-pos pos) new-pos))))
>   
>   (defun c-fl-decl-end (pos)
> -  ;; If POS is inside a declarator, return the end of the token that follows
> -  ;; the declarator, otherwise return nil.  POS being in a literal does not
> -  ;; count as being in a declarator (on pragmatic grounds).  POINT is not
> -  ;; preserved.
> +  ;; If POS is inside a declarator, return the position of the end of the
> +  ;; paren pair that terminates it, or of the end of the token that follows
> +  ;; the declarator, otherwise return nil.  If there is no such token, the end
> +  ;; of the last token in the buffer is used.  POS being in a literal is now
> +  ;; (2022-07) handled correctly.  POINT is not preserved.
>     (goto-char pos)
>     (let ((lit-start (c-literal-start))
>   	(lim (c-determine-limit 1000))
>   	enclosing-attribute pos1)
> -    (unless lit-start
> -      (c-backward-syntactic-ws
> -       lim)
> -      (when (setq enclosing-attribute (c-enclosing-c++-attribute))
> -	(goto-char (car enclosing-attribute))) ; Only happens in C++ Mode.
> -      (when (setq pos1 (c-on-identifier))
> -	(goto-char pos1)
> -	(let ((lim (save-excursion
> -		     (and (c-beginning-of-macro)
> -			  (progn (c-end-of-macro) (point))))))
> -	  (and (c-forward-declarator lim)
> -	       (if (eq (char-after) ?\()
> -		   (and
> -		    (c-go-list-forward nil lim)
> -		    (progn (c-forward-syntactic-ws lim)
> -			   (not (eobp)))
> -		    (progn
> -		      (if (looking-at c-symbol-char-key)
> -			  ;; Deal with baz (foo((bar)) type var), where
> -			  ;; foo((bar)) is not semantically valid.  The result
> -			  ;; must be after var).
> -			  (and
> -			   (goto-char pos)
> -			   (setq pos1 (c-on-identifier))
> -			   (goto-char pos1)
> -			   (progn
> -			     (c-backward-syntactic-ws lim)
> -			     (eq (char-before) ?\())
> -			   (c-fl-decl-end (1- (point))))
> -			(c-backward-syntactic-ws lim)
> -			(point))))
> -		 (and (progn (c-forward-syntactic-ws lim)
> -			     (not (eobp)))
> +    (if lit-start
> +	(goto-char lit-start))
> +    (c-backward-syntactic-ws lim)
> +    (when (setq enclosing-attribute (c-enclosing-c++-attribute))
> +      (goto-char (car enclosing-attribute)) ; Only happens in C++ Mode.
> +      (c-backward-syntactic-ws lim))
> +    (while (and (> (point) lim)
> +		(memq (char-before) '(?\[ ?\()))
> +      (backward-char)
> +      (c-backward-syntactic-ws lim))
> +    (when (setq pos1 (c-on-identifier))
> +      (goto-char pos1)
> +      (let ((lim (save-excursion
> +		   (and (c-beginning-of-macro)
> +			(progn (c-end-of-macro) (point))))))
> +	(and (c-forward-declarator lim)
> +	     (if (and (eq (char-after) ?\()
> +		      (c-go-list-forward nil lim))
> +		 (and
> +		  (progn (c-forward-syntactic-ws lim)
> +			 (not (eobp)))
> +		  (progn
> +		    (if (looking-at c-symbol-char-key)
> +			;; Deal with baz (foo((bar)) type var), where
> +			;; foo((bar)) is not semantically valid.  The result
> +			;; must be after var).
> +			(and
> +			 (goto-char pos)
> +			 (setq pos1 (c-on-identifier))
> +			 (goto-char pos1)
> +			 (progn
> +			   (c-backward-syntactic-ws lim)
> +			   (eq (char-before) ?\())
> +			 (c-fl-decl-end (1- (point))))
>   		      (c-backward-syntactic-ws lim)
> -		      (point)))))))))
> +		      (point))))
> +	       (if (progn (c-forward-syntactic-ws lim)
> +			  (not (eobp)))
> +		   (c-forward-over-token)
> +		 (let ((lit-start (c-literal-start)))
> +		   (when lit-start
> +		       (goto-char lit-start))
> +		   (c-backward-syntactic-ws)))
> +	       (and (>= (point) pos) (point))))))))
>   
>   (defun c-change-expand-fl-region (_beg _end _old-len)
>     ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock
>
>

[Message part 2 (text/html, inline)]

Reply sent to Alan Mackenzie <acm <at> muc.de>:
You have taken responsibility. (Wed, 24 Aug 2022 15:11:02 GMT) Full text and rfc822 format available.

Notification sent to Alan Mackenzie <acm <at> muc.de>:
bug acknowledged by developer. (Wed, 24 Aug 2022 15:11:02 GMT) Full text and rfc822 format available.

Message #33 received at 56841-done <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Bill Sacks <sacks <at> ucar.edu>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 56841-done <at> debbugs.gnu.org
Subject: Re: bug#56841: Emacs-28 C Mode: Fontification errors when arglist
 closing ) is on next line
Date: Wed, 24 Aug 2022 15:10:17 +0000
Hello, Bill.

On Mon, Aug 22, 2022 at 10:08:48 -0600, Bill Sacks wrote:
> Thank you very much for this fix, Alan. I have now tested it both with 
> my test case and in more realistic code, and it seems to fix the issues 
> I was encountering – thank you!

Thanks for the testing!

> Sorry for the delay on getting back to you about this.

No problem!  I've now committed the fix to the master branch of Emacs at
savannah, and I'm closing the bug with this post.

> Bill

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 22 Sep 2022 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 329 days ago.

Previous Next


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