Always collapse jumps in exec/eval, remove -collapse-jumps switch

There does not seem to be any reasonable use cases of not collapsing
jumps when the input is not comming from the user. Always collapse
them.

It could make sense to move jump collapsing out of context_wrap as
in general any action not comming directly from the user should
collapse them, at the moment a comment or mapping will not collapse
jumps, which is unfortunate.
This commit is contained in:
Maxime Coste 2018-02-24 19:02:15 +11:00
parent 933ac4d3d5
commit 4d11bb20c3
6 changed files with 17 additions and 21 deletions

View File

@ -54,6 +54,3 @@ when the commands have been executed: */*, *"*, *|*, *^*, *@*.
*-save-regs* <regs>::
regs is a string of registers to be restored after execution (overwrites
the list of registers saved by default, c.f. description)
*-collapse-jumps*::
collapse all jumps into a single one from initial selection

View File

@ -37,9 +37,9 @@ If no symbol is passed then the current selection is used as symbol name} \
re=$0;
sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re);
keys=re; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys);
out = out " %{" $2 " {MenuInfo}" re "} %{evaluate-commands -collapse-jumps %{ try %{ edit %{" tagroot $2 "}; execute-keys %{/\\Q" keys "<ret>vc} } catch %{ echo %{unable to find tag} } } }"
out = out " %{" $2 " {MenuInfo}" re "} %{evaluate-commands %{ try %{ edit %{" tagroot $2 "}; execute-keys %{/\\Q" keys "<ret>vc} } catch %{ echo %{unable to find tag} } } }"
}
/[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{evaluate-commands -collapse-jumps %{ edit %{" tagroot $2 "} %{" $3 "}}}" }
/[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{evaluate-commands %{ edit %{" tagroot $2 "} %{" $3 "}}}" }
END { print ( length(out) == 0 ? "echo -markup %{{Error}no such tag " ENVIRON["tagname"] "}" : "menu -markup -auto-single " out ) }'
}}

View File

@ -47,7 +47,7 @@ declare-option -docstring "name of the client in which all source code jumps wil
str jumpclient
define-command -hidden grep-jump %{
evaluate-commands -collapse-jumps %{
evaluate-commands %{ # use evaluate-commands to ensure jumps are collapsed
try %{
execute-keys '<a-x>s^((?:\w:)?[^:]+):(\d+):(\d+)?<ret>'
set-option buffer grep_current_line %val{cursor_line}
@ -58,7 +58,7 @@ define-command -hidden grep-jump %{
}
define-command grep-next-match -docstring 'Jump to the next grep match' %{
evaluate-commands -collapse-jumps -try-client %opt{jumpclient} %{
evaluate-commands -try-client %opt{jumpclient} %{
buffer '*grep*'
# First jump to enf of buffer so that if grep_current_line == 0
# 0g<a-l> will be a no-op and we'll jump to the first result.
@ -70,7 +70,7 @@ define-command grep-next-match -docstring 'Jump to the next grep match' %{
}
define-command grep-previous-match -docstring 'Jump to the previous grep match' %{
evaluate-commands -collapse-jumps -try-client %opt{jumpclient} %{
evaluate-commands -try-client %opt{jumpclient} %{
buffer '*grep*'
# See comment in grep-next-match
execute-keys "ge %opt{grep_current_line}g<a-h> <a-/>^[^:]+:\d+:<ret>"

View File

@ -55,7 +55,7 @@ define-command -hidden make-open-error -params 4 %{
}
define-command -hidden make-jump %{
evaluate-commands -collapse-jumps %{
evaluate-commands %{
try %{
execute-keys gl<a-?> "Entering directory" <ret><a-:>
# Try to parse the error into capture groups, failing on absolute paths
@ -71,7 +71,7 @@ define-command -hidden make-jump %{
}
define-command make-next-error -docstring 'Jump to the next make error' %{
evaluate-commands -collapse-jumps -try-client %opt{jumpclient} %{
evaluate-commands -try-client %opt{jumpclient} %{
buffer '*make*'
execute-keys "%opt{make_current_error_line}ggl" "/^(?:\w:)?[^:\n]+:\d+:(?:\d+:)?%opt{make_error_pattern}<ret>"
make-jump
@ -80,7 +80,7 @@ define-command make-next-error -docstring 'Jump to the next make error' %{
}
define-command make-previous-error -docstring 'Jump to the previous make error' %{
evaluate-commands -collapse-jumps -try-client %opt{jumpclient} %{
evaluate-commands -try-client %opt{jumpclient} %{
buffer '*make*'
execute-keys "%opt{make_current_error_line}g" "<a-/>^(?:\w:)?[^:\n]+:\d+:(?:\d+:)?%opt{make_error_pattern}<ret>"
make-jump

View File

@ -69,5 +69,5 @@ The page can be a word, or a word directly followed by a section number between
;;
esac
printf %s\\n "evaluate-commands -collapse-jumps -try-client %opt{docsclient} man-impl *man* $pagenum $subject"
printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl *man* $pagenum $subject"
} }

View File

@ -1522,8 +1522,7 @@ const ParameterDesc context_wrap_params = {
{ "no-hooks", { false, "disable hooks" } },
{ "with-maps", { false, "use user defined key mapping when executing keys" } },
{ "itersel", { false, "run once for each selection with that selection as the only one" } },
{ "save-regs", { true, "restore all given registers after execution (defaults to '/\"|^@')" } },
{ "collapse-jumps", { false, "collapse all jumps into a single one from initial selection" } } },
{ "save-regs", { true, "restore all given registers after execution (defaults to '/\"|^@')" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart, 1
};
@ -1675,17 +1674,17 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
}
else
{
Optional<JumpList> original_jump_list;
if (not draft and (bool)parser.get_switch("collapse-jumps"))
original_jump_list = c.jump_list();
auto original_jump_list = draft ? Optional<JumpList>{} : c.jump_list();
auto jump = draft ? Optional<SelectionList>{} : c.selections();
SelectionList jump = c.selections();
func(parser, c);
if (original_jump_list and c.jump_list() != *original_jump_list)
// If the jump list got mutated, collapse all jumps into a single one from original selections
if (not draft and c.jump_list() != *original_jump_list)
{
original_jump_list->push(std::move(*jump));
if (c.jump_list() != *original_jump_list)
c.jump_list() = std::move(*original_jump_list);
c.jump_list().push(std::move(jump));
}
}
}