aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-10 13:52:47 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-10 13:52:47 +0200
commitc419009f28dc89d8a556b1196de644a3536769e9 (patch)
tree58bd3561b1965f2af588a612d54f6cd515836331
parenta6e301c3c4e52cab0ca042af5934cfba3c76a9c0 (diff)
downloadvis-c419009f28dc89d8a556b1196de644a3536769e9.tar.gz
vis-c419009f28dc89d8a556b1196de644a3536769e9.tar.xz
Fix :q command
-rw-r--r--editor.c14
-rw-r--r--editor.h1
-rw-r--r--vis.c27
3 files changed, 24 insertions, 18 deletions
diff --git a/editor.c b/editor.c
index c2aa585..97d6fa9 100644
--- a/editor.c
+++ b/editor.c
@@ -214,12 +214,14 @@ static void editor_window_draw(EditorWin *win) {
void editor_draw(Editor *ed) {
erase();
- ed->windows_arrange(ed);
- for (EditorWin *win = ed->windows; win; win = win->next) {
- if (ed->win != win)
- editor_window_draw(win);
+ if (ed->windows) {
+ ed->windows_arrange(ed);
+ for (EditorWin *win = ed->windows; win; win = win->next) {
+ if (ed->win != win)
+ editor_window_draw(win);
+ }
+ editor_window_draw(ed->win);
}
- editor_window_draw(ed->win);
wnoutrefresh(stdscr);
}
@@ -319,6 +321,7 @@ void editor_window_close(Editor *ed) {
ed->win = win->next ? win->next : win->prev;
editor_window_detach(ed, win);
editor_window_free(ed, win);
+ editor_draw(ed);
}
Editor *editor_new(int width, int height) {
@@ -332,7 +335,6 @@ Editor *editor_new(int width, int height) {
ed->width = width;
ed->height = height;
ed->windows_arrange = editor_windows_arrange_horizontal;
- ed->running = true;
return ed;
err:
editor_free(ed);
diff --git a/editor.h b/editor.h
index 2f47b52..2efa7c5 100644
--- a/editor.h
+++ b/editor.h
@@ -98,7 +98,6 @@ struct Editor {
Regex *search_pattern; /* last used search pattern */
void (*windows_arrange)(Editor*); /* current layout which places the windows */
void (*statusbar)(EditorWin*); /* configurable user hook to draw statusbar */
- bool running; /* (TODO move elsewhere?) */
};
Editor *editor_new(int width, int height);
diff --git a/vis.c b/vis.c
index 1e97392..4150fae 100644
--- a/vis.c
+++ b/vis.c
@@ -133,11 +133,12 @@ typedef struct { /* command definitions for the ':'-prom
} Command;
/** global variables */
-static Editor *vis; /* global editor instance, keeps track of all windows etc. */
-static Mode *mode; /* currently active mode, used to search for keybindings */
-static Mode *mode_prev; /* mode which was active previously */
-static Action action; /* current action which is in progress */
-static Action action_prev; /* last operator action used by the repeat '.' key */
+static bool running = true; /* exit main loop once this becomes false */
+static Editor *vis; /* global editor instance, keeps track of all windows etc. */
+static Mode *mode; /* currently active mode, used to search for keybindings */
+static Mode *mode_prev; /* mode which was active previously */
+static Action action; /* current action which is in progress */
+static Action action_prev; /* last operator action used by the repeat '.' key */
/** operators */
static void op_change(OperatorContext *c);
@@ -625,7 +626,7 @@ static void insert_verbatim(const Arg *arg) {
}
static void quit(const Arg *arg) {
- vis->running = false;
+ running = false;
}
static void split(const Arg *arg) {
@@ -790,11 +791,15 @@ static bool cmd_open(const char *argv[]) {
static bool cmd_quit(const char *argv[]) {
bool force = strchr(argv[0], '!') != NULL;
- for (EditorWin *win = vis->windows; win; win = win->next) {
- if (text_modified(win->text) && !force)
- return false;
+ for (EditorWin *win = vis->windows; !force && win; win = win->next) {
+ if (win != vis->win && win->text == vis->win->text)
+ force = true;
}
- vis->running = false;
+ if (!force && text_modified(vis->win->text))
+ return false;
+ editor_window_close(vis);
+ if (!vis->windows)
+ running = false;
return true;
}
@@ -1028,7 +1033,7 @@ int main(int argc, char *argv[]) {
struct timeval idle = { .tv_usec = 0 }, *timeout = NULL;
Key key, key_prev, *key_mod = NULL;
- while (vis->running) {
+ while (running) {
if (screen.need_resize) {
resize_screen(&screen);
editor_resize(vis, screen.w, screen.h);