vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit b60df84d8b3542ddf144d4faf49fe1e60cfb4557 parent 343b6385d1c0b984fa9792d6cafad0b63df40a21 Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 22 Mar 2017 09:27:29 +0100 vis: do not indent empty lines when right shifting with `>` The exception being when the range is a single line. Diffstat:
| M | vis-operators.c | | | 7 | +++++-- |
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/vis-operators.c b/vis-operators.c @@ -107,10 +107,13 @@ static size_t op_shift_right(Vis *vis, Text *txt, OperatorContext *c) { /* if range ends at the begin of a line, skip line break */ if (pos == c->range.end) pos = text_line_prev(txt, pos); + bool multiple_lines = text_line_prev(txt, pos) >= c->range.start; do { - prev_pos = pos = text_line_begin(txt, pos); - if (text_insert(txt, pos, tab, tablen) && pos <= c->pos) + size_t end = text_line_end(txt, pos); + prev_pos = pos = text_line_begin(txt, end); + if ((!multiple_lines || pos != end) && + text_insert(txt, pos, tab, tablen) && pos <= c->pos) newpos += tablen; pos = text_line_prev(txt, pos); } while (pos >= c->range.start && pos != prev_pos);