2

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 ()
  (interactive)
  (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 ()
  (interactive)
  (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.

Jacek
  • 35
  • 4

1 Answers1

3

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
Dan
  • 32,980
  • 7
  • 102
  • 169
  • 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 '16 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 '16 at 17:58
  • Try (kbd "M-S-<return>"). – politza Oct 28 '16 at 18:07