vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 3f3c568016d98ca50e9db66eb7079fa9b5ffc73d parent e257aae08baeecb7f09383fa2ddbc5d09c9c621e Author: Marc André Tanner <mat@brain-dump.org> Date: Mon, 14 Mar 2016 14:06:07 +0100 sam: fix negative relative line number placement This should fix -0+,+0- Diffstat:
| M | sam.c | | | 18 | +++++++++++------- |
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/sam.c b/sam.c @@ -473,18 +473,22 @@ static Command *sam_parse(Vis *vis, const char *cmd, enum SamError *err) { } static Filerange address_line_evaluate(Address *addr, File *file, Filerange *range, int sign) { + Text *txt = file->text; size_t offset = addr->number != 0 ? addr->number : 1; - size_t line; + size_t start = range->start, end = range->end, line; if (sign > 0) { - line = text_lineno_by_pos(file->text, range->end); - line = text_pos_by_lineno(file->text, line + offset); + char c; + if (end > 0 && text_byte_get(txt, end-1, &c) && c == '\n') + end--; + line = text_lineno_by_pos(txt, end); + line = text_pos_by_lineno(txt, line + offset); } else if (sign < 0) { - line = text_lineno_by_pos(file->text, range->start); - line = offset < line ? text_pos_by_lineno(file->text, line - offset) : 0; + line = text_lineno_by_pos(txt, start); + line = offset < line ? text_pos_by_lineno(txt, line - offset) : 0; } else { - line = text_pos_by_lineno(file->text, addr->number); + line = text_pos_by_lineno(txt, addr->number); } - return text_range_new(line, text_line_next(file->text, line)); + return text_range_new(line, text_line_next(txt, line)); } static Filerange address_evaluate(Address *addr, File *file, Filerange *range, int sign) {