Skip to content

Commit fb43244

Browse files
author
Alan Mackenzie
committed
Objective C Mode imenu: cease recognizing "functions" within comments, etc.
This fixes bug #38749. * lisp/progmodes/cc-menus.el (cc-imenu-objc-function): Put a c-literal-limits test around the innards of the main re-search-backward loop.
1 parent a18373a commit fb43244

File tree

1 file changed

+50
-48
lines changed

1 file changed

+50
-48
lines changed

lisp/progmodes/cc-menus.el

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
(cc-bytecomp-defvar imenu-case-fold-search)
4646
(cc-bytecomp-defvar imenu-generic-expression)
4747
(cc-bytecomp-defvar imenu-create-index-function)
48+
(cc-bytecomp-defun c-literal-limits)
4849

4950

5051
;; imenu integration
@@ -437,55 +438,56 @@ Example:
437438
(goto-char (point-max))
438439
;;
439440
(while (re-search-backward cc-imenu-objc-generic-expression nil t)
440-
(setq langnum (if (match-beginning OBJC)
441-
OBJC
442-
(cond
443-
((match-beginning Cproto) Cproto)
444-
((match-beginning Cgeneralfunc) Cgeneralfunc)
445-
((match-beginning Cnoreturn) Cnoreturn))))
446-
(setq str (funcall func (match-beginning langnum) (match-end langnum)))
447-
;;
448-
(cond
449-
;;
450-
;; C
451-
;;
452-
((not (eq langnum OBJC))
453-
(setq clist (cons (cons str (match-beginning langnum)) clist)))
454-
;;
455-
;; ObjC
456-
;;
457-
;; An instance Method
458-
((eq (aref str 0) ?-)
459-
(setq str (concat "-" (cc-imenu-objc-method-to-selector str)))
460-
(setq methodlist (cons (cons str
461-
(match-beginning langnum))
462-
methodlist)))
463-
;; A factory Method
464-
((eq (aref str 0) ?+)
465-
(setq str (concat "+" (cc-imenu-objc-method-to-selector str)))
466-
(setq methodlist (cons (cons str
467-
(match-beginning langnum))
468-
methodlist)))
469-
;; Interface or implementation or protocol
470-
((eq (aref str 0) ?@)
471-
(setq classcount (1+ classcount))
441+
(when (not (c-literal-limits))
442+
(setq langnum (if (match-beginning OBJC)
443+
OBJC
444+
(cond
445+
((match-beginning Cproto) Cproto)
446+
((match-beginning Cgeneralfunc) Cgeneralfunc)
447+
((match-beginning Cnoreturn) Cnoreturn))))
448+
(setq str (funcall func (match-beginning langnum) (match-end langnum)))
449+
;;
472450
(cond
473-
((and (> (length str) implen)
474-
(string= (substring str 0 implen) "@implementation"))
475-
(setq str (substring str implen)
476-
str2 "@implementation"))
477-
((string= (substring str 0 intflen) "@interface")
478-
(setq str (substring str intflen)
479-
str2 "@interface"))
480-
((string= (substring str 0 prtlen) "@protocol")
481-
(setq str (substring str prtlen)
482-
str2 "@protocol")))
483-
(setq str (cc-imenu-objc-remove-white-space str))
484-
(setq methodlist (cons (cons str2
485-
(match-beginning langnum))
486-
methodlist))
487-
(setq toplist (cons (cons str methodlist) toplist)
488-
methodlist nil))))
451+
;;
452+
;; C
453+
;;
454+
((not (eq langnum OBJC))
455+
(setq clist (cons (cons str (match-beginning langnum)) clist)))
456+
;;
457+
;; ObjC
458+
;;
459+
;; An instance Method
460+
((eq (aref str 0) ?-)
461+
(setq str (concat "-" (cc-imenu-objc-method-to-selector str)))
462+
(setq methodlist (cons (cons str
463+
(match-beginning langnum))
464+
methodlist)))
465+
;; A factory Method
466+
((eq (aref str 0) ?+)
467+
(setq str (concat "+" (cc-imenu-objc-method-to-selector str)))
468+
(setq methodlist (cons (cons str
469+
(match-beginning langnum))
470+
methodlist)))
471+
;; Interface or implementation or protocol
472+
((eq (aref str 0) ?@)
473+
(setq classcount (1+ classcount))
474+
(cond
475+
((and (> (length str) implen)
476+
(string= (substring str 0 implen) "@implementation"))
477+
(setq str (substring str implen)
478+
str2 "@implementation"))
479+
((string= (substring str 0 intflen) "@interface")
480+
(setq str (substring str intflen)
481+
str2 "@interface"))
482+
((string= (substring str 0 prtlen) "@protocol")
483+
(setq str (substring str prtlen)
484+
str2 "@protocol")))
485+
(setq str (cc-imenu-objc-remove-white-space str))
486+
(setq methodlist (cons (cons str2
487+
(match-beginning langnum))
488+
methodlist))
489+
(setq toplist (cons (cons str methodlist) toplist)
490+
methodlist nil)))))
489491

490492
;; In this buffer, there is only one or zero @{interface|implementation|protocol}.
491493
(if (< classcount 2)

0 commit comments

Comments
 (0)