master 65ca6e153c6: Correct calculation of ObjC Mode imenu entries:
Alan Mackenzie <[email protected]>
| Newsgroups | gmane.emacs.diffs |
|---|---|
| Message-ID | <[email protected]> |
branch: master commit 65ca6e153c66891216f47ecb02e1276a870b4bd4 Author: Alan Mackenzie <[email protected]> Commit: Alan Mackenzie <[email protected]> Correct calculation of ObjC Mode imenu entries: This fixes a bug reported on 2026-08-08 on bug-cc-mode.gnu.org. * lisp/progmodes/cc-menus.el (cc-imenu-objc-generic-expression): Reverse the order of the tests in the regexp for a C function and for @implementation (etc.), so that "@end // Classname (foo)" won't get recognised as a C function. (cc-imenu-objc-function): Test an ostensible "C function" for having a ?@ at column 0. Further coding fixes to prevent ghost entries getting appended to the function's result, and to append all pertinent method entries. --- lisp/progmodes/cc-menus.el | 47 ++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lisp/progmodes/cc-menus.el b/lisp/progmodes/cc-menus.el index 5006ad78b54..55d8abe493c 100644 --- a/lisp/progmodes/cc-menus.el +++ b/lisp/progmodes/cc-menus.el @@ -304,26 +304,25 @@ nested angle brackets constructs." ;; Pick a token by (match-string 1) (car (cdr (nth 1 cc-imenu-c++-generic-expression))) ; -> index += 2 (prog2 (setq cc-imenu-objc-generic-expression-noreturn-index 1) "") - "\\|" - ;; > General function name regexp - ;; Pick a token by (match-string 3) - (car (cdr (nth 2 cc-imenu-c++-generic-expression))) ; -> index += 6 - (prog2 (setq cc-imenu-objc-generic-expression-general-func-index 3) "") ;; > Special case for definitions using phony prototype macros like: ;; > `int main _PROTO( (int argc,char *argv[]) )'. - ;; Pick a token by (match-string 8) + ;; Pick a token by (match-string 3) (if cc-imenu-c-prototype-macro-regexp (concat "\\|" (car (cdr (nth 3 cc-imenu-c++-generic-expression))) ; -> index += 1 - (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 10) "") + (progn (setq cc-imenu-objc-generic-expression-objc-base-index 4) + (setq cc-imenu-objc-generic-expression-general-func-index 5) + "") ) - (prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 9) "") + (progn (setq cc-imenu-objc-generic-expression-objc-base-index 3) + (setq cc-imenu-objc-generic-expression-general-func-index 4) + "") "") ; -> index += 0 - (prog2 (setq cc-imenu-objc-generic-expression-proto-index 9) "") + (prog2 (setq cc-imenu-objc-generic-expression-proto-index 3) "") ;; ;; For Objective-C - ;; Pick a token by (match-string 8 or 9) + ;; Pick a token by (match-string 3 or 4) ;; "\\|\\(" "^[-+][:" c-alnum "()*_<>\n\t ]*[;{]" ; Methods @@ -339,7 +338,11 @@ nested angle brackets constructs." "\\|" "^@implementation[\t ]+[" c-alnum "_]+" "\\|" - "^@protocol[\t ]+[" c-alnum "_]+" "\\)") + "^@protocol[\t ]+[" c-alnum "_]+" "\\)" + "\\|" + ;; > General function name regexp + ;; Pick a token by (match-string 4) + (car (cdr (nth 2 cc-imenu-c++-generic-expression)))) ; -> index += 6 "Imenu generic expression for ObjC mode. See `imenu-generic-expression'.") @@ -452,7 +455,9 @@ Example: ;; C ;; ((not (eq langnum OBJC)) - (setq clist (cons (cons str (match-beginning langnum)) clist))) + ;; Don't be fooled by @end // Classname. + (when (not (eq (aref (match-string-no-properties 0) 0) ?@)) + (setq clist (cons (cons str (match-beginning langnum)) clist)))) ;; ;; ObjC ;; @@ -481,14 +486,16 @@ Example: str2 "@interface")) ((string= (substring str 0 prtlen) "@protocol") (setq str (substring str prtlen) - str2 "@protocol"))) - (setq str (cc-imenu-objc-remove-white-space str)) - (setq methodlist (cons (cons str2 - (match-beginning langnum)) - methodlist)) - (setq toplist (cons (cons str methodlist) toplist) - methodlist nil))))) - + str2 "@protocol")) + (t (setq str2 nil))) + (when str2 + (setq str (cc-imenu-objc-remove-white-space str)) + (setq methodlist (cons (cons str2 + (match-beginning langnum)) + methodlist)) + (setq toplist + (cons (cons str methodlist) toplist) + methodlist nil)))))) ;; In this buffer, there is only one or zero @{interface|implementation|protocol}. (if (< classcount 2) (let ((classname (car (car toplist)))