summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-04-08 21:58:12 +1000
committerMaxime Coste <mawww@kakoune.org>2019-04-08 21:59:32 +1000
commitc8839e79041ef37849a4cb8ac5017eadc8ec9653 (patch)
treeec13d3d7a7898aabab17712aae2e11ae2a752c44 /src
parent08f1a471fd8213582e3e1a85906e3ebcad3bd68e (diff)
Add a ClientCreate and ClientClose hook
As discussed in #2830. Closes #2500.
Diffstat (limited to 'src')
-rw-r--r--src/client_manager.cc8
-rw-r--r--src/hook_manager.hh6
2 files changed, 12 insertions, 2 deletions
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<UserInterface>&& 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<Hook>)
{
- return make_array<EnumDesc<Hook>, 39>({
+ return make_array<EnumDesc<Hook>, 41>({
{Hook::BufCreate, "BufCreate"},
{Hook::BufNewFile, "BufNewFile"},
{Hook::BufOpenFile, "BufOpenFile"},
@@ -72,6 +74,8 @@ constexpr auto enum_desc(Meta::Type<Hook>)
{Hook::BufCloseFifo, "BufCloseFifo"},
{Hook::BufReadFifo, "BufReadFifo"},
{Hook::BufSetOption, "BufSetOption"},
+ {Hook::ClientCreate, "ClientCreate"},
+ {Hook::ClientClose, "ClientClose"},
{Hook::InsertBegin, "InsertBegin"},
{Hook::InsertChar, "InsertChar"},
{Hook::InsertDelete, "InsertDelete"},