diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2015-10-25 21:36:23 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2015-10-25 22:46:43 +0100 |
| commit | afe666ee88c7706954d6d6bea70ac18ecfd20312 (patch) | |
| tree | c9dcf33af16260afefbea3183f01a23fffe8ca27 | |
| parent | 81bae7262b21b7f19bfaf0de4499a56372ef2a20 (diff) | |
| download | vis-afe666ee88c7706954d6d6bea70ac18ecfd20312.tar.gz vis-afe666ee88c7706954d6d6bea70ac18ecfd20312.tar.xz | |
vis: clean up mark handling
| -rw-r--r-- | config.def.h | 4 | ||||
| -rw-r--r-- | editor.h | 4 | ||||
| -rw-r--r-- | vis.c | 32 | ||||
| -rw-r--r-- | vis.h | 7 |
4 files changed, 24 insertions, 23 deletions
diff --git a/config.def.h b/config.def.h index e299835..9d049fb 100644 --- a/config.def.h +++ b/config.def.h @@ -524,12 +524,12 @@ static KeyAction vis_action[] = { [VIS_ACTION_MARK_GOTO] = { "mark-goto", "Goto the position of the given mark", - mark, + mark_motion, { .i = MOVE_MARK } }, [VIS_ACTION_MARK_GOTO_LINE] = { "mark-goto-line", "Goto first non-blank character of the line containing the given mark", - mark_line, + mark_motion, { .i = MOVE_MARK_LINE } }, [VIS_ACTION_REDRAW] = { "editor-redraw", @@ -198,7 +198,7 @@ enum Mark { MARK_z, MARK_SELECTION_START, MARK_SELECTION_END, - MARK_LAST, + MARK_INVALID, }; struct File { @@ -208,7 +208,7 @@ struct File { bool is_stdin; struct stat stat; int refcount; - Mark marks[MARK_LAST]; + Mark marks[MARK_INVALID]; File *next, *prev; }; @@ -275,10 +275,8 @@ static const char *selection_end(Vis*, const char *keys, const Arg *arg); static const char *selection_restore(Vis*, const char *keys, const Arg *arg); /* use register indicated by arg->i for the current operator */ static const char *reg(Vis*, const char *keys, const Arg *arg); -/* perform a movement to mark arg->i */ -static const char *mark(Vis*, const char *keys, const Arg *arg); -/* perform a movement to the first non-blank on the line pointed by mark arg->i */ -static const char *mark_line(Vis*, const char *keys, const Arg *arg); +/* perform arg->i motion with a mark as argument */ +static const char *mark_motion(Vis*, const char *keys, const Arg *arg); /* {un,re}do last action, redraw window */ static const char *undo(Vis*, const char *keys, const Arg *arg); static const char *redo(Vis*, const char *keys, const Arg *arg); @@ -973,7 +971,7 @@ static const char *reg(Vis *vis, const char *keys, const Arg *arg) { } static const char *key2mark(Vis *vis, const char *keys, int *mark) { - *mark = -1; + *mark = MARK_INVALID; if (!keys[0]) return NULL; if (keys[0] >= 'a' && keys[0] <= 'z') @@ -988,24 +986,14 @@ static const char *key2mark(Vis *vis, const char *keys, int *mark) { static const char *mark_set(Vis *vis, const char *keys, const Arg *arg) { int mark; keys = key2mark(vis, keys, &mark); - if (mark != -1) { - size_t pos = view_cursor_get(vis->win->view); - vis->win->file->marks[mark] = text_mark_set(vis->win->file->text, pos); - } - return keys; -} - -static const char *mark(Vis *vis, const char *keys, const Arg *arg) { - int mark; - keys = key2mark(vis, keys, &mark); - vis_motion(vis, MOVE_MARK, mark); + vis_mark_set(vis, mark, view_cursor_get(vis->win->view)); return keys; } -static const char *mark_line(Vis *vis, const char *keys, const Arg *arg) { +static const char *mark_motion(Vis *vis, const char *keys, const Arg *arg) { int mark; keys = key2mark(vis, keys, &mark); - vis_motion(vis, MOVE_MARK_LINE, mark); + vis_motion(vis, arg->i, mark); return keys; } @@ -2819,7 +2807,7 @@ void vis_motion(Vis *vis, enum VisMotion motion, ...) { case MOVE_MARK_LINE: { int mark = va_arg(ap, int); - if (MARK_a <= mark && mark < MARK_LAST) + if (MARK_a <= mark && mark < MARK_INVALID) vis->action.mark = mark; else goto out; @@ -2894,3 +2882,9 @@ void vis_repeat(Vis *vis) { vis->action.count = count; action_do(vis, &vis->action); } + +void vis_mark_set(Vis *vis, enum VisMark mark, size_t pos) { + File *file = vis->win->file; + if (mark < LENGTH(file->marks)) + file->marks[mark] = text_mark_set(file->text, pos); +} @@ -151,6 +151,13 @@ bool vis_macro_record(Vis*, enum VisMacro); bool vis_macro_record_stop(Vis*); bool vis_macro_replay(Vis*, enum VisMacro); +enum VisMark { + /* TODO: temporary */ + VIS_MARK_INVALID, +}; + +void vis_mark_set(Vis*, enum VisMark mark, size_t pos); + void vis_repeat(Vis*); bool vis_cmd(Vis*, const char *cmdline); |
