Do not include non-primitive option value in *SetOption hook filter

Only include the value for int/str/bool options, for the rest just
write '<option name>=...'.

This should reduce the cost of some patterns such as repeatedly adding
a value inside a list option.

It seems very unlikely that the actual value would be matched by
a hook regex string for non primitive types.
main
Maxime Coste 2020-06-07 13:46:50 +10:00
parent 66f15cf4ad
commit f75d49e9ef
5 changed files with 16 additions and 4 deletions

View File

@ -16,6 +16,10 @@ released versions.
* `%val{...}` now expands to list of strings, `$kak_quoted_...` now work
as expected with these.
* `*SetOption` hooks filter string will contain a value only for options
of int/str/bool types to avoid performance issue with generating those
on more complex option types.
== Kakoune v2020.01.16
* Expose history tree through `$kak_history` and

View File

@ -685,7 +685,7 @@ void Buffer::on_option_changed(const Option& option)
m_flags &= ~Flags::ReadOnly;
}
run_hook_in_own_context(Hook::BufSetOption,
format("{}={}", option.name(), option.get_as_string(Quoting::Raw)));
format("{}={}", option.name(), option.get_desc_string()));
}
void Buffer::run_hook_in_own_context(Hook hook, StringView param, String client_name)

View File

@ -55,6 +55,7 @@ public:
virtual String get_as_string(Quoting quoting) const = 0;
virtual Vector<String> get_as_strings() const = 0;
virtual String get_desc_string() const = 0;
virtual void set_from_strings(ConstArrayView<String> strs) = 0;
virtual void add_from_strings(ConstArrayView<String> strs) = 0;
virtual void update(const Context& context) = 0;
@ -154,6 +155,14 @@ public:
return option_to_string(m_value, quoting);
}
String get_desc_string() const override
{
if constexpr (std::is_same_v<int, T> or std::is_same_v<bool, T> or std::is_same_v<String, T>)
return option_to_string(m_value, Quoting::Raw);
else
return "...";
}
void set_from_strings(ConstArrayView<String> strs) override
{
set(option_from_strings(Meta::Type<T>{}, strs));

View File

@ -19,7 +19,7 @@ void GlobalScope::on_option_changed(const Option& option)
{
Context empty_context{Context::EmptyContextFlag{}};
hooks().run_hook(Hook::GlobalSetOption,
format("{}={}", option.name(), option.get_as_string(Quoting::Raw)),
format("{}={}", option.name(), option.get_desc_string()),
empty_context);
}

View File

@ -346,8 +346,7 @@ void Window::clear_display_buffer()
void Window::on_option_changed(const Option& option)
{
run_hook_in_own_context(Hook::WinSetOption, format("{}={}", option.name(),
option.get_as_string(Quoting::Raw)));
run_hook_in_own_context(Hook::WinSetOption, format("{}={}", option.name(), option.get_desc_string()));
// an highlighter might depend on the option, so we need to redraw
force_redraw();
}