diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-11-07 09:23:43 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-11-07 12:16:34 +0100 |
| commit | 531a79020767081de9e75f1246172a405be45cc3 (patch) | |
| tree | 22ba222db3c88be11238d33339c4840a4d5abf4f | |
| parent | 3f3a7d42145ca869586c4b7f1d5c11aa5afe8eb9 (diff) | |
| download | vis-531a79020767081de9e75f1246172a405be45cc3.tar.gz vis-531a79020767081de9e75f1246172a405be45cc3.tar.xz | |
vis: prefix enum VisMotion values with VIS_
| -rw-r--r-- | main.c | 134 | ||||
| -rw-r--r-- | vis-core.h | 2 | ||||
| -rw-r--r-- | vis-modes.c | 2 | ||||
| -rw-r--r-- | vis-motions.c | 161 | ||||
| -rw-r--r-- | vis.c | 60 | ||||
| -rw-r--r-- | vis.h | 130 |
6 files changed, 225 insertions, 264 deletions
@@ -62,7 +62,7 @@ static const char *motiontype(Vis*, const char *keys, const Arg *arg); /* make the current action use the operator indicated by arg->i */ static const char *operator(Vis*, const char *keys, const Arg *arg); /* blocks to read a key and performs movement indicated by arg->i which - * should be one of MOVE_{RIGHT,LEFT}_{TO,TILL} */ + * should be one of VIS_MOVE_{RIGHT,LEFT}_{TO,TILL} */ static const char *movement_key(Vis*, const char *keys, const Arg *arg); /* perform the movement as indicated by arg->i */ static const char *movement(Vis*, const char *keys, const Arg *arg); @@ -273,157 +273,157 @@ static KeyAction vis_action[] = { [VIS_ACTION_CURSOR_CHAR_PREV] = { "cursor-char-prev", "Move cursor left, to the previous character", - movement, { .i = MOVE_CHAR_PREV } + movement, { .i = VIS_MOVE_CHAR_PREV } }, [VIS_ACTION_CURSOR_CHAR_NEXT] = { "cursor-char-next", "Move cursor right, to the next character", - movement, { .i = MOVE_CHAR_NEXT } + movement, { .i = VIS_MOVE_CHAR_NEXT } }, [VIS_ACTION_CURSOR_WORD_START_PREV] = { "cursor-word-start-prev", "Move cursor words backwards", - movement, { .i = MOVE_WORD_START_PREV } + movement, { .i = VIS_MOVE_WORD_START_PREV } }, [VIS_ACTION_CURSOR_WORD_START_NEXT] = { "cursor-word-start-next", "Move cursor words forwards", - movement, { .i = MOVE_WORD_START_NEXT } + movement, { .i = VIS_MOVE_WORD_START_NEXT } }, [VIS_ACTION_CURSOR_WORD_END_PREV] = { "cursor-word-end-prev", "Move cursor backwards to the end of word", - movement, { .i = MOVE_WORD_END_PREV } + movement, { .i = VIS_MOVE_WORD_END_PREV } }, [VIS_ACTION_CURSOR_WORD_END_NEXT] = { "cursor-word-end-next", "Move cursor forward to the end of word", - movement, { .i = MOVE_WORD_END_NEXT } + movement, { .i = VIS_MOVE_WORD_END_NEXT } }, [VIS_ACTION_CURSOR_LONGWORD_START_PREV] = { "cursor-longword-start-prev", "Move cursor WORDS backwards", - movement, { .i = MOVE_LONGWORD_START_PREV } + movement, { .i = VIS_MOVE_LONGWORD_START_PREV } }, [VIS_ACTION_CURSOR_LONGWORD_START_NEXT] = { "cursor-longword-start-next", "Move cursor WORDS forwards", - movement, { .i = MOVE_LONGWORD_START_NEXT } + movement, { .i = VIS_MOVE_LONGWORD_START_NEXT } }, [VIS_ACTION_CURSOR_LONGWORD_END_PREV] = { "cursor-longword-end-prev", "Move cursor backwards to the end of WORD", - movement, { .i = MOVE_LONGWORD_END_PREV } + movement, { .i = VIS_MOVE_LONGWORD_END_PREV } }, [VIS_ACTION_CURSOR_LONGWORD_END_NEXT] = { "cursor-longword-end-next", "Move cursor forward to the end of WORD", - movement, { .i = MOVE_LONGWORD_END_NEXT } + movement, { .i = VIS_MOVE_LONGWORD_END_NEXT } }, [VIS_ACTION_CURSOR_LINE_UP] = { "cursor-line-up", "Move cursor line upwards", - movement, { .i = MOVE_LINE_UP } + movement, { .i = VIS_MOVE_LINE_UP } }, [VIS_ACTION_CURSOR_LINE_DOWN] = { "cursor-line-down", "Move cursor line downwards", - movement, { .i = MOVE_LINE_DOWN } + movement, { .i = VIS_MOVE_LINE_DOWN } }, [VIS_ACTION_CURSOR_LINE_START] = { "cursor-line-start", "Move cursor to first non-blank character of the line", - movement, { .i = MOVE_LINE_START } + movement, { .i = VIS_MOVE_LINE_START } }, [VIS_ACTION_CURSOR_LINE_FINISH] = { "cursor-line-finish", "Move cursor to last non-blank character of the line", - movement, { .i = MOVE_LINE_FINISH } + movement, { .i = VIS_MOVE_LINE_FINISH } }, [VIS_ACTION_CURSOR_LINE_BEGIN] = { "cursor-line-begin", "Move cursor to first character of the line", - movement, { .i = MOVE_LINE_BEGIN } + movement, { .i = VIS_MOVE_LINE_BEGIN } }, [VIS_ACTION_CURSOR_LINE_END] = { "cursor-line-end", "Move cursor to end of the line", - movement, { .i = MOVE_LINE_LASTCHAR } + movement, { .i = VIS_MOVE_LINE_LASTCHAR } }, [VIS_ACTION_CURSOR_SCREEN_LINE_UP] = { "cursor-sceenline-up", "Move cursor screen/display line upwards", - movement, { .i = MOVE_SCREEN_LINE_UP } + movement, { .i = VIS_MOVE_SCREEN_LINE_UP } }, [VIS_ACTION_CURSOR_SCREEN_LINE_DOWN] = { "cursor-screenline-down", "Move cursor screen/display line downwards", - movement, { .i = MOVE_SCREEN_LINE_DOWN } + movement, { .i = VIS_MOVE_SCREEN_LINE_DOWN } }, [VIS_ACTION_CURSOR_SCREEN_LINE_BEGIN] = { "cursor-screenline-begin", "Move cursor to beginning of screen/display line", - movement, { .i = MOVE_SCREEN_LINE_BEGIN } + movement, { .i = VIS_MOVE_SCREEN_LINE_BEGIN } }, [VIS_ACTION_CURSOR_SCREEN_LINE_MIDDLE] = { "cursor-screenline-middle", "Move cursor to middle of screen/display line", - movement, { .i = MOVE_SCREEN_LINE_MIDDLE } + movement, { .i = VIS_MOVE_SCREEN_LINE_MIDDLE } }, [VIS_ACTION_CURSOR_SCREEN_LINE_END] = { "cursor-screenline-end", "Move cursor to end of screen/display line", - movement, { .i = MOVE_SCREEN_LINE_END } + 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 = MOVE_BRACKET_MATCH } + movement, { .i = VIS_MOVE_BRACKET_MATCH } }, [VIS_ACTION_CURSOR_PARAGRAPH_PREV] = { "cursor-paragraph-prev", "Move cursor paragraph backward", - movement, { .i = MOVE_PARAGRAPH_PREV } + movement, { .i = VIS_MOVE_PARAGRAPH_PREV } }, [VIS_ACTION_CURSOR_PARAGRAPH_NEXT] = { "cursor-paragraph-next", "Move cursor paragraph forward", - movement, { .i = MOVE_PARAGRAPH_NEXT } + movement, { .i = VIS_MOVE_PARAGRAPH_NEXT } }, [VIS_ACTION_CURSOR_SENTENCE_PREV] = { "cursor-sentence-prev", "Move cursor sentence backward", - movement, { .i = MOVE_SENTENCE_PREV } + movement, { .i = VIS_MOVE_SENTENCE_PREV } }, [VIS_ACTION_CURSOR_SENTENCE_NEXT] = { "cursor-sentence-next", "Move cursor sentence forward", - movement, { .i = MOVE_SENTENCE_NEXT } + movement, { .i = VIS_MOVE_SENTENCE_NEXT } }, [VIS_ACTION_CURSOR_FUNCTION_START_PREV] = { "cursor-function-start-prev", "Move cursor backwards to start of function", - movement, { .i = MOVE_FUNCTION_START_PREV } + movement, { .i = VIS_MOVE_FUNCTION_START_PREV } }, [VIS_ACTION_CURSOR_FUNCTION_START_NEXT] = { "cursor-function-start-next", "Move cursor forwards to start of function", - movement, { .i = MOVE_FUNCTION_START_NEXT } + movement, { .i = VIS_MOVE_FUNCTION_START_NEXT } }, [VIS_ACTION_CURSOR_FUNCTION_END_PREV] = { "cursor-function-end-prev", "Move cursor backwards to end of function", - movement, { .i = MOVE_FUNCTION_END_PREV } + movement, { .i = VIS_MOVE_FUNCTION_END_PREV } }, [VIS_ACTION_CURSOR_FUNCTION_END_NEXT] = { "cursor-function-end-next", "Move cursor forwards to end of function", - movement, { .i = MOVE_FUNCTION_END_NEXT } + movement, { .i = VIS_MOVE_FUNCTION_END_NEXT } }, [VIS_ACTION_CURSOR_COLUMN] = { "cursor-column", "Move cursor to given column of current line", - movement, { .i = MOVE_COLUMN } + movement, { .i = VIS_MOVE_COLUMN } }, [VIS_ACTION_CURSOR_LINE_FIRST] = { "cursor-line-first", @@ -438,37 +438,37 @@ static KeyAction vis_action[] = { [VIS_ACTION_CURSOR_WINDOW_LINE_TOP] = { "cursor-window-line-top", "Move cursor to top line of the window", - movement, { .i = MOVE_WINDOW_LINE_TOP } + movement, { .i = VIS_MOVE_WINDOW_LINE_TOP } }, [VIS_ACTION_CURSOR_WINDOW_LINE_MIDDLE] = { "cursor-window-line-middle", "Move cursor to middle line of the window", - movement, { .i = MOVE_WINDOW_LINE_MIDDLE } + movement, { .i = VIS_MOVE_WINDOW_LINE_MIDDLE } }, [VIS_ACTION_CURSOR_WINDOW_LINE_BOTTOM] = { "cursor-window-line-bottom", "Move cursor to bottom line of the window", - movement, { .i = MOVE_WINDOW_LINE_BOTTOM } + movement, { .i = VIS_MOVE_WINDOW_LINE_BOTTOM } }, [VIS_ACTION_CURSOR_SEARCH_NEXT] = { "cursor-search-forward", "Move cursor to bottom line of the window", - movement, { .i = MOVE_SEARCH_NEXT } + movement, { .i = VIS_MOVE_SEARCH_NEXT } }, [VIS_ACTION_CURSOR_SEARCH_PREV] = { "cursor-search-backward", "Move cursor to bottom line of the window", - movement, { .i = MOVE_SEARCH_PREV } + movement, { .i = VIS_MOVE_SEARCH_PREV } }, [VIS_ACTION_CURSOR_SEARCH_WORD_FORWARD] = { "cursor-search-word-forward", "Move cursor to next occurence of the word under cursor", - movement, { .i = MOVE_SEARCH_WORD_FORWARD } + movement, { .i = VIS_MOVE_SEARCH_WORD_FORWARD } }, [VIS_ACTION_CURSOR_SEARCH_WORD_BACKWARD] = { "cursor-search-word-backward", "Move cursor to previous occurence of the word under cursor", - movement, { .i = MOVE_SEARCH_WORD_BACKWARD } + movement, { .i = VIS_MOVE_SEARCH_WORD_BACKWARD } }, [VIS_ACTION_WINDOW_PAGE_UP] = { "window-page-up", @@ -523,42 +523,42 @@ static KeyAction vis_action[] = { [VIS_ACTION_DELETE_CHAR_PREV] = { "delete-char-prev", "Delete the previous character", - delete, { .i = MOVE_CHAR_PREV } + delete, { .i = VIS_MOVE_CHAR_PREV } }, [VIS_ACTION_DELETE_CHAR_NEXT] = { "delete-char-next", "Delete the next character", - delete, { .i = MOVE_CHAR_NEXT } + delete, { .i = VIS_MOVE_CHAR_NEXT } }, [VIS_ACTION_DELETE_LINE_BEGIN] = { "delete-line-begin", "Delete until the start of the current line", - delete, { .i = MOVE_LINE_BEGIN } + delete, { .i = VIS_MOVE_LINE_BEGIN } }, [VIS_ACTION_DELETE_WORD_PREV] = { "delete-word-prev", "Delete the previous WORD", - delete, { .i = MOVE_LONGWORD_START_PREV } + delete, { .i = VIS_MOVE_LONGWORD_START_PREV } }, [VIS_ACTION_JUMPLIST_PREV] = { "jumplist-prev", "Go to older cursor position in jump list", - movement, { .i = MOVE_JUMPLIST_PREV } + movement, { .i = VIS_MOVE_JUMPLIST_PREV } }, [VIS_ACTION_JUMPLIST_NEXT] = { "jumplist-next", "Go to newer cursor position in jump list", - movement, { .i = MOVE_JUMPLIST_NEXT } + movement, { .i = VIS_MOVE_JUMPLIST_NEXT } }, [VIS_ACTION_CHANGELIST_PREV] = { "changelist-prev", "Go to older cursor position in change list", - movement, { .i = MOVE_CHANGELIST_PREV } + movement, { .i = VIS_MOVE_CHANGELIST_PREV } }, [VIS_ACTION_CHANGELIST_NEXT] = { "changelist-next", "Go to newer cursor position in change list", - movement, { .i = MOVE_CHANGELIST_NEXT } + movement, { .i = VIS_MOVE_CHANGELIST_NEXT } }, [VIS_ACTION_UNDO] = { "editor-undo", @@ -598,12 +598,12 @@ static KeyAction vis_action[] = { [VIS_ACTION_MARK_GOTO] = { "mark-goto", "Goto the position of the given mark", - mark_motion, { .i = MOVE_MARK } + mark_motion, { .i = VIS_MOVE_MARK } }, [VIS_ACTION_MARK_GOTO_LINE] = { "mark-goto-line", "Goto first non-blank character of the line containing the given mark", - mark_motion, { .i = MOVE_MARK_LINE } + mark_motion, { .i = VIS_MOVE_MARK_LINE } }, [VIS_ACTION_REDRAW] = { "editor-redraw", @@ -618,12 +618,12 @@ static KeyAction vis_action[] = { [VIS_ACTION_TOTILL_REPEAT] = { "totill-repeat", "Repeat latest to/till motion", - movement, { .i = MOVE_TOTILL_REPEAT } + movement, { .i = VIS_MOVE_TOTILL_REPEAT } }, [VIS_ACTION_TOTILL_REVERSE] = { "totill-reverse", "Repeat latest to/till motion but in opposite direction", - movement, { .i = MOVE_TOTILL_REVERSE } + movement, { .i = VIS_MOVE_TOTILL_REVERSE } }, [VIS_ACTION_PROMPT_SEARCH_FORWARD] = { "search-forward", @@ -638,22 +638,22 @@ static KeyAction vis_action[] = { [VIS_ACTION_TILL_LEFT] = { "till-left", "Till after the occurrence of character to the left", - movement_key, { .i = MOVE_LEFT_TILL } + movement_key, { .i = VIS_MOVE_LEFT_TILL } }, [VIS_ACTION_TILL_RIGHT] = { "till-right", "Till before the occurrence of character to the right", - movement_key, { .i = MOVE_RIGHT_TILL } + movement_key, { .i = VIS_MOVE_RIGHT_TILL } }, [VIS_ACTION_TO_LEFT] = { "to-left", "To the first occurrence of character to the left", - movement_key, { .i = MOVE_LEFT_TO } + movement_key, { .i = VIS_MOVE_LEFT_TO } }, [VIS_ACTION_TO_RIGHT] = { "to-right", "To the first occurrence of character to the right", - movement_key, { .i = MOVE_RIGHT_TO } + movement_key, { .i = VIS_MOVE_RIGHT_TO } }, [VIS_ACTION_REGISTER] = { "register", @@ -738,17 +738,17 @@ static KeyAction vis_action[] = { [VIS_ACTION_APPEND_CHAR_NEXT] = { "append-char-next", "Append text after the cursor", - insertmode, { .i = MOVE_CHAR_NEXT } + insertmode, { .i = VIS_MOVE_CHAR_NEXT } }, [VIS_ACTION_APPEND_LINE_END] = { "append-line-end", "Append text after the end of the line", - insertmode, { .i = MOVE_LINE_END }, + insertmode, { .i = VIS_MOVE_LINE_END }, }, [VIS_ACTION_INSERT_LINE_START] = { "insert-line-start", "Insert text before the first non-blank in the line", - insertmode, { .i = MOVE_LINE_START }, + insertmode, { .i = VIS_MOVE_LINE_START }, }, [VIS_ACTION_OPEN_LINE_ABOVE] = { "open-line-above", @@ -763,7 +763,7 @@ static KeyAction vis_action[] = { [VIS_ACTION_JOIN_LINE_BELOW] = { "join-line-below", "Join line(s)", - join, { .i = MOVE_LINE_NEXT }, + join, { .i = VIS_MOVE_LINE_NEXT }, }, [VIS_ACTION_JOIN_LINES] = { "join-lines", @@ -1202,7 +1202,7 @@ static const char *replace(Vis *vis, const char *keys, const Arg *arg) { memcpy(key, keys, len); key[len] = '\0'; vis_operator(vis, VIS_OP_REPLACE); - vis_motion(vis, MOVE_NOP); + vis_motion(vis, VIS_MOVE_NOP); vis_keys_inject(vis, next, key); vis_keys_inject(vis, next+len, "<Escape>"); return next; @@ -1213,7 +1213,7 @@ static const char *count(Vis *vis, const char *keys, const Arg *arg) { int count = vis_count_get(vis); if (0 <= digit && digit <= 9) { if (digit == 0 && count == 0) - vis_motion(vis, MOVE_LINE_BEGIN); + vis_motion(vis, VIS_MOVE_LINE_BEGIN); vis_count_set(vis, count * 10 + digit); } return keys; @@ -1221,11 +1221,11 @@ static const char *count(Vis *vis, const char *keys, const Arg *arg) { static const char *gotoline(Vis *vis, const char *keys, const Arg *arg) { if (vis_count_get(vis)) - vis_motion(vis, MOVE_LINE); + vis_motion(vis, VIS_MOVE_LINE); else if (arg->i < 0) - vis_motion(vis, MOVE_FILE_BEGIN); + vis_motion(vis, VIS_MOVE_FILE_BEGIN); else - vis_motion(vis, MOVE_FILE_END); + vis_motion(vis, VIS_MOVE_FILE_END); return keys; } @@ -1395,7 +1395,7 @@ static const char *prompt_backspace(Vis *vis, const char *keys, const Arg *arg) if (!cmd || !*cmd) vis_mode_switch(vis, VIS_MODE_NORMAL); else - delete(vis, keys, &(const Arg){ .i = MOVE_CHAR_PREV }); + delete(vis, keys, &(const Arg){ .i = VIS_MOVE_CHAR_PREV }); free(cmd); return keys; } @@ -1517,10 +1517,10 @@ static const char *window(Vis *vis, const char *keys, const Arg *arg) { static const char *openline(Vis *vis, const char *keys, const Arg *arg) { vis_operator(vis, VIS_OP_INSERT); if (arg->i > 0) { - vis_motion(vis, MOVE_LINE_END); + vis_motion(vis, VIS_MOVE_LINE_END); vis_keys_inject(vis, keys, "<Enter>"); } else { - vis_motion(vis, MOVE_LINE_BEGIN); + vis_motion(vis, VIS_MOVE_LINE_BEGIN); vis_keys_inject(vis, keys, "<Enter><Up>"); } return keys; @@ -159,7 +159,7 @@ struct Vis { /* TODO: make part of Vis struct? enable dynamic modes? */ extern Mode vis_modes[VIS_MODE_LAST]; -extern Movement moves[MOVE_INVALID]; +extern Movement moves[VIS_MOVE_INVALID]; extern Operator ops[VIS_OP_INVALID]; diff --git a/vis-modes.c b/vis-modes.c index 42c9d8a..6e2e196 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -76,7 +76,7 @@ static void vis_mode_visual_line_enter(Vis *vis, Mode *old) { view_cursors_selection_start(c); vis_modes[VIS_MODE_OPERATOR].parent = &vis_modes[VIS_MODE_TEXTOBJ]; } - vis_motion(vis, MOVE_LINE_END); + vis_motion(vis, VIS_MOVE_LINE_END); } static void vis_mode_visual_line_leave(Vis *vis, Mode *new) { diff --git a/vis-motions.c b/vis-motions.c index b0a6f09..6a8ef2e 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -3,105 +3,6 @@ #include "text-objects.h" #include "text-util.h" -/** movements which can be used besides the one in text-motions.h and view.h */ - -/* search in forward direction for the word under the cursor */ -static size_t search_word_forward(Vis*, Text *txt, size_t pos); -/* search in backward direction for the word under the cursor */ -static size_t search_word_backward(Vis*, Text *txt, size_t pos); -/* search again for the last used search pattern */ -static size_t search_forward(Vis*, Text *txt, size_t pos); -static size_t search_backward(Vis*, Text *txt, size_t pos); -/* goto action.mark */ -static size_t mark_goto(Vis*, File *txt, size_t pos); -/* goto first non-blank char on line pointed by action.mark */ -static size_t mark_line_goto(Vis*, File *txt, size_t pos); -/* goto to next occurence of action.key to the right */ -static size_t to(Vis*, Text *txt, size_t pos); -/* goto to position before next occurence of action.key to the right */ -static size_t till(Vis*, Text *txt, size_t pos); -/* goto to next occurence of action.key to the left */ -static size_t to_left(Vis*, Text *txt, size_t pos); -/* goto to position after next occurence of action.key to the left */ -static size_t till_left(Vis*, Text *txt, size_t pos); -/* goto line number action.count */ -static size_t line(Vis*, Text *txt, size_t pos); -/* goto to byte action.count on current line */ -static size_t column(Vis*, Text *txt, size_t pos); -/* goto the action.count-th line from top of the focused window */ -static size_t view_lines_top(Vis*, View*); -/* goto the start of middle line of the focused window */ -static size_t view_lines_middle(Vis*, View*); -/* goto the action.count-th line from bottom of the focused window */ -static size_t view_lines_bottom(Vis*, View*); -/* navigate the change list */ -static size_t window_changelist_next(Vis*, Win*, size_t pos); -static size_t window_changelist_prev(Vis*, Win*, size_t pos); -/* navigate the jump list */ -static size_t window_jumplist_next(Vis*, Win*, size_t pos); -static size_t window_jumplist_prev(Vis*, Win*, size_t pos); -static size_t window_nop(Vis*, Win*, size_t pos); - -Movement moves[] = { - [MOVE_LINE_UP] = { .cur = view_line_up, .type = LINEWISE }, - [MOVE_LINE_DOWN] = { .cur = view_line_down, .type = LINEWISE }, - [MOVE_SCREEN_LINE_UP] = { .cur = view_screenline_up, }, - [MOVE_SCREEN_LINE_DOWN] = { .cur = view_screenline_down, }, - [MOVE_SCREEN_LINE_BEGIN] = { .cur = view_screenline_begin, .type = CHARWISE }, - [MOVE_SCREEN_LINE_MIDDLE] = { .cur = view_screenline_middle, .type = CHARWISE }, - [MOVE_SCREEN_LINE_END] = { .cur = view_screenline_end, .type = CHARWISE|INCLUSIVE }, - [MOVE_LINE_PREV] = { .txt = text_line_prev, }, - [MOVE_LINE_BEGIN] = { .txt = text_line_begin, }, - [MOVE_LINE_START] = { .txt = text_line_start, }, - [MOVE_LINE_FINISH] = { .txt = text_line_finish, .type = INCLUSIVE }, - [MOVE_LINE_LASTCHAR] = { .txt = text_line_lastchar, .type = INCLUSIVE }, - [MOVE_LINE_END] = { .txt = text_line_end, }, - [MOVE_LINE_NEXT] = { .txt = text_line_next, }, - [MOVE_LINE] = { .vis = line, .type = LINEWISE|IDEMPOTENT|JUMP}, - [MOVE_COLUMN] = { .vis = column, .type = CHARWISE|IDEMPOTENT}, - [MOVE_CHAR_PREV] = { .txt = text_char_prev, .type = CHARWISE }, - [MOVE_CHAR_NEXT] = { .txt = text_char_next, .type = CHARWISE }, - [MOVE_LINE_CHAR_PREV] = { .txt = text_line_char_prev, .type = CHARWISE }, - [MOVE_LINE_CHAR_NEXT] = { .txt = text_line_char_next, .type = CHARWISE }, - [MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE }, - [MOVE_WORD_START_NEXT] = { .txt = text_word_start_next, .type = CHARWISE }, - [MOVE_WORD_END_PREV] = { .txt = text_word_end_prev, .type = CHARWISE|INCLUSIVE }, - [MOVE_WORD_END_NEXT] = { .txt = text_word_end_next, .type = CHARWISE|INCLUSIVE }, - [MOVE_LONGWORD_START_PREV] = { .txt = text_longword_start_prev, .type = CHARWISE }, - [MOVE_LONGWORD_START_NEXT] = { .txt = text_longword_start_next, .type = CHARWISE }, - [MOVE_LONGWORD_END_PREV] = { .txt = text_longword_end_prev, .type = CHARWISE|INCLUSIVE }, - [MOVE_LONGWORD_END_NEXT] = { .txt = text_longword_end_next, .type = CHARWISE|INCLUSIVE }, - [MOVE_SENTENCE_PREV] = { .txt = text_sentence_prev, .type = LINEWISE }, - [MOVE_SENTENCE_NEXT] = { .txt = text_sentence_next, .type = LINEWISE }, - [MOVE_PARAGRAPH_PREV] = { .txt = text_paragraph_prev, .type = LINEWISE|JUMP }, - [MOVE_PARAGRAPH_NEXT] = { .txt = text_paragraph_next, .type = LINEWISE|JUMP }, - [MOVE_FUNCTION_START_PREV] = { .txt = text_function_start_prev, .type = LINEWISE|JUMP }, - [MOVE_FUNCTION_START_NEXT] = { .txt = text_function_start_next, .type = LINEWISE|JUMP }, - [MOVE_FUNCTION_END_PREV] = { .txt = text_function_end_prev, .type = LINEWISE|JUMP }, - [MOVE_FUNCTION_END_NEXT] = { .txt = text_function_end_next, .type = LINEWISE|JUMP }, - [MOVE_BRACKET_MATCH] = { .txt = text_bracket_match, .type = INCLUSIVE|JUMP }, - [MOVE_FILE_BEGIN] = { .txt = text_begin, .type = LINEWISE|JUMP }, - [MOVE_FILE_END] = { .txt = text_end, .type = LINEWISE|JUMP }, - [MOVE_LEFT_TO] = { .vis = to_left, }, - [MOVE_RIGHT_TO] = { .vis = to, .type = INCLUSIVE }, - [MOVE_LEFT_TILL] = { .vis = till_left, }, - [MOVE_RIGHT_TILL] = { .vis = till, .type = INCLUSIVE }, - [MOVE_MARK] = { .file = mark_goto, .type = JUMP|IDEMPOTENT }, - [MOVE_MARK_LINE] = { .file = mark_line_goto, .type = LINEWISE|JUMP|IDEMPOTENT}, - [MOVE_SEARCH_WORD_FORWARD] = { .vis = search_word_forward, .type = JUMP }, - [MOVE_SEARCH_WORD_BACKWARD]= { .vis = search_word_backward, .type = JUMP }, - [MOVE_SEARCH_NEXT] = { .vis = search_forward, .type = JUMP }, - [MOVE_SEARCH_PREV] = { .vis = search_backward, .type = JUMP }, - [MOVE_WINDOW_LINE_TOP] = { .view = view_lines_top, .type = LINEWISE|JUMP|IDEMPOTENT }, - [MOVE_WINDOW_LINE_MIDDLE] = { .view = view_lines_middle, .type = LINEWISE|JUMP|IDEMPOTENT }, - [MOVE_WINDOW_LINE_BOTTOM] = { .view = view_lines_bottom, .type = LINEWISE|JUMP|IDEMPOTENT }, - [MOVE_CHANGELIST_NEXT] = { .win = window_changelist_next, .type = INCLUSIVE }, - [MOVE_CHANGELIST_PREV] = { .win = window_changelist_prev, .type = INCLUSIVE }, - [MOVE_JUMPLIST_NEXT] = { .win = window_jumplist_next, .type = INCLUSIVE }, - [MOVE_JUMPLIST_PREV] = { .win = window_jumplist_prev, .type = INCLUSIVE }, - [MOVE_NOP] = { .win = window_nop, .type = IDEMPOTENT }, -}; - /** utility functions */ static char *get_word_at(Text *txt, size_t pos) { @@ -117,7 +18,7 @@ static char *get_word_at(Text *txt, size_t pos) { return buf; } -/** movement implementations */ +/** motion implementations */ static size_t search_word_forward(Vis *vis, Text *txt, size_t pos) { char *word = get_word_at(txt, pos); @@ -267,3 +168,63 @@ static size_t window_nop(Vis *vis, Win *win, size_t pos) { return pos; } +Movement moves[] = { + [VIS_MOVE_LINE_UP] = { .cur = view_line_up, .type = LINEWISE }, + [VIS_MOVE_LINE_DOWN] = { .cur = view_line_down, .type = LINEWISE }, + [VIS_MOVE_SCREEN_LINE_UP] = { .cur = view_screenline_up, }, + [VIS_MOVE_SCREEN_LINE_DOWN] = { .cur = view_screenline_down, }, + [VIS_MOVE_SCREEN_LINE_BEGIN] = { .cur = view_screenline_begin, .type = CHARWISE }, + [VIS_MOVE_SCREEN_LINE_MIDDLE] = { .cur = view_screenline_middle, .type = CHARWISE }, + [VIS_MOVE_SCREEN_LINE_END] = { .cur = view_screenline_end, .type = CHARWISE|INCLUSIVE }, + [VIS_MOVE_LINE_PREV] = { .txt = text_line_prev, }, + [VIS_MOVE_LINE_BEGIN] = { .txt = text_line_begin, }, + [VIS_MOVE_LINE_START] = { .txt = text_line_start, }, + [VIS_MOVE_LINE_FINISH] = { .txt = text_line_finish, .type = INCLUSIVE }, + [VIS_MOVE_LINE_LASTCHAR] = { .txt = text_line_lastchar, .type = INCLUSIVE }, + [VIS_MOVE_LINE_END] = { .txt = text_line_end, }, + [VIS_MOVE_LINE_NEXT] = { .txt = text_line_next, }, + [VIS_MOVE_LINE] = { .vis = line, .type = LINEWISE|IDEMPOTENT|JUMP }, + [VIS_MOVE_COLUMN] = { .vis = column, .type = CHARWISE|IDEMPOTENT }, + [VIS_MOVE_CHAR_PREV] = { .txt = text_char_prev, .type = CHARWISE }, + [VIS_MOVE_CHAR_NEXT] = { .txt = text_char_next, .type = CHARWISE }, + [VIS_MOVE_LINE_CHAR_PREV] = { .txt = text_line_char_prev, .type = CHARWISE }, + [VIS_MOVE_LINE_CHAR_NEXT] = { .txt = text_line_char_next, .type = CHARWISE }, + [VIS_MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE }, + [VIS_MOVE_WORD_START_NEXT] = { .txt = text_word_start_next, .type = CHARWISE }, + [VIS_MOVE_WORD_END_PREV] = { .txt = text_word_end_prev, .type = CHARWISE|INCLUSIVE }, + [VIS_MOVE_WORD_END_NEXT] = { .txt = text_word_end_next, .type = CHARWISE|INCLUSIVE }, + [VIS_MOVE_LONGWORD_START_PREV] = { .txt = text_longword_start_prev, .type = CHARWISE }, + [VIS_MOVE_LONGWORD_START_NEXT] = { .txt = text_longword_start_next, .type = CHARWISE }, + [VIS_MOVE_LONGWORD_END_PREV] = { .txt = text_longword_end_prev, .type = CHARWISE|INCLUSIVE }, + [VIS_MOVE_LONGWORD_END_NEXT] = { .txt = text_longword_end_next, .type = CHARWISE|INCLUSIVE }, + [VIS_MOVE_SENTENCE_PREV] = { .txt = text_sentence_prev, .type = LINEWISE }, + [VIS_MOVE_SENTENCE_NEXT] = { .txt = text_sentence_next, .type = LINEWISE }, + [VIS_MOVE_PARAGRAPH_PREV] = { .txt = text_paragraph_prev, .type = LINEWISE|JUMP }, + [VIS_MOVE_PARAGRAPH_NEXT] = { .txt = text_paragraph_next, .type = LINEWISE|JUMP }, + [VIS_MOVE_FUNCTION_START_PREV] = { .txt = text_function_start_prev, .type = LINEWISE|JUMP }, + [VIS_MOVE_FUNCTION_START_NEXT] = { .txt = text_function_start_next, .type = LINEWISE|JUMP }, + [VIS_MOVE_FUNCTION_END_PREV] = { .txt = text_function_end_prev, .type = LINEWISE|JUMP }, + [VIS_MOVE_FUNCTION_END_NEXT] = { .txt = text_function_end_next, .type = LINEWISE|JUMP }, + [VIS_MOVE_BRACKET_MATCH] = { .txt = text_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 }, + [VIS_MOVE_LEFT_TO] = { .vis = to_left, }, + [VIS_MOVE_RIGHT_TO] = { .vis = to, .type = INCLUSIVE }, + [VIS_MOVE_LEFT_TILL] = { .vis = till_left, }, + [VIS_MOVE_RIGHT_TILL] = { .vis = till, .type = INCLUSIVE }, + [VIS_MOVE_MARK] = { .file = mark_goto, .type = JUMP|IDEMPOTENT }, + [VIS_MOVE_MARK_LINE] = { .file = mark_line_goto, .type = LINEWISE|JUMP|IDEMPOTENT }, + [VIS_MOVE_SEARCH_WORD_FORWARD] = { .vis = search_word_forward, .type = JUMP }, + [VIS_MOVE_SEARCH_WORD_BACKWARD]= { .vis = search_word_backward, .type = JUMP }, + [VIS_MOVE_SEARCH_NEXT] = { .vis = search_forward, .type = JUMP }, + [VIS_MOVE_SEARCH_PREV] = { .vis = search_backward, .type = JUMP }, + [VIS_MOVE_WINDOW_LINE_TOP] = { .view = view_lines_top, .type = LINEWISE|JUMP|IDEMPOTENT }, + [VIS_MOVE_WINDOW_LINE_MIDDLE] = { .view = view_lines_middle, .type = LINEWISE|JUMP|IDEMPOTENT }, + [VIS_MOVE_WINDOW_LINE_BOTTOM] = { .view = view_lines_bottom, .type = LINEWISE|JUMP|IDEMPOTENT }, + [VIS_MOVE_CHANGELIST_NEXT] = { .win = window_changelist_next, .type = INCLUSIVE }, + [VIS_MOVE_CHANGELIST_PREV] = { .win = window_changelist_prev, .type = INCLUSIVE }, + [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 }, +}; + @@ -633,7 +633,7 @@ static void action_do(Vis *vis, Action *a) { if (a->op) { /* we do not support visual repeat, still do something resonable */ if (vis->mode->visual && !a->movement && !a->textobj) - a->movement = &moves[MOVE_NOP]; + a->movement = &moves[VIS_MOVE_NOP]; /* operator implementations must not change the mode, * they might get called multiple times (once for every cursor) @@ -673,9 +673,9 @@ static bool prompt_cmd(Vis *vis, char type, const char *cmd) { return true; switch (type) { case '/': - return vis_motion(vis, MOVE_SEARCH_FORWARD, cmd); + return vis_motion(vis, VIS_MOVE_SEARCH_FORWARD, cmd); case '?': - return vis_motion(vis, MOVE_SEARCH_BACKWARD, cmd); + return vis_motion(vis, VIS_MOVE_SEARCH_BACKWARD, cmd); case '+': case ':': return vis_cmd(vis, cmd); @@ -1000,14 +1000,14 @@ bool vis_operator(Vis *vis, enum VisOperator id) { /* hacky way to handle double operators i.e. things like * dd, yy etc where the second char isn't a movement */ vis->action.type = LINEWISE; - vis_motion(vis, MOVE_LINE_NEXT); + vis_motion(vis, VIS_MOVE_LINE_NEXT); } else { vis->action.op = op; } /* put is not a real operator, does not need a range to operate on */ if (id == VIS_OP_PUT_AFTER) - vis_motion(vis, MOVE_NOP); + vis_motion(vis, VIS_MOVE_NOP); return true; } @@ -1021,32 +1021,32 @@ bool vis_motion(Vis *vis, enum VisMotion motion, ...) { va_start(ap, motion); switch (motion) { - case MOVE_WORD_START_NEXT: + case VIS_MOVE_WORD_START_NEXT: if (vis->action.op == &ops[VIS_OP_CHANGE]) - motion = MOVE_WORD_END_NEXT; + motion = VIS_MOVE_WORD_END_NEXT; break; - case MOVE_LONGWORD_START_NEXT: + case VIS_MOVE_LONGWORD_START_NEXT: if (vis->action.op == &ops[VIS_OP_CHANGE]) - motion = MOVE_LONGWORD_END_NEXT; + motion = VIS_MOVE_LONGWORD_END_NEXT; break; - case MOVE_SEARCH_FORWARD: - case MOVE_SEARCH_BACKWARD: + case VIS_MOVE_SEARCH_FORWARD: + case VIS_MOVE_SEARCH_BACKWARD: { const char *pattern = va_arg(ap, char*); if (text_regex_compile(vis->search_pattern, pattern, REG_EXTENDED)) { vis_cancel(vis); goto err; } - if (motion == MOVE_SEARCH_FORWARD) - motion = MOVE_SEARCH_NEXT; + if (motion == VIS_MOVE_SEARCH_FORWARD) + motion = VIS_MOVE_SEARCH_NEXT; else - motion = MOVE_SEARCH_PREV; + motion = VIS_MOVE_SEARCH_PREV; break; } - case MOVE_RIGHT_TO: - case MOVE_LEFT_TO: - case MOVE_RIGHT_TILL: - case MOVE_LEFT_TILL: + case VIS_MOVE_RIGHT_TO: + case VIS_MOVE_LEFT_TO: + case VIS_MOVE_RIGHT_TILL: + case VIS_MOVE_LEFT_TILL: { const char *key = va_arg(ap, char*); if (!key) @@ -1056,31 +1056,31 @@ bool vis_motion(Vis *vis, enum VisMotion motion, ...) { vis->last_totill = motion; break; } - case MOVE_TOTILL_REPEAT: + case VIS_MOVE_TOTILL_REPEAT: if (!vis->last_totill) goto err; motion = vis->last_totill; break; - case MOVE_TOTILL_REVERSE: + case VIS_MOVE_TOTILL_REVERSE: switch (vis->last_totill) { - case MOVE_RIGHT_TO: - motion = MOVE_LEFT_TO; + case VIS_MOVE_RIGHT_TO: + motion = VIS_MOVE_LEFT_TO; break; - case MOVE_LEFT_TO: - motion = MOVE_RIGHT_TO; + case VIS_MOVE_LEFT_TO: + motion = VIS_MOVE_RIGHT_TO; break; - case MOVE_RIGHT_TILL: - motion = MOVE_LEFT_TILL; + case VIS_MOVE_RIGHT_TILL: + motion = VIS_MOVE_LEFT_TILL; break; - case MOVE_LEFT_TILL: - motion = MOVE_RIGHT_TILL; + case VIS_MOVE_LEFT_TILL: + motion = VIS_MOVE_RIGHT_TILL; break; default: goto err; } break; - case MOVE_MARK: - case MOVE_MARK_LINE: + case VIS_MOVE_MARK: + case VIS_MOVE_MARK_LINE: { int mark = va_arg(ap, int); if (VIS_MARK_a <= mark && mark < VIS_MARK_INVALID) @@ -180,82 +180,82 @@ enum VisOperator { bool vis_operator(Vis*, enum VisOperator); enum VisMotion { - MOVE_LINE_DOWN, - MOVE_LINE_UP, - MOVE_SCREEN_LINE_UP, - MOVE_SCREEN_LINE_DOWN, - MOVE_SCREEN_LINE_BEGIN, - MOVE_SCREEN_LINE_MIDDLE, - MOVE_SCREEN_LINE_END, - MOVE_LINE_PREV, - MOVE_LINE_BEGIN, - MOVE_LINE_START, - MOVE_LINE_FINISH, - MOVE_LINE_LASTCHAR, - MOVE_LINE_END, - MOVE_LINE_NEXT, - MOVE_LINE, - MOVE_COLUMN, - MOVE_CHAR_PREV, - MOVE_CHAR_NEXT, - MOVE_LINE_CHAR_PREV, - MOVE_LINE_CHAR_NEXT, - MOVE_WORD_START_NEXT, - MOVE_WORD_END_PREV, - MOVE_WORD_END_NEXT, - MOVE_WORD_START_PREV, - MOVE_LONGWORD_START_PREV, - MOVE_LONGWORD_START_NEXT, - MOVE_LONGWORD_END_PREV, - MOVE_LONGWORD_END_NEXT, - MOVE_SENTENCE_PREV, - MOVE_SENTENCE_NEXT, - MOVE_PARAGRAPH_PREV, - MOVE_PARAGRAPH_NEXT, - MOVE_FUNCTION_START_PREV, - MOVE_FUNCTION_START_NEXT, - MOVE_FUNCTION_END_PREV, - MOVE_FUNCTION_END_NEXT, - MOVE_BRACKET_MATCH, - MOVE_LEFT_TO, - MOVE_RIGHT_TO, - MOVE_LEFT_TILL, - MOVE_RIGHT_TILL, - MOVE_FILE_BEGIN, - MOVE_FILE_END, - MOVE_MARK, - MOVE_MARK_LINE, - MOVE_SEARCH_WORD_FORWARD, - MOVE_SEARCH_WORD_BACKWARD, - MOVE_SEARCH_NEXT, - MOVE_SEARCH_PREV, - MOVE_WINDOW_LINE_TOP, - MOVE_WINDOW_LINE_MIDDLE, - MOVE_WINDOW_LINE_BOTTOM, - MOVE_CHANGELIST_NEXT, - MOVE_CHANGELIST_PREV, - MOVE_JUMPLIST_NEXT, - MOVE_JUMPLIST_PREV, - MOVE_NOP, - MOVE_INVALID, /* denotes the end of the "real" motions */ + VIS_MOVE_LINE_DOWN, + VIS_MOVE_LINE_UP, + VIS_MOVE_SCREEN_LINE_UP, + VIS_MOVE_SCREEN_LINE_DOWN, + VIS_MOVE_SCREEN_LINE_BEGIN, + VIS_MOVE_SCREEN_LINE_MIDDLE, + VIS_MOVE_SCREEN_LINE_END, + VIS_MOVE_LINE_PREV, + VIS_MOVE_LINE_BEGIN, + VIS_MOVE_LINE_START, + VIS_MOVE_LINE_FINISH, + VIS_MOVE_LINE_LASTCHAR, + VIS_MOVE_LINE_END, + VIS_MOVE_LINE_NEXT, + VIS_MOVE_LINE, + VIS_MOVE_COLUMN, + VIS_MOVE_CHAR_PREV, + VIS_MOVE_CHAR_NEXT, + VIS_MOVE_LINE_CHAR_PREV, + VIS_MOVE_LINE_CHAR_NEXT, + VIS_MOVE_WORD_START_NEXT, + VIS_MOVE_WORD_END_PREV, + VIS_MOVE_WORD_END_NEXT, + VIS_MOVE_WORD_START_PREV, + VIS_MOVE_LONGWORD_START_PREV, + VIS_MOVE_LONGWORD_START_NEXT, + VIS_MOVE_LONGWORD_END_PREV, + VIS_MOVE_LONGWORD_END_NEXT, + VIS_MOVE_SENTENCE_PREV, + VIS_MOVE_SENTENCE_NEXT, + VIS_MOVE_PARAGRAPH_PREV, + VIS_MOVE_PARAGRAPH_NEXT, + VIS_MOVE_FUNCTION_START_PREV, + VIS_MOVE_FUNCTION_START_NEXT, + VIS_MOVE_FUNCTION_END_PREV, + VIS_MOVE_FUNCTION_END_NEXT, + VIS_MOVE_BRACKET_MATCH, + VIS_MOVE_LEFT_TO, + VIS_MOVE_RIGHT_TO, + VIS_MOVE_LEFT_TILL, + VIS_MOVE_RIGHT_TILL, + VIS_MOVE_FILE_BEGIN, + VIS_MOVE_FILE_END, + VIS_MOVE_MARK, + VIS_MOVE_MARK_LINE, + VIS_MOVE_SEARCH_WORD_FORWARD, + VIS_MOVE_SEARCH_WORD_BACKWARD, + VIS_MOVE_SEARCH_NEXT, + VIS_MOVE_SEARCH_PREV, + VIS_MOVE_WINDOW_LINE_TOP, + VIS_MOVE_WINDOW_LINE_MIDDLE, + VIS_MOVE_WINDOW_LINE_BOTTOM, + VIS_MOVE_CHANGELIST_NEXT, + VIS_MOVE_CHANGELIST_PREV, + VIS_MOVE_JUMPLIST_NEXT, + VIS_MOVE_JUMPLIST_PREV, + VIS_MOVE_NOP, + VIS_MOVE_INVALID, /* denotes the end of the "real" motions */ /* pseudo motions: keep them at the end to save space in array definition */ - MOVE_TOTILL_REPEAT, - MOVE_TOTILL_REVERSE, - MOVE_SEARCH_FORWARD, - MOVE_SEARCH_BACKWARD, + VIS_MOVE_TOTILL_REPEAT, + VIS_MOVE_TOTILL_REVERSE, + VIS_MOVE_SEARCH_FORWARD, + VIS_MOVE_SEARCH_BACKWARD, }; /* set motion to perform, the following take an additional argument: * - * - MOVE_SEARCH_FORWARD and MOVE_SEARCH_BACKWARD + * - VIS_MOVE_SEARCH_FORWARD and VIS_MOVE_SEARCH_BACKWARD * * expect the search pattern as const char * * - * - MOVE_{LEFT,RIGHT}_{TO,TILL} + * - VIS_MOVE_{LEFT,RIGHT}_{TO,TILL} * * expect the character to search for as const char * * - * - MOVE_MARK and MOVE_MARK_LINE + * - VIS_MOVE_MARK and VIS_MOVE_MARK_LINE * * expect a valid enum VisMark */ |
