aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-10-25 21:36:23 +0100
committerMarc André Tanner <mat@brain-dump.org>2015-10-25 22:46:43 +0100
commitafe666ee88c7706954d6d6bea70ac18ecfd20312 (patch)
treec9dcf33af16260afefbea3183f01a23fffe8ca27 /vis.c
parent81bae7262b21b7f19bfaf0de4499a56372ef2a20 (diff)
downloadvis-afe666ee88c7706954d6d6bea70ac18ecfd20312.tar.gz
vis-afe666ee88c7706954d6d6bea70ac18ecfd20312.tar.xz
vis: clean up mark handling
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c32
1 files changed, 13 insertions, 19 deletions
diff --git a/vis.c b/vis.c
index 74264a4..5ea6715 100644
--- a/vis.c
+++ b/vis.c
@@ -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);
+}