Emacs Lisp 中 setq 和 setq-default 的区别 - The difference between setq and setq-default in Emacs Lisp

问题:

I have a question about Emacs Lisp.我有一个关于 Emacs Lisp 的问题。 What is the difference between setq and setq-default ? setqsetq-default 有什么区别?

Tutorials say setq takes effect in the local buffer while setq-default affects all buffers.教程说setq本地缓冲区中生效,而setq-default影响所有缓冲区。

For example, if I wrote (setq a-var a-vars-value) in init.el , I found after starting Emacs and opening a new buffer, the a-var is also there and its value is a-vars-value .例如,如果我在init.el 中写了(setq a-var a-vars-value) ,我发现在启动 Emacs 并打开一个新缓冲区后, a-var也在那里,它的值为a-vars-value I thought it was not supposed to be there.我认为它不应该在那里。 It seems there is no difference between setq and setq-default .似乎setqsetq-default之间没有区别。

Is there something wrong with my understanding?我的理解有问题吗?

For example:例如:

  1. I wrote (setq hello 123) in the init.el file, and I run emacs abuffer in the shell, then I input "hello Cx Ce" , it shows "123".我在init.el文件中写了(setq hello 123) ,在shell中运行emacs abuffer ,然后输入“hello Cx Ce” ,显示“123”。 The same happens when I run this in all new buffers.当我在所有新缓冲区中运行它时,也会发生同样的情况。

  2. I wrote (setq tab-width 4) in the init.el file.我在init.el文件中写了(setq tab-width 4) When I run tab-width Cx Ce , it shows "8" (Current mode is 'Text').当我运行tab-width Cx Ce 时,它显示“8”(当前模式为“文本”)。 However, when I use (setq-default tab-width 4) , it show "4".但是,当我使用(setq-default tab-width 4) 时,它显示“4”。 I can't explain this phenomenon.我无法解释这种现象。


解决方案:

参考: https://stackoom.com/en/question/1EFYW
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章