Check all buffer are saved in :kill, and add :kill! to avoid that
This commit is contained in:
parent
61c155fc40
commit
da40828801
|
@ -599,7 +599,8 @@ command `q!` has to be used).
|
||||||
* `w[rite]a[ll]`: write all buffers that are associated to a file.
|
* `w[rite]a[ll]`: write all buffers that are associated to a file.
|
||||||
* `q[uit][!]`: exit Kakoune, use quit! to force quitting even if there is some
|
* `q[uit][!]`: exit Kakoune, use quit! to force quitting even if there is some
|
||||||
unsaved buffers remaining.
|
unsaved buffers remaining.
|
||||||
* `kill`: terminate the current session, all the clients as well as the server
|
* `kill[!]`: terminate the current session, all the clients as well as the server,
|
||||||
|
use kill! to ignore unsaved buffers
|
||||||
* `w[a]q[!]`: write the current buffer (or all buffers when `waq` is used) and quit
|
* `w[a]q[!]`: write the current buffer (or all buffers when `waq` is used) and quit
|
||||||
* `b[uffer] <name>`: switch to buffer <name>
|
* `b[uffer] <name>`: switch to buffer <name>
|
||||||
* `b[uffer]n[ext]`: switch to the next buffer
|
* `b[uffer]n[ext]`: switch to the next buffer
|
||||||
|
|
|
@ -271,6 +271,28 @@ const CommandDesc writeall_cmd = {
|
||||||
[](const ParametersParser&, Context&, const ShellContext&){ write_all_buffers(); }
|
[](const ParametersParser&, Context&, const ShellContext&){ write_all_buffers(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void ensure_all_buffers_are_saved()
|
||||||
|
{
|
||||||
|
Vector<String> names;
|
||||||
|
for (auto& buffer : BufferManager::instance())
|
||||||
|
{
|
||||||
|
if ((buffer->flags() & Buffer::Flags::File) and buffer->is_modified())
|
||||||
|
names.push_back(buffer->name());
|
||||||
|
}
|
||||||
|
if (not names.empty())
|
||||||
|
{
|
||||||
|
String message = "modified buffers remaining: [";
|
||||||
|
for (auto it = names.begin(); it != names.end(); ++it)
|
||||||
|
{
|
||||||
|
if (it != names.begin())
|
||||||
|
message += ", ";
|
||||||
|
message += *it;
|
||||||
|
}
|
||||||
|
message += "]";
|
||||||
|
throw runtime_error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const CommandDesc kill_cmd = {
|
const CommandDesc kill_cmd = {
|
||||||
"kill",
|
"kill",
|
||||||
nullptr,
|
nullptr,
|
||||||
|
@ -279,6 +301,21 @@ const CommandDesc kill_cmd = {
|
||||||
CommandFlags::None,
|
CommandFlags::None,
|
||||||
CommandHelper{},
|
CommandHelper{},
|
||||||
CommandCompleter{},
|
CommandCompleter{},
|
||||||
|
[](const ParametersParser&, Context&, const ShellContext&){
|
||||||
|
ensure_all_buffers_are_saved();
|
||||||
|
throw kill_session{};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const CommandDesc force_kill_cmd = {
|
||||||
|
"kill!",
|
||||||
|
nullptr,
|
||||||
|
"kill current session, quit all clients and server, do not check for unsaved buffers",
|
||||||
|
no_params,
|
||||||
|
CommandFlags::None,
|
||||||
|
CommandHelper{},
|
||||||
|
CommandCompleter{},
|
||||||
[](const ParametersParser&, Context&, const ShellContext&){ throw kill_session{}; }
|
[](const ParametersParser&, Context&, const ShellContext&){ throw kill_session{}; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -286,26 +323,7 @@ template<bool force>
|
||||||
void quit()
|
void quit()
|
||||||
{
|
{
|
||||||
if (not force and ClientManager::instance().count() == 1)
|
if (not force and ClientManager::instance().count() == 1)
|
||||||
{
|
ensure_all_buffers_are_saved();
|
||||||
Vector<String> names;
|
|
||||||
for (auto& buffer : BufferManager::instance())
|
|
||||||
{
|
|
||||||
if ((buffer->flags() & Buffer::Flags::File) and buffer->is_modified())
|
|
||||||
names.push_back(buffer->name());
|
|
||||||
}
|
|
||||||
if (not names.empty())
|
|
||||||
{
|
|
||||||
String message = "modified buffers remaining: [";
|
|
||||||
for (auto it = names.begin(); it != names.end(); ++it)
|
|
||||||
{
|
|
||||||
if (it != names.begin())
|
|
||||||
message += ", ";
|
|
||||||
message += *it;
|
|
||||||
}
|
|
||||||
message += "]";
|
|
||||||
throw runtime_error(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// unwind back to this client event handler.
|
// unwind back to this client event handler.
|
||||||
throw client_removed{ true };
|
throw client_removed{ true };
|
||||||
}
|
}
|
||||||
|
@ -1872,8 +1890,9 @@ void register_commands()
|
||||||
register_command(write_cmd);
|
register_command(write_cmd);
|
||||||
register_command(writeall_cmd);
|
register_command(writeall_cmd);
|
||||||
register_command(writeall_quit_cmd);
|
register_command(writeall_quit_cmd);
|
||||||
register_command(quit_cmd);
|
|
||||||
register_command(kill_cmd);
|
register_command(kill_cmd);
|
||||||
|
register_command(force_kill_cmd);
|
||||||
|
register_command(quit_cmd);
|
||||||
register_command(force_quit_cmd);
|
register_command(force_quit_cmd);
|
||||||
register_command(write_quit_cmd);
|
register_command(write_quit_cmd);
|
||||||
register_command(force_write_quit_cmd);
|
register_command(force_write_quit_cmd);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user