which function is this?


As a short tip: in many of the programming modes, you can get the name of the function where your cursor is currently in using which-function-mode. You can set it globally in your .emacs, or make it mode specific using some hook, for example:
(add-hook 'c-mode-common-hook 
(lambda ()
(which-function-mode t)))

After you do this, the name of the current function will appear in the modeline (the status-bar).

Now, apart from the mode line, emacs also knows the concept of the header line. This is the first line of the display; it seems little used. However, if you'd like to have the function name there, maybe because the mode line is full already, see this trick on EmacsWiki (scroll down).

which-function-mode does not work for all modes; it needs some help from the major mode to figure out what counts as a function; in my emacs, the following modes work (you can check from the which-func-modes variable):


(emacs-lisp-mode c-mode c++-mode perl-mode cperl-mode python-mode makefile-mode sh-mode
fortran-mode f90-mode ada-mode diff-mode)

I hope your own functions do fit on your screen, making which-function-mode less needed -- function should not be too long or complex. But it's still useful when reading other people's code, of course. Note, there are other ways to not loose your orientation when reading code; earlier, we discussed hideshow, which enables showing/hiding the function bodies.

No comments:

Post a Comment

Followers

Popular Posts