开发者

Is there a built-in Emacs Lisp form to only set a variable if it is unbound?

I've created the following macro in elisp. It will set the value "val" to a variable "var" only if the variable is unbound. This exists so variables开发者_开发知识库 set in your .emacs file do not get trampled over somewhere else.

(defmacro set-ifunbound (var val)
  `(if (not (boundp ',var))
       (setq ,var ,val)
     (identity ,var)))

Surely, this has to be a common pattern. Is there a built in way of doing the same thing?


defvar does exactly that. It assigns a value to a variable only if it's unbound.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜