Skip to content
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

Backspace does not work in keybindings #1665

Closed
tprodanov opened this issue Mar 2, 2023 · 7 comments
Closed

Backspace does not work in keybindings #1665

tprodanov opened this issue Mar 2, 2023 · 7 comments

Comments

@tprodanov
Copy link

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.

@tprodanov
Copy link
Author

Just noticed, that I cannot set Alt+Delete as well, but can set Ctrl+Delete. Probably, here the reason is different.

@tprodanov
Copy link
Author

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.

@krader1961
Copy link
Contributor

The key names were made case-sensitive 2.5 years ago in commit 9edcb78. 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).

@krader1961
Copy link
Contributor

See also isssue #1058. I really should find a few hours to implement that feature.

@xiaq
Copy link
Member

xiaq commented Mar 3, 2023

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 (4187d41). @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?

@krader1961
Copy link
Contributor

Note that there are other keyboard protocols for encoding modifier keys. See here and here. It's possible your terminal is configured to use one of those protocols rather then the much older "prefix with an escape when Alt is pressed" protocol that Elvish recognizes.

@xiaq
Copy link
Member

xiaq commented Dec 30, 2024

Closing this:

@xiaq xiaq closed this as completed Dec 30, 2024
@github-project-automation github-project-automation bot moved this from ❓Triage to ✅Done in All Elvish issues Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

3 participants