diff options
| author | Rob Pilling <robpilling@gmail.com> | 2016-04-12 22:56:29 +0100 |
|---|---|---|
| committer | Rob Pilling <robpilling@gmail.com> | 2016-04-12 22:56:29 +0100 |
| commit | 255da074c15de15d45eb1582c819d68ee480800d (patch) | |
| tree | 339ae9529e55a2a71b5c66d79fda08ff3c533c25 /text-motions.c | |
| parent | 3939baaac101cea08c711638dfd537f4a039d0ae (diff) | |
| download | vis-255da074c15de15d45eb1582c819d68ee480800d.tar.gz vis-255da074c15de15d45eb1582c819d68ee480800d.tar.xz | |
Add "[{" and "]}" motions to jump to a block's start/end
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/text-motions.c b/text-motions.c index 0ad8e81..e948fae 100644 --- a/text-motions.c +++ b/text-motions.c @@ -6,6 +6,7 @@ #include "text-motions.h" #include "text-util.h" #include "util.h" +#include "text-objects.h" #define space(c) (isspace((unsigned char)c)) #define boundary(c) (isboundary((unsigned char)c)) @@ -586,6 +587,31 @@ size_t text_function_end_prev(Text *txt, size_t pos) { return text_function_end_direction(txt, pos, -1); } +static size_t text_paren_start_end(Text *txt, size_t pos, int direction, Filerange (*rangefn)(Text *, size_t)) { + /* don't select (as a text obj) a bracket we're currently on */ + size_t offbracketpos = pos + direction; + + Filerange r = rangefn(txt, offbracketpos); + if (!text_range_valid(&r)) + return pos; + + /* we want the outer text object */ + r.start += direction; + r.end -= direction; + if (!text_range_valid(&r)) + return pos; + + return direction < 0 ? r.start : r.end; +} + +size_t text_block_start(Text *txt, size_t pos) { + return text_paren_start_end(txt, pos, -1, text_object_curly_bracket); +} + +size_t text_block_end(Text *txt, size_t pos) { + return text_paren_start_end(txt, pos, +1, text_object_curly_bracket); +} + size_t text_bracket_match(Text *txt, size_t pos) { return text_bracket_match_symbol(txt, pos, NULL); } |
