emacs - (读取命令...)在空白输入时返回奇怪的对象

标签 emacs elisp string-interning

我需要提示用户输入命令,使用 read-command ,然后根据用户是否在迷你缓冲区上输入空字符串来执行操作。

大多数时候,read-command返回有效命令。但是,当用户输入空白字符串(只需在迷你缓冲区中按 Enter 键)时,会返回一个奇怪的对象,它既不是 nil ,也不是字符串,也不是命令(根据 stringpcommandp )。

ELISP> (setq strange-object (read-command "Enter some command" nil) )
ELISP> (equal nil strange-object)
nil
ELISP> (if strange-object "YES" "NO")
"YES"
ELISP> (mapcar (lambda (fun) (funcall fun strange-object)) (list 'stringp 'commandp 'char-or-string-p 'functionp 'integerp 'listp) )
(nil nil nil nil nil nil)
ELISP> (prin1-to-string strange-object)
""
ELISP> (equal "" strange-object)
nil

我怎样才能:

  1. 访问该对象的读取语法?
  2. 确定对象的类型,无需与定义的每个类型谓词进行匹配 here
  3. 测试该对象是否相等?
  4. 为什么是read-command行为不端?规范read-command :

read-command is a built-in function in `minibuf.c'.

(read-command PROMPT &optional DEFAULT-VALUE)

Read the name of a command and return as a symbol. Prompt with PROMPT. By default, return DEFAULT-VALUE or its first element if it is a list.

[back]

我预计nil ,因为这就是我传递的 DEFAULT-VALUE ,但显然read-command不在乎。

我尝试加载 minibuf.c 的源代码看看发生了什么,但我也无法让它发挥作用。我已经下载了emacs-23.3b.tar.gz来自here并让 emacs 在那里寻找源代码,但找不到它。 minibuf.c 也不行。似乎存在在那里。非常令人沮丧的事情,我将不胜感激任何指点。

最佳答案

Elisp 手册是您的 friend 。 C-h i,选择 Elisp。然后i并输入read-command。作为描述的一部分,您会看到以下内容:

 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.

阅读完整说明。但仅此一点就可以帮助您理解。返回的值是一个名称为空的符号

关于emacs - (读取命令...)在空白输入时返回奇怪的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19106759/

相关文章:

date - 时间戳的emacs org-mode语言

emacs - 获取emacs中的处理器数量

emacs - 如何让 Emacs 显示与实际存储的字符不同的字符?

javascript - 为什么 Javascript ===/== 字符串相等有时具有常数时间复杂度,有时具有线性时间复杂度?

Emacs Clojure 模式制表符缩进在某些情况下很大

Emacs + magit - 垂直责备

emacs - 建议emacs交互功能: before

lisp - Elisp 中各种形式的循环和迭代

java - 字符串实习真的有用吗?

python - Python 会实习生字符串吗?