]> git.neil.brown.name Git - edlib.git/commitdiff
Define doc:set-attr and use in line-count.
authorNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 03:21:58 +0000 (14:21 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 04:10:10 +0000 (15:10 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
lib-line-count.c

index 2d8129dc95ad4ee1b8e391785727d4d31109ada0..c1f9c84d33c34e58aaefa02b757dd544509cdd37 100644 (file)
@@ -333,6 +333,18 @@ DEF_CMD(doc_do_replace)
        return 1;
 }
 
+DEF_CMD(doc_attr_set)
+{
+       struct doc_data *dd = ci->home->data;
+       struct doc *d = dd->doc;
+
+       if (ci->str2 == NULL && ci->extra == 1)
+               attr_set_int(&d->attrs, ci->str, ci->numeric);
+       else
+               attr_set_str(&d->attrs, ci->str, ci->str2, -1);
+       return 1;
+}
+
 static struct map *doc_default_cmd;
 
 static void init_doc_defaults(void)
@@ -351,6 +363,7 @@ static void init_doc_defaults(void)
        key_add(doc_default_cmd, "Move-Line", &doc_line);
        key_add(doc_default_cmd, "Move-View-Large", &doc_page);
        key_add(doc_default_cmd, "Replace", &doc_do_replace);
+       key_add(doc_default_cmd, "doc:attr-set", &doc_attr_set);
 }
 
 DEF_CMD(doc_handle)
diff --git a/core.h b/core.h
index 8964e04a3c7dbd76df18196ac7913f73b683c7a3..284a8baad1961bfc867c6f32f8b1a046daa80b98 100644 (file)
--- a/core.h
+++ b/core.h
@@ -497,6 +497,22 @@ static inline int call5(char *key, struct pane *focus, int numeric, struct mark
        return key_handle_focus(&ci);
 }
 
+static inline int call7(char *key, struct pane *focus, int numeric, struct mark *m,
+                       char *str, int extra, char *str2, struct mark *m2)
+{
+       struct cmd_info ci = {0};
+
+       ci.key = key;
+       ci.focus = focus;
+       ci.numeric = numeric;
+       ci.mark = m;
+       ci.mark2 = m2;
+       ci.str = str;
+       ci.str2 = str2;
+       ci.extra = extra;
+       return key_handle_focus(&ci);
+}
+
 struct call_return {
        struct command c;
        struct mark *m, *m2;
index 1b85c3390c3efce9e759dde16b7c70c468c48265..7227cee291535e3f9aea547288bdd990b5de6f1a 100644 (file)
@@ -128,7 +128,6 @@ static void count_calculate(struct doc *d, struct mark *start, struct mark *end)
        int type = doc_find_view(d->home, &count_notify);
        int lines, words, chars, l, w, c;
        struct mark *m, *m2;
-       struct attrset **attrs;
 
        if (type < 0)
                type = doc_add_view(d->home, &count_notify, 0);
@@ -207,13 +206,16 @@ static void count_calculate(struct doc *d, struct mark *start, struct mark *end)
                chars += c;
        }
 done:
-       if (end)
-               attrs = &end->attrs;
-       else
-               attrs = &d->attrs;
-       attr_set_int(attrs, "lines", lines);
-       attr_set_int(attrs, "words", words);
-       attr_set_int(attrs, "chars", chars);
+       if (end) {
+               struct attrset **attrs = &end->attrs;
+               attr_set_int(attrs, "lines", lines);
+               attr_set_int(attrs, "words", words);
+               attr_set_int(attrs, "chars", chars);
+       } else {
+               call5("doc:attr-set", d->home, lines, NULL, "lines", 1);
+               call5("doc:attr-set", d->home, words, NULL, "words", 1);
+               call5("doc:attr-set", d->home, chars, NULL, "chars", 1);
+       }
 }
 
 DEF_CMD(count_lines)