I have to remap a lot of keys in existing maps while still remembering the old value of the map. To do that, I wrote some functions that go through lists of keys and lists of keymaps:

(defun Daselt/remap (keylist map)
  "A handy function for remapping keys."
  (mapcar (lambda (i)
            (define-key map (kbd (car i)) (nth 1 i))) keylist))

(defun Daselt-basic/remap-map-list (maplist)
  "This remaps the keys of each map according to the corresponding list."
  (mapcar (lambda (i)
            (Daselt/remap (symbol-value (intern (concat "Daselt-basic/" i "-list")))
                          (intern i))) maplist))

Now, when I have a list Daselt-basic/global-map-list of entries of the form (list '"key" #'command), I can use

(Daselt/remap Daselt-basic/global-map-list global-map)

and it works. However, if I have a list

(defconst Daselt-basic/initial-maps-list
  (list '"global-map")
  "List of maps that are remapped without calling with-eval-after-load.")

and I do

(Daselt-basic/remap-map-list Daselt/initial-maps-list)

I get the error

Wrong type argument: keymapp, global-map

But global-map is a keymap. What is happening?

  • You cannot call a function “as a variable”. That’s just nonsense. I have no idea what you’re trying to say, but that’s not it. Also, putting a ' in front of a quoted string doesn’t do anything. '"foo" is just the same as "foo".
    – db48x
    Commented Feb 16 at 21:05

1 Answer 1


You’re passing a list of strings to Daselt-basic/remap-map-list. It then calls intern on each one to convert it to a symbol. It then passes the symbol to Daselt/remap, which passes it along to define-key. But define-key wants a keymap, and a symbol is not a keymap. It might be the name of a variable that holds a keymap, but it isn’t the keymap itself. You need to retrieve the value of the variable with symbol-value.

The code would probably be cleaner if the map list contained a list of symbols instead of a list of strings, like this:

(defconst Daselt-basic/initial-maps-list
  (list 'global-map)
  "List of maps that are remapped without calling with-eval-after-load.")

You would need one less call to intern, but you would need to call symbol-name on it before you could concatenate up the new symbol name. The real advantage is that your users are presumably already used to naming variables with symbols. It is very unnatural to pass along a list of strings that correspond to variable names, because variable names are symbols.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.