Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Question about which-key-undo #354

Open
A7R7 opened this issue Aug 1, 2023 · 1 comment
Open

Question about which-key-undo #354

A7R7 opened this issue Aug 1, 2023 · 1 comment

Comments

@A7R7
Copy link

A7R7 commented Aug 1, 2023

TL;DR: How to bind which-key-undo to DEL after every prefix?

I'm an emacs noob comming from Neovim recently. Neovim also has a which-key plugin which by default uses DEL to undo keystrokes. I want to bring that feature to my emacs config.

From the readme we know that there's a which-key-undo command that can achieve this. Also, we can press C-h u in the which-key-mode-map to undo keystrokes. However, C-h u is not as fast as a simple DEL. Sometimes you just typed some wrong keystrokes and want to clear them quickly. Pressing other keys such as ESC that eventually leads to xxx is undefined is also an option, but that make me feel 'dangerous'.

So generally I'd like to bind which-key-undo to DEL. But that raises another question: I need to bind DEL after every prefix in emacs for it to work. It can be done manually, but that's troublesome. I wonder if there is a better practice to achieve this?

Your advice is highly appreciated!

@justbur
Copy link
Owner

justbur commented Aug 10, 2023

Hm, I'm not familiar with how which-key works in neovim.

In this package, which-key was designed to be passive and not intercept all key presses, which is why a certain key like C-h is used to "escape" the normal key reading routine. You could try (current-active-maps) and recurse down through them defining DEL to be which-key-undo for every possible prefix. That only takes care of maps that are active though.

Another possibility, and maybe better, would be to define a list of prefixes and bind which-key-undo to DEL at each prefix in override-global-map. Something like

(setq my-prefixes '("C-x"))
(mapcar
 (lambda (x)
   (define-key override-global-map (kbd (concat x " DEL")) #'which-key-undo))
 my-prefixes)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants