aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h4
-rw-r--r--editor.h4
-rw-r--r--vis.c32
-rw-r--r--vis.h7
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",
diff --git a/editor.h b/editor.h
index 2ee106a..abb0b57 100644
--- a/editor.h
+++ b/editor.h
@@ -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;
};
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);
+}
diff --git a/vis.h b/vis.h
index cb19905..288b3c0 100644
--- a/vis.h
+++ b/vis.h
@@ -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);