0

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?

Drew
  • 29,895
  • 7
  • 74
  • 104
RNP
  • 27
  • 6
  • 2
    Try `(define-key my-keys-mode-map (kbd "C-;") #'right-char)`. – Lindydancer Jun 01 '16 at 08:59
  • @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 Jun 02 '16 at 04:28
  • 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 Jun 02 '16 at 07:41
  • Nice. @Lindydancer, thanks for the education. – RNP Jun 02 '16 at 08:10

1 Answers1

1

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.

Drew
  • 29,895
  • 7
  • 74
  • 104