reddit / emacs

General.el which-key integration: can I prevent display of the binding entirely based on some predicate condition?

IuppiterStator · 2022-04-18 19:49
I currently have `:predicate '(derived-mode-p 'dired-mode) "/" '(my/toggle-dired-hide-details :wk "Dired-details")` defining a key-binding under a prefix in my general.el setup. If not in `dired-mode` though it still displays the "/ -> Dired-details" string in the mini-buffer after hitting the prefix key. I tried adding `:major-modes '(dired-mode)` to the sexp where this binding is described. Doing that yields "/ -> nil" in the mini-buffer for that key-binding when not in `dired-mode`. What I'd like is the binding for "/" under that prefix to not show up at all if not in `dired-mode`. Is there a way to accomplish this?
_noctuid · 2022-04-18 22:53
Where are you binding this key? If possible, bind the key in dired-mode-map instead of using a predicate. It's better to use key map based replacements wherever poasible: https://github.com/justbur/emacs-which-key#keymap-based-replacement If for whatever reason you can't do that, which-key supports a function to determine the replacement.