summaryrefslogtreecommitdiff
path: root/src/commands.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-02-19 20:58:49 +1100
committerMaxime Coste <mawww@kakoune.org>2025-02-19 21:25:39 +1100
commiteb7d34333b0698e8e1a8af4f2be908ab08cb2089 (patch)
tree4b53ba24111ce88901669c3e7651b5ec4edb4f87 /src/commands.cc
parent9eda509282ebc881207c2d8278085cb53835641c (diff)
Cleanup file.cc/hh dependencies
file.cc/hh should not know about Context, Buffer, etc... It should be a pretty low level set of helper functions. Move buffer related functions to buffer_utils and extract busy indicators to callers.
Diffstat (limited to 'src/commands.cc')
-rw-r--r--src/commands.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 0f892004..ddc94c3b 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -618,7 +618,11 @@ void do_write_buffer(Context& context, Optional<String> filename, WriteFlags fla
auto method = write_method.value_or_compute([&] { return context.options()["writemethod"].get<WriteMethod>(); });
context.hooks().run_hook(Hook::BufWritePre, effective_filename, context);
- write_buffer_to_file(context, buffer, effective_filename, method, flags);
+ BusyIndicator busy_indicator{context, [&](std::chrono::seconds elapsed) {
+ return DisplayLine{format("waiting while writing buffer '{}' ({}s)", buffer.name(), elapsed.count()),
+ context.faces()["Information"]};
+ }};
+ write_buffer_to_file(buffer, effective_filename, method, flags);
context.hooks().run_hook(Hook::BufWritePost, effective_filename, context);
}
@@ -673,7 +677,11 @@ void write_all_buffers(const Context& context, bool sync = false, Optional<Write
auto method = write_method.value_or_compute([&] { return context.options()["writemethod"].get<WriteMethod>(); });
auto flags = sync ? WriteFlags::Sync : WriteFlags::None;
buffer->run_hook_in_own_context(Hook::BufWritePre, buffer->name(), context.name());
- write_buffer_to_file(context, *buffer, buffer->name(), method, flags);
+ BusyIndicator busy_indicator{context, [&](std::chrono::seconds elapsed) {
+ return DisplayLine{format("waiting while writing buffer ({}s)", elapsed.count()),
+ context.faces()["Information"]};
+ }};
+ write_buffer_to_file(*buffer, buffer->name(), method, flags);
buffer->run_hook_in_own_context(Hook::BufWritePost, buffer->name(), context.name());
}
}
@@ -1555,7 +1563,13 @@ const CommandDesc echo_cmd = {
message.push_back('\n');
if (auto filename = parser.get_switch("to-file"))
- write_to_file(context, *filename, message);
+ {
+ BusyIndicator busy_indicator{context, [&](std::chrono::seconds elapsed) {
+ return DisplayLine{format("waiting while writing to '{}' ({}s)", *filename, elapsed.count()),
+ context.faces()["Information"]};
+ }};
+ write_to_file(*filename, message);
+ }
else if (auto command = parser.get_switch("to-shell-script"))
ShellManager::instance().eval(*command, context, message, ShellManager::Flags::None, shell_context);
else if (parser.get_switch("debug"))