Only create a default *scratch* when we dont have any non debug buffers

Fixes #852
Closes #856
This commit is contained in:
Maxime Coste 2016-10-11 00:45:05 +01:00
parent 780a4605fa
commit 5440d31f99
4 changed files with 27 additions and 19 deletions

View File

@ -45,6 +45,9 @@ Buffer* BufferManager::create_buffer(String name, Buffer::Flags flags,
auto& buffer = *m_buffers.front();
buffer.on_registered();
if (contains(m_buffer_trash, &buffer))
throw runtime_error("Buffer got removed during its creation");
return &buffer;
}
@ -82,6 +85,15 @@ Buffer& BufferManager::get_buffer(StringView name)
return *res;
}
Buffer& BufferManager::get_first_buffer()
{
if (not contains_that(m_buffers, [](const std::unique_ptr<Buffer>& p)
{ return not (p->flags() & Buffer::Flags::Debug); }))
create_buffer("*scratch*", Buffer::Flags::None);
return *m_buffers.front();
}
void BufferManager::backup_modified_buffers()
{
for (auto& buf : m_buffers)

View File

@ -30,6 +30,8 @@ public:
Buffer* get_buffer_ifp(StringView name);
Buffer& get_buffer(StringView name);
Buffer& get_first_buffer();
void backup_modified_buffers();
void clear_buffer_trash();

View File

@ -40,7 +40,7 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
EnvVarMap env_vars,
StringView init_commands)
{
Buffer& buffer = **BufferManager::instance().begin();
Buffer& buffer = BufferManager::instance().get_first_buffer();
WindowAndSelections ws = get_free_window(buffer);
Client* client = new Client{std::move(ui), std::move(ws.window),
std::move(ws.selections), std::move(env_vars),

View File

@ -564,17 +564,12 @@ int run_server(StringView session, StringView init_command,
{
write_to_debug_buffer(format("error while opening command line files: {}", error.what()));
}
else
buffer_manager.create_buffer("*scratch*", Buffer::Flags::None);
try
{
if (not daemon)
{
local_client = client_manager.create_client(
create_local_ui(ui_type), get_env_vars(), init_command);
if (local_client)
if (not daemon and
(local_client = client_manager.create_client(
create_local_ui(ui_type), get_env_vars(), init_command)))
{
auto& selections = local_client->context().selections_write_only();
auto& buffer = selections.buffer();
@ -587,7 +582,6 @@ int run_server(StringView session, StringView init_command,
get_face("Error")
});
}
}
while (not terminate and (not client_manager.empty() or daemon))
{