0

I have the following keymap defined to navigate my Emacs windows:

(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
(define-key my-keys-minor-mode-map (kbd "C-M-j") 'windmove-left)
(define-key my-keys-minor-mode-map (kbd "C-M-l") 'windmove-right)
(define-key my-keys-minor-mode-map (kbd "C-M-i") 'windmove-up)
(define-key my-keys-minor-mode-map (kbd "C-M-k") 'windmove-down)
(define-key my-keys-minor-mode-map (kbd "C-M-u") 'toggle-maximize-buffer)

(define-minor-mode my-keys-minor-mode
  "A minor mode so that my key settings override annoying major modes."
  t " my-keys" 'my-keys-minor-mode-map)

(my-keys-minor-mode 1)

This works great, except when I am viewing a PDF (DocView). In that case, Whenever I press any of the shortcuts I get errors like:

Wrong type argument: wholenump, -56

What could be going on?

In case it helps I am using GNU Emacs on OS X. I installed with the following command, as suggested in this other answer:

brew install emacs --HEAD --use-git-head --cocoa --with-gnutls --with-rsvg --with-imagemagick

My version specifically is:

GNU Emacs 24.4.50.1 (x86_64-apple-darwin13.4.0, NS appkit-1265.21 Version 10.9.5 (Build 13F34))
 of 2014-09-27 on josh.host.net

Could this be a bug? Or perhaps am I not defining this keymap correctly?

3
  • 1
    I don't get this behaviour (GNU Emacs 24.3.1) on Debian. Have you tried running emacs -Q and just evaluating the incriminated snippet to make sure the undesirable effect is not due to some other part of your configuration file? Sep 29, 2014 at 19:08
  • I don't get that behavior either. If you can reproduce it, it'd be nice to get a backtrace (M-x toggle-debug-on-error) to get feel of who's complaining about wholenump)
    – Sigma
    Sep 30, 2014 at 4:57
  • 1
    You may also want to check out bind-key.el (comes with use-package) to override keys. It's one less thing you have to maintain yourself.
    – aerique
    Oct 7, 2014 at 6:43

1 Answer 1

1

You should almost never use make-keymap. As a rule of thumb, if you don't know whether to use make-keymap or make-sparse-keymap use the latter. Only use make-keymap when the keymap is used to temporarily or permanently replace the default global map.

Also bindings should be established inside the defvar form:

(defvar my-keys-minor-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "C-M-j") 'windmove-left)
    ...
    map))

This way reloading the library does not override user customizations done in some other file or temporarily, i.e. when using eval-buffer to load some experimental changes the user has made. For personal code that doesn't matter much (provided you don't extend the map elsewhere) but it is still good practice to set the default value inside defvar. (defvar does never change the value of a variable. It only sets the value if the symbol was previously undefined as a variable).

The wholenump error might be related to the use of make-keymap, but until you help us to help you by providing a backtrace as requested by @Sigma, you likely won't get any help with that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.