diff --git a/src/buffer.cc b/src/buffer.cc index fddf473e..99ec68f1 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -708,12 +708,14 @@ void Buffer::on_option_changed(const Option& option) format("{}={}", option.name(), option.get_as_string())); } -void Buffer::run_hook_in_own_context(StringView hook_name, StringView param) +void Buffer::run_hook_in_own_context(StringView hook_name, StringView param, String client_name) { if (m_flags & Buffer::Flags::NoHooks) return; - InputHandler hook_handler({ *this, Selection{} }, Context::Flags::Transient); + InputHandler hook_handler{{ *this, Selection{} }, + Context::Flags::Transient, + std::move(client_name)}; hooks().run_hook(hook_name, param, hook_handler.context()); } diff --git a/src/buffer.hh b/src/buffer.hh index 839b3d62..4db6f32a 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -190,7 +190,8 @@ public: ValueMap& values() const { return m_values; } - void run_hook_in_own_context(StringView hook_name, StringView param); + void run_hook_in_own_context(StringView hook_name, StringView param, + String client_name = ""); void reload(StringView data, timespec fs_timestamp = InvalidTime); diff --git a/src/commands.cc b/src/commands.cc index f711a525..0186a2f6 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -338,7 +338,7 @@ const CommandDesc write_cmd = { write_buffer, }; -void write_all_buffers() +void write_all_buffers(Context& context) { // Copy buffer list because hooks might be creating/deleting buffers Vector> buffers; @@ -350,9 +350,9 @@ void write_all_buffers() if ((buffer->flags() & Buffer::Flags::File) and buffer->is_modified() and !(buffer->flags() & Buffer::Flags::ReadOnly)) { - buffer->run_hook_in_own_context("BufWritePre", buffer->name()); + buffer->run_hook_in_own_context("BufWritePre", buffer->name(), context.name()); write_buffer_to_file(*buffer, buffer->name()); - buffer->run_hook_in_own_context("BufWritePost", buffer->name()); + buffer->run_hook_in_own_context("BufWritePost", buffer->name(), context.name()); } } } @@ -365,7 +365,7 @@ const CommandDesc write_all_cmd = { CommandFlags::None, CommandHelper{}, CommandCompleter{}, - [](const ParametersParser&, Context&, const ShellContext&){ write_all_buffers(); } + [](const ParametersParser&, Context& context, const ShellContext&){ write_all_buffers(context); } }; static void ensure_all_buffers_are_saved() @@ -490,7 +490,7 @@ const CommandDesc write_all_quit_cmd = { CommandCompleter{}, [](const ParametersParser& parser, Context& context, const ShellContext&) { - write_all_buffers(); + write_all_buffers(context); quit(context); } }; diff --git a/src/window.cc b/src/window.cc index 2c48d278..78e75be9 100644 --- a/src/window.cc +++ b/src/window.cc @@ -367,12 +367,15 @@ void Window::on_option_changed(const Option& option) } -void Window::run_hook_in_own_context(StringView hook_name, StringView param) +void Window::run_hook_in_own_context(StringView hook_name, StringView param, + String client_name) { if (m_buffer->flags() & Buffer::Flags::NoHooks) return; - InputHandler hook_handler({ *m_buffer, Selection{} }, Context::Flags::Transient); + InputHandler hook_handler{{ *m_buffer, Selection{} }, + Context::Flags::Transient, + std::move(client_name)}; hook_handler.context().set_window(*this); if (m_client) hook_handler.context().set_client(*m_client); diff --git a/src/window.hh b/src/window.hh index 90e5d58a..68ecc636 100644 --- a/src/window.hh +++ b/src/window.hh @@ -56,7 +56,8 @@ private: void on_option_changed(const Option& option) override; void scroll_to_keep_selection_visible_ifn(const Context& context); - void run_hook_in_own_context(StringView hook_name, StringView param); + void run_hook_in_own_context(StringView hook_name, StringView param, + String client_name = ""); SafePtr m_buffer; SafePtr m_client;