src: Allow :write-all to use -atomic, fix usage

It seems that when -atomic was implemented for `:write`, the usage
strings were not updated to reflect that a new flag was available.

The `write-all` command didn't benefit from the implementation of
the new flag despite also writing files - this commit fixes that.
This commit is contained in:
Frank LENORMAND 2020-02-09 17:00:54 +01:00
parent e9cf0f23f2
commit e06d61a3e0

View File

@ -503,7 +503,7 @@ void write_buffer(const ParametersParser& parser, Context& context, const ShellC
const CommandDesc write_cmd = { const CommandDesc write_cmd = {
"write", "write",
"w", "w",
"write [-sync] [<filename>]: write the current buffer to its file " "write [<switches>] [<filename>]: write the current buffer to its file "
"or to <filename> if specified", "or to <filename> if specified",
write_params, write_params,
CommandFlags::None, CommandFlags::None,
@ -515,7 +515,7 @@ const CommandDesc write_cmd = {
const CommandDesc force_write_cmd = { const CommandDesc force_write_cmd = {
"write!", "write!",
"w!", "w!",
"write! [-sync] [<filename>]: write the current buffer to its file " "write! [<switches>] [<filename>]: write the current buffer to its file "
"or to <filename> if specified, even when the file is write protected", "or to <filename> if specified, even when the file is write protected",
write_params, write_params,
CommandFlags::None, CommandFlags::None,
@ -524,7 +524,7 @@ const CommandDesc force_write_cmd = {
write_buffer<true>, write_buffer<true>,
}; };
void write_all_buffers(const Context& context, bool sync = false) void write_all_buffers(const Context& context, bool sync = false, bool atomic = false)
{ {
// Copy buffer list because hooks might be creating/deleting buffers // Copy buffer list because hooks might be creating/deleting buffers
Vector<SafePtr<Buffer>> buffers; Vector<SafePtr<Buffer>> buffers;
@ -538,9 +538,10 @@ void write_all_buffers(const Context& context, bool sync = false)
buffer->is_modified()) buffer->is_modified())
and !(buffer->flags() & Buffer::Flags::ReadOnly)) and !(buffer->flags() & Buffer::Flags::ReadOnly))
{ {
auto mode = context.options()["writemethod"].get<WriteMethod>(); auto mode = atomic ? WriteMethod::Replace : context.options()["writemethod"].get<WriteMethod>();
auto flags = sync ? WriteFlags::Sync : WriteFlags::None;
buffer->run_hook_in_own_context(Hook::BufWritePre, buffer->name(), context.name()); buffer->run_hook_in_own_context(Hook::BufWritePre, buffer->name(), context.name());
write_buffer_to_file(*buffer, buffer->name(), mode, sync ? WriteFlags::Sync : WriteFlags::None); write_buffer_to_file(*buffer, buffer->name(), mode, flags);
buffer->run_hook_in_own_context(Hook::BufWritePost, buffer->name(), context.name()); buffer->run_hook_in_own_context(Hook::BufWritePost, buffer->name(), context.name());
} }
} }
@ -549,16 +550,17 @@ void write_all_buffers(const Context& context, bool sync = false)
const CommandDesc write_all_cmd = { const CommandDesc write_all_cmd = {
"write-all", "write-all",
"wa", "wa",
"write-all [-sync]: write all changed buffers that are associated to a file", "write-all [<switches>]: write all changed buffers that are associated to a file",
ParameterDesc{ ParameterDesc{
{ { "sync", { false, "force the synchronization of the file onto the filesystem" } } }, write_params.switches,
ParameterDesc::Flags::None, 0, 0 ParameterDesc::Flags::None, 0, 0
}, },
CommandFlags::None, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, CommandCompleter{},
[](const ParametersParser& parser, Context& context, const ShellContext&){ [](const ParametersParser& parser, Context& context, const ShellContext&){
write_all_buffers(context, (bool)parser.get_switch("sync")); write_all_buffers(context,
(bool)parser.get_switch("sync"), (bool)parser.get_switch("atomic"));
} }
}; };