简体   繁体   English

如何在Emacs中使用全局默认值在缓冲区中使变量成为本地变量

[英]How can I make variable local in a buffer with global default in Emacs

In .emacs I have variable defined as: 在.emacs中,我将变量定义为:

(setq-default prevent-highlight-symbol-mode nil)

I use it to disable red tabs: 我用它来禁用红色标签:

(add-hook 'font-lock-mode-hook
          (lambda()
            (if (and (null (memql major-mode highlight-chars-disable))
                     (not prevent-highlight-symbol-mode))
                 (hc-highlight-tabs))))

and use it in project-specifics macro 并在专案巨集中使用

(project-specifics "projects/some-project"
  (setq prevent-highlight-symbol-mode t)
  (setq indent-tabs-mode t))

but when I open a file in some-project directory and I check for prevent-highlight-symbol-mode in any buffer I've got t not nil , it's set globaly. 但是当我打开某些项目目录中的文件,我检查prevent-highlight-symbol-mode中的任何缓冲区我有tnil ,它的设置globaly。 How can I make that variable local in a buffer? 如何在缓冲区中将该变量设置为局部变量?

make-local-variable makes a variable have a local binding in the current buffer. make-local-variable使变量在当前缓冲区中具有本地绑定。

make-variable-buffer-local makes a variable have a local binding in all buffers (even future ones). make-variable-buffer-local使变量在所有缓冲区(甚至将来的缓冲区)中都具有本地绑定。

If you have done (make-local-variable 'A-VAR) in the current buffer then (setq A-VAR A-VALUE) sets the local value. 如果在当前缓冲区中完成了(make-local-variable 'A-VAR) ,则(setq A-VAR A-VALUE)设置本地值。 You can also do it using just (set (make-local-variable 'A-VAR) A-VALUE) . 您也可以只使用(set (make-local-variable 'A-VAR) A-VALUE)

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

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