diff options
| author | Maxime Coste <mawww@kakoune.org> | 2020-02-15 18:34:18 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2020-02-15 18:34:18 +1100 |
| commit | df4f71aaed0ef7a9dcba6e80201d94f2fe3c1615 (patch) | |
| tree | 741e6309f473bcd2ee1a4607a95fb23a9c7b9381 /src | |
| parent | 940b1b617521860130fd83c895bd4ab352f86d44 (diff) | |
| parent | e06d61a3e01fcf86d28ccb81ec65b229a1ee7e99 (diff) | |
Merge remote-tracking branch 'lenormf/fix-write-switches'
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/commands.cc b/src/commands.cc index 21ee4d0b..3b0d29ee 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -503,7 +503,7 @@ void write_buffer(const ParametersParser& parser, Context& context, const ShellC const CommandDesc write_cmd = { "write", "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", write_params, CommandFlags::None, @@ -515,7 +515,7 @@ const CommandDesc write_cmd = { const CommandDesc force_write_cmd = { "write!", "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", write_params, CommandFlags::None, @@ -524,7 +524,7 @@ const CommandDesc force_write_cmd = { 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 Vector<SafePtr<Buffer>> buffers; @@ -538,9 +538,10 @@ void write_all_buffers(const Context& context, bool sync = false) buffer->is_modified()) 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()); - 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()); } } @@ -549,16 +550,17 @@ void write_all_buffers(const Context& context, bool sync = false) const CommandDesc write_all_cmd = { "write-all", "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{ - { { "sync", { false, "force the synchronization of the file onto the filesystem" } } }, + write_params.switches, ParameterDesc::Flags::None, 0, 0 }, CommandFlags::None, CommandHelper{}, CommandCompleter{}, [](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")); } }; |
