emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master dde7f2d: Fix some bugs in c-defun-name. This fixes


From: Alan Mackenzie
Subject: [Emacs-diffs] master dde7f2d: Fix some bugs in c-defun-name. This fixes bug #25623.
Date: Wed, 12 Jul 2017 16:19:01 -0400 (EDT)

branch: master
commit dde7f2d48b53996bdf767a8cf91aafc2e10add23
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Fix some bugs in c-defun-name.  This fixes bug #25623.
    
    * lisp/progmodes/cc-cmds.el (c-defun-name): Fix some bugs to do with 
structs,
    etc.
---
 lisp/progmodes/cc-cmds.el | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el
index 121ba24..dec59c5 100644
--- a/lisp/progmodes/cc-cmds.el
+++ b/lisp/progmodes/cc-cmds.el
@@ -1843,19 +1843,25 @@ with a brace block."
          (unless (eq where 'at-header)
            (c-backward-to-nth-BOF-{ 1 where)
            (c-beginning-of-decl-1))
+         (when (looking-at c-typedef-key)
+           (goto-char (match-end 0))
+           (c-forward-syntactic-ws))
 
          ;; Pick out the defun name, according to the type of defun.
          (cond
           ;; struct, union, enum, or similar:
-          ((and (looking-at c-type-prefix-key)
-                (progn (c-forward-token-2 2) ; over "struct foo "
-                       (or (eq (char-after) ?\{)
-                           (looking-at c-symbol-key)))) ; "struct foo bar ..."
-           (save-match-data (c-forward-token-2))
-           (when (eq (char-after) ?\{)
-             (c-backward-token-2)
-             (looking-at c-symbol-key))
-           (match-string-no-properties 0))
+          ((looking-at c-type-prefix-key)
+           (let ((key-pos (point)))
+             (c-forward-token-2 1)     ; 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
@@ -1900,7 +1906,8 @@ with a brace block."
                (c-backward-syntactic-ws))
              (setq name-end (point))
              (c-back-over-compound-identifier)
-             (buffer-substring-no-properties (point) name-end)))))))))
+             (and (looking-at c-symbol-start)
+                  (buffer-substring-no-properties (point) name-end))))))))))
 
 (defun c-declaration-limits (near)
   ;; Return a cons of the beginning and end positions of the current



reply via email to

[Prev in Thread] Current Thread [Next in Thread]