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

Is it possible to filter out some bindings, such that they are never shown? #272

Closed minad closed 3 years ago

minad commented 3 years ago

I found some variable (ignore-bindings '("self-insert-command" "ignore" "ignore-event" "company-ignore")) which is used internally. But I didn't find a possibility to customize this. Is it possible to generalize this by adding a custom filter function which is always applied to the results of the which-key--get-bindings function? The default function could filter self-insert-command etc.

justbur commented 3 years ago

You can use which-key-replacement-alist to do this already. See the docstring of that variable.

Here's an example that will hide the binding for "C-x DEL"

(add-to-list 'which-key-replacement-alist '(("C-x DEL" . nil) . t))

This is equivalent to

(which-key-add-key-based-replacements "C-x DEL" t)
minad commented 3 years ago

Thank you! I want to hide based on the command name and it was not clear to me how this works. But this is indeed documented and I overlooked it. The replacement mechanism is more powerful than it seemed to me. It is even possible to specify a function, which transforms the replacement!

This works:

(add-to-list 'which-key-replacement-alist '((nil . "command-name") . t))