diff --git a/src/client_manager.cc b/src/client_manager.cc index d06e7259..f742809d 100644 --- a/src/client_manager.cc +++ b/src/client_manager.cc @@ -134,6 +134,7 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer) if (buf.get() != &buffer) { client->context().change_buffer(*buf); + client->set_last_buffer(nullptr); break; } } diff --git a/src/commands.cc b/src/commands.cc index 6304378d..abe95c1c 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1288,8 +1288,14 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) func(parser, c); }; if (*bufnames == "*") - for (auto buffer : BufferManager::instance()) + { + // copy buffer list as we might be mutating the buffer list + // in the loop. + Vector> buffers{BufferManager::instance().begin(), + BufferManager::instance().end()}; + for (auto buffer : buffers) context_wrap_for_buffer(*buffer); + } else for (auto& name : split(*bufnames, ',')) context_wrap_for_buffer(BufferManager::instance().get_buffer(name));