代码之家  ›  专栏  ›  技术社区  ›  OTZ

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

  •  2
  • OTZ  · 技术社区  · 15 年前

    这太奇怪了。如果变量在交互会话中被命名为“s”,则无法对其设置任何值:

    (setq s 'foo)
    => foo
    
    s
    => nil
    

    为什么?

    更新1:

    下面是s上描述变量的输出:

    s is void as a variable.
    
    Documentation:
    Not documented as a variable.
    

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

    更新2:

    事实证明,它不会发生在普通的emacs上(这意味着我加载到.emacs中的某个模块或.emacs中的某些代码会导致这种情况)。 所以现在的问题是:

    当描述变量收益率时,原始数据源会是什么样子的? <var> void是变量吗?

    我试过了 setq , defconst , defvar defcustom 但这些都没有产生我要显示的信息。

    更新3:

    上面显示的消息是在变量没有被绑定时生成的(尽管它可以 fbound )。

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

    所以最新的问题是: 有什么方法可以防止某个变量名 不被束缚?

    3 回复  |  直到 12 年前
        1
  •  1
  •   Eli Barzilay    15 年前

    修改后问题的答案:

    (defvar s)
    

    唯一的问题是这不会让你使用 describe-variable 以互动的方式。

    (然后你可以做 (setplist 's '(variable-documentation "Meh")) 为它设置描述而不经过 defvar .

        2
  •  1
  •   Drew    12 年前

    把你的初始文件对分( ~/.emacs )递归直到找到导致问题的sexp。如果是一个sexp加载另一个库,那么要么不要使用该库,要么先找出它的问题所在,以同样的方式修复它:递归地平分该库中的代码,等等。

    这是一个二进制搜索,非常快速。您可以快速地对文件的一半进行注释,然后使用3/4、7/8等 M-x comment-region (我把它绑在 C-x ; )前缀为arg, comment-region 取消注释。

        3
  •  0
  •   Gilles 'SO- stop being evil'    15 年前

    使用Emacs23.1,运行以下代码可以 C-h v s RET 显示s作为变量是无效的,但我无法重现 setq 检索变量的值(我同意这很奇怪)。

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

    我怀疑是Emacs24的特定功能或错误。