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 /vis-motions.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 'vis-motions.c')
| -rw-r--r-- | vis-motions.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/vis-motions.c b/vis-motions.c index 3278546..91224b5 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -194,6 +194,13 @@ static size_t bracket_match(Text *txt, size_t pos) { return pos; } +static size_t percent(Vis *vis, Text *txt, size_t pos) { + int ratio = vis_count_get_default(vis, 0); + if (ratio > 100) + ratio = 100; + return text_size(txt) * ratio / 100; +} + void vis_motion_type(Vis *vis, enum VisMotionType type) { vis->action.type = type; } @@ -342,5 +349,6 @@ Movement vis_motions[] = { [VIS_MOVE_JUMPLIST_NEXT] = { .win = window_jumplist_next, .type = INCLUSIVE }, [VIS_MOVE_JUMPLIST_PREV] = { .win = window_jumplist_prev, .type = INCLUSIVE }, [VIS_MOVE_NOP] = { .win = window_nop, .type = IDEMPOTENT }, + [VIS_MOVE_PERCENT] = { .vis = percent, .type = IDEMPOTENT }, }; |
