首页 > 解决方案 > 在 elisp 中设置键绑定时出现“参数类型错误:commandp,my/function”

问题描述

这可能看起来像重复,但我已经尝试了所有其他解决方案但没有成功。

我的 init 文件中有一个函数,如下所示:

(defun my/function ()
  "Comment or uncomment the current line or text selection."
  (interactive)
  (let (p1 p2)
    (if (use-region-p)

当我设置键绑定时:

(global-set-key (kbd "C-x C-.") 'my/function)

我收到以下错误:

wrong type of argument: commandp, my/function

当我转身时debug-on-error,这就是我得到的:

 call-interactively(my/function nil nil)
  command-execute(my/function)

我究竟做错了什么?

标签: debuggingemacskey-bindings

解决方案


你绑定的函数必须是一个命令,即:它必须(interactive)在里面。跑步(commandp 'my/function)应该告诉你它是否如此。

(在您的问题中,您确实有(interactive)in 定义,但一定出了问题,也许重新评估函数的定义会解决它)


推荐阅读