diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-01-28 16:30:44 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-01-28 16:30:44 +0100 |
| commit | a649cfb83e65cb88111527b6fe92e92ecc38a71e (patch) | |
| tree | 7ff2cbf9fbc08988f8a66968bf7adffe64dd8671 /main.c | |
| parent | d0ed5fef6a4098a7991a7e6ab44076a423721212 (diff) | |
| download | vis-a649cfb83e65cb88111527b6fe92e92ecc38a71e.tar.gz vis-a649cfb83e65cb88111527b6fe92e92ecc38a71e.tar.xz | |
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.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -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) { |
