WhichFuncMode (also known as WhichFunctionMode) is a minor mode, that when activated displays the current function name in the mode line. It works under certain major modes, like CcMode or PerlMode. To activate it, type
M-x which-function-mode RET
or enter the following piece of elisp into your `.emacs` file to make it permanent :
(which-function-mode 1)
WhichFuncMode is based on ImenuMode, so if it doesn’t show correct current function name (and mode supports imenu), try
M-x imenu RET *Rescan* RET RET
To show the function in the HeaderLine instead of the ModeLine,
(which-function-mode)
(setq mode-line-format (delete (assoc 'which-func-mode
mode-line-format) mode-line-format)
which-func-header-line-format '(which-func-mode ("" which-func-format)))
(defadvice which-func-ff-hook (after header-line activate)
(when which-func-mode
(setq mode-line-format (delete (assoc 'which-func-mode
mode-line-format) mode-line-format)
header-line-format which-func-header-line-format)))
(Note: Emacs 24.2.91 seems to put the which-func configuration in ‘mode-line-misc-info’ instead, so you may need to replace ‘mode-line-format’ with ‘mode-line-misc-info’ in the above snippet.)
To get other languages to work with which-func, simple add the name of a programing mode with support for Imenu to ‘which-func-modes’.
(eval-after-load "which-func"
'(add-to-list 'which-func-modes 'java-mode))To configure a language for which-func mode, you need to configure it for ImenuMode.
WhichFuncMode shows which function’s source code you are in, ElDoc shows where you are in a parameter list to a function call. They both are mode-configurable.
An alternative mode that offers similar functionality for several programming languages is SemanticIdleBreadcrumbsMode.
Another alternative mode is cfm. Cfm (display current function or method) will display class-qualified member function names (A::foo), particularly useful for C++ and Java classes that embed member function definitions (that is, without the three-box model).