From c152fbe3b6a328fe94a542c3734dfe61f67255ec Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 18 Sep 2016 13:47:22 +0100 Subject: [PATCH] Make idle timeout and filesystem check timeout configurable --- README.asciidoc | 5 +++++ doc/manpages/options.asciidoc | 8 ++++++++ src/input_handler.cc | 27 +++++++++++++++++---------- src/main.cc | 11 +++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 3be86bbd..db933813 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -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 <>). diff --git a/doc/manpages/options.asciidoc b/doc/manpages/options.asciidoc index 405336d1..c6ab0494 100644 --- a/doc/manpages/options.asciidoc +++ b/doc/manpages/options.asciidoc @@ -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), diff --git a/src/input_handler.cc b/src/input_handler.cc index 1fb68f86..a8970164 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -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()}; +} + +std::chrono::milliseconds get_fs_check_timeout(const Context& context) +{ + return std::chrono::milliseconds{context.options()["fs_check_timeout"].get()}; +} 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()); } diff --git a/src/main.cc b/src/main.cc index 0049f6be..3175ac5e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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( + "idle_timeout", "timeout, in milliseconds, before idle hooks are triggered", 50); + reg.declare_option( + "fs_check_timeout", "timeout, in milliseconds, between file system buffer modification checks", + 500); reg.declare_option("ui_options", "colon separated list of = options that are " "passed to and interpreted by the user interface\n"