aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-03-14 14:06:07 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-04-03 13:22:14 +0200
commit8bb3dd7817c0e3b7d9c621ea86925a08a90cf1d1 (patch)
tree8477c1b9ee47568ebdae7ef0aa17a815b47e47cf
parenta69369cc9ca61c63f4370f29cd9c24bd07ba6e09 (diff)
downloadvis-8bb3dd7817c0e3b7d9c621ea86925a08a90cf1d1.tar.gz
vis-8bb3dd7817c0e3b7d9c621ea86925a08a90cf1d1.tar.xz
sam: fix negative relative line number placement
This should fix -0+,+0-
-rw-r--r--sam.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/sam.c b/sam.c
index a3b746a..b050cfc 100644
--- 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) {