0
votes

The code below from my .emacs works fine normally but gives me an "Invalid keymap my-keys-mode-map" error when I try to byte compile it.

(eval-and-compile
  (defvar my-keys-mode-map (make-sparse-keymap) "my-keys-mode keymap.")

  (define-minor-mode my-keys-mode
    "A minor mode to override major modes keys."
    t " my-keys" 'my-keys-mode-map)

  (bind-key "C-;" (quote right-char) my-keys-mode-map)
  (bind-key "C-j" (quote left-char) my-keys-mode-map)
)

The error is on the bind-key line. I have tried define-key instead of bind-key, or using make-keymap instead of make-sparse-map but without luck. I am not too proficient with elisp. Is there some other way to define the key-map so that it is recognized by the byte compiler?

1
Try (define-key my-keys-mode-map (kbd "C-;") #'right-char). - Lindydancer
@Lindydancer, the problem was the quote before my keymap, as Drew mentioned below. But what does the # before the symbol in your suggestion do? - RNP
it's used to quote functions. In this case, it would be roughly the same as a plain quote. However, if you use a plain quote before a lambda the system will see it as a plain list and thus not compile it. - Lindydancer
Nice. @Lindydancer, thanks for the education. - RNP

1 Answers

1
votes

Remove the quote in front of the keymap symbol in the define-minor-mode.

In other words, the minor-mode definition should be this:

(define-minor-mode my-keys-mode
  "A minor mode to override major modes keys."
  t " my-keys" my-keys-mode-map)

You need to pass a keymap, not a symbol (whose value is a keymap), to define-minor-mode.