From a649cfb83e65cb88111527b6fe92e92ecc38a71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 28 Jan 2016 16:30:44 +0100 Subject: vis: implement nn% Moves to the given percentage of the file in bytes (not lines). This is useful when dealing with huge files because it is a constant time operation. Performance could still be improved by adapting the display code not to rely on line numbers at all. --- main.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index f9fea56..dab27ea 100644 --- a/main.c +++ b/main.c @@ -107,6 +107,8 @@ static const char *call(Vis*, const char *keys, const Arg *arg); static const char *window(Vis*, const char *keys, const Arg *arg); /* show info about Unicode character at cursor position */ static const char *unicode_info(Vis*, const char *keys, const Arg *arg); +/* either go to count % of ile or to matching item */ +static const char *percent(Vis*, const char *keys, const Arg *arg); enum { VIS_ACTION_EDITOR_SUSPEND, @@ -132,7 +134,7 @@ enum { VIS_ACTION_CURSOR_SCREEN_LINE_BEGIN, VIS_ACTION_CURSOR_SCREEN_LINE_MIDDLE, VIS_ACTION_CURSOR_SCREEN_LINE_END, - VIS_ACTION_CURSOR_BRACKET_MATCH, + VIS_ACTION_CURSOR_PERCENT, VIS_ACTION_CURSOR_PARAGRAPH_PREV, VIS_ACTION_CURSOR_PARAGRAPH_NEXT, VIS_ACTION_CURSOR_SENTENCE_PREV, @@ -385,10 +387,10 @@ static KeyAction vis_action[] = { "Move cursor to end of screen/display line", movement, { .i = VIS_MOVE_SCREEN_LINE_END } }, - [VIS_ACTION_CURSOR_BRACKET_MATCH] = { - "cursor-match-bracket", - "Match corresponding symbol if cursor is on a bracket character", - movement, { .i = VIS_MOVE_BRACKET_MATCH } + [VIS_ACTION_CURSOR_PERCENT] = { + "cursor-percent", + "Move to count % of file or matching item", + percent }, [VIS_ACTION_CURSOR_PARAGRAPH_PREV] = { "cursor-paragraph-prev", @@ -1602,6 +1604,14 @@ static const char *unicode_info(Vis *vis, const char *keys, const Arg *arg) { return keys; } +static const char *percent(Vis *vis, const char *keys, const Arg *arg) { + if (vis_count_get(vis) == VIS_COUNT_UNKNOWN) + vis_motion(vis, VIS_MOVE_BRACKET_MATCH); + else + vis_motion(vis, VIS_MOVE_PERCENT); + return keys; +} + static Vis *vis; static void signal_handler(int signum, siginfo_t *siginfo, void *context) { -- cgit v1.2.3