jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.41k stars 260 forks source link

Support keymap symbol in bind-key. Fix #845 #846

Closed wyuenho closed 4 years ago

wyuenho commented 4 years ago

Sometimes, there are packages such as prettier that expose commands that one would like to bind to multiple modes in their mode hooks. In which case the mode map will likely be dynamically constructed from the mode symbol, and one would like to bind keys like the following:

(dolist (mode '(css-mode js-mode ...))
  (let ((mode-hook (derived-mode-hook-name mode)))
    (add-hook mode-hook (lambda ()
       (bind-key "C-c f" 'prettier-prettify (derived-mode-map-name mode)))))

The problem is, bind-key currently does not support KEYMAP supplied as a symbol, and if it is supplied as a (symbol-value (derived-mode-map-name mode)), there's no way to reverse lookup the name of the variable from the symbol value later on when constructing the buffer for describe-personal-bindings, hence #845 .

This PR proposes a fix to this problem by supporting KEYMAP as symbols, while preserving backward compatibility.

wyuenho commented 4 years ago

@jwiegley How does this look?

jwiegley commented 4 years ago

If this is backward compatible with how things worked before, then it sounds good to me.

wyuenho commented 4 years ago

It is :)