I'm trying to add some bindings to undo-tree-visualizer-mode-map. To do so I use:

(define-key undo-tree-visualizer-mode-map (kbd "S-l") 'undo-tree-visualizer-quit)

But it doesn't work, and if I do describe-keymap afterwards I see that the binding wasn't added.

There seems to be a few keymap where this behavior happens, such as ivy-occur-mode-map and Info-mode-map as well.

Any idea why is that? And how can I add bindings to those keymaps?

  • 1
    What is describe-keymap? My emacs does not know it and I cannot find it in the elisp manual. Where does it come from? – NickD Jan 27 '20 at 1:11
  • @NickD describe-keymap is an interactive autoloaded Lisp function in ‘help-fns+.el’. It basically pretty prints all bindings to commands in a given keymap. – Didier A. Jan 27 '20 at 4:26
  • Thank you for the pointer! – NickD Jan 27 '20 at 13:41

You need to use L rather than S-l.

This is a quirk of key sequences in Emacs -- for letters (a-z), the shift modifier syntax S- won't do what you want, unless C- is also used in the sequence.

You should therefore write upper-case letters explicitly in key sequences.

See also https://stackoverflow.com/q/38180797/324105

For clarity:

(kbd "L")

(kbd "S-l")

(kbd "C-l")

(kbd "C-L")

(kbd "C-S-l")

Arguably Emacs ought to translate [33554540] to "L", or otherwise recognise it as intended, but in practice (at least at present) that doesn't happen.

  • Oh, I did not know that. That's good to know, but I also realized my mistake, I was doing eval-last-sexp but my define-key was quoted ' and somehow I was assuming it was evaluating without the quote. – Didier A. Jan 27 '20 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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