diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-14 14:06:07 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-03 13:22:14 +0200 |
| commit | 8bb3dd7817c0e3b7d9c621ea86925a08a90cf1d1 (patch) | |
| tree | 8477c1b9ee47568ebdae7ef0aa17a815b47e47cf /sam.c | |
| parent | a69369cc9ca61c63f4370f29cd9c24bd07ba6e09 (diff) | |
| download | vis-8bb3dd7817c0e3b7d9c621ea86925a08a90cf1d1.tar.gz vis-8bb3dd7817c0e3b7d9c621ea86925a08a90cf1d1.tar.xz | |
sam: fix negative relative line number placement
This should fix -0+,+0-
Diffstat (limited to 'sam.c')
| -rw-r--r-- | sam.c | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -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) { |
