vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit d8e6a73f75255d6aeb36ed0c0e8d5ea9e5617f1c parent c57cd88854797a518e9a0dd5a140c1f95de60074 Author: Marc André Tanner <mat@brain-dump.org> Date: Tue, 9 Sep 2014 10:44:56 +0200 Detect whether a file is already opened when splitting a window Diffstat:
| M | vis.c | | | 16 | +++++++++++++--- |
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/vis.c b/vis.c @@ -78,13 +78,23 @@ static void vis_windows_arrange_vertical(Vis *vis) { static void vis_window_split_internal(Vis *vis, const char *filename) { VisWin *sel = vis->win; if (filename) { - // TODO check that this file isn't already open - vis_window_new(vis, filename); - } else if (sel) { + // TODO? move this to vis_window_new + sel = NULL; + for (VisWin *w = vis->windows; w; w = w->next) { + const char *f = text_filename(w->text); + if (f && strcmp(f, filename) == 0) { + sel = w; + break; + } + } + } + if (sel) { VisWin *win = vis_window_new_text(vis, sel->text); win->text = sel->text; window_syntax_set(win->win, window_syntax_get(sel->win)); window_cursor_to(win->win, window_cursor_get(sel->win)); + } else { + vis_window_new(vis, filename); } }