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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章