Do not record prompt history when executing user mode mappings

Commit 217dd6a1d (Disable history when executing maps, 2015-11-10)
made it so with

	map global normal X %{:echo 123<ret>}

X does not add to prompt history (%reg{:}).

Unfortunately this behavior was not extended to mappings in the "user"
keymap, nor to mappings in custom user modes.
In my experience, not adding to history is almost always the expected
behavior for mappings. Most users achieve this by adding a leading space:

	map global user X %{: echo 123<ret>}

but that's awkward. We should have good defaults (no nnoremap)
and map should work the same way across all modes.

Fix this by also disabling history when executing user mappings. This
is a breaking change but I think it only breaks hypothetical scenarios.

I found some uses where user mappings add to history but none of them
looks intentional.

f702a641d1/.config/kak/kakrc (L169)
604ef1c1c2/kakrc (L96)
d22e7d6f68/kak/kakrc (L71)
https://grep.app/search?q=map%20%28global%7Cbuffer%7Cwindow%29%20user%20.%2A%5B%21%3A/%5D%5B%5E%20%5D.%2A%3Cret%3E&regexp=true
This commit is contained in:
Johannes Altmanninger 2022-07-31 11:19:48 +02:00
parent e83dbdcd2c
commit a36473f4bb
4 changed files with 5 additions and 5 deletions

View File

@ -18,6 +18,8 @@ released versions.
* History registers `%reg{colon}`, `%reg{slash}` and `%reg{pipe}` now
have reverse chronological order
* Executing user mode mappings no longer adds to prompt history registers by default.
== Kakoune 2021.11.07
* Support for curly and separately colored underlines (undocumented in 2021.10.28)

View File

@ -59,13 +59,9 @@ It's common to use a normal-mode or user-mode mapping to trigger a command,
like this:
----
map global user n ': make-next-error<ret>'
map global user n :make-next-error<ret>
----
Note the space between the `:` and the command. This prevents Kakoune from
adding this command to the prompt history, so the user won't have to scroll
past it to review commands they actually typed.
If you make a normal-mode mapping, you can prefix it with a count or a register
name like any other normal-mode key. You can forward this information to the
command you invoke with the `%val{count}` and `%val{register}` expansions

View File

@ -2620,6 +2620,7 @@ void enter_user_mode(Context& context, String mode_name, KeymapMode mode, bool l
auto& mapping = context.keymaps().get_mapping(key, mode);
ScopedSetBool disable_keymaps(context.keymaps_disabled());
ScopedSetBool disable_history(context.history_disabled());
InputHandler::ScopedForceNormal force_normal{context.input_handler(), {}};

View File

@ -2014,6 +2014,7 @@ void exec_user_mappings(Context& context, NormalParams params)
auto& mapping = context.keymaps().get_mapping(key, KeymapMode::User);
ScopedSetBool disable_keymaps(context.keymaps_disabled());
ScopedSetBool disable_history(context.history_disabled());
InputHandler::ScopedForceNormal force_normal{context.input_handler(), params};