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

, <return> no longer inserts "," #6

Closed morganwillcock closed 1 year ago

morganwillcock commented 1 year ago

The documentation states that pressing the , key followed by the return key should insert a ",":

Assuming vanilla Emacs key bindings have not been changed and Devil has not been customised, here are some examples that demonstrate how Devil may be used: ...

  1. Similarly, type , RET to type a comma followed by the enter key. This is another special key.

...but when typing , <return> with version 0.4.0, I now get the message Devil: C-<return> is undefined.

susam commented 1 year ago

Thank you for reporting this issue. This was a bug introduced in commit 60f6968.

I have fixed it now in commit 2925d97. This version should soon become available in MELPA. I'll create a new release in a few days, so that this fix becomes available in MELPA Stable and NonGNU ELPA as well.

susam commented 1 year ago

On further thinking, it turns out a proper resolution to this issue is going to be more involved due to the way how function keys (supported in GUI Emacs) get automatically translated to terminal keys using the keymap named local-function-key-map. For example, Emacs translates C-<return> to C-RET if nothing is bound to C-<return>. However, if some command is bound to C-<return> then it avoids this translation. Therefore, a proper fix to this issue would need to account for this so that the translations can invoke commands bound to both types of key bindings (function-key-based as well as terminal-key-based key bindings).

I will work on this when I get more spare time. Until then, I hope the workaround pushed as part of commit 2925d97 resolves the immediate issue for you.

susam commented 1 year ago

A more wholesome fix for this issue has been developed in commit cfa68ae. It now supports , RET and , <return> as special keys to produce the same behaviour as typing , followed by the enter. The fix goes further in supporting translating function keys like <tab>, <backspace>, etc. to terminal keys like TAB, DEL, etc. using local-function-key-map if it cannot find a binding with the function keys. This mimics how Emacs supports both function keys and terminal keys while looking up bindings.

With this fix, now in vanilla Emacs with Devil, typing , m m <backspace> first translates the key sequence to M-<backspace>. Since no command is bound to it, local-function-key-map is applied and the key sequence is further translated to M-DEL. Since backward-kill-word is bound to M-DEL, it is then executed.

The fix is available in the latest version on MELPA. It will become available on NonGNU ELPA and MELPA Stable when a new release (version 0.5.0) is made. A new release is expected to be made by the end of this month. I will close this issue once this fix is available in the next stable version.

morganwillcock commented 1 year ago

Testing with commit e9d2024 (to fix the isearch issue) I think there is a new problem where the newline is not inserted.

When typing , <return> "," is inserted at point, but point remains on the same line. The message Devil: <return> is undefined is printed.

I am using the GUI version of Emacs rather than the terminal version, if that helps to recreate the problem.

susam commented 1 year ago

@morganwillcock Sorry about the new issue. In commit e9d2024 I forgot that the key sequences supplied to the devil-key-executor calls used to implement the special key sequences also need to undergo an additional translation according to local-function-key-map. I have pushed commit 4729fb4 to resolve this issue. I will be testing it out over the next one week. You are welcome to test it out too.

susam commented 1 year ago

The fixes discussed in this thread are now available in version 0.5.0.