Subject: Re: bug#70435: 30.0.50; cc-mode: <> are sometimes not recognized as parentheses

From: Alan Mackenzie <[email-masked]>
Date: Thu, 2 May 2024 13:16:27 +0000

Hello, Géza.

On Thu, May 02, 2024 at 14:49:57 +0200, Herman, Géza wrote:

> Alan Mackenzie <[email-masked]> writes:

> > Géza, would you be prepared to do a little more testing if I modified
> > the patch?

> Sure, I'm happy to test whether a modified patch still fixes the issue.

Thanks, that's appreciated.

The modified patch is quite a bit shorter than the first one, but it does
a little more.  There was a subtle detail about deleting an unterminated
string, too.

Please remove the first patch from your cc-engine.el, then apply the
patch below.  Byte compile cc-engine.el, then load the resulting CC Mode
into a running Emacs (or restart Emacs).  The test case should (still) be
fixed.

Any testing you can do on real code would also be appreciated.  Please
confirm, again, that the bug is truly fixed, or tell me what still needs
to be fixed.  Thanks!

Here's the patch.  It should apply cleanly to the Emacs master:

diff -r 072940aaeb40 cc-engine.el
--- a/cc-engine.el	Sun Apr 14 07:59:01 2024 +0000
+++ b/cc-engine.el	Thu May 02 13:05:48 2024 +0000
@@ -7172,7 +7172,7 @@
   ;; FIXME!!!  This routine ignores the possibility of macros entirely.
   ;; 2010-01-29.
 
-  (when (> end beg)
+  (when (or old-len (> end beg))
     ;; Extend the region (BEG END) to deal with any complicating literals.
     (let* ((lit-search-beg (if (memq (char-before beg) '(?/ ?*))
 			       (1- beg) beg))
@@ -7246,7 +7246,8 @@
 		  (c-put-char-properties beg end 'syntax-table '(1))
 		  ;; If an open string's opener has just been neutralized,
 		  ;; do the same to the terminating LF.
-		  (when (and end-literal-end
+		  (when (and (> end beg)
+			     end-literal-end
 			     (eq (char-before end-literal-end) ?\n)
 			     (equal (c-get-char-property
 				     (1- end-literal-end) 'syntax-table)

-- 
Alan Mackenzie (Nuremberg, Germany).