diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-01 10:12:45 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-03 13:22:14 +0200 |
| commit | 907f4afb2ee7ee61cdbf01e8fa7bdfae2098dae2 (patch) | |
| tree | 88c4aae952c9c83e67d63bfeb32c4a63eac117c4 | |
| parent | c8e7be3107f39c32cf503db45a73b165659406c8 (diff) | |
| download | vis-907f4afb2ee7ee61cdbf01e8fa7bdfae2098dae2.tar.gz vis-907f4afb2ee7ee61cdbf01e8fa7bdfae2098dae2.tar.xz | |
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
| -rw-r--r-- | sam.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -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 '?': |
