Emacs Lisp error "Wrong type argument: commandp"

10

以下代码有什么问题:

(defun test
  (interactive)
  (message "hello"))
(global-set-key '[f4]  'test)

当我使用eval-region命令并按下F4时,我收到以下错误:

Wrong type argument: commandp, test

4
请尝试使用空参数列表调用(defun test () ...) - uselpa
是的,它有效。非常感谢!您可以将其作为答案给出,我会接受它。 - Håkon Hægland
1个回答

17

你的test函数缺少参数列表,因此Emacs将(interactive)表单解释为arglist。因此,你定义了一个带有1个参数的非交互函数,而不是没有参数的交互式命令。

你需要的是:

(defun test ()
  "My command test"
  (interactive)
  (message "hello"))

经验教训:

  1. 始终添加文档字符串 - 如果您这样做了,Emacs会发出警告。
  2. 使用elint(随Emacs一起提供,尝试C-h a elint RET)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接