From 7c8b4449273f3f0983b3f858f46988ef42cbdc18 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 7 Feb 2019 12:08:24 +0100 Subject: [PATCH] Reduce default escape delay 300ms was waaay too long, and even 100ms wasn't necessary. Emacs' evil mode uses 10ms (0.01s), so let's stay a tad higher in case some terminals are slow. If anyone really wants to be able to type alt+h with escape, let them raise the timeout. Fixes #3904. --- CHANGELOG.md | 1 + doc_src/index.hdr.in | 2 +- share/functions/fish_vi_key_bindings.fish | 6 ----- src/input_common.cpp | 2 +- tests/bind.expect | 28 +++++++---------------- tests/bind.expect.out | 5 ++-- 6 files changed, 13 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a92390c6..9c7844b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - fish_clipboard_* now supports wayland by means of [wl-clipboard](https://github.com/bugaevc/wl-clipboard). - mandoc can now be used to format the output from `--help` if nroff is not installed - New color options for the pager have been added (#5524). +- The default escape delay (to differentiate between the escape key and an alt-combination) has been reduced to 30ms, down from 300ms for the default mode and 100ms for vi-mode (#3904). ======= diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 3d0f9bd99..d3be1e5d2 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -901,7 +901,7 @@ The user can change the settings of `fish` by changing the values of certain var - `fish_ambiguous_width` controls the computed width of ambiguous East Asian characters. This should be set to 1 if your terminal emulator renders these characters as single-width (typical), or 2 if double-width. -- `fish_escape_delay_ms` overrides the default timeout of 300ms (default key bindings) or 10ms (vi key bindings) after seeing an escape character before giving up on matching a key binding. See the documentation for the bind builtin command. This delay facilitates using escape as a meta key. +- `fish_escape_delay_ms` overrides the default timeout of 30ms after seeing an escape character before giving up on matching a key binding. See the documentation for the bind builtin command. This delay facilitates using escape as a meta key. - `fish_greeting`, the greeting message printed on startup. diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 44b05913b..5d39be4c9 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -31,12 +31,6 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' return end - # The default escape timeout is 300ms. But for users of Vi bindings that can be slightly - # annoying when trying to switch to Vi "normal" mode. So set a shorter timeout in this case - # unless the user has explicitly set the delay. - set -q fish_escape_delay_ms - or set -g fish_escape_delay_ms 100 - set -l init_mode insert # These are only the special vi-style keys # not end/home, we share those. diff --git a/src/input_common.cpp b/src/input_common.cpp index a9fc3bc11..1e04176f4 100644 --- a/src/input_common.cpp +++ b/src/input_common.cpp @@ -31,7 +31,7 @@ /// Time in milliseconds to wait for another byte to be available for reading /// after \x1B is read before assuming that escape key was pressed, and not an /// escape sequence. -#define WAIT_ON_ESCAPE_DEFAULT 300 +#define WAIT_ON_ESCAPE_DEFAULT 30 static int wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT; /// Characters that have been read and returned by the sequence matching code. diff --git a/tests/bind.expect b/tests/bind.expect index 98bebc295..6f9e97e52 100644 --- a/tests/bind.expect +++ b/tests/bind.expect @@ -3,7 +3,7 @@ spawn $fish expect_prompt # Fish should start in default-mode (i.e., emacs) bindings. The default escape -# timeout is 300ms. +# timeout is 30ms. # Verify the emacs transpose word (\et) behavior using various delays, # including none, after the escape character. @@ -21,7 +21,7 @@ expect_prompt -re {\r\ndef abc\r\n} { # the words. send "echo ghi jkl" send "\033" -sleep 0.050 +sleep 0.010 send "t\r" expect_prompt -re {\r\njkl ghi\r\n} { puts "emacs transpose words, default timeout: short delay" @@ -33,7 +33,7 @@ expect_prompt -re {\r\njkl ghi\r\n} { # occur and the "t" should become part of the text that is echoed. send "echo mno pqr" send "\033" -sleep 0.400 +sleep 0.200 send "t\r" expect_prompt -re {\r\nmno pqrt\r\n} { puts "emacs transpose words, default timeout: long delay" @@ -54,10 +54,6 @@ expect_prompt -re {\r\ndefault\r\npaste} { send "set -g fish_key_bindings fish_vi_key_bindings\r" expect_prompt -# These vi tests assume the fish_vi_key_bindings default escape timeout of -# 10ms is in effect; not the 300ms timeout for the default-mode. -# - # Go through a prompt cycle to let fish catch up, it may be slow due to ASAN send "echo success: default escape timeout\r" expect_prompt -re {\r\nsuccess: default escape timeout\r\n} { @@ -66,14 +62,6 @@ expect_prompt -re {\r\nsuccess: default escape timeout\r\n} { puts stderr "prime vi mode, default timeout" } -# Verify the default timeout has been set to the expected value. -send "echo fish_escape_delay_ms=\$fish_escape_delay_ms\r" -expect_prompt -re {\r\nfish_escape_delay_ms=100\r\n} { - puts "vi-mode default timeout set correctly" -} unmatched { - puts stderr "vi-mode default timeout not set correctly" -} - send "echo fail: default escape timeout" send "\033" # Delay needed to allow fish to transition to vi "normal" mode. The delay is @@ -170,9 +158,9 @@ sleep 0.350 send "ddi" send "echo success: lengthened escape timeout\r" expect_prompt -re {\r\nsuccess: lengthened escape timeout\r\n} { - puts "vi replace line, 100ms timeout: long delay" + puts "vi replace line, 200ms timeout: long delay" } unmatched { - puts stderr "vi replace line, 100ms timeout: long delay" + puts stderr "vi replace line, 200ms timeout: long delay" } # Verify that we don't switch to vi normal mode if we don't wait long enough @@ -183,9 +171,9 @@ sleep 0.050 send "ddi" send "inserted\r" expect_prompt -re {\r\nfail: no normal modediinserted\r\n} { - puts "vi replace line, 100ms timeout: short delay" + puts "vi replace line, 200ms timeout: short delay" } unmatched { - puts stderr "vi replace line, 100ms timeout: short delay" + puts stderr "vi replace line, 200ms timeout: short delay" } # Test 't' binding that contains non-zero arity function (forward-jump) followed @@ -223,7 +211,7 @@ expect_prompt -re {\r\nfish_escape_delay_ms=200\r\n} { puts stderr "default-mode custom timeout not set correctly" } -# Reset it to 100ms. +# Set it to 100ms. send "set -g fish_escape_delay_ms 100\r" expect_prompt diff --git a/tests/bind.expect.out b/tests/bind.expect.out index 6fd079f7f..55667d0f6 100644 --- a/tests/bind.expect.out +++ b/tests/bind.expect.out @@ -3,7 +3,6 @@ emacs transpose words, default timeout: short delay emacs transpose words, default timeout: long delay emacs bind modes prime vi mode, default timeout -vi-mode default timeout set correctly vi replace line, default timeout: long delay vi mode replace char, default timeout: long delay vi mode delete char, default timeout: long delay @@ -11,8 +10,8 @@ vi mode forward-jump-till character, default timeout: long delay vi mode backward-jump-till character, default timeout: long delay vi mode backward-jump-to character and repeat, default timeout: long delay vi mode backward-jump-to character, and reverse, default timeout: long delay -vi replace line, 100ms timeout: long delay -vi replace line, 100ms timeout: short delay +vi replace line, 200ms timeout: long delay +vi replace line, 200ms timeout: short delay t-binding success vi bind modes default-mode custom timeout set correctly