2

我需要使用 提示用户输入命令,read-command然后根据用户是否在 minibuffer 上输入空字符串来采取行动。

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

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. 在不匹配定义的每个类型谓词的情况下确定对象的类型此处定义的每个类型谓词的情况下确定对象的类型
  3. 测试这个对象是否相等?
  4. 为什么read-command行为不端?规格read-command

read-command 是 `minibuf.c' 中的内置函数。

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

读取命令的名称并作为符号返回。用 PROMPT 提示。默认情况下,如果是列表,则返回 DEFAULT-VALUE 或其第一个元素。

[背部]

我预料到nil了,因为那是我通过的DEFAULT-VALUE,但显然read-command不在乎。

我已经尝试加载源代码minibuf.c以查看发生了什么,但我也无法让它工作。我已经emacs-23.3b.tar.gz这里下载并让 emacs 在那里寻找源代码,但它无法找到它。那里似乎也不minibuf.c存在。非常令人沮丧的东西,我将不胜感激任何指针。

4

1 回答 1

3

Elisp 手册是您的朋友。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.

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

于 2013-10-01T02:07:31.297 回答