From 907f4afb2ee7ee61cdbf01e8fa7bdfae2098dae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 1 Apr 2016 10:12:45 +0200 Subject: sam: treat single line numbers as motions not ranges That is something like :sam +5 or :sam 10 will move to the start of the selected line instead of selecting the whole line. TODO: due to the current implementation it will also affect :sam x/pattern/-10+10 --- sam.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sam.c') diff --git a/sam.c b/sam.c index e8b083b..97857b8 100644 --- a/sam.c +++ b/sam.c @@ -21,7 +21,7 @@ typedef struct Command Command; typedef struct CommandDef CommandDef; struct Address { - char type; /* # (char) l (line) / ? . $ + - , ; * */ + char type; /* # (char) l (line) g (goto line) / ? . $ + - , ; * */ Regex *regex; /* NULL denotes default for x, y, X, and Y commands */ size_t number; /* line or character number */ Address *left; /* left hand side of a compound address , ; */ @@ -235,6 +235,8 @@ static Address *address_parse_simple(Vis *vis, const char **s, enum SamError *er case '5': case '6': case '7': case '8': case '9': addr.type = 'l'; addr.number = parse_number(s); + if (!**s && !vis->mode->visual) + addr.type = 'g'; break; case '/': /* regexp forwards */ case '?': /* regexp backwards */ @@ -488,7 +490,11 @@ static Filerange address_line_evaluate(Address *addr, File *file, Filerange *ran } else { line = text_pos_by_lineno(txt, addr->number); } - return text_range_new(line, text_line_next(txt, line)); + + if (addr->type == 'g') + return text_range_new(line, line); + else + return text_range_new(line, text_line_next(txt, line)); } static Filerange address_evaluate(Address *addr, File *file, Filerange *range, int sign) { @@ -505,6 +511,7 @@ static Filerange address_evaluate(Address *addr, File *file, Filerange *range, i ret = text_range_new(addr->number, addr->number); break; case 'l': + case 'g': ret = address_line_evaluate(addr, file, range, sign); break; case '?': -- cgit v1.2.3