aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-24 08:25:01 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-24 08:25:01 +0200
commit4c0d935f7ac9675f3d2fb444b48084b44efc583f (patch)
treedbeb26e0337f26efb1b7d483dee7893043d2a506 /vis.c
parent1693856c4f6449fdf747ea822b9691954c9ed9a7 (diff)
downloadvis-4c0d935f7ac9675f3d2fb444b48084b44efc583f.tar.gz
vis-4c0d935f7ac9675f3d2fb444b48084b44efc583f.tar.xz
Implement :saveas command
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/vis.c b/vis.c
index 0a5cf8e..d444377 100644
--- a/vis.c
+++ b/vis.c
@@ -438,8 +438,14 @@ static bool cmd_split(const char *argv[]);
static bool cmd_vsplit(const char *argv[]);
/* save the file displayed in the current window and close it */
static bool cmd_wq(const char *argv[]);
-/* save the file displayed in the current window to the name given */
+/* save the file displayed in the current window to the name given.
+ * do not change internal filname association. further :w commands
+ * without arguments will still write to the old filename */
static bool cmd_write(const char *argv[]);
+/* save the file displayed in the current window to the name given,
+ * associate the new name with the buffer. further :w commands
+ * without arguments will write to the new filename */
+static bool cmd_saveas(const char *argv[]);
static void action_reset(Action *a);
static void switchmode_to(Mode *new_mode);
@@ -1204,6 +1210,10 @@ static bool cmd_write(const char *argv[]) {
Text *text = vis->win->text;
if (!argv[1])
argv[1] = text_filename_get(text);
+ if (!argv[1]) {
+ editor_info_show(vis, "Filename expected");
+ return false;
+ }
for (const char **file = &argv[1]; *file; file++) {
if (text_save(text, *file)) {
editor_info_show(vis, "Can't write `%s'", *file);
@@ -1213,6 +1223,14 @@ static bool cmd_write(const char *argv[]) {
return true;
}
+static bool cmd_saveas(const char *argv[]) {
+ if (cmd_write(argv)) {
+ text_filename_set(vis->win->text, argv[1]);
+ return true;
+ }
+ return false;
+}
+
static bool exec_command(char *cmdline) {
static bool init = false;
if (!init) {