From 9e64bf166ac329103a98baafce10e42242898373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Tue, 5 Apr 2016 16:00:37 +0200 Subject: vis: let remove all but the count cursor column --- config.def.h | 3 ++- main.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/config.def.h b/config.def.h index a72af52..26ff499 100644 --- a/config.def.h +++ b/config.def.h @@ -231,7 +231,7 @@ static const KeyBinding bindings_normal[] = { { "", ACTION(REDO) }, { "g+", ACTION(LATER) }, { "g-", ACTION(EARLIER) }, - { "", ACTION(REDRAW) }, + { "", ACTION(CURSORS_REMOVE_COLUMN_EXCEPT) }, { ":", ACTION(PROMPT_SHOW) }, { "ZZ", ALIAS(":wq") }, { "ZQ", ALIAS(":q!") }, @@ -266,6 +266,7 @@ static const KeyBinding bindings_visual[] = { { "", ALIAS("") }, { "", ACTION(MODE_NORMAL) }, { "", ACTION(CURSORS_REMOVE_COLUMN) }, + { "", ACTION(CURSORS_REMOVE_COLUMN_EXCEPT) }, { "v", ALIAS("") }, { "V", ACTION(MODE_VISUAL_LINE) }, { ":", ACTION(PROMPT_SHOW) }, diff --git a/main.c b/main.c index 35c1bc4..0b45816 100644 --- a/main.c +++ b/main.c @@ -52,6 +52,8 @@ static const char *cursors_clear(Vis*, const char *keys, const Arg *arg); static const char *cursors_remove(Vis*, const char *keys, const Arg *arg); /* remove count (or arg->i)-th cursor column */ static const char *cursors_remove_column(Vis*, const char *keys, const Arg *arg); +/* remove all but the count (or arg->i)-th cursor column */ +static const char *cursors_remove_column_except(Vis*, const char *keys, const Arg *arg); /* move to the previous (arg->i < 0) or next (arg->i > 0) cursor */ static const char *cursors_navigate(Vis*, const char *keys, const Arg *arg); /* select the word the cursor is currently over */ @@ -257,6 +259,7 @@ enum { VIS_ACTION_CURSORS_REMOVE_ALL, VIS_ACTION_CURSORS_REMOVE_LAST, VIS_ACTION_CURSORS_REMOVE_COLUMN, + VIS_ACTION_CURSORS_REMOVE_COLUMN_EXCEPT, VIS_ACTION_CURSORS_PREV, VIS_ACTION_CURSORS_NEXT, VIS_ACTION_SELECTIONS_ROTATE_LEFT, @@ -962,6 +965,11 @@ static const KeyAction vis_action[] = { "Remove count cursor column", cursors_remove_column, { .i = 1 } }, + [VIS_ACTION_CURSORS_REMOVE_COLUMN_EXCEPT] = { + "cursors-remove-column-except", + "Remove all but the count cursor column", + cursors_remove_column_except, { .i = 1 } + }, [VIS_ACTION_CURSORS_PREV] = { "cursors-prev", "Move to the previous cursor", @@ -1427,6 +1435,31 @@ static const char *cursors_remove_column(Vis *vis, const char *keys, const Arg * return keys; } +static const char *cursors_remove_column_except(Vis *vis, const char *keys, const Arg *arg) { + View *view = vis_view(vis); + int max = view_cursors_column_count(view); + int column = vis_count_get_default(vis, arg->i) - 1; + if (column >= max) + column = max - 1; + if (!view_cursors_multiple(view)) { + vis_redraw(vis); + return keys; + } + + Cursor *cur = view_cursors(view); + Cursor *col = view_cursors_column(view, column); + for (Cursor *next; cur; cur = next) { + next = view_cursors_next(cur); + if (cur == col) + col = view_cursors_column_next(col, column); + else + view_cursors_dispose(cur); + } + + vis_count_set(vis, VIS_COUNT_UNKNOWN); + return keys; +} + static const char *cursors_navigate(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); if (!view_cursors_multiple(view)) { -- cgit v1.2.3