【问题标题】:Emacs Lisp error "Wrong type argument: commandp"Emacs Lisp 错误“错误类型参数:commandp”
【发布时间】:2013-12-31 08:25:53
【问题描述】:

以下代码有什么问题:

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

当使用 eval-region 评估这个然后按 F4 我得到错误:

Wrong type argument: commandp, test

【问题讨论】:

  • 尝试(defun test () ...),参数列表为空。
  • 是的,它有效。非常感谢!你可以给它作为答案,我会接受它..

标签: emacs elisp


【解决方案1】:

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

你想要的是:

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

经验教训:

  1. 总是添加一个文档字符串——如果你这样做了,Emacs 会抱怨的
  2. 使用elint(Emacs 自带,试试 C-h a elint RET)。

【讨论】:

  • 感谢您的建议!
猜你喜欢
  • 2014-07-29
  • 1970-01-01
  • 1970-01-01
  • 2010-11-18
  • 1970-01-01
  • 1970-01-01
  • 2012-02-24
  • 1970-01-01
  • 2020-11-12
相关资源
最近更新 更多