Commit fb432446 authored by Alan Mackenzie's avatar Alan Mackenzie

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.
parent a18373a9
Pipeline #4512 passed with stage
in 54 minutes and 27 seconds
......@@ -45,6 +45,7 @@
(cc-bytecomp-defvar imenu-case-fold-search)
(cc-bytecomp-defvar imenu-generic-expression)
(cc-bytecomp-defvar imenu-create-index-function)
(cc-bytecomp-defun c-literal-limits)
;; imenu integration
......@@ -437,55 +438,56 @@ Example:
(goto-char (point-max))
;;
(while (re-search-backward cc-imenu-objc-generic-expression nil t)
(setq langnum (if (match-beginning OBJC)
OBJC
(cond
((match-beginning Cproto) Cproto)
((match-beginning Cgeneralfunc) Cgeneralfunc)
((match-beginning Cnoreturn) Cnoreturn))))
(setq str (funcall func (match-beginning langnum) (match-end langnum)))
;;
(cond
;;
;; C
;;
((not (eq langnum OBJC))
(setq clist (cons (cons str (match-beginning langnum)) clist)))
;;
;; ObjC
;;
;; An instance Method
((eq (aref str 0) ?-)
(setq str (concat "-" (cc-imenu-objc-method-to-selector str)))
(setq methodlist (cons (cons str
(match-beginning langnum))
methodlist)))
;; A factory Method
((eq (aref str 0) ?+)
(setq str (concat "+" (cc-imenu-objc-method-to-selector str)))
(setq methodlist (cons (cons str
(match-beginning langnum))
methodlist)))
;; Interface or implementation or protocol
((eq (aref str 0) ?@)
(setq classcount (1+ classcount))
(when (not (c-literal-limits))
(setq langnum (if (match-beginning OBJC)
OBJC
(cond
((match-beginning Cproto) Cproto)
((match-beginning Cgeneralfunc) Cgeneralfunc)
((match-beginning Cnoreturn) Cnoreturn))))
(setq str (funcall func (match-beginning langnum) (match-end langnum)))
;;
(cond
((and (> (length str) implen)
(string= (substring str 0 implen) "@implementation"))
(setq str (substring str implen)
str2 "@implementation"))
((string= (substring str 0 intflen) "@interface")
(setq str (substring str intflen)
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))))
;;
;; C
;;
((not (eq langnum OBJC))
(setq clist (cons (cons str (match-beginning langnum)) clist)))
;;
;; ObjC
;;
;; An instance Method
((eq (aref str 0) ?-)
(setq str (concat "-" (cc-imenu-objc-method-to-selector str)))
(setq methodlist (cons (cons str
(match-beginning langnum))
methodlist)))
;; A factory Method
((eq (aref str 0) ?+)
(setq str (concat "+" (cc-imenu-objc-method-to-selector str)))
(setq methodlist (cons (cons str
(match-beginning langnum))
methodlist)))
;; Interface or implementation or protocol
((eq (aref str 0) ?@)
(setq classcount (1+ classcount))
(cond
((and (> (length str) implen)
(string= (substring str 0 implen) "@implementation"))
(setq str (substring str implen)
str2 "@implementation"))
((string= (substring str 0 intflen) "@interface")
(setq str (substring str intflen)
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)))))
;; In this buffer, there is only one or zero @{interface|implementation|protocol}.
(if (< classcount 2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment