vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit f935c18bb274a94d105e17fcb45f5a0909b1fe3b parent 884fe4a8a1a5aa75c5ef68296d4cabf89880c2eb Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 14 Jan 2016 20:46:49 +0100 vis: inline expand_tab Diffstat:
| M | vis-operators.c | | | 6 | ++++-- |
| M | vis.c | | | 11 | ----------- |
2 files changed, 4 insertions(+), 13 deletions(-)
diff --git a/vis-operators.c b/vis-operators.c @@ -82,9 +82,11 @@ static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) { } static size_t op_shift_right(Vis *vis, Text *txt, OperatorContext *c) { - size_t pos = text_line_begin(txt, c->range.end), prev_pos; - const char *tab = expandtab(vis); + char spaces[9] = " "; + spaces[MIN(vis->tabwidth, LENGTH(spaces) - 1)] = '\0'; + const char *tab = vis->expandtab ? spaces : "\t"; size_t tablen = strlen(tab); + size_t pos = text_line_begin(txt, c->range.end), prev_pos; /* if range ends at the begin of a line, skip line break */ if (pos == c->range.end) diff --git a/vis.c b/vis.c @@ -46,17 +46,6 @@ static Macro *macro_get(Vis *vis, enum VisMacro m); static void macro_replay(Vis *vis, const Macro *macro); -const char *expandtab(Vis *vis) { - static char spaces[9]; - int tabwidth = vis->tabwidth; - tabwidth = MIN(tabwidth, LENGTH(spaces) - 1); - for (int i = 0; i < tabwidth; i++) - spaces[i] = ' '; - spaces[tabwidth] = '\0'; - return vis->expandtab ? spaces : "\t"; -} - - /** window / file handling */ static void file_free(Vis *vis, File *file) {