From 04f924dd91d2c9345598218db6560f509bba5484 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 10 Dec 2015 14:21:58 +1100 Subject: [PATCH] Define doc:set-attr and use in line-count. Signed-off-by: NeilBrown --- core-doc.c | 13 +++++++++++++ core.h | 16 ++++++++++++++++ lib-line-count.c | 18 ++++++++++-------- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/core-doc.c b/core-doc.c index 2d8129dc..c1f9c84d 100644 --- a/core-doc.c +++ b/core-doc.c @@ -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 8964e04a..284a8baa 100644 --- 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; diff --git a/lib-line-count.c b/lib-line-count.c index 1b85c339..7227cee2 100644 --- a/lib-line-count.c +++ b/lib-line-count.c @@ -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) -- 2.39.5