Emacs Lisp:无法为名为's'的变量设置任何值

时间:2010-10-03 22:38:01

标签: emacs lisp elisp

这是相当奇怪的。如果变量在交互式会话中被命名为's',我就无法为变量设置任何值:

(setq s 'foo)
=> foo

s
=> nil

为什么?

更新1:

以下是s:

中describe-variable的输出
s is void as a variable.

Documentation:
Not documented as a variable.

为什么在emacs lisp中s作为全局变量保持无效?

更新2:

原来,它不会发生在一个vanilla emacs上(意思是我加载的一个模块.emacs或.emacs中的一些代码导致这个)。 所以现在的问题是:

当描述变量收益率“<var>作为变量无效时,原始来源会是什么样的?”

我使用setqdefconstdefvardefcustom进行了尝试,但这些都没有产生我正在展示的消息。

更新3:

当变量实际上没有绑定时,会产生上面显示的消息(虽然它可以是fbound)。

(describe-variable 'non-existent)
=> "non-existent is void as a variable.

Documentation:
Not documented as a variable."

所以最新的问题是:有没有办法阻止某个变量名称 从被约束?

3 个答案:

答案 0 :(得分:1)

您修改后的问题的答案:

(defvar s)

唯一的问题是,这不会让您以交互方式使用describe-variable

(然后,您可以执行(setplist 's '(variable-documentation "Meh"))之类的操作,为其设置说明,而无需通过defvar

答案 1 :(得分:1)

以递归方式将您的初始文件(~/.emacs)平分,直到找到导致问题的性别。如果它是一个加载另一个库的sexp,那么要么不使用该库,要么通过首先找出它的问题来修复它,同样的方法:递归地对该库中的代码进行二等分等等。

这是一个二元搜索,它非常快。您可以使用M-x comment-region(我将其绑定到C-x ;)快速注释掉文件的一半,然后是3/4,7 / 8等。使用前缀arg,comment-region取消注释。

答案 2 :(得分:0)

使用Emacs 23.1,运行以下代码会使C-h v s RET显示“s作为变量是无效的。”,但我无法重现setq与检索变量值之间的不一致(我同意这很奇怪。

(setq s t)
(make-local-variable 's)
(makunbound 's)

我怀疑Emacs 24特有的功能或错误。