mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 10:06:49 +08:00
Only expand abbreviations if cursor is directly at command token
On a commandline like "ls arg" (cursor at end) we do not expand abbrevations on enter. OTOH, on "ls " we do expand. This can be frustrating because it means that the two obvious ways to suppress abbrevation expansion (C-Space or post-expansion C-Z) cannot be used to suppress expansion of a command without arguments. (One workaround is "ls #".) Only expand-on-execute if the cursor is at the command name (no space in between). This is a strict improvement for realistic scenarios, because if there is a space, the user has already expressed the intent to not expand the abbreviation. (I hope no one is using recursive abbreviations.) Closes #8423
This commit is contained in:
parent
a32fa8fac9
commit
64dddfc6ce
|
@ -86,6 +86,7 @@ Interactive improvements
|
|||
- ``history`` and ``__fish_print_help`` now properly support ``less`` before version 530, including the version that ships with macOS. (:issue:`8157`).
|
||||
- ``help`` now knows which section is in which document again (:issue:`8245`).
|
||||
- fish's highlighter will now color options (starting with ``-`` or ``--``) with the color given in the new $fish_color_option, up to the first ``--``. It falls back on $fish_color_param, so nothing changes for existing setups (:issue:`8292`).
|
||||
- When executing a command, abbreviations are no longer expanded when the cursor is separated from the command by spaces, making it easier to suppress abbreviation expansion of commands without arguments. (:issue:`8423`).
|
||||
|
||||
New or improved bindings
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -3325,7 +3325,7 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat
|
|||
if (command_test_result == 0 || command_test_result == PARSER_TEST_INCOMPLETE) {
|
||||
// This command is valid, but an abbreviation may make it invalid. If so, we
|
||||
// will have to test again.
|
||||
if (expand_abbreviation_as_necessary(1)) {
|
||||
if (expand_abbreviation_as_necessary(0)) {
|
||||
// Trigger syntax highlighting as we are likely about to execute this command.
|
||||
this->super_highlight_me_plenty();
|
||||
if (conf.syntax_check_ok) {
|
||||
|
|
40
tests/checks/tmux-abbr.fish
Normal file
40
tests/checks/tmux-abbr.fish
Normal file
|
@ -0,0 +1,40 @@
|
|||
#RUN: %fish %s
|
||||
#REQUIRES: command -v tmux
|
||||
|
||||
set -g isolated_tmux_fish_extra_args -C '
|
||||
set -g fish_autosuggestion_enabled 0
|
||||
function abbr-test
|
||||
end
|
||||
abbr -g abbr-test "abbr-test [expanded]"
|
||||
'
|
||||
isolated-tmux-start
|
||||
|
||||
# Expand abbreviations on space.
|
||||
isolated-tmux send-keys abbr-test Space arg1 Enter
|
||||
tmux-sleep
|
||||
# CHECK: prompt {{\d+}}> abbr-test [expanded] arg1
|
||||
|
||||
# Expand abbreviations at the cursor when executing.
|
||||
isolated-tmux send-keys abbr-test Enter
|
||||
tmux-sleep
|
||||
# CHECK: prompt {{\d+}}> abbr-test [expanded]
|
||||
|
||||
# Use Control+Z right after abbreviation expansion, to keep going without expanding.
|
||||
isolated-tmux send-keys abbr-test Space C-z 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
|
||||
# CHECK: prompt {{\d+}}> abbr-test arg3
|
||||
|
||||
# Do not expand abbrevation if the cursor is not at the command, even if it's just white space.
|
||||
# This makes the behavior more consistent with the above two scenarios.
|
||||
isolated-tmux send-keys abbr-test C-Space Enter
|
||||
tmux-sleep
|
||||
# CHECK: prompt {{\d+}}> abbr-test
|
||||
|
||||
# CHECK: prompt {{\d+}}>
|
||||
|
||||
isolated-tmux capture-pane -p
|
Loading…
Reference in New Issue
Block a user