1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-07-15 00:20:29 +03:00

Echo an information message about *scratch* buffer and leave it empty

Having to manually clear the scratch was never really nice and hopefully
this will be less annoying and as helpful to newcomers.
This commit is contained in:
Maxime Coste 2024-06-05 19:49:35 +10:00
parent 727d2391c7
commit 51ec633718
2 changed files with 11 additions and 9 deletions

View File

@ -101,9 +101,7 @@ Buffer& BufferManager::get_buffer_matching(const Regex& regex)
Buffer& BufferManager::get_first_buffer()
{
if (all_of(m_buffers, [](auto& b) { return (b->flags() & Buffer::Flags::Debug); }))
create_buffer("*scratch*", Buffer::Flags::None,
{StringData::create("*** this is a *scratch* buffer which won't be automatically saved ***\n"),
StringData::create("*** use it for notes or open a file buffer with the :edit command ***\n")},
create_buffer("*scratch*", Buffer::Flags::None, {StringData::create("\n")},
ByteOrderMark::None, EolFormat::Lf, {InvalidTime, {}, {}});
return *m_buffers.back();

View File

@ -64,24 +64,28 @@ Client* ClientManager::create_client(std::unique_ptr<UserInterface>&& ui, int pi
std::move(on_exit)};
m_clients.emplace_back(client);
auto& context = client->context();
if (buffer->name() == "*scratch*")
context.print_status({"This *scratch* buffer won't be automatically saved",
context.faces()["Information"]});
if (init_coord)
{
auto& selections = client->context().selections_write_only();
auto& selections = context.selections_write_only();
selections = SelectionList(*buffer, buffer->clamp(*init_coord));
client->context().window().center_line(init_coord->line);
context.window().center_line(init_coord->line);
}
try
{
auto& context = client->context();
context.hooks().run_hook(Hook::ClientCreate, context.name(), context);
CommandManager::instance().execute(init_cmds, context);
}
catch (Kakoune::runtime_error& error)
{
client->context().print_status({error.what().str(), client->context().faces()["Error"]});
client->context().hooks().run_hook(Hook::RuntimeError, error.what(),
client->context());
context.print_status({error.what().str(), context.faces()["Error"]});
context.hooks().run_hook(Hook::RuntimeError, error.what(),
context);
}
// Do not return the client if it already got moved to the trash