Emacs (读取命令…)在空白输入时返回奇怪的对象

Emacs (读取命令…)在空白输入时返回奇怪的对象,emacs,elisp,string-interning,Emacs,Elisp,String Interning,我需要使用read command,提示用户输入命令,然后根据用户是否在minibuffer上输入了空字符串来执行操作 大多数情况下,readcommand返回有效的命令。但是当用户输入一个空白字符串时(只需在小缓冲区中点击enter键),就会返回一个奇怪的对象,它既不是nil,也不是字符串,也不是命令(根据stringp和commandp) 我怎样才能: 是否访问此对象的读取语法 确定对象的类型,而不与定义的每个类型谓词匹配 测试是否与此对象相等 为什么read命令行为不正常?读取命令的规范:

我需要使用
read command
,提示用户输入命令,然后根据用户是否在minibuffer上输入了空字符串来执行操作

大多数情况下,
readcommand
返回有效的命令。但是当用户输入一个空白字符串时(只需在小缓冲区中点击enter键),就会返回一个奇怪的对象,它既不是
nil
,也不是字符串,也不是命令(根据
stringp
commandp

我怎样才能:

  • 是否访问此对象的读取语法
  • 确定对象的类型,而不与定义的每个类型谓词匹配
  • 测试是否与此对象相等
  • 为什么
    read命令
    行为不正常?
    读取命令的规范
  • read命令是“minibuf.c”中的内置函数

    (读取命令提示&可选默认值)

    读取命令名并以符号形式返回。用提示符提示。 默认情况下,返回default-VALUE或其第一个元素(如果是列表)

    [返回]

    我期望
    nil
    ,因为这是我传递的
    DEFAULT-VALUE
    ,但显然
    read命令
    并不在意


    我已经尝试加载
    minibuf.c
    的源代码来查看发生了什么,但是我也没能让它正常工作。我从中下载了
    emacs-23.3b.tar.gz
    ,让emacs在那里查找源代码,但它找不到。那里似乎也不存在
    minibuf.c
    。非常令人沮丧的东西,我将感谢任何指点。

    Elisp手册是您的朋友<代码>C-h i,选择Elisp。然后
    i
    并输入
    readcommand
    。作为描述的一部分,您可以看到:

     The argument DEFAULT specifies what to return if the user enters
     null input.  It can be a symbol, a string or a list of strings.
     If it is a string, `read-command' interns it before returning it.
     If it is a list, `read-command' interns the first element of this
     list.  If DEFAULT is `nil', that means no default has been
     specified; then if the user enters null input, the return value is
     `(intern "")', that is, a symbol whose name is an empty string.
    

    阅读完整的描述。但单凭这一点就可以帮助你理解。返回的值是一个名为空的符号。

    (equal(intern“”)奇怪对象)==>t。我不知道为什么这不是正常的
    read命令
    文档的一部分,为什么这些重要信息隐藏在一些晦涩难懂的手册中。如此多本可以避免的挫折。谢谢你的回答。关于如何找到这些c函数的源代码,有什么提示吗?我同意在这种情况下,doc字符串可以说得更多一些,特别是因为代码不在Lisp中。如果您对此感到强烈,请考虑提交一个bug /增强请求:<代码> M X报告Emacs Bug 。我从未注意到我们返回这个有趣的“空符号”。在我看来,这似乎是一个错误的功能:这个空符号有点不寻常(在Emacs trunk中,我们已经使其正确打印+可读,但仍然)。@Stefan:同意。在这种情况下,如果改变这种行为,我不认为会有太多的破坏。我怀疑很多代码是否使用了
    read命令
    ,我也不认为这些代码中有多少使用了这个“特性”,即这个返回值。
     The argument DEFAULT specifies what to return if the user enters
     null input.  It can be a symbol, a string or a list of strings.
     If it is a string, `read-command' interns it before returning it.
     If it is a list, `read-command' interns the first element of this
     list.  If DEFAULT is `nil', that means no default has been
     specified; then if the user enters null input, the return value is
     `(intern "")', that is, a symbol whose name is an empty string.