aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2020-01-28 11:36:40 +0100
committerMarc André Tanner <mat@brain-dump.org>2020-01-28 11:44:26 +0100
commit91d49a0dd0feac1a97b63091ce7f6f32e619fff8 (patch)
tree6d5dfb262da796a7b97f4393b33fff9a189365fb
parentef74b81681de576881fe7533b851332d4660d967 (diff)
downloadvis-91d49a0dd0feac1a97b63091ce7f6f32e619fff8.tar.gz
vis-91d49a0dd0feac1a97b63091ce7f6f32e619fff8.tar.xz
vis: support an optional exit status in :q and :qall commands
This can for example be used to abort git commit messages with :q! 1.
-rw-r--r--man/vis.16
-rw-r--r--sam.c4
-rw-r--r--vis-cmds.c6
3 files changed, 8 insertions, 8 deletions
diff --git a/man/vis.1 b/man/vis.1
index 0b77656..7cb1aa9 100644
--- a/man/vis.1
+++ b/man/vis.1
@@ -1206,11 +1206,11 @@ split window horizontally
.It Ic :vsplit Op Ar file name
split window vertically
.
-.It Ic :q Ns Op Cm "!"
+.It Ic :q Ns Oo Cm "!" Oc Op Ar exit code
close currently focused window
.
-.It Ic :qall Ns Op Cm "!"
-close all windows, exit editor
+.It Ic :qall Ns Oo Cm "!" Oc Op Ar exit code
+close all windows, terminate editor with exit code (defaults to 0)
.El
.Pp
Commands taking a file name will invoke the
diff --git a/sam.c b/sam.c
index 16f811c..11d245b 100644
--- a/sam.c
+++ b/sam.c
@@ -209,7 +209,7 @@ static const CommandDef cmds[] = {
CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_edit
}, {
"q", VIS_HELP("Quit the current window")
- CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_quit
+ CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_quit
}, {
"cd", VIS_HELP("Change directory")
CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_cd
@@ -241,7 +241,7 @@ static const CommandDef cmds[] = {
CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_open
}, {
"qall", VIS_HELP("Exit vis")
- CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_qall
+ CMD_ARGV|CMD_FORCE|CMD_ONCE|CMD_ADDRESS_NONE|CMD_DESTRUCTIVE, NULL, cmd_qall
}, {
"set", VIS_HELP("Set option")
CMD_ARGV|CMD_ONCE|CMD_ADDRESS_NONE, NULL, cmd_set
diff --git a/vis-cmds.c b/vis-cmds.c
index eb56eb2..960013c 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -506,7 +506,7 @@ static bool cmd_quit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selec
}
vis_window_close(win);
if (!has_windows(vis))
- vis_exit(vis, EXIT_SUCCESS);
+ vis_exit(vis, argv[1] ? atoi(argv[1]) : EXIT_SUCCESS);
return true;
}
@@ -517,7 +517,7 @@ static bool cmd_qall(Vis *vis, Win *win, Command *cmd, const char *argv[], Selec
vis_window_close(win);
}
if (!has_windows(vis)) {
- vis_exit(vis, EXIT_SUCCESS);
+ vis_exit(vis, argv[1] ? atoi(argv[1]) : EXIT_SUCCESS);
return true;
} else {
info_unsaved_changes(vis);
@@ -567,7 +567,7 @@ static bool cmd_wq(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti
File *file = win->file;
bool unmodified = file->fd == -1 && !file->name && !text_modified(file->text);
if (unmodified || cmd_write(vis, win, cmd, argv, sel, range))
- return cmd_quit(vis, win, cmd, argv, sel, range);
+ return cmd_quit(vis, win, cmd, (const char*[]){argv[0], NULL}, sel, range);
return false;
}