aboutsummaryrefslogtreecommitdiff
path: root/sam.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-04 10:10:22 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-04 10:10:22 +0200
commit749099c3f828a6289cb9b7a673be14f3938ab10d (patch)
treea87f87309270130828df00d16cce3654a8e764d8 /sam.c
parent56977c546f8809ab354ffb036264fa02e29c152b (diff)
downloadvis-749099c3f828a6289cb9b7a673be14f3938ab10d.tar.gz
vis-749099c3f828a6289cb9b7a673be14f3938ab10d.tar.xz
sam: fix special handling of single line numbers
If only line numbers are given (either in absolute or relative form) we treat it as motion instead of a range specifier. That is :nn moves to line nn, but does not select it. This should however not affect other range specifiers such as :n,m
Diffstat (limited to 'sam.c')
-rw-r--r--sam.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/sam.c b/sam.c
index 5d43410..c57d217 100644
--- a/sam.c
+++ b/sam.c
@@ -355,8 +355,6 @@ 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 */
@@ -914,14 +912,27 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
for (Cursor *c = view_cursors(view), *next; c; c = next) {
next = view_cursors_next(c);
Filerange sel;
+ size_t pos = view_cursors_pos(c);
if (vis->mode->visual) {
sel = view_cursors_selection_get(c);
} else if (cmd->cmd->address) {
- size_t start = view_cursors_pos(c);
- size_t end = text_char_next(txt, start);
- sel = text_range_new(start, end);
+ /* convert a single line range to a goto line motion */
+ if (!multiple_cursors && cmd->cmd->cmddef->func == cmd_print) {
+ Address *addr = cmd->cmd->address;
+ switch (addr->type) {
+ case '+':
+ case '-':
+ addr = addr->right;
+ /* fall through */
+ case 'l':
+ if (addr && addr->type == 'l' && !addr->right)
+ addr->type = 'g';
+ break;
+ }
+ }
+ sel = text_range_new(pos, text_char_next(txt, pos));
} else if (multiple_cursors) {
- sel = text_object_line(txt, view_cursors_pos(c));
+ sel = text_object_line(txt, pos);
} else {
sel = text_range_new(0, text_size(txt));
}