elvish
elvish copied to clipboard
Backspace does not work in keybindings
Setting set edit:insert:binding["Alt+Backspace"] = { echo A } does not give any errors, but also will not do anything if I press Alt+Backspace.
xev produces the following output:
KeyPress event, serial 34, synthetic NO, window 0x2600001,
root 0x7b2, subw 0x0, time 3896800, (1696,883), root:(1700,985),
state 0x0, keycode 22 (keysym 0xff08, BackSpace), same_screen YES,
XLookupString gives 1 bytes: (08) "
XmbLookupString gives 1 bytes: (08) "
XFilterEvent returns: False
Setting set edit:insert:binding["Alt+BackSpace"] = { echo A } produces an error Exception: bad key: BackSpace.
Just noticed, that I cannot set Alt+Delete as well, but can set Ctrl+Delete. Probably, here the reason is different.
Running
for key [Ctrl Alt Meta Shift] { var k = $key; set edit:insert:binding[$k+Backspace] = { echo $k } }
allows to run Ctrl+Backspace, but print Meta. All other bindings with Backspace still do not work.
Moreover, the following line produces very strange output:
for key [Ctrl Alt Meta Shift] { echo $key ($edit:insert:binding[$key+Backspace]) }
Ctrl Ctrl
Alt Meta
Meta Meta
Shift Shift
I use st terminal, $TERM is screen-256color inside tmux and st-256color outside of tmux.
Setting the same bindings for Delete works for Ctrl and Shift inside tmux, but work for nothing without tmux.
The key names were made case-sensitive 2.5 years ago in commit 9edcb780. That's why Backspace works but BackSpace does not. From the documentation:
Key modifiers and names are case sensitive.
Note that the xev command isn't particularly helpful because Elvish does not receive X window system events.
What you're trying to do works for me (I pressed Alt-Backspace after setting the binding):
elvish> set edit:insert:binding[Alt-Backspace] = { echo yes }
[bytes out] yes
elvish>
The likely reason it doesn't work for you is you haven't configured your terminal to cause the Alt modifier to preface the output with an escape character. What do you see if you press Alt-a then Ctrl-d after starting the od command as in this example from my system:
elvish> od -tx1z
^[a
0000000 1b 61 0a >.a.<
0000003
Note I'm using Alt-a in the example because Alt-Backspace will cause the backspace char to erase the previous (if any) character. Using something like Alt-a makes it easy to tell if your terminal is correctly configured to insert an escape character (the 1b in the od output above).
See also isssue #1058. I really should find a few hours to implement that feature.
Modified function keys are not well supported across terminals. It's likely that the terminal is not sending anything at all, or it could be sending something that Elvish's key code parser doesn't recognize.
I've just reinstated a feature that should help debug this issue (https://github.com/elves/elvish/commit/4187d41da4dc3c976d4b7a22bcc3fe8388afddb1). @tprodanov if you run Elvish from the latest commit (see the project README for how to do that), and press Alt-Backspace, does it complain about "unbound key"?
If it doesn't: run cat, and type x and then Alt-Backspace - what do you see?