From 43fc5b0078db48583f1222d8b9b96ba87f2e8fc7 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 7 Feb 2022 13:31:56 +0100 Subject: [PATCH] Make show completion menu again when autocomplete is off As pointed out in [1], when insert mode autocomplete is disabled, could be used to activate insert mode completions temporarily [2]. This regressed in 6f7c5aed (Do not show custom completions when autocomplete is off, 2022-01-03). Fix this by enabling completions on /. This allows us to remove a special case for explicit completers. Alternative behavior (future?): make toggle completion like . This can be done today, as suggested by Screwtape on IRC: map global insert %{:toggle-ctrl-n} define-command toggle-ctrl-n %{ hook global InsertCompletionShow .* %{ map window insert } hook global InsertCompletionHide .* %{ unmap window insert } } [1] https://github.com/mawww/kakoune/pull/4493#issuecomment-1031189823 [2] completion only lives for the lifetime of the completion menu, whereas lasts until you exit insert mode. This means that autocompletion is much more convenient than or f, because those require an explicit completion request for each path component. --- src/insert_completer.cc | 3 ++- test/regression/0-autocomplete-overrules-completers/in | 1 + test/regression/0-autocomplete-overrules-completers/out | 1 + test/regression/0-autocomplete-overrules-completers/rc | 4 +++- .../regression/0-autocomplete-overrules-completers/script | 8 ++++---- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index f32b35ca..8f67f155 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -414,6 +414,7 @@ InsertCompleter::~InsertCompleter() void InsertCompleter::select(int index, bool relative, Vector& keystrokes) { + m_enabled = true; if (not setup_ifn()) return; @@ -461,7 +462,7 @@ void InsertCompleter::select(int index, bool relative, Vector& keystrokes) void InsertCompleter::update(bool allow_implicit) { - m_enabled = allow_implicit or m_explicit_completer; + m_enabled = allow_implicit; if (m_explicit_completer and try_complete(m_explicit_completer)) return; diff --git a/test/regression/0-autocomplete-overrules-completers/in b/test/regression/0-autocomplete-overrules-completers/in index b28b04f6..fd40910d 100644 --- a/test/regression/0-autocomplete-overrules-completers/in +++ b/test/regression/0-autocomplete-overrules-completers/in @@ -1,3 +1,4 @@ + diff --git a/test/regression/0-autocomplete-overrules-completers/out b/test/regression/0-autocomplete-overrules-completers/out index ee504471..851d052a 100644 --- a/test/regression/0-autocomplete-overrules-completers/out +++ b/test/regression/0-autocomplete-overrules-completers/out @@ -1,3 +1,4 @@ a2 +a3 ./ui-in diff --git a/test/regression/0-autocomplete-overrules-completers/rc b/test/regression/0-autocomplete-overrules-completers/rc index a3c831f3..e3078f0f 100644 --- a/test/regression/0-autocomplete-overrules-completers/rc +++ b/test/regression/0-autocomplete-overrules-completers/rc @@ -1,6 +1,8 @@ set-option global autocomplete prompt declare-option -hidden completions line1_completions declare-option -hidden completions line2_completions -set-option global completers option=line1_completions option=line2_completions +declare-option -hidden completions line3_completions +set-option global completers option=line1_completions option=line2_completions option=line3_completions set-option global line1_completions "1.1+0@%val(timestamp)" "a1||a1" set-option global line2_completions "2.1+0@%val(timestamp)" "a2||a2" +set-option global line3_completions "3.1+0@%sh{echo $(($kak_timestamp+1))}" "a3||a3" diff --git a/test/regression/0-autocomplete-overrules-completers/script b/test/regression/0-autocomplete-overrules-completers/script index 5a4d2aaf..eff89ea3 100644 --- a/test/regression/0-autocomplete-overrules-completers/script +++ b/test/regression/0-autocomplete-overrules-completers/script @@ -1,10 +1,10 @@ ui_out -ignore 4 ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "i" ] }' sleep .2 # trigger insert completion auto update -# Implicit completion is disabled via autocomplete. -ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "" ] }' -# Implicit completion can be toggled. -ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji" ] }' +# Implicit completion can be toggled with . +ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji" ] }' +# Implicit completion can be toggled with . +ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji" ] }' # Explicit completion still works. ui_in '{ "jsonrpc": "2.0", "method": "keys", "params": [ "ji./ui-f" ] }'