I'm trying to define the keymap for a major mode but keep getting the error: Wrong type argument: keymapp.

What am I doing wrong?

(defun insert-text ()
  (let ((x (read-string "Enter text to be printed: ")))
    (insert x)))

(defvar test-mode-map
  (let ((map (make-keymap)))
    (define-key map (kbd "M-S-RET") 'insert-text)))

(defun test-mode ()
  (setq major-mode 'test-mode
    mode-name  "Test Mode")
  (use-local-map test-mode-map))

I read another question with a similar error but it doesn't really help.

1 Answer 1


The problem is in the let-binding of your defvar form.

The let will return the value of its last form. Currently, the last form is define-key, which returns the function symbol which you bound to the keys.

Instead, you want to return the map you created:

(defvar test-mode-map
  (let ((map (make-keymap)))
    (define-key map (kbd "M-S-RET") 'insert-text)
    map))                           ; need to return the keymap

(keymapp test-mode-map)             ; => t
  • That solves the keymapp error, but when I press "M-S-RET" I get "M-RET is undefined". Is the keybinding not allowed?
    – Jacek
    Oct 28, 2016 at 17:52
  • @Jacek: for this site, we try to keep questions and answers discrete rather than do a lot of follow-up through comments. I'd suggest you work with the keybinding in question for a while and try other options to isolate the problem. If you still have problems after a while, post a second, discrete question about it.
    – Dan
    Oct 28, 2016 at 17:58
  • Try (kbd "M-S-<return>").
    – politza
    Oct 28, 2016 at 18:07

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.