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,29 +564,23 @@ 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)
if (not daemon and
(local_client = client_manager.create_client(
create_local_ui(ui_type), get_env_vars(), init_command)))
{
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();
selections = SelectionList(buffer, buffer.clamp(target_coord));
local_client->context().window().center_line(target_coord.line);
if (local_client)
{
auto& selections = local_client->context().selections_write_only();
auto& buffer = selections.buffer();
selections = SelectionList(buffer, buffer.clamp(target_coord));
local_client->context().window().center_line(target_coord.line);
if (startup_error)
local_client->print_status({
"error during startup, see *debug* buffer for details",
get_face("Error")
});
}
if (startup_error)
local_client->print_status({
"error during startup, see *debug* buffer for details",
get_face("Error")
});
}
while (not terminate and (not client_manager.empty() or daemon))