aboutsummaryrefslogtreecommitdiff
path: root/sam.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-12-14 13:37:47 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-12-14 14:44:49 +0100
commitb531213d198405ba0ff1a2982d8b258fb10d7697 (patch)
tree3bc3456b7fe4ddb9a66605e9c15a17457e7ec97f /sam.c
parente80d859867e515d95492e61bf5dca08a1c325130 (diff)
downloadvis-b531213d198405ba0ff1a2982d8b258fb10d7697.tar.gz
vis-b531213d198405ba0ff1a2982d8b258fb10d7697.tar.xz
vis: add new :set savemethod auto|atomic|inplace option
Specifies how the current file should be saved, `atomic` which uses rename(2) to atomically replace the file, `inplace` which truncates the file and then rewrites it or `auto` which tries the former before falling back to the latter. The rename method fails for symlinks, hardlinks, in case of insufficient directory permissions or when either the file owner, group, POSIX ACL or SELinux labels can not be restored. The option defaults to `auto`.
Diffstat (limited to 'sam.c')
-rw-r--r--sam.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/sam.c b/sam.c
index 960c670..dc4023c 100644
--- a/sam.c
+++ b/sam.c
@@ -294,6 +294,7 @@ enum {
OPTION_CURSOR_LINE,
OPTION_COLOR_COLUMN,
OPTION_HORIZON,
+ OPTION_SAVE_METHOD,
};
static const OptionDef options[] = {
@@ -372,6 +373,11 @@ static const OptionDef options[] = {
OPTION_TYPE_NUMBER, OPTION_FLAG_WINDOW,
"Number of bytes to consider for syntax highlighting",
},
+ [OPTION_SAVE_METHOD] = {
+ { "savemethod" },
+ OPTION_TYPE_STRING, OPTION_FLAG_WINDOW,
+ "Save method to use for current file 'auto', 'atomic' or 'inplace'",
+ },
};
bool sam_init(Vis *vis) {
@@ -1349,9 +1355,10 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs
return false;
}
- TextSave *ctx = text_save_begin(text, *name, TEXT_SAVE_AUTO);
+ TextSave *ctx = text_save_begin(text, *name, file->save_method);
if (!ctx) {
- vis_info_show(vis, "Can't write `%s': %s", *name, strerror(errno));
+ const char *msg = errno ? strerror(errno) : "try changing `:set savemethod`";
+ vis_info_show(vis, "Can't write `%s': %s", *name, msg);
return false;
}