susam / devil

Emacs minor mode that intercepts and translates keystrokes to provide a modifier-free non-modal editing experience
https://susam.github.io/devil/
Other
169 stars 10 forks source link

How to "end" repeated keys? #10

Closed rudolf-adamkovic closed 1 year ago

rudolf-adamkovic commented 1 year ago

Say I type <DEVIL> n n to move 2 lines down, and now I want to type the word next. What key should I press?

P.S. This should be mentioned in the manual, especially in the "Make All Keys Repeatable" section, IMO.

susam commented 1 year ago

@salutis,

Thank you for creating this question. I believe the current manual does answer your question, although it is perhaps much too concise and easy to miss. Here is the relevant sentence from the manual that I think answers this question:

Typing any other key stops the repetition and the default behaviour of the other key is then observed.

For example, if we are moving several lines down with <devil> n n n, typing any other key (e.g., a, <left>, or absolutely anything other than n) ends the repeatable key sequence. A good way to end the repeatable key could be to type , g which translates to C-g and invokes keyboard-quit.

I'll take the liberty to explain a bit more about how repeatable keys work in Devil. Before doing that, I should mention that the behaviour described above is exactly how we stop repeatable keys in repeat-mode too. Say, in vanilla Emacs (with or without Devil), we enable repeat-mode with M-x repeat-mode RET and begin undoing edits with C-x u u u. But let us say, we now want to type umbrella. To do so, we have to type some other key to end the ongoing repeatable key sequence.

Devil uses the Emacs transient map facility to implement repeatable keys. The mode repeat-mode also does the same thing. Any transient map set with KEEP-PRED as true remains active as long as we keep typing a key that belongs to the transient keymap. Typing any other key deactivates the transient map. See C-h f set-transient-map RET for more details about this.

rudolf-adamkovic commented 1 year ago

@susam Thank you for taking the time to not only solve the problem but also to teach me why things work the way they do!