Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Lisp error "Wrong type argument: commandp"

What is wrong with the following code:

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

When evaluating this with eval-region and then pressing F4 I get the error:

Wrong type argument: commandp, test
like image 663
Håkon Hægland Avatar asked Dec 12 '13 18:12

Håkon Hægland


1 Answers

You are missing the argument list of your test function, so Emacs interprets the (interactive) form as the arglist. Thus you have defined a non-interactive function of 1 argument instead of interactive command of no arguments.

What you want is:

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

Lessons learned:

  1. Always add a doc string - if you did, Emacs would have complained
  2. Use elint (comes with Emacs, try C-h a elint RET).
like image 77
sds Avatar answered Nov 12 '22 15:11

sds