diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2014-09-17 14:28:45 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2014-09-17 14:46:03 +0200 |
| commit | 89bc5a0344deafdeddde58b625376f23602c075b (patch) | |
| tree | 3aa7672c1f4e7f3a01858f40af7efc2dd081655d /vis.c | |
| parent | 3469424ef143b125619de805eefb1480a4e2b227 (diff) | |
| download | vis-89bc5a0344deafdeddde58b625376f23602c075b.tar.gz vis-89bc5a0344deafdeddde58b625376f23602c075b.tar.xz | |
Implement right shift operator
Diffstat (limited to 'vis.c')
| -rw-r--r-- | vis.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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) { |
