diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index d482f28a9..0fae2a17b 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -4,6 +4,7 @@ #include "buffer.hh" #include "exception.hh" #include "string.hh" +#include "client_manager.hh" namespace Kakoune { @@ -35,6 +36,8 @@ void BufferManager::unregister_buffer(Buffer& buffer) { if (*it == &buffer) { + if (ClientManager::has_instance()) + ClientManager::instance().ensure_no_client_uses_buffer(buffer); m_buffers.erase(it); return; } diff --git a/src/commands.cc b/src/commands.cc index d720359e4..0baec150b 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -234,7 +234,6 @@ void delete_buffer(const CommandParameters& params, Context& context) if (manager.count() == 1) throw runtime_error("buffer " + buffer.name() + " is the last one"); - ClientManager::instance().ensure_no_client_uses_buffer(buffer); delete &buffer; } diff --git a/src/utils.hh b/src/utils.hh index 6337bc247..0db71f40a 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -33,6 +33,11 @@ public: ms_instance = nullptr; } + static bool has_instance() + { + return ms_instance != nullptr; + } + protected: Singleton() {