From 4c0d935f7ac9675f3d2fb444b48084b44efc583f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 24 Sep 2014 08:25:01 +0200 Subject: Implement :saveas command --- vis.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'vis.c') 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) { -- cgit v1.2.3