vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 35daacfef99180260f71ee99160db17e92ef601d parent 0aeb170c0770db38ced8abc3405b3c79dd2b9ace Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 13 Jan 2016 11:59:05 +0100 vis: fix tab expansion if enabled Closes #144 Diffstat:
| M | vis.c | | | 19 | +++++++++++++++++-- |
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/vis.c b/vis.c @@ -1218,8 +1218,23 @@ const char *vis_mode_status(Vis *vis) { } void vis_insert_tab(Vis *vis) { - const char *tab = expandtab(vis); - vis_insert_key(vis, tab, strlen(tab)); + if (!vis->expandtab) { + vis_insert_key(vis, "\t", 1); + return; + } + char spaces[9]; + int tabwidth = MIN(vis->tabwidth, LENGTH(spaces) - 1); + for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) { + size_t pos = view_cursors_pos(c); + /* FIXME: this does not take double width characters into account */ + int chars = text_line_char_get(vis->win->file->text, pos); + int count = tabwidth - (chars % tabwidth); + for (int i = 0; i < count; i++) + spaces[i] = ' '; + spaces[count] = '\0'; + vis_insert(vis, pos, spaces, count); + view_cursors_scroll_to(c, pos + count); + } } static void copy_indent_from_previous_line(Win *win) {