From 163eb6dbc6758e84f8ce107632777fd06c8ac92d Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 29 Aug 2022 08:00:53 +0200 Subject: Disable history only for prompts that are never shown in the UI My terminal allows to map and independently. I like to use as escape key so I have this mapping: map global prompt Unfortunately, this is not equivalent to . Since mappings are run with history disabled, will not add the command to the prompt history. So disabling command history inside mappings is wrong in case the command prompt was created before mapping execution. The behavior should be: "a prompt that is both created and closed inside a noninteractive context does not add to prompt history", where "noninteractive" means inside a mapping, hook, command, execute-keys or evaluate-commands. Implement this behavior, it should better meet user expectations. Scripts can always use "set-register" to add to history. Here are my test cases: 1. Basic regression test (needs above mapping): :nop should be added to history --- 2. Create the prompt in a noninteractive context: :exec %{:} now we're back in the interactive context, so we can type: nop should be added to history --- 3. To check if it works for nested prompts, first set up this mapping. map global prompt ':nop should NOT be added to history' map global prompt ':nop should be added to history first' Then type :nop should be added to history second the inner command run by should not be added to history because it only existed in a noninteractive context. --- See also the discussion https://github.com/mawww/kakoune/pull/4692 We could automate the tests if we had a test setup that allowed feeding interactive key input into Kakoune instead of using "execute-commands". Some projects use tmux, or maybe we can mock the terminal. --- src/normal.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/normal.cc') diff --git a/src/normal.cc b/src/normal.cc index 01f56a01..e34c76d5 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1016,7 +1016,7 @@ void select_regex(Context& context, NormalParams params) RegisterManager::instance()[reg].restore(context, saved_reg); if (event == PromptEvent::Abort) return; - if (not context.noninteractive()) + if (context.input_handler().history_enabled()) RegisterManager::instance()[reg].set(context, ex.str()); auto& selections = context.selections(); @@ -1038,7 +1038,7 @@ void split_regex(Context& context, NormalParams params) RegisterManager::instance()[reg].restore(context, saved_reg); if (event == PromptEvent::Abort) return; - if (not context.noninteractive()) + if (context.input_handler().history_enabled()) RegisterManager::instance()[reg].set(context, ex.str()); auto& selections = context.selections(); @@ -1142,7 +1142,7 @@ void keep(Context& context, NormalParams params) RegisterManager::instance()[reg].restore(context, saved_reg); if (event == PromptEvent::Abort) return; - if (not context.noninteractive()) + if (context.input_handler().history_enabled()) RegisterManager::instance()[reg].set(context, regex.str()); if (regex.empty() or regex.str().empty()) -- cgit v1.2.3