Skip to content

Commit

Permalink
Add "[(" and "])" motions for jumping to a parenthese pair's start/end
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrippling committed Apr 12, 2016
1 parent 255da07 commit 0280cf8
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -139,6 +139,8 @@ Operators can be forced to work line wise by specifying `V`.
[] (previous end of C-like function)
[{ (previous start of block)
]} (next start of block)
[( (previous start of parenthese pair)
]) (next start of parenthese pair)
{ (previous paragraph)
( (previous sentence)
[[ (previous start of C-like function)
Expand Down
2 changes: 2 additions & 0 deletions config.def.h
Expand Up @@ -32,6 +32,8 @@ static const KeyBinding bindings_motions[] = {
{ "[[", ACTION(CURSOR_FUNCTION_START_PREV) },
{ "[{", ACTION(CURSOR_BLOCK_START) },
{ "]}", ACTION(CURSOR_BLOCK_END) },
{ "[(", ACTION(CURSOR_PARENTHESE_START) },
{ "])", ACTION(CURSOR_PARENTHESE_END) },
{ "$", ACTION(CURSOR_LINE_LASTCHAR) },
{ "^", ACTION(CURSOR_LINE_START) },
{ "}", ACTION(CURSOR_PARAGRAPH_NEXT) },
Expand Down
12 changes: 12 additions & 0 deletions main.c
Expand Up @@ -161,6 +161,8 @@ enum {
VIS_ACTION_CURSOR_FUNCTION_END_NEXT,
VIS_ACTION_CURSOR_BLOCK_START,
VIS_ACTION_CURSOR_BLOCK_END,
VIS_ACTION_CURSOR_PARENTHESE_START,
VIS_ACTION_CURSOR_PARENTHESE_END,
VIS_ACTION_CURSOR_COLUMN,
VIS_ACTION_CURSOR_LINE_FIRST,
VIS_ACTION_CURSOR_LINE_LAST,
Expand Down Expand Up @@ -477,6 +479,16 @@ static const KeyAction vis_action[] = {
"Move cursor to the closing curly brace in a block",
movement, { .i = VIS_MOVE_BLOCK_END }
},
[VIS_ACTION_CURSOR_PARENTHESE_START] = {
"cursor-parenthese-start",
"Move cursor to the opening parenthese inside a pair of parentheses",
movement, { .i = VIS_MOVE_PARENTHESE_START }
},
[VIS_ACTION_CURSOR_PARENTHESE_END] = {
"cursor-parenthese-end",
"Move cursor to the closing parenthese inside a pair of parentheses",
movement, { .i = VIS_MOVE_PARENTHESE_END }
},
[VIS_ACTION_CURSOR_COLUMN] = {
"cursor-column",
"Move cursor to given column of current line",
Expand Down
8 changes: 8 additions & 0 deletions text-motions.c
Expand Up @@ -612,6 +612,14 @@ 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_parenthese_start(Text *txt, size_t pos) {
return text_paren_start_end(txt, pos, -1, text_object_paranthese);
}

size_t text_parenthese_end(Text *txt, size_t pos) {
return text_paren_start_end(txt, pos, +1, text_object_paranthese);
}

size_t text_bracket_match(Text *txt, size_t pos) {
return text_bracket_match_symbol(txt, pos, NULL);
}
Expand Down
2 changes: 2 additions & 0 deletions text-motions.h
Expand Up @@ -114,6 +114,8 @@ size_t text_section_prev(Text*, size_t pos);
*/
size_t text_block_start(Text*, size_t pos);
size_t text_block_end(Text*, size_t pos);
size_t text_parenthese_start(Text*, size_t pos);
size_t text_parenthese_end(Text*, size_t pos);
/* search coresponding '(', ')', '{', '}', '[', ']', '>', '<', '"', ''' */
size_t text_bracket_match(Text*, size_t pos);
/* same as above but explicitly specify symbols to match */
Expand Down
2 changes: 2 additions & 0 deletions vis-motions.c
Expand Up @@ -368,6 +368,8 @@ const Movement vis_motions[] = {
[VIS_MOVE_FUNCTION_END_NEXT] = { .txt = text_function_end_next, .type = LINEWISE|JUMP },
[VIS_MOVE_BLOCK_START] = { .txt = text_block_start, .type = JUMP },
[VIS_MOVE_BLOCK_END] = { .txt = text_block_end, .type = JUMP },
[VIS_MOVE_PARENTHESE_START] = { .txt = text_parenthese_start, .type = JUMP },
[VIS_MOVE_PARENTHESE_END] = { .txt = text_parenthese_end, .type = JUMP },
[VIS_MOVE_BRACKET_MATCH] = { .txt = bracket_match, .type = INCLUSIVE|JUMP },
[VIS_MOVE_FILE_BEGIN] = { .txt = text_begin, .type = LINEWISE|JUMP },
[VIS_MOVE_FILE_END] = { .txt = text_end, .type = LINEWISE|JUMP },
Expand Down
2 changes: 2 additions & 0 deletions vis.h
Expand Up @@ -221,6 +221,8 @@ enum VisMotion {
VIS_MOVE_FUNCTION_END_NEXT,
VIS_MOVE_BLOCK_START,
VIS_MOVE_BLOCK_END,
VIS_MOVE_PARENTHESE_START,
VIS_MOVE_PARENTHESE_END,
VIS_MOVE_BRACKET_MATCH,
VIS_MOVE_LEFT_TO,
VIS_MOVE_RIGHT_TO,
Expand Down

0 comments on commit 0280cf8

Please sign in to comment.