summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-mode.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2022-08-24 14:42:11 +0000
committerAlan Mackenzie <acm@muc.de>2022-08-24 14:45:46 +0000
commit3835255a38dc8c2a37c063fdcb7f3486094893e9 (patch)
treeb91c792317f26b82a470ef4dffbb78a29d1f233f /lisp/progmodes/cc-mode.el
parent044e11641bc0bfaf0d735bd57f04333f9616cfc7 (diff)
downloademacs-3835255a38dc8c2a37c063fdcb7f3486094893e9.tar.gz
emacs-3835255a38dc8c2a37c063fdcb7f3486094893e9.tar.bz2
emacs-3835255a38dc8c2a37c063fdcb7f3486094893e9.zip
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.
Diffstat (limited to 'lisp/progmodes/cc-mode.el')
-rw-r--r--lisp/progmodes/cc-mode.el86
1 files changed, 48 insertions, 38 deletions
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