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

Paul Nathan picture Paul Nathan · Aug 9, 2009 · Viewed 25.5k times · Source

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.

Answer

brendan picture brendan · Aug 9, 2009

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.