Fix {Alt,Shift}-Return bindings not expanding abbreviations

Today,

    bind foo "commandline -f expand-abbr; commandline -i \n"

does not work because this
1. enqueues an expand-abbr readline event
2. "commandline -i" inserts \n
3. processes the expand-abbr readline event

Since there is no abbreviation on the new line, this doesn't do anything.

PR https://github.com/fish-shell/fish-shell/pull/9398 would fix this
particular instance however it does not fix the issue that "commandline -i"
is run before the expand-abbr is processed by the reader. This is harmless
here but there would be a problem if "commandline" tried to read commandline
state that was created by a preceding command.

It's not super clear to me whether the above binding should work as one
would naively expect. That would imply that "commandline" would need to
drain all input events (at least all synthetic ones) from the input queue,
to ensure it sees the current state.

Fortunately the parent commit makes it so if we separate them

    bind foo "commandline -f expand-abbr" "commandline -i \n"

both will be separate events and the commandline state will be synced after
each of them. This fixes abbreviation expansion here.

Also, we can now mix readline cmds and shell commands, which makes it shorter.
This commit is contained in:
Johannes Altmanninger 2024-03-22 07:33:16 +01:00
parent c3cd68dda5
commit 789a280ee8

View File

@ -184,11 +184,11 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod
bind --preset $argv ">" self-insert expand-abbr
bind --preset $argv "<" self-insert expand-abbr
# Shift+Return as sent with XTerm.vt100.formatOtherKeys: 0
bind --preset $argv \e\[27\;2\;13~ "commandline -f expand-abbr; commandline -i \n"
bind --preset $argv \e\[27\;2\;13~ expand-abbr "commandline -i \n"
# Shift+Return CSI u sequence, sent with XTerm.vt100.formatOtherKeys: 1
bind --preset $argv \e\[13\;2u "commandline -f expand-abbr; commandline -i \n"
bind --preset $argv \e\n "commandline -f expand-abbr; commandline -i \n"
bind --preset $argv \e\r "commandline -f expand-abbr; commandline -i \n"
bind --preset $argv \e\[13\;2u expand-abbr "commandline -i \n"
bind --preset $argv \e\n expand-abbr "commandline -i \n"
bind --preset $argv \e\r expand-abbr "commandline -i \n"
# Closing a command substitution expands abbreviations
bind --preset $argv ")" self-insert expand-abbr
# Ctrl-space inserts space without expanding abbrs