aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h1
-rw-r--r--editor.c9
-rw-r--r--editor.h2
-rw-r--r--vis.c16
4 files changed, 22 insertions, 6 deletions
diff --git a/config.def.h b/config.def.h
index c7696ca..7b99cf5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -51,6 +51,7 @@ enum {
static Command cmds[] = {
{ "^[0-9]+", cmd_gotoline },
{ "^o(pen)?", cmd_open },
+ { "^qa(ll)?", cmd_qall },
{ "^q(quit)?", cmd_quit },
{ "^r(ead)?", cmd_read },
{ "^sp(lit)?", cmd_split },
diff --git a/editor.c b/editor.c
index 97d6fa9..a7ef802 100644
--- a/editor.c
+++ b/editor.c
@@ -316,9 +316,10 @@ static void editor_window_detach(Editor *ed, EditorWin *win) {
win->next = win->prev = NULL;
}
-void editor_window_close(Editor *ed) {
- EditorWin *win = ed->win;
- ed->win = win->next ? win->next : win->prev;
+void editor_window_close(EditorWin *win) {
+ Editor *ed = win->editor;
+ if (ed->win == win)
+ ed->win = win->next ? win->next : win->prev;
editor_window_detach(ed, win);
editor_window_free(ed, win);
editor_draw(ed);
@@ -343,7 +344,7 @@ err:
void editor_free(Editor *ed) {
while (ed->windows)
- editor_window_close(ed);
+ editor_window_close(ed->windows);
editor_prompt_free(ed->prompt);
text_regex_free(ed->search_pattern);
for (int i = 0; i < REG_LAST; i++)
diff --git a/editor.h b/editor.h
index 2efa7c5..8ca1a79 100644
--- a/editor.h
+++ b/editor.h
@@ -128,7 +128,7 @@ void editor_syntax_unload(Editor*);
/* creates a new window, and loads the given file. if filename is NULL
* an unamed / empty buffer is created */
bool editor_window_new(Editor*, const char *filename);
-void editor_window_close(Editor *vis);
+void editor_window_close(EditorWin*);
/* if filename is non NULL it is equivalent to window_new call above.
* if however filename is NULL a new window is created and linked to the
* same underlying text as the currently selected one. changes will
diff --git a/vis.c b/vis.c
index b99e1dc..8439856 100644
--- a/vis.c
+++ b/vis.c
@@ -380,6 +380,8 @@ static bool cmd_gotoline(const char *argv[]);
static bool cmd_open(const char *argv[]);
/* close the current window, if argv[0] contains a '!' discard modifications */
static bool cmd_quit(const char *argv[]);
+/* close all windows, exit editor, if argv[0] contains a '!' discard modifications */
+static bool cmd_qall(const char *argv[]);
/* for each argument try to insert the file content at current cursor postion */
static bool cmd_read(const char *argv[]);
static bool cmd_substitute(const char *argv[]);
@@ -862,12 +864,24 @@ static bool cmd_quit(const char *argv[]) {
}
if (!force && text_modified(vis->win->text))
return false;
- editor_window_close(vis);
+ editor_window_close(vis->win);
if (!vis->windows)
running = false;
return true;
}
+static bool cmd_qall(const char *argv[]) {
+ bool force = strchr(argv[0], '!') != NULL;
+ for (EditorWin *next, *win = vis->windows; win; win = next) {
+ next = win->next;
+ if (!text_modified(vis->win->text) || force)
+ editor_window_close(win);
+ }
+ if (!vis->windows)
+ running = false;
+ return vis->windows == NULL;
+}
+
static bool cmd_read(const char *argv[]) {
size_t pos = window_cursor_get(vis->win->win);
for (const char **file = &argv[1]; *file; file++) {