From d4ecea56df42a714992269e3f4315e950095258e Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 3 May 2024 08:30:27 +0200 Subject: [PATCH] Fix regression spuriously expanding abbr with cursor outside token Given "abbr foo something", the input sequence foo would re-expand the abbreviation on the second space which is surprising because the cursor is not at or inside the command token. This looks to be a regression from 00432df42 (Trigger abbreviations after inserting process separators, 2024-04-13) Happily, 69583f303 (Allow restricting abbreviations to specific commands (#10452), 2024-04-24) made some changes that mean the bad commit seems no longer necessary. Not sure why it works but I'll take it. --- .../functions/__fish_shared_key_bindings.fish | 22 +++++++++---------- src/input.rs | 1 - src/input_common.rs | 1 - src/reader.rs | 7 ------ tests/checks/tmux-abbr.fish | 5 +++++ 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 989440d69..bb04677ba 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -105,20 +105,20 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod or exit # protect against invalid $argv # Space and other command terminators expands abbrs _and_ inserts itself. - bind --preset $argv space self-insert expand-abbr-backtrack - bind --preset $argv ";" self-insert expand-abbr-backtrack - bind --preset $argv "|" self-insert expand-abbr-backtrack - bind --preset $argv "&" self-insert expand-abbr-backtrack - bind --preset $argv ">" self-insert expand-abbr-backtrack - bind --preset $argv "<" self-insert expand-abbr-backtrack - bind --preset $argv shift-enter "commandline -i \n" expand-abbr-backtrack - $legacy_bind --preset $argv \e\[27\;2\;13~ "commandline -i \n" expand-abbr-backtrack # Sent with XTerm.vt100.formatOtherKeys: 0 - bind --preset $argv alt-enter "commandline -i \n" expand-abbr-backtrack - bind --preset $argv ")" self-insert expand-abbr-backtrack # Closing a command substitution. + bind --preset $argv space self-insert expand-abbr + bind --preset $argv ";" self-insert expand-abbr + bind --preset $argv "|" self-insert expand-abbr + bind --preset $argv "&" self-insert expand-abbr + bind --preset $argv ">" self-insert expand-abbr + bind --preset $argv "<" self-insert expand-abbr + bind --preset $argv shift-enter "commandline -i \n" expand-abbr + $legacy_bind --preset $argv \e\[27\;2\;13~ "commandline -i \n" expand-abbr # Sent with XTerm.vt100.formatOtherKeys: 0 + bind --preset $argv alt-enter "commandline -i \n" expand-abbr + bind --preset $argv ")" self-insert expand-abbr # Closing a command substitution. bind --preset $argv ctrl-space 'test -n "$(commandline)" && commandline -i " "' bind --preset $argv -k nul 'test -n "$(commandline)" && commandline -i " "' # Shift-space behaves like space because it's easy to mistype. - bind --preset $argv shift-space 'commandline -i " "' expand-abbr-backtrack + bind --preset $argv shift-space 'commandline -i " "' expand-abbr bind --preset $argv enter execute bind --preset $argv ctrl-j execute diff --git a/src/input.rs b/src/input.rs index 8793f13d3..ec3e1915c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -166,7 +166,6 @@ const INPUT_FUNCTION_METADATA: &[InputFunctionMetadata] = &[ make_md(L!("execute"), ReadlineCmd::Execute), make_md(L!("exit"), ReadlineCmd::Exit), make_md(L!("expand-abbr"), ReadlineCmd::ExpandAbbr), - make_md(L!("expand-abbr-backtrack"), ReadlineCmd::ExpandAbbrBacktrack), make_md(L!("force-repaint"), ReadlineCmd::ForceRepaint), make_md(L!("forward-bigword"), ReadlineCmd::ForwardBigword), make_md(L!("forward-char"), ReadlineCmd::ForwardChar), diff --git a/src/input_common.rs b/src/input_common.rs index d2a77d305..5324bae25 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -114,7 +114,6 @@ pub enum ReadlineCmd { FuncAnd, FuncOr, ExpandAbbr, - ExpandAbbrBacktrack, DeleteOrExit, Exit, CancelCommandline, diff --git a/src/reader.rs b/src/reader.rs index 544fe1625..30acab14f 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -3116,13 +3116,6 @@ impl ReaderData { self.inputter.function_set_status(false); } } - rl::ExpandAbbrBacktrack => { - if self.expand_abbreviation_at_cursor(2) { - self.inputter.function_set_status(true); - } else { - self.inputter.function_set_status(false); - } - } rl::Undo | rl::Redo => { let (elt, el) = self.active_edit_line_mut(); let ok = if c == rl::Undo { el.undo() } else { el.redo() }; diff --git a/tests/checks/tmux-abbr.fish b/tests/checks/tmux-abbr.fish index c8af9fe51..a822b540c 100644 --- a/tests/checks/tmux-abbr.fish +++ b/tests/checks/tmux-abbr.fish @@ -24,6 +24,11 @@ isolated-tmux send-keys abbr-test Space C-z arg2 Enter tmux-sleep # CHECK: prompt {{\d+}}> abbr-test arg2 +# Same with a redundant space; it does not expand abbreviations. +isolated-tmux send-keys C-u abbr-test Space C-z Space arg2 Enter +tmux-sleep +# CHECK: prompt {{\d+}}> abbr-test arg2 + # Or use Control+Space ("bind -k nul") to the same effect. isolated-tmux send-keys abbr-test C-Space arg3 Enter tmux-sleep