vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 157193a0439d625f28bc2cdbf4e707874e9030dc
parent 626b15256f844e97eaf32f587ff4385a13fee88a
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 30 Dec 2016 17:06:14 +0100

sam: change write command implementation to not change argv[]

The same Command struct might be used for multiple command executions.

An example is `:X wq` which is roughly equivalent to `:wqa` in vim.

Diffstat:
Msam.c | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/sam.c b/sam.c @@ -1292,10 +1292,10 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs return false; File *file = win->file; Text *text = file->text; - bool noname = !argv[1]; - if (!argv[1]) - argv[1] = file->name ? strdup(file->name) : NULL; - if (!argv[1]) { + const char *filename = argv[1]; + if (!filename) + filename = file->name; + if (!filename) { if (file->fd == -1) { vis_info_show(vis, "Filename expected"); return false; @@ -1330,7 +1330,7 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs return true; } - if (noname && cmd->flags != '!') { + if (!argv[1] && cmd->flags != '!') { if (vis->mode->visual) { vis_info_show(vis, "WARNING: file will be reduced to active selection"); return false; @@ -1342,7 +1342,7 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs } } - for (const char **name = &argv[1]; *name; name++) { + for (const char **name = argv[1] ? &argv[1] : (const char*[]){ filename, NULL }; *name; name++) { struct stat meta; if (cmd->flags != '!' && file->stat.st_mtime && stat(*name, &meta) == 0 && file->stat.st_mtime < meta.st_mtime) {