views:

246

answers:

2

I would like to have which-function-mode on by default when I open up Emacs. I've added the following lines to my .emacs file.

(setq which-func-mode t) 
(setq which-function-mode t)

When I open up a .cpp file and navigate to the body of a function, I'm not seeing the function name in the status bar at the bottom like I should. If I then run M-x which-function-mode, the message is "Which-Function mode disabled" so it looks like the line in my .emacs file takes but is not quite working.

Am I setting the wrong thing in my .emacs file or is something else going wrong?

+5  A: 

You probably need a hook to automatically turn which-func-mode on whenever you load a file.

Try something like:


(add-hook 'c++-mode-hook '(lambda () (which-func-mode t)))
PP
+3  A: 

Unfortunately setq won't work for this, as this is a function, not a variable. You need to either use 'customize' to set the variable, or to call the 'which-function-mode' function passing a value of 't'.

'customize' is the way that emacs deals with configuring functionality for most packages nowadays. Often doing 'M-x customize-apropos' followed by a the name of the package will give you most of the configuration options for that package. If you know the specific name of the configuration parameter, you can also use 'customize-variable' to go to that specific parameter. Note that the items in 'customize-variable' are not always variables per se - often customize calls a function or performs some other activity to actually perform the configuration.

I think you probably want to use 'customize' for this.

M-x customize-variable<RET>
which-function-mode

should give you something like the following:

alt text

Toggle the value to 'on', then set for the current session and save for future sessions. If you don't like customize, you can just call the function from your .emacs:

(which-function-mode t)

This is in emacs 23, but I believe 22 should be similar.... For emacs 21, I don't believe customize was in there by default (it's been a long time, though so I could be wrong), and you might have to use the function call form instead.

Peter Hart
Thanks for the explanation, that helped. Setting it in my customizations file worked fine.
Stephen Burke