Search code examples
emacscommandkey-bindings

"Wrong type argument: commandp" error when binding a lambda to a key


I am getting a "Wrong type argument: commandp, (lambda nil (forward-line 5))" here.

(global-set-key [?\M-n] (lambda () (forward-line 5)))

What is the error? I'm fairly sure it's simple & I'm missing something obvious.


Solution

  • global-set-key expects an interactive command. (lambda () (interactive) (forward-line 5)) ought to work.

    By the way, C-h f commandp is a pretty good starting point for errors like that.