From: Alan Mackenzie Date: Wed, 24 Aug 2022 14:42:11 +0000 (+0000) Subject: CC Mode: Fontify args correctly when arglist closing ) is not on the same line X-Git-Tag: emacs-29.0.90~1893^2~58 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3835255a38dc8c2a37c063fdcb7f3486094893e9;p=emacs.git CC Mode: Fontify args correctly when arglist closing ) is not on the same line This fixes 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. Correctly handle an unmatched (. Better handle point starting inside a [ or (. Tidy up the handling of syntactic whitespace at the end of the buffer. --- diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index bc6155dd668..f46c909fea5 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -9557,7 +9557,7 @@ point unchanged and return nil." (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 --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 027fd8f42f5..9327dbf7758 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -2440,49 +2440,59 @@ with // and /*, not more generic line and block comments." (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