aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-17 14:28:45 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-17 14:46:03 +0200
commit89bc5a0344deafdeddde58b625376f23602c075b (patch)
tree3aa7672c1f4e7f3a01858f40af7efc2dd081655d
parent3469424ef143b125619de805eefb1480a4e2b227 (diff)
downloadvis-89bc5a0344deafdeddde58b625376f23602c075b.tar.gz
vis-89bc5a0344deafdeddde58b625376f23602c075b.tar.xz
Implement right shift operator
-rw-r--r--config.def.h1
-rw-r--r--vis.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index d78c076..d3c0e88 100644
--- a/config.def.h
+++ b/config.def.h
@@ -198,6 +198,7 @@ static KeyBinding vis_operators[] = {
{ { NONE('c') }, operator, { .i = OP_CHANGE } },
{ { NONE('y') }, operator, { .i = OP_YANK } },
{ { NONE('p') }, operator, { .i = OP_PUT } },
+ { { NONE('>') }, operator, { .i = OP_SHIFT_RIGHT } },
{ /* empty last element, array terminator */ },
};
diff --git a/vis.c b/vis.c
index 3804246..4b9a36f 100644
--- a/vis.c
+++ b/vis.c
@@ -151,6 +151,7 @@ static void op_change(OperatorContext *c);
static void op_yank(OperatorContext *c);
static void op_put(OperatorContext *c);
static void op_delete(OperatorContext *c);
+static void op_shift_right(OperatorContext *c);
/* these can be passed as int argument to operator(&(const Arg){ .i = OP_*}) */
enum {
@@ -158,6 +159,7 @@ enum {
OP_CHANGE,
OP_YANK,
OP_PUT,
+ OP_SHIFT_RIGHT,
};
static Operator ops[] = {
@@ -165,6 +167,7 @@ static Operator ops[] = {
[OP_CHANGE] = { op_change, false },
[OP_YANK] = { op_yank, false },
[OP_PUT] = { op_put, true },
+ [OP_SHIFT_RIGHT] = { op_shift_right, false },
};
#define PAGE INT_MAX
@@ -465,6 +468,28 @@ static void op_put(OperatorContext *c) {
window_cursor_to(vis->win->win, pos + c->reg->len);
}
+static const char *expand_tab(void) {
+ return "\t";
+}
+
+static void op_shift_right(OperatorContext *c) {
+ Text *txt = vis->win->text;
+ size_t pos = text_line_begin(txt, c->range.end), prev_pos;
+ const char *tab = expand_tab();
+ size_t tablen = strlen(tab);
+
+ /* if range ends at the begin of a line, skip line break */
+ if (pos == c->range.end)
+ pos = text_line_prev(txt, pos);
+
+ do {
+ prev_pos = pos = text_line_begin(txt, pos);
+ text_insert(txt, pos, tab, tablen);
+ pos = text_line_prev(txt, pos);
+ } while (pos >= c->range.start && pos != prev_pos);
+ editor_draw(vis);
+}
+
/** movement implementations of type: size_t (*move)(const Arg*) */
static size_t search_forward(const Arg *arg) {