diff options
author | Alan Mackenzie <acm@muc.de> | 2018-08-26 11:05:22 +0000 |
---|---|---|
committer | Alan Mackenzie <acm@muc.de> | 2018-08-26 11:05:22 +0000 |
commit | 5c642b2dc1b666ae488225b76251750a8cf331be (patch) | |
tree | 9a431d2db895d6059fe4b29fdaf9edeefe939230 /lisp/progmodes/cc-cmds.el | |
parent | 0edf60583245cc6f3fd53ddae2f21748a4a1b239 (diff) | |
download | emacs-5c642b2dc1b666ae488225b76251750a8cf331be.tar.gz |
CC Mode: make c-display-defun-name work with a pointer return type.
Fixes bug #32403.
* lisp/progmodes/cc-cmds.el (c-in-function-trailer-p): No longer insist on
c-beginning-of-decl-1 returning 'same.
(c-where-wrt-brace-construct): Tighten up the test for looking at a symbol by
excluding keywords. When point is after a }, do not return 'at-function-end
for a struct/union/class/...
(c-defun-name-1): Considerably simplify, by amalgamating the two cond arms
which find structs etc., and by using functions like c-forward-declarator
rather than the faulty analysis of the source by hand.
Diffstat (limited to 'lisp/progmodes/cc-cmds.el')
-rw-r--r-- | lisp/progmodes/cc-cmds.el | 83 |
1 files changed, 30 insertions, 53 deletions
diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 31cf0b11596..478ccf18029 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -1383,7 +1383,7 @@ No indentation or other \"electric\" behavior is performed." (let ((eo-block (point)) bod) (and (eq (char-before) ?\}) - (eq (car (c-beginning-of-decl-1 lim)) 'previous) + (memq (car (c-beginning-of-decl-1 lim)) '(same previous)) (setq bod (point)) ;; Look for struct or union or ... If we find one, it might ;; be the return type of a function, or the like. Exclude @@ -1445,10 +1445,17 @@ No indentation or other \"electric\" behavior is performed." (consp paren-state) (consp (car paren-state)) (eq start (cdar paren-state)) - (not - (progn + (or + (save-excursion (c-forward-syntactic-ws) - (looking-at c-symbol-start)))) + (or (not (looking-at c-symbol-start)) + (looking-at c-keywords-regexp))) + (save-excursion + (goto-char (caar paren-state)) + (c-beginning-of-decl-1 + (and least-enclosing + (c-safe-position least-enclosing paren-state))) + (not (looking-at c-defun-type-name-decl-key))))) 'at-function-end) (t ;; Find the start of the current declaration. NOTE: If we're in the @@ -1841,7 +1848,7 @@ or NIL if there isn't one. \"Defun\" here means a function, or other top level construct with a brace block." (c-save-buffer-state (beginning-of-defun-function end-of-defun-function - where pos decl name-start name-end case-fold-search) + where pos decl0 decl type-pos tag-pos case-fold-search) (save-excursion ;; Move back out of any macro/comment/string we happen to be in. @@ -1861,31 +1868,10 @@ other top level construct with a brace block." (when (looking-at c-typedef-key) (goto-char (match-end 0)) (c-forward-syntactic-ws)) + (setq type-pos (point)) ;; Pick out the defun name, according to the type of defun. (cond - ;; struct, union, enum, or similar: - ((save-excursion - (and - (looking-at c-defun-type-name-decl-key) - (consp (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)) - (or (not (or (eq (char-after) ?{) - (and c-recognize-knr-p - (c-in-knr-argdecl)))) - (progn (c-backward-syntactic-ws) - (not (eq (char-before) ?\))))))) - (let ((key-pos (point))) - (c-forward-over-token-and-ws) ; over "struct ". - (cond - ((looking-at c-symbol-key) ; "struct foo { ..." - (buffer-substring-no-properties key-pos (match-end 0))) - ((eq (char-after) ?{) ; "struct { ... } foo" - (when (c-go-list-forward) - (c-forward-syntactic-ws) - (when (looking-at c-symbol-key) ; a bit bogus - there might - ; be several identifiers. - (match-string-no-properties 0))))))) - ((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs! ;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory ;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK @@ -1901,32 +1887,23 @@ other top level construct with a brace block." (c-backward-syntactic-ws) (point)))) - (t - ;; Normal function or initializer. - (when - (and - (consp - (setq decl - (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))) - (setq name-start (car decl)) - (progn (if (and (looking-at c-after-suffixed-type-decl-key) - (match-beginning 1)) - (c-forward-keyword-clause 1)) - t) - (or (eq (char-after) ?{) - (and c-recognize-knr-p - (c-in-knr-argdecl))) - (goto-char name-start) - (c-forward-name) - (eq (char-after) ?\()) - (c-backward-syntactic-ws) - (when (eq (char-before) ?\=) ; struct foo bar = {0, 0} ; - (c-backward-token-2) - (c-backward-syntactic-ws)) - (setq name-end (point)) - (c-back-over-compound-identifier) - (and (looking-at c-symbol-start) - (buffer-substring-no-properties (point) name-end))))))))) + (t ; Normal function or initializer. + (when (looking-at c-defun-type-name-decl-key) ; struct, etc. + (goto-char (match-end 0)) + (c-forward-syntactic-ws) + (setq tag-pos (point)) + (goto-char type-pos)) + (setq decl0 (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil)) + (when (consp decl0) + (goto-char (car decl0)) + (setq decl (c-forward-declarator))) + (and decl + (car decl) (cadr decl) + (buffer-substring-no-properties + (if (eq (car decl) tag-pos) + type-pos + (car decl)) + (cadr decl))))))))) (defun c-defun-name () "Return the name of the current defun, or NIL if there isn't one. |