I have written a function init-set-key-mappings that sets all the global keys in .emacs file.
(defun init-set-key-mappings ()
"All the key mappings go here"
(let ((mappings (list
'("\C-ca" 'open-fileline))))
(mapcar (lambda (mapping)
(let ((key (car mapping))
(func (cadr mapping)))
(progn
(message (format "map key %s to %s" key func))
(global-set-key key func))))
mappings)))
It evaluates fine, but when I press C-c a, Emacs complains “Wrong type argument commandp, (quote open-fileline)”
What am I doing wrong?
EDIT: I found the answer. Removing the quote before open-file seems to fix the problem. Why
is it being a symbol the problem? Isn’t this how functions are passed around – as symbols?
You double-quoted the function
open-fileline. In the expressionthe first quote indicates that everything in the following list is quoted. You then added a second quote to
open-fileline. Which means the list doesn’t actually contain a symbol as the second element of it’s car, but a quoted symbol. Compare:and