开发者

Setting the value of a new global variable in emacs

I have this line in a function:

(let (v1) (v2)
    ... more code here ...
    (setq matchAgainstDirectory (
      read-directory-name "Set directory to match against:")))))))

matchAgainstDirectory is not in the list of values declared by let, so I assume that it will set a global value.

I want to set it to nil at some point, but if I press M-x RET set-variable RET, matchAgainstDirectory doesn't appear as a valid variable name. Why is this?

I know I can do开发者_Go百科 M-x ielm, and write there (setq matchAgainstDirectory ()), but I'm looking for a shorter way of doing this. Does such a thing exist?


For the variable to show up when you do M-x set-variable, it must be defined via defvar because (as the docs say):

M-x set-variable is limited to user option variables, but you can set any variable with a Lisp expression, using the function setq.

So, define it as a variable with:

(defvar matchAgainstDirectory nil "some comment") 

or

(defvar matchAgainstDirectory) ; value and comment are optional

So, put that in your code somewhere at the top-level (not in your let statement).

setq doesn't create a user option variable, it just creates an emacs lisp variable - which aren't intended to be set manually by the user via M-x set-variable.


You can also use M-: (setq matchAgainstDirectory nil) RET which is slightly shorter than invoking ielm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜