Emacs Lisp error "Invalid type argument: commandp"

What is wrong with the following code:

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

Evaluating this with eval-region , and then pressing F4 , I get an error:

 Wrong type argument: commandp, test 
+6
source share
1 answer

You are missing the argument list of your test function, which is why Emacs interprets the form (interactive) as an arglist. Thus, you defined a non-interactive function from 1 argument instead of an interactive command without arguments.

What would you like:

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

Lessons learned:

  • Always add a doc line - if you did, Emacs complained
  • Use elint (comes with Emacs, try Cha elint RET ).
+10
source

All Articles