aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-07-27 20:44:49 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-07-28 13:21:50 +0200
commitc9499ddd97d1bb8395e896050e92c6eee7e4b205 (patch)
tree77228c1a6b3c71716a155c3b7dac1bbde33683dd
parentc6031d7f1f3278979c9f5c9f4802b4e1f1cbd683 (diff)
downloadvis-c9499ddd97d1bb8395e896050e92c6eee7e4b205.tar.gz
vis-c9499ddd97d1bb8395e896050e92c6eee7e4b205.tar.xz
vis: add an operator to create new cursors
The operator creates a new cursor at the start of every line covered by the given range. It is currently only available as CTRL+O in visual mode.
-rw-r--r--config.def.h1
-rw-r--r--vis.c15
2 files changed, 16 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index f8f07bf..950fd54 100644
--- a/config.def.h
+++ b/config.def.h
@@ -421,6 +421,7 @@ static KeyBinding vis_mode_normal[] = {
static KeyBinding vis_mode_visual[] = {
{ { KEY(BACKSPACE) }, operator, { .i = OP_DELETE } },
{ { KEY(DELETE) }, operator, { .i = OP_DELETE } },
+ { { CONTROL('O') }, operator, { .i = OP_CURSOR } },
{ { NONE(ESC) }, switchmode, { .i = VIS_MODE_NORMAL } },
{ { CONTROL('c') }, switchmode, { .i = VIS_MODE_NORMAL } },
{ { NONE('v') }, switchmode, { .i = VIS_MODE_NORMAL } },
diff --git a/vis.c b/vis.c
index 216ee2f..9ca92cd 100644
--- a/vis.c
+++ b/vis.c
@@ -56,6 +56,7 @@ static size_t op_case_change(OperatorContext *c);
static size_t op_join(OperatorContext *c);
static size_t op_repeat_insert(OperatorContext *c);
static size_t op_repeat_replace(OperatorContext *c);
+static size_t op_cursor(OperatorContext *c);
/* these can be passed as int argument to operator(&(const Arg){ .i = OP_*}) */
enum {
@@ -69,6 +70,7 @@ enum {
OP_JOIN,
OP_REPEAT_INSERT,
OP_REPEAT_REPLACE,
+ OP_CURSOR,
};
static Operator ops[] = {
@@ -82,6 +84,7 @@ static Operator ops[] = {
[OP_JOIN] = { op_join },
[OP_REPEAT_INSERT] = { op_repeat_insert },
[OP_REPEAT_REPLACE] = { op_repeat_replace },
+ [OP_CURSOR] = { op_cursor },
};
#define PAGE INT_MAX
@@ -568,6 +571,18 @@ static size_t op_case_change(OperatorContext *c) {
return c->pos;
}
+static size_t op_cursor(OperatorContext *c) {
+ Text *txt = vis->win->file->text;
+ View *view = vis->win->view;
+ Filerange r = text_range_linewise(txt, &c->range);
+ for (size_t line = text_range_line_first(txt, &r); line != EPOS; line = text_range_line_next(txt, &r, line)) {
+ Cursor *cursor = view_cursors_new(view);
+ if (cursor)
+ view_cursors_to(cursor, text_line_start(txt, line));
+ }
+ return EPOS;
+}
+
static size_t op_join(OperatorContext *c) {
Text *txt = vis->win->file->text;
size_t pos = text_line_begin(txt, c->range.end), prev_pos;