在emacs中设置新全局变量的值
我在函数中有一行:在emacs中设置新全局变量的值,emacs,elisp,Emacs,Elisp,我在函数中有一行: (let (v1) (v2) ... more code here ... (setq matchAgainstDirectory ( read-directory-name "Set directory to match against:"))))))) matchaginstdirectory不在let声明的值列表中,因此我假设它将设置一个全局值 我想在某个时候将其设置为nil,但如果我按M-x RET set variable RET,ma
(let (v1) (v2)
... more code here ...
(setq matchAgainstDirectory (
read-directory-name "Set directory to match against:")))))))
matchaginstdirectory
不在let
声明的值列表中,因此我假设它将设置一个全局值
我想在某个时候将其设置为nil
,但如果我按M-x RET set variable RET
,matchaginstdirectory
不会显示为有效的变量名。为什么会这样
我知道我可以做
M-x ielm
,并在那里写(setq matchaginsdirectory())
,但我正在寻找一种更短的方法。是否存在这样的情况?若要在执行M-x set variable时显示变量,必须通过定义它,因为(如:
M-x set变量仅限于用户选项变量,但您可以设置
任何带有Lisp表达式的变量,使用函数setq
因此,将其定义为具有以下内容的变量:
(defvar matchAgainstDirectory nil "some comment")
或
因此,把它放在代码中顶层的某个地方(而不是放在let
语句中)
setq
不创建用户选项变量,它只创建一个emacs lisp变量-用户不打算通过M-x set变量手动设置该变量。您也可以使用M-:(setq matchaginstdirectory nil)
RET,它比调用ielm
略短,因此,如果我通过setq
定义某个东西,没有函数允许我更改它的变量?顺便问一下,你是如何创建按钮查找M-x set variable
?@Geo更新的答案以提供更多信息的,但简而言之,'no'请看,包装在tags M-x set变量中(注释中不解释该变量)。您还可以使用M-:(setq matchaginstdirectory nil)RET
比调用ielm略短。Phils,你为什么不发布一个答案呢?我不认为这完全是你想要的,但可以肯定。在这种情况下,它比ielm
版本短得多/快得多。
(defvar matchAgainstDirectory) ; value and comment are optional