vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 464221817ac1a52b5fceb5ddc48d9ceb3eaaf47f parent 5a7de1943e12a6193e554f5aecb216e1a03abf38 Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 15 Apr 2016 16:39:09 +0200 vis: calculate auto indent for all cursors individually Diffstat:
| M | vis.c | | | 15 | +++++++++------ |
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/vis.c b/vis.c @@ -1111,10 +1111,9 @@ void vis_insert_tab(Vis *vis) { } } -static void copy_indent_from_previous_line(Win *win) { - View *view = win->view; +static void copy_indent_from_previous_line(Win *win, Cursor *cur) { Text *text = win->file->text; - size_t pos = view_cursor_get(view); + size_t pos = view_cursors_pos(cur); size_t prev_line = text_line_prev(text, pos); if (pos == prev_line) return; @@ -1125,7 +1124,8 @@ static void copy_indent_from_previous_line(Win *win) { if (!buf) return; len = text_bytes_get(text, begin, len, buf); - vis_insert_key(win->vis, buf, len); + text_insert(text, pos, buf, len); + view_cursors_scroll_to(cur, pos + len); free(buf); } @@ -1133,8 +1133,11 @@ void vis_insert_nl(Vis *vis) { const char *nl = text_newline_char(vis->win->file->text); vis_insert_key(vis, nl, strlen(nl)); - if (vis->autoindent) - copy_indent_from_previous_line(vis->win); + if (!vis->autoindent) + return; + + for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) + copy_indent_from_previous_line(vis->win, c); } Regex *vis_regex(Vis *vis, const char *pattern) {