diff options
| -rw-r--r-- | vis-motions.c | 91 | ||||
| -rw-r--r-- | vis.c | 90 |
2 files changed, 91 insertions, 90 deletions
diff --git a/vis-motions.c b/vis-motions.c index 8c2146f..4cd700f 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -1,3 +1,4 @@ +#include <string.h> #include <regex.h> #include "vis-core.h" #include "text-motions.h" @@ -163,6 +164,96 @@ static size_t window_nop(Vis *vis, Win *win, size_t pos) { return pos; } +void vis_motion_type(Vis *vis, enum VisMotionType type) { + vis->action.type = type; +} + +bool vis_motion(Vis *vis, enum VisMotion motion, ...) { + va_list ap; + va_start(ap, motion); + + switch (motion) { + case VIS_MOVE_WORD_START_NEXT: + if (vis->action.op == &ops[VIS_OP_CHANGE]) + motion = VIS_MOVE_WORD_END_NEXT; + break; + case VIS_MOVE_LONGWORD_START_NEXT: + if (vis->action.op == &ops[VIS_OP_CHANGE]) + motion = VIS_MOVE_LONGWORD_END_NEXT; + break; + 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 == VIS_MOVE_SEARCH_FORWARD) + motion = VIS_MOVE_SEARCH_NEXT; + else + motion = VIS_MOVE_SEARCH_PREV; + break; + } + 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) + goto err; + strncpy(vis->search_char, key, sizeof(vis->search_char)); + vis->search_char[sizeof(vis->search_char)-1] = '\0'; + vis->last_totill = motion; + break; + } + case VIS_MOVE_TOTILL_REPEAT: + if (!vis->last_totill) + goto err; + motion = vis->last_totill; + break; + case VIS_MOVE_TOTILL_REVERSE: + switch (vis->last_totill) { + case VIS_MOVE_RIGHT_TO: + motion = VIS_MOVE_LEFT_TO; + break; + case VIS_MOVE_LEFT_TO: + motion = VIS_MOVE_RIGHT_TO; + break; + case VIS_MOVE_RIGHT_TILL: + motion = VIS_MOVE_LEFT_TILL; + break; + case VIS_MOVE_LEFT_TILL: + motion = VIS_MOVE_RIGHT_TILL; + break; + default: + goto err; + } + break; + case VIS_MOVE_MARK: + case VIS_MOVE_MARK_LINE: + { + int mark = va_arg(ap, int); + if (VIS_MARK_a <= mark && mark < VIS_MARK_INVALID) + vis->action.mark = mark; + else + goto err; + break; + } + default: + break; + } + + vis->action.movement = &moves[motion]; + va_end(ap); + action_do(vis, &vis->action); + return true; +err: + va_end(ap); + return false; +} + Movement moves[] = { [VIS_MOVE_LINE_UP] = { .cur = view_line_up, .type = LINEWISE }, [VIS_MOVE_LINE_DOWN] = { .cur = view_line_down, .type = LINEWISE }, @@ -1034,92 +1034,6 @@ void vis_mode_switch(Vis *vis, enum VisMode mode) { mode_set(vis, &vis_modes[mode]); } -bool vis_motion(Vis *vis, enum VisMotion motion, ...) { - va_list ap; - va_start(ap, motion); - - switch (motion) { - case VIS_MOVE_WORD_START_NEXT: - if (vis->action.op == &ops[VIS_OP_CHANGE]) - motion = VIS_MOVE_WORD_END_NEXT; - break; - case VIS_MOVE_LONGWORD_START_NEXT: - if (vis->action.op == &ops[VIS_OP_CHANGE]) - motion = VIS_MOVE_LONGWORD_END_NEXT; - break; - 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 == VIS_MOVE_SEARCH_FORWARD) - motion = VIS_MOVE_SEARCH_NEXT; - else - motion = VIS_MOVE_SEARCH_PREV; - break; - } - 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) - goto err; - strncpy(vis->search_char, key, sizeof(vis->search_char)); - vis->search_char[sizeof(vis->search_char)-1] = '\0'; - vis->last_totill = motion; - break; - } - case VIS_MOVE_TOTILL_REPEAT: - if (!vis->last_totill) - goto err; - motion = vis->last_totill; - break; - case VIS_MOVE_TOTILL_REVERSE: - switch (vis->last_totill) { - case VIS_MOVE_RIGHT_TO: - motion = VIS_MOVE_LEFT_TO; - break; - case VIS_MOVE_LEFT_TO: - motion = VIS_MOVE_RIGHT_TO; - break; - case VIS_MOVE_RIGHT_TILL: - motion = VIS_MOVE_LEFT_TILL; - break; - case VIS_MOVE_LEFT_TILL: - motion = VIS_MOVE_RIGHT_TILL; - break; - default: - goto err; - } - break; - case VIS_MOVE_MARK: - case VIS_MOVE_MARK_LINE: - { - int mark = va_arg(ap, int); - if (VIS_MARK_a <= mark && mark < VIS_MARK_INVALID) - vis->action.mark = mark; - else - goto err; - break; - } - default: - break; - } - - vis->action.movement = &moves[motion]; - va_end(ap); - action_do(vis, &vis->action); - return true; -err: - va_end(ap); - return false; -} - static Macro *macro_get(Vis *vis, enum VisMacro m) { if (m == VIS_MACRO_LAST_RECORDED) return vis->last_recording; @@ -1219,10 +1133,6 @@ void vis_mark_set(Vis *vis, enum VisMark mark, size_t pos) { file->marks[mark] = text_mark_set(file->text, pos); } -void vis_motion_type(Vis *vis, enum VisMotionType type) { - vis->action.type = type; -} - int vis_count_get(Vis *vis) { return vis->action.count; } |
