Function: c-defun-name-1
c-defun-name-1 is a byte-compiled function defined in cc-cmds.el.gz.
Signature
(c-defun-name-1)
Documentation
Return name of current defun, at current narrowing, or nil if there isn't one.
"Defun" here means a function, or other top level construct
with a brace block.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-cmds.el.gz
(defun c-defun-name-1 ()
"Return name of current defun, at current narrowing, or nil if there isn't one.
\"Defun\" here means a function, or other top level construct
with a brace block."
(c-save-buffer-state
(beginning-of-defun-function end-of-defun-function
where pos decl0 decl type-pos tag-pos case-fold-search)
(save-excursion
;; Move back out of any macro/comment/string we happen to be in.
(c-beginning-of-macro)
(setq pos (c-literal-start))
(if pos (goto-char pos))
(setq where (c-where-wrt-brace-construct))
;; Move to the beginning of the current defun, if any, if we're not
;; already there.
(if (memq where '(outwith-function at-function-end))
nil
(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))
(setq type-pos (point))
;; Pick out the defun name, according to the type of defun.
(cond
((looking-at "DEFUN\\s-*(") ;"DEFUN\\_>") think of XEmacs!
;; DEFUN ("file-name-directory", Ffile_name_directory, Sfile_name_directory, ...) ==> Ffile_name_directory
;; DEFUN(POSIX::STREAM-LOCK, stream lockp &key BLOCK SHARED START LENGTH) ==> POSIX::STREAM-LOCK
(down-list 1)
(c-forward-syntactic-ws)
(when (eq (char-after) ?\")
(forward-sexp 1)
(c-forward-token-2)) ; over the comma and following WS.
(buffer-substring-no-properties
(point)
(progn
(c-forward-token-2)
(c-backward-syntactic-ws)
(point))))
((and (c-major-mode-is 'objc-mode) (looking-at "[-+]\\s-*(")) ; Objective-C method
;; Move to the beginning of the method name.
(c-forward-token-2 2 t)
(let* ((class
(save-excursion
(when (re-search-backward
"^\\s-*@\\(implementation\\|class\\|interface\\)\\s-+\\(\\sw+\\)" nil t)
(match-string-no-properties 2))))
(limit (save-excursion (re-search-forward "[;{]" nil t)))
(method (when (re-search-forward "\\(\\sw+:?\\)" limit t)
(match-string-no-properties 1))))
(when (and class method)
;; Add the parameter labels onto name. They always end in ':'.
(while (re-search-forward "\\(\\sw+:\\)" limit 1)
(setq method (concat method (match-string-no-properties 1))))
(concat "[" class " " method "]"))))
(t ; Normal function or initializer.
(when (looking-at c-defun-type-name-decl-key) ; struct, etc.
(goto-char (match-end 0))
(c-forward-syntactic-ws)
(setq tag-pos (point))
(goto-char type-pos))
(setq decl0 (c-forward-decl-or-cast-1 (c-point 'bosws) 'top nil))
(when (consp decl0)
(goto-char (car decl0))
(setq decl (c-forward-declarator)))
(and decl
(car decl) (cadr decl)
(buffer-substring-no-properties
(if (eq (car decl) tag-pos)
type-pos
(car decl))
(cadr decl)))))))))