vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 2f59a5d62d62071293686bd61ff56cbfff28d5a6 parent 0fd391c4d3966ab1f559fe632ccc8f6ca244f31a Author: Marc André Tanner <mat@brain-dump.org> Date: Mon, 4 Apr 2016 10:10:22 +0200 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:
| M | sam.c | | | 23 | +++++++++++++++++------ |
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git 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)); }