vis

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

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

commit b0bb9ad72ee4dd4012590b1b917fe8b9a43495e9
parent 87e92e570ed1d7e547639a40a3932bf6f6c11dcb
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Sat, 27 Sep 2014 15:59:08 +0200

Implement :bdelete

Diffstat:
MREADME | 1+
Mconfig.def.h | 1+
Mvis.c | 21+++++++++++++++++++++
3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/README b/README @@ -420,6 +420,7 @@ and their current support in vis. At the ':'-command prompt only the following commands are recognized: :nnn go to line nnn + :bdelete close all windows which display the same file as the current one :edit replace current file with a new one or reload it from disk :open open a new window :qall close all windows, exit editor diff --git a/config.def.h b/config.def.h @@ -48,6 +48,7 @@ enum { /* command recognized at the ':'-prompt. tested top to bottom, first match wins. */ static Command cmds[] = { { "^[0-9]+$", cmd_gotoline, false }, + { "^bd(elete)?!?$", cmd_bdelete, false }, { "^e(dit)?!?$", cmd_edit, false }, { "^new$", cmd_new, false }, { "^o(pen)?$", cmd_open, false }, diff --git a/vis.c b/vis.c @@ -457,6 +457,8 @@ static bool cmd_open(const char *argv[]); static bool cmd_edit(const char *argv[]); /* close the current window, if argv[0] contains a '!' discard modifications */ static bool cmd_quit(const char *argv[]); +/* close all windows which show current file. if argv[0] contains a '!' discard modifications */ +static bool cmd_bdelete(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 */ @@ -1221,6 +1223,25 @@ static bool cmd_quit(const char *argv[]) { return true; } +static bool cmd_bdelete(const char *argv[]) { + bool force = strchr(argv[0], '!') != NULL; + Text *txt = vis->win->text; + if (text_modified(txt) && !force) { + editor_info_show(vis, "No write since last change " + "(add ! to override)"); + return false; + } + for (EditorWin *next, *win = vis->windows; win; win = next) { + next = win->next; + if (win->text == txt) + editor_window_close(win); + } + + if (!vis->windows) + quit(NULL); + return true; +} + static bool cmd_qall(const char *argv[]) { bool force = strchr(argv[0], '!') != NULL; for (EditorWin *next, *win = vis->windows; win; win = next) {