aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-01-03 03:30:46 -0800
committerMatthias Braun <matze@braunis.de>2015-01-03 12:33:36 -0800
commitcb5a83dfd1d6c8bf417a3ad280bac0826635397d (patch)
tree4afc36a9b0009970d09a4523a8ac46e172136ba1
parent67302f89d8ae4c7960db2872b44f6ea3af8628be (diff)
downloadvis-cb5a83dfd1d6c8bf417a3ad280bac0826635397d.tar.gz
vis-cb5a83dfd1d6c8bf417a3ad280bac0826635397d.tar.xz
Add the :x(it)? command
-rw-r--r--config.def.h1
-rw-r--r--vis.c11
2 files changed, 12 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index 361610c..cfd1771 100644
--- a/config.def.h
+++ b/config.def.h
@@ -63,6 +63,7 @@ static Command cmds[] = {
{ "^v(split)?$", cmd_vsplit, false },
{ "^wq!?$", cmd_wq, false },
{ "^w(rite)?$", cmd_write, false },
+ { "^x(it)?!?$", cmd_xit, false },
{ /* array terminator */ },
};
diff --git a/vis.c b/vis.c
index 7ccfa22..8504946 100644
--- a/vis.c
+++ b/vis.c
@@ -509,6 +509,8 @@ static bool cmd_new(Filerange*, const char *argv[]);
static bool cmd_vnew(Filerange*, const char *argv[]);
/* save the file displayed in the current window and close it */
static bool cmd_wq(Filerange*, const char *argv[]);
+/* save the file displayed in the current window if it was changed, then close the window */
+static bool cmd_xit(Filerange*, const char *argv[]);
/* 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 */
@@ -1380,6 +1382,15 @@ static bool cmd_quit(Filerange *range, const char *argv[]) {
return true;
}
+static bool cmd_xit(Filerange *range, const char *argv[]) {
+ if (text_modified(vis->win->text) && !cmd_write(range, argv)) {
+ bool force = strchr(argv[0], '!') != NULL;
+ if (!force)
+ return false;
+ }
+ return cmd_quit(range, argv);
+}
+
static bool cmd_bdelete(Filerange *range, const char *argv[]) {
bool force = strchr(argv[0], '!') != NULL;
Text *txt = vis->win->text;