开发者

Emacs Setting which-function-mode

开发者 https://www.devze.com 2022-12-11 22:34 出处:网络
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.

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 .ema开发者_如何学Ccs file takes but is not quite working.

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


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:

Emacs Setting which-function-mode

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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号