aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-06-15 12:40:30 +0200
committerMarc André Tanner <mat@brain-dump.org>2017-06-15 15:51:43 +0200
commit6aac9391ee4f38459d5fa53e82dc11647d755126 (patch)
treee409d9b92d0e27059d427f363d3b7b411cc293d7
parent6ecf4a118520c168b3dd58679c03ff5fac6cb504 (diff)
downloadvis-6aac9391ee4f38459d5fa53e82dc11647d755126.tar.gz
vis-6aac9391ee4f38459d5fa53e82dc11647d755126.tar.xz
vis: implement subtraction of selections
-rw-r--r--main.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/main.c b/main.c
index 1966edf..3253a22 100644
--- a/main.c
+++ b/main.c
@@ -84,6 +84,8 @@ static const char *selections_union(Vis*, const char *keys, const Arg *arg);
static const char *selections_intersect(Vis*, const char *keys, const Arg *arg);
/* perform complement of current active selections */
static const char *selections_complement(Vis*, const char *keys, const Arg *arg);
+/* subtract selections from register */
+static const char *selections_minus(Vis*, const char *keys, const Arg *arg);
/* adjust current used count according to keys */
static const char *count(Vis*, const char *keys, const Arg *arg);
/* move to the count-th line or if not given either to the first (arg->i < 0)
@@ -291,6 +293,7 @@ enum {
VIS_ACTION_SELECTIONS_UNION,
VIS_ACTION_SELECTIONS_INTERSECT,
VIS_ACTION_SELECTIONS_COMPLEMENT,
+ VIS_ACTION_SELECTIONS_MINUS,
VIS_ACTION_TEXT_OBJECT_WORD_OUTER,
VIS_ACTION_TEXT_OBJECT_WORD_INNER,
VIS_ACTION_TEXT_OBJECT_LONGWORD_OUTER,
@@ -1076,6 +1079,11 @@ static const KeyAction vis_action[] = {
VIS_HELP("Complement selections")
selections_complement
},
+ [VIS_ACTION_SELECTIONS_MINUS] = {
+ "vis-selections-minus",
+ VIS_HELP("Subtract selections from register")
+ selections_minus
+ },
[VIS_ACTION_TEXT_OBJECT_WORD_OUTER] = {
"vis-textobject-word-outer",
VIS_HELP("A word leading and trailing whitespace included")
@@ -1753,6 +1761,34 @@ static const char *selections_complement(Vis *vis, const char *keys, const Arg *
return keys;
}
+static const char *selections_minus(Vis *vis, const char *keys, const Arg *arg) {
+ View *view = vis_view(vis);
+ enum VisRegister reg = vis_register_used(vis);
+ Array a = view_selections_get_all(view);
+ Array b = vis_register_selections_get(vis, reg);
+ Array sel;
+ array_init_from(&sel, &a);
+ Array b_complement;
+ array_init_from(&b_complement, &b);
+
+ Filerange universe = text_range_new(0, 0);
+ Filerange *max = array_get(&a, array_length(&a)-1);
+ if (max)
+ universe = text_range_new(max->end, max->end);
+ complement(&b_complement, &b, &universe);
+ intersect(&sel, &a, &b_complement);
+
+ view_selections_set_all(view, &sel);
+ vis_cancel(vis);
+
+ array_release(&a);
+ array_release(&b);
+ array_release(&b_complement);
+ array_release(&sel);
+
+ return keys;
+}
+
static const char *replace(Vis *vis, const char *keys, const Arg *arg) {
if (!keys[0]) {
vis_keymap_disable(vis);