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.

1 Answer 1

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 
3
  • That solves the keymapp error, but when I press "M-S-RET" I get "M-RET is undefined". Is the keybinding not allowed? Commented 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. Commented Oct 28, 2016 at 17:58
  • Try (kbd "M-S-<return>"). Commented Oct 28, 2016 at 18:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.