Function: cc-imenu-objc-function

cc-imenu-objc-function is a byte-compiled function defined in cc-menus.el.gz.

Signature

(cc-imenu-objc-function)

Documentation

Imenu support for Objective C mode.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-menus.el.gz
(defun cc-imenu-objc-function ()
  "Imenu support for Objective C mode."
  (let (methodlist
	clist
	;;
	;; OBJC, Cnoreturn, Cgeneralfunc, Cproto are constants.
	;;
	;;                  *Warning for developers*
	;; These constants depend on `cc-imenu-c++-generic-expression'.
	;;
	(OBJC cc-imenu-objc-generic-expression-objc-base-index)
	;; Special case to match a line like `main() {}'
	(Cnoreturn cc-imenu-objc-generic-expression-noreturn-index)
	;; General function name regexp
	(Cgeneralfunc cc-imenu-objc-generic-expression-general-func-index)
	;; Special case for definitions using phony prototype macros like:
	(Cproto cc-imenu-objc-generic-expression-proto-index)
	langnum
	;;
	(classcount 0)
	toplist
	str
	str2
	(intflen (length "@interface"))
	(implen  (length "@implementation"))
	(prtlen  (length "@protocol"))
	(func
	 ;;
	 ;; Does this emacs have buffer-substring-no-properties?
	 ;;
	 (if (fboundp 'buffer-substring-no-properties)
	     'buffer-substring-no-properties
	   'buffer-substring)))
    (goto-char (point-max))
    ;;
    (while (re-search-backward cc-imenu-objc-generic-expression nil t)
      (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
	 ;;
	 ;; 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)
	(let ((classname (car (car toplist)))
	      (p (cdr (car (cdr (car toplist)))))
	      last)
	  (setq toplist (cons (cons classname p) (cdr (cdr (car toplist)))))
	  ;; Add C lang token
	  (if clist
	      (progn
		(setq last toplist)
		(while (cdr last)
		  (setq last (cdr last)))
		(setcdr last clist))))
      ;; Add C lang tokens as a sub menu
      (if clist
	  (setq toplist (cons (cons "C" clist) toplist))))
    ;;
    toplist
    ))