diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-04-04 09:22:26 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-04-04 09:31:49 +0200 |
| commit | ca0b1fe1a590aa640fb20fcdfde3aeed3a0eac03 (patch) | |
| tree | 3ed66754cf50cc2c38a93179f61e397f67778bb1 | |
| parent | dd730eb1feb46e9688350b0ff401694653f90554 (diff) | |
| download | vis-ca0b1fe1a590aa640fb20fcdfde3aeed3a0eac03.tar.gz vis-ca0b1fe1a590aa640fb20fcdfde3aeed3a0eac03.tar.xz | |
vis: add motions to move by codepoints
Some people might prefer this for <Backspace> behavior. Except for that
and debugging purposes using `ga` and `g8` it is not yet that useful.
| -rw-r--r-- | config.def.h | 6 | ||||
| -rw-r--r-- | main.c | 12 | ||||
| -rw-r--r-- | text-motions.c | 12 | ||||
| -rw-r--r-- | text-motions.h | 3 | ||||
| -rw-r--r-- | vis-motions.c | 8 | ||||
| -rw-r--r-- | vis.h | 2 |
6 files changed, 41 insertions, 2 deletions
diff --git a/config.def.h b/config.def.h index 1fba42a..ffc9577 100644 --- a/config.def.h +++ b/config.def.h @@ -62,8 +62,10 @@ static const KeyBinding bindings_motions[] = { { "F", ACTION(TO_LEFT) }, { "f", ACTION(TO_RIGHT) }, { "go", ACTION(CURSOR_BYTE) }, - { "gh", ACTION(CURSOR_BYTE_LEFT) }, - { "gl", ACTION(CURSOR_BYTE_RIGHT) }, + { "gH", ACTION(CURSOR_BYTE_LEFT) }, + { "gL", ACTION(CURSOR_BYTE_RIGHT) }, + { "gh", ACTION(CURSOR_CODEPOINT_PREV) }, + { "gl", ACTION(CURSOR_CODEPOINT_NEXT) }, { "g0", ACTION(CURSOR_SCREEN_LINE_BEGIN) }, { "g_", ACTION(CURSOR_LINE_FINISH) }, { "G", ACTION(CURSOR_LINE_LAST) }, @@ -134,6 +134,8 @@ enum { VIS_ACTION_CURSOR_CHAR_NEXT, VIS_ACTION_CURSOR_LINE_CHAR_PREV, VIS_ACTION_CURSOR_LINE_CHAR_NEXT, + VIS_ACTION_CURSOR_CODEPOINT_PREV, + VIS_ACTION_CURSOR_CODEPOINT_NEXT, VIS_ACTION_CURSOR_WORD_START_PREV, VIS_ACTION_CURSOR_WORD_START_NEXT, VIS_ACTION_CURSOR_WORD_END_PREV, @@ -332,6 +334,16 @@ static const KeyAction vis_action[] = { VIS_HELP("Move cursor right, to the next character on the same line") movement, { .i = VIS_MOVE_LINE_CHAR_NEXT } }, + [VIS_ACTION_CURSOR_CODEPOINT_PREV] = { + "vis-motion-codepoint-prev", + VIS_HELP("Move to the previous Unicode codepoint") + movement, { .i = VIS_MOVE_CODEPOINT_PREV } + }, + [VIS_ACTION_CURSOR_CODEPOINT_NEXT] = { + "vis-motion-codepoint-next", + VIS_HELP("Move to the next Unicode codepoint") + movement, { .i = VIS_MOVE_CODEPOINT_NEXT } + }, [VIS_ACTION_CURSOR_WORD_START_PREV] = { "vis-motion-word-start-prev", VIS_HELP("Move cursor words backwards") diff --git a/text-motions.c b/text-motions.c index ee8220e..210e1f4 100644 --- a/text-motions.c +++ b/text-motions.c @@ -39,6 +39,18 @@ size_t text_char_prev(Text *txt, size_t pos) { return it.pos; } +size_t text_codepoint_next(Text *txt, size_t pos) { + Iterator it = text_iterator_get(txt, pos); + text_iterator_codepoint_next(&it, NULL); + return it.pos; +} + +size_t text_codepoint_prev(Text *txt, size_t pos) { + Iterator it = text_iterator_get(txt, pos); + text_iterator_codepoint_prev(&it, NULL); + return it.pos; +} + static size_t find_next(Text *txt, size_t pos, const char *s, bool line) { if (!s) return pos; diff --git a/text-motions.h b/text-motions.h index cca84c1..5df4e32 100644 --- a/text-motions.h +++ b/text-motions.h @@ -16,6 +16,9 @@ size_t text_end(Text*, size_t pos); size_t text_char_next(Text*, size_t pos); size_t text_char_prev(Text*, size_t pos); +size_t text_codepoint_next(Text*, size_t pos); +size_t text_codepoint_prev(Text*, size_t pos); + /* find the given substring either in forward or backward direction. * does not wrap around at file start / end. if no match is found return * original position */ diff --git a/vis-motions.c b/vis-motions.c index 1ceb958..0166117 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -491,6 +491,14 @@ const Movement vis_motions[] = { .txt = text_line_char_next, .type = CHARWISE, }, + [VIS_MOVE_CODEPOINT_PREV] = { + .txt = text_codepoint_prev, + .type = CHARWISE, + }, + [VIS_MOVE_CODEPOINT_NEXT] = { + .txt = text_codepoint_next, + .type = CHARWISE, + }, [VIS_MOVE_WORD_NEXT] = { .vis = word_next, .type = CHARWISE|IDEMPOTENT, @@ -269,6 +269,8 @@ enum VisMotion { VIS_MOVE_CHAR_NEXT, VIS_MOVE_LINE_CHAR_PREV, VIS_MOVE_LINE_CHAR_NEXT, + VIS_MOVE_CODEPOINT_PREV, + VIS_MOVE_CODEPOINT_NEXT, VIS_MOVE_WORD_NEXT, VIS_MOVE_WORD_START_NEXT, VIS_MOVE_WORD_END_PREV, |
