Only create a default *scratch* when we dont have any non debug buffers
Fixes #852 Closes #856
This commit is contained in:
parent
780a4605fa
commit
5440d31f99
|
@ -45,6 +45,9 @@ Buffer* BufferManager::create_buffer(String name, Buffer::Flags flags,
|
||||||
auto& buffer = *m_buffers.front();
|
auto& buffer = *m_buffers.front();
|
||||||
buffer.on_registered();
|
buffer.on_registered();
|
||||||
|
|
||||||
|
if (contains(m_buffer_trash, &buffer))
|
||||||
|
throw runtime_error("Buffer got removed during its creation");
|
||||||
|
|
||||||
return &buffer;
|
return &buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +85,15 @@ Buffer& BufferManager::get_buffer(StringView name)
|
||||||
return *res;
|
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()
|
void BufferManager::backup_modified_buffers()
|
||||||
{
|
{
|
||||||
for (auto& buf : m_buffers)
|
for (auto& buf : m_buffers)
|
||||||
|
|
|
@ -30,6 +30,8 @@ public:
|
||||||
Buffer* get_buffer_ifp(StringView name);
|
Buffer* get_buffer_ifp(StringView name);
|
||||||
Buffer& get_buffer(StringView name);
|
Buffer& get_buffer(StringView name);
|
||||||
|
|
||||||
|
Buffer& get_first_buffer();
|
||||||
|
|
||||||
void backup_modified_buffers();
|
void backup_modified_buffers();
|
||||||
|
|
||||||
void clear_buffer_trash();
|
void clear_buffer_trash();
|
||||||
|
|
|
@ -40,7 +40,7 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
|
||||||
EnvVarMap env_vars,
|
EnvVarMap env_vars,
|
||||||
StringView init_commands)
|
StringView init_commands)
|
||||||
{
|
{
|
||||||
Buffer& buffer = **BufferManager::instance().begin();
|
Buffer& buffer = BufferManager::instance().get_first_buffer();
|
||||||
WindowAndSelections ws = get_free_window(buffer);
|
WindowAndSelections ws = get_free_window(buffer);
|
||||||
Client* client = new Client{std::move(ui), std::move(ws.window),
|
Client* client = new Client{std::move(ui), std::move(ws.window),
|
||||||
std::move(ws.selections), std::move(env_vars),
|
std::move(ws.selections), std::move(env_vars),
|
||||||
|
|
30
src/main.cc
30
src/main.cc
|
@ -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()));
|
write_to_debug_buffer(format("error while opening command line files: {}", error.what()));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
buffer_manager.create_buffer("*scratch*", Buffer::Flags::None);
|
|
||||||
|
|
||||||
try
|
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(
|
auto& selections = local_client->context().selections_write_only();
|
||||||
create_local_ui(ui_type), get_env_vars(), init_command);
|
auto& buffer = selections.buffer();
|
||||||
|
selections = SelectionList(buffer, buffer.clamp(target_coord));
|
||||||
|
local_client->context().window().center_line(target_coord.line);
|
||||||
|
|
||||||
if (local_client)
|
if (startup_error)
|
||||||
{
|
local_client->print_status({
|
||||||
auto& selections = local_client->context().selections_write_only();
|
"error during startup, see *debug* buffer for details",
|
||||||
auto& buffer = selections.buffer();
|
get_face("Error")
|
||||||
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))
|
while (not terminate and (not client_manager.empty() or daemon))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user