diff options
| author | Randy Palamar <randy@rnpnr.xyz> | 2025-11-23 19:09:25 -0700 |
|---|---|---|
| committer | Randy Palamar <randy@rnpnr.xyz> | 2025-11-24 05:25:51 -0700 |
| commit | 1953c287ace801a6606abd6c3ead0ff345645bec (patch) | |
| tree | edcb6793827457591d6b01dd701684e9e4ad3709 /sam.c | |
| parent | 5aaf2082445032b5c0f49346a81453074d384cb3 (diff) | |
| download | vis-1953c287ace801a6606abd6c3ead0ff345645bec.tar.gz vis-1953c287ace801a6606abd6c3ead0ff345645bec.tar.xz | |
text-io: make TextSave visible
Having a failure case on allocing a TextSave is stupid. Ideally
there would be no allocations in the file saving path but we have
to replace the braindead dirname(3) with an internal
implementation.
Diffstat (limited to 'sam.c')
| -rw-r--r-- | sam.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -1688,8 +1688,8 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Sele if (write_entire_file) *r = text_range_new(0, text_size(text)); - TextSave *ctx = text_save_begin(text, AT_FDCWD, path, file->save_method); - if (!ctx) { + TextSave ctx = text_save_default(.txt = text, .method = file->save_method, .filename = path); + if (!text_save_begin(&ctx)) { const char *msg = errno ? strerror(errno) : "try changing `:set savemethod`"; vis_info_show(vis, "Can't write `%s': %s", path, msg); goto err; @@ -1700,18 +1700,19 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Sele for (Selection *s = view_selections(&win->view); s; s = view_selections_next(s)) { Filerange range = visual ? view_selections_get(s) : *r; - ssize_t written = text_save_write_range(ctx, &range); + ssize_t written = text_save_write_range(&ctx, &range); failure = (written == -1 || (size_t)written != text_range_size(&range)); - if (failure) { - text_save_cancel(ctx); + if (failure || !visual) break; - } + } - if (!visual) - break; + if (!failure) { + failure = !text_save_commit(&ctx); + } else { + text_save_cancel(&ctx); } - if (failure || !text_save_commit(ctx)) { + if (failure) { vis_info_show(vis, "Can't write `%s': %s", path, strerror(errno)); goto err; } |
