Emacs Setting which-function-mode

守給你的承諾、 提交于 2020-01-24 10:30:12

问题


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?


回答1:


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:

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.




回答2:


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)))



回答3:


In your init.el or wherever you store your emacs configuration simply place the following line:

(which-function-mode 1)

It should only work for progamming modes and org mode. I only tested in a .txt file to make sure it didn't show up. If you need granularity do something like:

(add-hook 'python-mode-hook (lambda() (which-function-mode 1)))



来源:https://stackoverflow.com/questions/1730903/emacs-setting-which-function-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!