diff --git a/rc/ctags.kak b/rc/ctags.kak index 66617750..4ec6affc 100644 --- a/rc/ctags.kak +++ b/rc/ctags.kak @@ -23,9 +23,9 @@ def -params 0..1 \ re=$0; sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re); keys=re; gsub(/", keys); gsub(/\t/, "", keys); - out = out " %{" $2 " {MenuInfo}" re "} %{try %{ edit %{" $2 "}; exec %{/\\Q" keys "vc} } catch %{ echo %{unable to find tag} } }" + out = out " %{" $2 " {MenuInfo}" re "} %{eval -collapse-jumps %{ try %{ edit %{" $2 "}; exec %{/\\Q" keys "vc} } catch %{ echo %{unable to find tag} } } }" } - /[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{edit %{" $2 "} %{" $3 "}}" } + /[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{eval -collapse-jumps %{ edit %{" $2 "} %{" $3 "}}}" } END { print length(out) == 0 ? "echo -color Error no such tag " ENVIRON["tagname"] : "menu -markup -auto-single " out }' }} diff --git a/src/commands.cc b/src/commands.cc index 1df0d097..468100aa 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1216,7 +1216,8 @@ 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" } } }, + { "save-regs", { true, "restore all given registers after execution" } }, + { "collapse-jumps", { false, "collapse all jumps into a single one from initial selection" } } }, ParameterDesc::Flags::SwitchesOnlyAtStart, 1 }; @@ -1358,11 +1359,21 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) Context& c = *real_context; + const bool collapse_jumps = (bool)parser.get_switch("collapse-jumps"); + SelectionList jump = c.selections(); + JumpList original_jump_list = collapse_jumps ? c.jump_list() : JumpList{}; + ScopedSetBool disable_hooks(c.user_hooks_disabled(), no_hooks); ScopedSetBool disable_keymaps(c.keymaps_disabled(), no_keymaps); ScopedSetBool disable_history(c.history_disabled()); func(parser, c); + + if (collapse_jumps and c.jump_list() != original_jump_list) + { + c.jump_list() = std::move(original_jump_list); + c.jump_list().push(std::move(jump)); + } } } diff --git a/src/context.hh b/src/context.hh index 91307c8c..9a6045f3 100644 --- a/src/context.hh +++ b/src/context.hh @@ -58,6 +58,13 @@ struct JumpList const SelectionList& backward(const SelectionList& current); void forget_buffer(Buffer& buffer); + friend bool operator==(const JumpList& lhs, const JumpList& rhs) + { + return lhs.m_jumps == rhs.m_jumps and lhs.m_current == rhs.m_current; + } + + friend bool operator!=(const JumpList& lhs, const JumpList& rhs) { return not (lhs == rhs); } + private: using Contents = Vector; Contents m_jumps;