]> git.eshelyaron.com Git - emacs.git/commitdiff
CC Mode: Compensate for backward-sexp ignoring trailing commas after {...}
authorAlan Mackenzie <acm@muc.de>
Fri, 7 Dec 2018 17:38:03 +0000 (17:38 +0000)
committerAlan Mackenzie <acm@muc.de>
Fri, 7 Dec 2018 17:39:38 +0000 (17:39 +0000)
This fixes bug #32808.

* lisp/progmodes/cc-engine.el (c-beginning-of-statement-1): New variable
comma-delimited, set when we're about to scan backward over a comma.  Do not
reckon a brace block as bounding a statement when it is followed or preceded
by a comma (except when argument comma-delim is non-nil).
(c-guess-basic-syntax, CASE 9C): Call c-beginning-of-statement-1 with argument
comma-delim changed to non-nil.

lisp/progmodes/cc-engine.el

index 9cd2174b665d86ff357b1b8568502df1f5a9415d..376d0bb3d3a53fc009715e3779198ef5ec40f2a4 100644 (file)
@@ -1080,12 +1080,15 @@ comment at the start of cc-engine.el for more info."
                (let ((before-sws-pos (point))
                      ;; The end position of the area to search for statement
                      ;; barriers in this round.
-                     (maybe-after-boundary-pos pos))
+                     (maybe-after-boundary-pos pos)
+                     comma-delimited)
 
                  ;; Go back over exactly one logical sexp, taking proper
                  ;; account of macros and escaped EOLs.
                  (while
                      (progn
+                       (setq comma-delimited (and (not comma-delim)
+                                                  (eq (char-before) ?\,)))
                        (unless (c-safe (c-backward-sexp) t)
                          ;; Give up if we hit an unbalanced block.  Since the
                          ;; stack won't be empty the code below will report a
@@ -1121,6 +1124,7 @@ comment at the start of cc-engine.el for more info."
                         ;; Just gone back over a brace block?
                         ((and
                           (eq (char-after) ?{)
+                          (not comma-delimited)
                           (not (c-looking-at-inexpr-block lim nil t))
                           (save-excursion
                             (c-backward-token-2 1 t nil)
@@ -1132,8 +1136,11 @@ comment at the start of cc-engine.el for more info."
                              (if (and (looking-at c-symbol-start)
                                       (not (looking-at c-keywords-regexp)))
                                  (c-backward-token-2 1 t nil))
-                             (not (looking-at
-                                   c-opt-block-decls-with-vars-key)))))
+                             (and
+                              (not (looking-at
+                                    c-opt-block-decls-with-vars-key))
+                              (or comma-delim
+                                  (not (eq (char-after) ?\,)))))))
                          (save-excursion
                            (c-forward-sexp) (point)))
                         ;; Just gone back over some paren block?
@@ -12711,7 +12718,7 @@ comment at the start of cc-engine.el for more info."
                               (c-back-over-member-initializers)
                               (point)))
                            (c-most-enclosing-brace state-cache (point))))
-             (c-beginning-of-statement-1 lim)
+             (c-beginning-of-statement-1 lim nil nil t)
              (c-add-stmt-syntax 'brace-list-intro nil t lim paren-state)))
 
           ;; CASE 9D: this is just a later brace-list-entry or