Make idle timeout and filesystem check timeout configurable

This commit is contained in:
Maxime Coste 2016-09-18 13:47:22 +01:00
parent 6faed96b68
commit c152fbe3b6
4 changed files with 41 additions and 10 deletions

View File

@ -909,6 +909,11 @@ Some options are built in Kakoune, and can be used to control it's behaviour:
modification is detected.
* `debug` _flags(hooks|shell|profile)_: dump various debug information in
the `*debug*` buffer.
* `idle_timeout` _int_: timeout, in milliseconds, with no user input that will
trigger the `InsertIdle` and `NormalIdle` hooks.
* `fs_checkout_timeout` _int_: timeout, in milliseconds, between checks in
normal mode of modifications of the file associated with the current buffer
on the filesystem.
* `modelinefmt` _string_: A format string used to generate the mode line, that
string is first expanded as a command line would be (expanding `%...{...}`
strings), then markup tags are applied (see <<Markup strings>>).

View File

@ -138,6 +138,14 @@ Builtin options
*debug* 'flags(hooks|shell|profile)'::
dump various debug information in the '\*debug*' buffer
*idle_timeout* 'int'::
timeout, in milliseconds, with no user input that will trigger the
*InsertIdle* and *NormalIdle* hooks.
*fs_checkout_timeout* 'int'::
timeout, in milliseconds, between checks in normal mode of modifications
of the file associated with the current buffer on the filesystem.
*modelinefmt* 'string'::
A format string used to generate the mode line, that string is first
expanded as a command line would be (expanding '%...{...}' strings),

View File

@ -56,8 +56,15 @@ private:
namespace InputModes
{
static constexpr std::chrono::milliseconds idle_timeout{50};
static constexpr std::chrono::milliseconds fs_check_timeout{500};
std::chrono::milliseconds get_idle_timeout(const Context& context)
{
return std::chrono::milliseconds{context.options()["idle_timeout"].get<int>()};
}
std::chrono::milliseconds get_fs_check_timeout(const Context& context)
{
return std::chrono::milliseconds{context.options()["fs_check_timeout"].get<int>()};
}
struct MouseHandler
{
@ -140,7 +147,7 @@ public:
Timer::Callback() : Timer::Callback([this](Timer& timer) {
if (context().has_client())
context().client().check_if_buffer_needs_reloading();
timer.set_next_date(Clock::now() + fs_check_timeout);
timer.set_next_date(Clock::now() + get_fs_check_timeout(context()));
})},
m_single_command(single_command)
{}
@ -150,8 +157,8 @@ public:
if (context().has_client())
context().client().check_if_buffer_needs_reloading();
m_fs_check_timer.set_next_date(Clock::now() + fs_check_timeout);
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
m_fs_check_timer.set_next_date(Clock::now() + get_fs_check_timeout(context()));
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
context().hooks().run_hook("NormalBegin", "", context());
}
@ -178,7 +185,7 @@ public:
auto cp = key.codepoint();
if (m_mouse_handler.handle_key(key, context()))
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
if (cp and isdigit(*cp))
{
int new_val = m_params.count * 10 + *cp - '0';
@ -241,7 +248,7 @@ public:
}
context().hooks().run_hook("NormalKey", key_to_str(key), context());
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
}
DisplayLine mode_line() const override
@ -961,7 +968,7 @@ public:
void on_enabled() override
{
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
}
void on_disabled() override
@ -1099,7 +1106,7 @@ public:
{
insert(*cp);
context().hooks().run_hook("InsertKey", key_to_str(key), context());
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
}
}, "raw insert", "enter key to insert");
update_completions = false;
@ -1113,7 +1120,7 @@ public:
context().hooks().run_hook("InsertKey", key_to_str(key), context());
if (update_completions)
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
if (moved)
context().hooks().run_hook("InsertMove", key_to_str(key), context());
}

View File

@ -204,6 +204,12 @@ static void check_scrolloff(const CharCoord& so)
throw runtime_error{"scroll offset must be positive or zero"};
}
static void check_timeout(const int& timeout)
{
if (timeout < 50)
throw runtime_error{"the minimum acceptable timeout is 50 milliseconds"};
}
void register_options()
{
OptionsRegistry& reg = GlobalScope::instance().option_registry();
@ -247,6 +253,11 @@ void register_options()
reg.declare_option("autoreload",
"autoreload buffer when a filesystem modification is detected",
Autoreload::Ask);
reg.declare_option<int, check_timeout>(
"idle_timeout", "timeout, in milliseconds, before idle hooks are triggered", 50);
reg.declare_option<int, check_timeout>(
"fs_check_timeout", "timeout, in milliseconds, between file system buffer modification checks",
500);
reg.declare_option("ui_options",
"colon separated list of <key>=<value> options that are "
"passed to and interpreted by the user interface\n"