From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bill Sacks Newsgroups: gmane.emacs.bugs Subject: 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-ID: <94a87aa6-63d1-dcd9-cbb3-2c9b585fad28@ucar.edu> References: <83a68q6624.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------D3124A73698BF7E5EC3EFD49" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19894"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:52.0) Gecko/20100101 PostboxApp/7.0.56 Cc: 56841@debbugs.gnu.org, Eli Zaretskii To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 22 21:08:14 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oQCmT-0004v6-0m for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 Aug 2022 21:08:13 +0200 Original-Received: from localhost ([::1]:36572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQCmR-00062K-SK for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 Aug 2022 15:08:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQ9z4-0006iL-K5 for bug-gnu-emacs@gnu.org; Mon, 22 Aug 2022 12:09:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQ9z4-0007pC-Ax for bug-gnu-emacs@gnu.org; Mon, 22 Aug 2022 12:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oQ9z4-0000vD-7F for bug-gnu-emacs@gnu.org; Mon, 22 Aug 2022 12:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Bill Sacks Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Aug 2022 16:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56841 X-GNU-PR-Package: emacs Original-Received: via spool by 56841-submit@debbugs.gnu.org id=B56841.16611845413533 (code B ref 56841); Mon, 22 Aug 2022 16:09:02 +0000 Original-Received: (at 56841) by debbugs.gnu.org; 22 Aug 2022 16:09:01 +0000 Original-Received: from localhost ([127.0.0.1]:41575 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oQ9z2-0000uq-FF for submit@debbugs.gnu.org; Mon, 22 Aug 2022 12:09:01 -0400 Original-Received: from mail-io1-f48.google.com ([209.85.166.48]:41526) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oQ9yy-0000ub-W2 for 56841@debbugs.gnu.org; Mon, 22 Aug 2022 12:08:59 -0400 Original-Received: by mail-io1-f48.google.com with SMTP id p187so1219623iod.8 for <56841@debbugs.gnu.org>; Mon, 22 Aug 2022 09:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucar-edu.20210112.gappssmtp.com; s=20210112; h=content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:from:to:cc; bh=uHixNa2vkpTeqjhclPwQRTiewnNwk7HANHWAslCAoNc=; b=U/i4llNVl6tpg+bZ7gFHvxhdStP7UnC12mNjjuaTOESerT7OSUKU6LKIBZP1oQnBT0 d443BkTIUVu2WeGYn8QFJFJFNhltP+1WxkBi4Xw/nUuyfpvG6ve1EwwPNXz+qmIggzMt DJwX/G+OjmVrltJarh7FNoYvgtc3+RIdaNKGiY5xcKD78dmXY0uv7IxI6aY2RJqx/I/7 9UXIZcnypiy9d4D4kXHIOAsbk0GRpAe6U31dgPW75XznEg0SUEU4frReDn2m6gFy6wqP hdiai08OcU9pFF1jbyFnBTmtgMPf53WmOTeqc3RXwSGAxHKGhtFhGPQzm0160Ai3fn5e w2vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:x-gm-message-state:from:to :cc; bh=uHixNa2vkpTeqjhclPwQRTiewnNwk7HANHWAslCAoNc=; b=0wAQ4S6JKo739DavS2NNElrmkWvRU6qlpSfZa5RZ88BDwaT0a5mqxKTD46RWvSf7To 0YA6ASBGsbPJFpfeE8iToHayWhgiIXbezGoGIocM2wEJG8kd+sq0MzFuFzDLtzIpSQs1 jlNAOgVFeZcQ9YhvqUpT4vL+6nliIhXoJPpzwCeuTeSwNaV5QlT7YEqSNcbMi5UvzPTp uisOQoPweUwSkxvTEj9Fv7qmoJHg5k9O61SGSjbCMdo1zd5GmZU05+BzunxiyoaSbxxv VKZhtmTAj1+rggYImnV5Xueym8SvYOODz7bEwlrBTexkhuiHlmOxKKCybMRDZYSmP7xl PVxQ== X-Gm-Message-State: ACgBeo2m4weW/5o0SzAiU3HkMMyFLA9tO5dqLDF9gPA30tGeiAhCHCJU 9s3g/i72kgRaxvLQ8GI0GDwjVWja9+9tYhGoNS/xQD2BLPxQ1DNS56A76/mn2XDVKg2ldsaq+Nt WM6tET8dHz6FMJ0f0yKTZ5H1a32r4tAu4QmwVrSlbwitC/znvLEyqBzl6EDSwTA== X-Google-Smtp-Source: AA6agR7KjIkf8BZ65GIaIhBJIIwhDruADVGh16biQPi+l7+Fni69AJTPzRow9HIkk79J6n7Ux/zZTQ== X-Received: by 2002:a05:6638:379a:b0:349:e1ff:ed2c with SMTP id w26-20020a056638379a00b00349e1ffed2cmr1882608jal.114.1661184530254; Mon, 22 Aug 2022 09:08:50 -0700 (PDT) Original-Received: from [192.168.0.79] (97-118-158-229.hlrn.qwest.net. [97.118.158.229]) by smtp.gmail.com with ESMTPSA id i36-20020a023b64000000b003434b40289dsm5241993jaf.165.2022.08.22.09.08.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Aug 2022 09:08:49 -0700 (PDT) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:240454 Archived-At: This is a multi-part message in MIME format. --------------D3124A73698BF7E5EC3EFD49 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit 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 >>> Date: Sat, 30 Jul 2022 13:05:24 +0000 >>> From: Alan Mackenzie >>> 1. Start emacs -Q. >>> 2. Insert the following file in C Mode: >>> void myfunc( >>> ) { >>> } >>> 3. In line 2 (the first blank line) type "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 > > --------------D3124A73698BF7E5EC3EFD49 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit 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@ucar.edu>
Date: Sat, 30 Jul 2022 13:05:24 +0000
From: Alan Mackenzie <acm@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



--------------D3124A73698BF7E5EC3EFD49--