From 9c85d9b389233c95ef68f51eb719afe5cb0ad3f2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 5 Mar 2018 11:17:57 +1100 Subject: [PATCH] Support changing autoreload option directly from the reload message Pressing Y or N will set the buffer (or window, if it is set at that scope) autoreload option to the corresponding value, avoiding infinite loops where a file getting constantly modified prevents the user from using Kakoune. --- src/client.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/client.cc b/src/client.cc index 28fe97aef..225a10b29 100644 --- a/src/client.cc +++ b/src/client.cc @@ -294,14 +294,28 @@ void Client::on_buffer_reload_key(Key key) { auto& buffer = context().buffer(); - if (key == 'y' or key == Key::Return) + auto set_autoreload = [this](Autoreload autoreload) { + auto* option = &context().options()["autoreload"]; + // Do not touch global autoreload, set it at least at buffer level + if (&option->manager() == &GlobalScope::instance().options()) + option = &context().buffer().options().get_local_option("autoreload"); + option->set(autoreload); + }; + + if (key == 'y' or key == 'Y' or key == Key::Return) + { reload_buffer(); - else if (key == 'n' or key == Key::Escape) + if (key == 'Y') + set_autoreload(Autoreload::Yes); + } + else if (key == 'n' or key == 'N' or key == Key::Escape) { // reread timestamp in case the file was modified again buffer.set_fs_timestamp(get_fs_timestamp(buffer.name())); print_status({ format("'{}' kept", buffer.display_name()), get_face("Information") }); + if (key == 'N') + set_autoreload(Autoreload::No); } else { @@ -347,7 +361,8 @@ void Client::check_if_buffer_needs_reloading() StringView bufname = buffer.display_name(); info_show(format("reload '{}' ?", bufname), format("'{}' was modified externally\n" - "press or y to reload, or n to keep", + " y, : reload | n, : keep\n" + " Y: always reload | N: always keep\n", bufname), {}, InfoStyle::Modal); m_buffer_reload_dialog_opened = true;