vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 01457900cf3b6d70e228ef91fda35a14b82c5f2e
parent a6d58ef5f5050b2e48c1ec638e946c53a92ec36a
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 28 Jul 2015 08:01:36 +0200

vis: try to align cursors on the same column with CTRL-A

Diffstat:
Mconfig.def.h | 1+
Mvis.c | 19+++++++++++++++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -362,6 +362,7 @@ static KeyBinding vis_mode_normal[] = { { { NONE(ESC) }, cursors_clear, { } }, { { CONTROL('K') }, cursors_new, { .i = -1 } }, { { CONTROL('J') }, cursors_new, { .i = +1 } }, + { { CONTROL('A') }, cursors_align, { } }, { { CONTROL('w'), NONE('n') }, cmd, { .s = "open" } }, { { CONTROL('w'), NONE('c') }, cmd, { .s = "q" } }, { { CONTROL('w'), NONE('s') }, cmd, { .s = "split" } }, diff --git a/vis.c b/vis.c @@ -322,6 +322,8 @@ static void totill_reverse(const Arg *arg); static void replace(const Arg *arg); /* create a new cursor on the previous (arg->i < 0) or next (arg->i > 0) line */ static void cursors_new(const Arg *arg); +/* try to align all cursors on the same column */ +static void cursors_align(const Arg *arg); /* remove all but the primary cursor and their selections */ static void cursors_clear(const Arg *arg); /* adjust action.count by arg->i */ @@ -842,6 +844,23 @@ static void cursors_new(const Arg *arg) { view_cursors_to(cursor, pos); } +static void cursors_align(const Arg *arg) { + View *view = vis->win->view; + Text *txt = vis->win->file->text; + int mincol = INT_MAX; + for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) { + size_t pos = view_cursors_pos(c); + int col = text_line_char_get(txt, pos); + if (col < mincol) + mincol = col; + } + for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) { + size_t pos = view_cursors_pos(c); + size_t col = text_line_char_set(txt, pos, mincol); + view_cursors_to(c, col); + } +} + static void cursors_clear(const Arg *arg) { View *view = vis->win->view; if (view_cursors_count(view) > 1)