diff --git a/doc/pages/hooks.asciidoc b/doc/pages/hooks.asciidoc index 0fe6a566..a0f00bf4 100644 --- a/doc/pages/hooks.asciidoc +++ b/doc/pages/hooks.asciidoc @@ -140,6 +140,13 @@ name. Hooks with no description will always use an empty string. executed when a fifo buffer closes its fifo file descriptor either because the buffer is being deleted or the writing end has been closed +*ClientCreate* `client name`:: + executed when a new client is created. + +*ClientClose* `client name`:: + executed when a client is closed, after it was removed from the client + list. + *RuntimeError* `error message`:: an error was encountered while executing a user command diff --git a/src/client_manager.cc b/src/client_manager.cc index 943d7963..9ca5f555 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -64,7 +64,9 @@ Client* ClientManager::create_client(std::unique_ptr&& ui, int pi try { - CommandManager::instance().execute(init_cmds, client->context()); + auto& context = client->context(); + context.hooks().run_hook(Hook::ClientCreate, context.name(), context); + CommandManager::instance().execute(init_cmds, context); } catch (Kakoune::runtime_error& error) { @@ -116,10 +118,14 @@ void ClientManager::remove_client(Client& client, bool graceful, int status) kak_assert(contains(m_client_trash, &client)); return; } + client.exit(status); m_client_trash.push_back(std::move(*it)); m_clients.erase(it); + auto& context = client.context(); + context.hooks().run_hook(Hook::ClientClose, context.name(), context); + if (not graceful and m_clients.empty()) BufferManager::instance().backup_modified_buffers(); } diff --git a/src/hook_manager.hh b/src/hook_manager.hh index fa72cdc3..1653791c 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -28,6 +28,8 @@ enum class Hook BufCloseFifo, BufReadFifo, BufSetOption, + ClientCreate, + ClientClose, InsertBegin, InsertChar, InsertDelete, @@ -60,7 +62,7 @@ enum class Hook constexpr auto enum_desc(Meta::Type) { - return make_array, 39>({ + return make_array, 41>({ {Hook::BufCreate, "BufCreate"}, {Hook::BufNewFile, "BufNewFile"}, {Hook::BufOpenFile, "BufOpenFile"}, @@ -72,6 +74,8 @@ constexpr auto enum_desc(Meta::Type) {Hook::BufCloseFifo, "BufCloseFifo"}, {Hook::BufReadFifo, "BufReadFifo"}, {Hook::BufSetOption, "BufSetOption"}, + {Hook::ClientCreate, "ClientCreate"}, + {Hook::ClientClose, "ClientClose"}, {Hook::InsertBegin, "InsertBegin"}, {Hook::InsertChar, "InsertChar"}, {Hook::InsertDelete, "InsertDelete"},