diff options
author | Alan Mackenzie <acm@muc.de> | 2022-10-04 13:22:32 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2022-10-04 13:22:32 +0000 |
commit | 121c3d44be84ad1d4c5cccd629bb6994252950d1 (patch) | |
tree | a34f85f9990b3ab67efb29facd235180da5a26e5 /lisp/progmodes/cc-mode.el | |
parent | 9565f45876f4911a0f27fced215f7e86d59655e8 (diff) | |
download | emacs-121c3d44be84ad1d4c5cccd629bb6994252950d1.tar.gz emacs-121c3d44be84ad1d4c5cccd629bb6994252950d1.tar.bz2 emacs-121c3d44be84ad1d4c5cccd629bb6994252950d1.zip |
CC Mode: Make c-forward-declarator move over a suffix after parens, e.g. const
Also tidy up several inaccuracies in the code.
* lisp/progmodes/cc-engine.el (c-forward-decl-arglist): Move point for modes
other than C++ Mode.
(c-forward-declarator): Move over a suffix following arglist parens
(e.g. const). Set the ARGLIST element of the return value to non-nil on
encountering an unbalanced open parenthesis. Don't move forward out of
enclosing parens.
* lisp/progmodes/cc-mode.el (c-fl-decl-end): Handle being in a multi-line
string. Move forward over token after declarator.
Diffstat (limited to 'lisp/progmodes/cc-mode.el')
-rw-r--r-- | lisp/progmodes/cc-mode.el | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 732b2b10549..2003b09ded2 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -2458,9 +2458,12 @@ with // and /*, not more generic line and block comments." (goto-char pos) (let ((lit-start (c-literal-start)) (lim (c-determine-limit 1000)) - enclosing-attribute pos1) + enclosing-attribute pos1 ml-delim) (if lit-start (goto-char lit-start)) + (when (and lit-start c-ml-string-opener-re + (setq ml-delim (c-ml-string-opener-around-point))) + (goto-char (car ml-delim))) (c-backward-syntactic-ws lim) (when (setq enclosing-attribute (c-enclosing-c++-attribute)) (goto-char (car enclosing-attribute)) ; Only happens in C++ Mode. @@ -2471,43 +2474,43 @@ with // and /*, not more generic line and block comments." (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))))) - (decl-res (c-forward-declarator lim))) - (if (or (cadr (cddr (cddr decl-res))) ; We scanned an arglist. - (and (eq (char-after) ?\() ; Move over a non arglist (...). - (prog1 (c-go-list-forward nil lim) - (c-forward-syntactic-ws lim)))) - (if (looking-at c-symbol-char-key) - ;; Deal with baz (foo((bar)) type var), where `pos' - ;; was inside foo, but 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)) - (if (progn (c-forward-syntactic-ws lim) - (not (eobp))) - (progn - (c-forward-over-token) - ;; Cope with having POS withing a syntactically invalid - ;; (...), by moving backward out of the parens and trying - ;; again. - (when (and (eq (char-before) ?\)) - (c-go-list-backward (point) lim)) - (c-fl-decl-end (point)))) - (let ((lit-start (c-literal-start))) - (when lit-start - (goto-char lit-start)) - (c-backward-syntactic-ws))) - (and (>= (point) pos) (point))))))) + (let* ((lim1 (save-excursion + (and (c-beginning-of-macro) + (progn (c-end-of-macro) (point))))) + (decl-res (c-forward-declarator))) + (if (or (cadr (cddr (cddr decl-res))) ; We scanned an arglist. + (and (eq (char-after) ?\() ; Move over a non arglist (...). + (prog1 (c-go-list-forward) + (c-forward-syntactic-ws)))) + (if (looking-at c-symbol-char-key) + ;; Deal with baz (foo((bar)) type var), where `pos' + ;; was inside foo, but 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 lim1) + (eq (char-before) ?\()) + (c-fl-decl-end (1- (point)))) + (c-forward-over-token) + (point)) + (if (progn (c-forward-syntactic-ws) + (not (eobp))) + (progn + (c-forward-over-token) + ;; Cope with having POS withing a syntactically invalid + ;; (...), by moving backward out of the parens and trying + ;; again. + (when (and (eq (char-before) ?\)) + (c-go-list-backward (point) lim1)) + (c-fl-decl-end (point)))) + (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 |