Support collapsing jumps in eval and exec

Fixes #535
This commit is contained in:
Maxime Coste 2015-12-23 02:46:13 +00:00
parent aa92ca96c8
commit 1288a1d385
3 changed files with 21 additions and 3 deletions

View File

@ -23,9 +23,9 @@ def -params 0..1 \
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 "} %{try %{ edit %{" $2 "}; exec %{/\\Q" keys "<ret><c-d>vc} } catch %{ echo %{unable to find tag} } }"
out = out " %{" $2 " {MenuInfo}" re "} %{eval -collapse-jumps %{ try %{ edit %{" $2 "}; exec %{/\\Q" keys "<ret>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 }'
}}

View File

@ -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));
}
}
}

View File

@ -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<SelectionList, MemoryDomain::Selections>;
Contents m_jumps;