简体   繁体   English

如何在Emacs中更改主要模式的缓冲区局部变量?

[英]how to change buffer-local variable for a major mode in Emacs?

Generally, how can I customize the value of a buffer-local variable in Emacs? 通常,如何在Emacs中自定义缓冲区局部变量的值? For example, the variable w3m-lnum-mode is buffer-local, if I set (setq w3m-lnum-mode t) in .emacs , its value in a w3m mode buffer is still nil. 例如,变量w3m-lnum-mode是局部于缓冲区的,如果我在.emacs设置(setq w3m-lnum-mode t) ,则其在w3m模式缓冲区中的值仍为nil。 How could I set it to t in w3m major mode? 如何在w3m主模式下将其设置为t

Major modes have a hook variable for this sort of thing. 主要模式具有用于此类情况的hook变量。 Look for w3m-mode-hook . 寻找w3m-mode-hook

(defun my-w3m-hook nil
  (setq w3m-lnum-mode t))
(add-hook 'w3m-mode-hook #'my-w3m-hook)

The indirection to hook a separate function is not absolutely necessary, but simplifies the management of the hook functionality (otherwise you'd have to restart Emacs or jump through several hoops to add something to an existing hook; now all you need to do is evaluate a new defun of the function called from the hook). 间接挂钩一个单独的函数不是绝对必要的,但是可以简化挂钩功能的管理(否则,您必须重新启动Emacs或跳过几个箍以向现有的挂钩中添加一些东西;现在您要做的就是评估新defun的函数从钩子调用)。

You can set a default like so: 您可以这样设置默认值:

(setq-default w3m-lnum-mode t)

For fine-grained control, use a hook as RNAer suggests. 对于细粒度的控制,请使用RNAer建议的钩子。 As far as I can tell though, this is not a normal local variable but a minor mode variable. 据我所知,这不是普通的局部变量,而是次要模式变量。 You actually probably want to do (w3m-lnum-mode 1) . 您实际上可能想做(w3m-lnum-mode 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM