Skip to content
Permalink
Browse files

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

Fixes #852
Closes #856
  • Loading branch information...
mawww committed Oct 10, 2016
1 parent 780a460 commit 5440d31f995d9143e4f14a343a41aaab227ffbad
Showing with 28 additions and 20 deletions.
  1. +12 −0 src/buffer_manager.cc
  2. +2 −0 src/buffer_manager.hh
  3. +1 −1 src/client_manager.cc
  4. +13 −19 src/main.cc
@@ -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)
@@ -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();
@@ -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),
@@ -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);

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")
});
}
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")
});
}

while (not terminate and (not client_manager.empty() or daemon))

0 comments on commit 5440d31

Please sign in to comment.
You can’t perform that action at this time.