emacs-diffs
[Top][All Lists]
Advanced

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

emacs-28 dc3d01a5af: CC Mode: Fix a c-backward-token-2 call wrongly jump


From: Alan Mackenzie
Subject: emacs-28 dc3d01a5af: CC Mode: Fix a c-backward-token-2 call wrongly jumping back over macros.
Date: Sat, 2 Jul 2022 12:16:17 -0400 (EDT)

branch: emacs-28
commit dc3d01a5aff4017ac071bf7f72ab4df493d2b2f6
Author: Alan Mackenzie <acm@muc.de>
Commit: Alan Mackenzie <acm@muc.de>

    CC Mode: Fix a c-backward-token-2 call wrongly jumping back over macros.
    
    This fixes bug #56256.
    
    * lisp/progmodes/cc-fonts.el (c-font-lock-c++-lambda-captures): Replace a
    c-backward-token-2, which could jump back too far leading to an infinite
    loop, with a save-excursion to remember the point we've got to go back to.
---
 lisp/progmodes/cc-fonts.el | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 63df267b43..49e8763a28 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1826,7 +1826,7 @@ casts and declarations are fontified.  Used on level 2 
and higher."
   ;; font-lock-keyword-face.  It always returns NIL to inhibit this and
   ;; prevent a repeat invocation.  See elisp/lispref page "Search-based
   ;; Fontification".
-  (let (mode capture-default id-start id-end declaration sub-begin sub-end)
+  (let (mode capture-default id-start id-end declaration sub-begin sub-end tem)
     (while (and (< (point) limit)
                (search-forward "[" limit t))
       (when (progn (backward-char)
@@ -1838,15 +1838,18 @@ casts and declarations are fontified.  Used on level 2 
and higher."
                        (char-after)))
        ;; Is the first element of the list a bare "=" or "&"?
        (when mode
-         (forward-char)
-         (c-forward-syntactic-ws)
-         (if (memq (char-after) '(?, ?\]))
-             (progn
-               (setq capture-default mode)
-               (when (eq (char-after) ?,)
-                 (forward-char)
-                 (c-forward-syntactic-ws)))
-           (c-backward-token-2)))
+         (setq tem nil)
+         (save-excursion
+           (forward-char)
+           (c-forward-syntactic-ws)
+           (if (memq (char-after) '(?, ?\]))
+               (progn
+                 (setq capture-default mode)
+                 (when (eq (char-after) ?,)
+                   (forward-char)
+                   (c-forward-syntactic-ws))
+                 (setq tem (point)))))
+         (if tem (goto-char tem)))
 
        ;; Go round the following loop once per captured item.  We use "\\s)"
        ;; rather than "\\]" here to avoid infinite looping in this situation:



reply via email to

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