From a36473f4bb3c7ec31cfba638a9cbdfd2b6efb9e8 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 31 Jul 2022 11:19:48 +0200 Subject: [PATCH 1/2] 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} 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} 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. https://github.com/Delapouite/dot-in-the-sky/blob/f702a641d119fba558c06b24e5aba0ac73269076/.config/kak/kakrc#L169 https://github.com/mawww/config/blob/604ef1c1c2f4722505d3d29a4fc95e763a1fddbb/kakrc#L96 https://github.com/SolitudeSF/dot/blob/d22e7d6f681091fc3737fe460802f6d818bb7d18/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®exp=true --- doc/pages/changelog.asciidoc | 2 ++ doc/pages/mapping.asciidoc | 6 +----- src/commands.cc | 1 + src/normal.cc | 1 + 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index 8cd81a80..76f53f67 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -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) diff --git a/doc/pages/mapping.asciidoc b/doc/pages/mapping.asciidoc index c029383b..019a6bcf 100644 --- a/doc/pages/mapping.asciidoc +++ b/doc/pages/mapping.asciidoc @@ -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' +map global user n :make-next-error ---- -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 diff --git a/src/commands.cc b/src/commands.cc index f07c768b..d9f2500a 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -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(), {}}; diff --git a/src/normal.cc b/src/normal.cc index 09aad6f8..68a5fd6f 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -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}; From 395f43837898a1a1ac19755e479ad6aa1a574c25 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sat, 30 Jul 2022 22:28:02 +0200 Subject: [PATCH 2/2] Remove unnecessary leading space in prompt from mappings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We often use the pattern «map global normal ": foo"». The space after the colon is unnecessary since execution of the mapping won't add to history anyway, since 217dd6a1d (Disable history when executing maps, 2015-11-10). With the parent commit, the space is no longer necessary for user mappings, so there is no reason to continue the cargo-cult. Remove the space from mappings to set a good example. --- doc/pages/mapping.asciidoc | 2 +- rc/filetype/diff.kak | 2 +- rc/filetype/mail.kak | 4 ++-- rc/tools/doc.kak | 2 +- rc/tools/git.kak | 4 ++-- rc/tools/man.kak | 10 +++++----- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/doc/pages/mapping.asciidoc b/doc/pages/mapping.asciidoc index 019a6bcf..0ba142c4 100644 --- a/doc/pages/mapping.asciidoc +++ b/doc/pages/mapping.asciidoc @@ -68,7 +68,7 @@ command you invoke with the `%val{count}` and `%val{register}` expansions (See <>). For example: ---- -map global normal = ': echo Got count %val{count} and reg %val{register}' +map global normal = ':echo Got count %val{count} and reg %val{register}' ---- == Mappable keys diff --git a/rc/filetype/diff.kak b/rc/filetype/diff.kak index 2655b9b5..5be241f2 100644 --- a/rc/filetype/diff.kak +++ b/rc/filetype/diff.kak @@ -4,7 +4,7 @@ hook global BufCreate .*\.(diff|patch) %{ hook global WinSetOption filetype=diff %{ require-module diff - map buffer normal %{: diff-jump} + map buffer normal :diff-jump } hook -group diff-highlight global WinSetOption filetype=diff %{ diff --git a/rc/filetype/mail.kak b/rc/filetype/mail.kak index 9fb2d14e..92c2e17c 100644 --- a/rc/filetype/mail.kak +++ b/rc/filetype/mail.kak @@ -4,9 +4,9 @@ hook global BufCreate .+\.eml %{ hook global WinSetOption filetype=mail %{ require-module mail - map buffer normal %{: diff-jump} + map buffer normal :diff-jump hook -once -always window WinSetOption filetype=.* %{ - unmap buffer normal %{: diff-jump} + unmap buffer normal :diff-jump } } diff --git a/rc/tools/doc.kak b/rc/tools/doc.kak index d5227ee4..e710a80f 100644 --- a/rc/tools/doc.kak +++ b/rc/tools/doc.kak @@ -131,7 +131,7 @@ define-command -params 1 -hidden doc-render %{ set-option buffer readonly true add-highlighter buffer/ ranges doc_render_ranges add-highlighter buffer/ wrap -word -indent - map buffer normal ': doc-follow-link' + map buffer normal :doc-follow-link } define-command -params 0..2 \ diff --git a/rc/tools/git.kak b/rc/tools/git.kak index d361a6c7..d8e7ef87 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -104,8 +104,8 @@ define-command -params 1.. \ # We need to unmap in case an existing buffer changes type, # for example if the user runs "git show" and "git status". map_diff_goto_source=$([ -n "${map_diff_goto_source}" ] \ - && printf %s "map buffer normal %[: git-diff-goto-source] -docstring 'Jump to source from git diff'" \ - || printf %s "unmap buffer normal %[: git-diff-goto-source]") + && printf %s "map buffer normal :git-diff-goto-source -docstring 'Jump to source from git diff'" \ + || printf %s "unmap buffer normal :git-diff-goto-source") printf %s "evaluate-commands -try-client '$kak_opt_docsclient' %{ edit! -fifo ${output} *git* diff --git a/rc/tools/man.kak b/rc/tools/man.kak index facfaedf..d2b7a16b 100644 --- a/rc/tools/man.kak +++ b/rc/tools/man.kak @@ -14,7 +14,7 @@ hook -group man-highlight global WinSetOption filetype=man %{ # References to other manpages add-highlighter window/man-highlight/ regex [-a-zA-Z0-9_.]+\([a-z0-9]+\) 0:header - map window normal ': man-jump' + map window normal :man-jump hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/man-highlight @@ -141,7 +141,7 @@ man-jump %{ # Suggested keymaps for a user mode declare-user-mode man -map global man 'g' -docstring 'Jump to a man page using selected man page link' ': man-jump' -map global man 'j' -docstring 'Go to next man page link' ': man-link-next' -map global man 'k' -docstring 'Go to previous man page link' ': man-link-prev' -map global man 'm' -docstring 'Look up a man page' ':man' +map global man 'g' -docstring 'Jump to a man page using selected man page link' :man-jump +map global man 'j' -docstring 'Go to next man page link' :man-link-next +map global man 'k' -docstring 'Go to previous man page link' :man-link-prev +map global man 'm' -docstring 'Look up a man page' :man