justbur / emacs-which-key

Emacs package that displays available keybindings in popup
GNU General Public License v3.0
1.74k stars 87 forks source link

How to have limit which-key to subset of keymaps #277

Open zcaudate opened 3 years ago

zcaudate commented 3 years ago

I'd like to have which-key only display only the choices for mode when it is present

for example, I'd like to toggle iedit mode and have which-key display just the iedit mode keys.

Is there a way to do this?

justbur commented 3 years ago

At the moment I don’t think it’s straight forward to only display a particular mode’s keys based on a keymap. However, the vast majority of commands from a mode share a common prefix, like ‘which-key-‘ and filtering on a prefix is definitely possible using the replacement alist

On Sat, Dec 19, 2020 at 10:19 PM Chris Zheng notifications@github.com wrote:

I'd like to have which-key only display only the choices for mode when it is present

for example, I'd like to toggle iedit mode and have which-key display just the iedit mode keys.

Is there a way to do this?

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/justbur/emacs-which-key/issues/277, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ3E7SCF5WJIMJBYHM2USDSVVUNLANCNFSM4VCYJ2JQ .

zcaudate commented 3 years ago

is there an example that I can go off.

basically, I'd like to have a hook for a given minor-mode (iEdit) that only shows it's own keybindings (ignoring other modes like Paredit mode)

or, if there was some way to further customise key bindings are shown (in Ranger/Dired)

justbur commented 3 years ago

Here's one way to go:

(setq which-key-allow-multiple-replacements nil)
(setq which-key-replacement-alist '(((nil . "iedit-") . (nil . nil))
                                    ((nil . nil) . t)))

In this setup, a command starting with iedit- will get passed through unchanged (the first item in the alist), while any other command will be discarded (the second item in the alist). Disallowing multiple matches through the first setting is important here.

zcaudate commented 3 years ago

@justbur. thanks for that. Your example initially confused me until I started playing with it. I think there's actually an easier solution that's already in the library - which-key-show-keymap. I'll need to hook it in with the iedit mode itself.

Will play around with it once I get more time.