-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add replacements for minor mode bindings #212
Comments
Hm, there are a couple of tricky parts I can think of off the top of my head:
What would the case be where this is valuable? I would think that in most cases the minor-mode activates and deactivates the bindings automatically and that all of the bindings are prefixed with the name of the minor mode, so that needing to know whether the mode is active or not is unnecessary. |
I run into that all the time. I have bindings where the same keys are bound to different commands, depending on the active minor mode. Currently, |
I failed to note that the proposed mechanism is not backwards compatible when |
Ok, I think I understand the problem better. You're right about The problem with the mode-specific binding part is that there is one major-mode and simultaneously any number of minor modes active at one time, so there are conflicts to resolve there.
There's a more straightforward way to handle this problem I think. You can replace based on key and/or command name, so if you defined your replacements based on command name you would have to worry about the times when that command is not available. I could add a helper function for this kind of replacement if you wanted. There's also IMO a nicer way of specifying replacements that gets around this problem. You can do (setq which-key-enable-extended-define-key t)
(define-key my-map "k" '("My Command Name" . command)) and it will show "My Command Name" for |
I like @justbur's solution, but I also think having |
Sorry for the intermission, I was on an extended vacation.
Each active binding is provided by exactly one mode (or it's global). I don't see any potential conflicts when looking up the description.
I use which-key mainly for prefix keys, so this is not an option here.
Edit: Sorry, I accidentally hit the |
@erikarvstedt I'd review (and probably accept) a PR for this if it doesn't get too messy |
We are sorting out bindings in Spacemacs and this feature will be very welcome. |
Yep, will probably be helpful for doom-emacs, too. I'll work it out in the next few days. |
Currently, it's not possible to define key description replacements that are specific to minor modes.
A cursory look at the code seems to suggest that this should be rather easy to implement:
Rename
which-key-add-major-mode-key-based-replacements
towhich-key-add-mode-key-based-replacements
. The function itself can be left unchanged.In
which-key--get-current-bindings
, store for each binding the mode (major or minor) that provided the binding. This info is readily provided bydescribe-buffer-bindings
. (Storenil
if the binding is global.)In
which-key--maybe-replace
, instead of using the current major-mode for mode-specific replacments, use the mode that provided the binding.Do you think this approach is feasible or am I missing something?
This should probably be a breeze to implement. If you're low on time, I'd try an implementation by myself.
The text was updated successfully, but these errors were encountered: