From d61cc39d4e4c3a18d6f3a024d6693efe624cdfa3 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 26 May 2023 09:47:35 +1000 Subject: [PATCH] doc: add default doc:get-attr which returns pane attribute. Sometimes we want an attribute which can vary with location in the document, but offen i satisfied with a document-wide value. fill:start-re is a good example. Provide a default doc:get-attr, which will be called if no attr can be found at the specific location. This returns a pane attribute is possible. Also ensure all current doc:get-attr function fall through if they cannot find a value. Signed-off-by: NeilBrown --- DOC/TODO.md | 2 +- core-doc.c | 17 +++++++++++++++++ doc-text.c | 2 ++ python/module-notmuch.py | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/DOC/TODO.md b/DOC/TODO.md index d46bc6e2..129313a8 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -150,7 +150,7 @@ Requirements for a v1.0 release Core features ------------- -- [ ] allow doc:get-attr to get a pane attribute if there is no content attribute. +- [X] allow doc:get-attr to get a pane attribute if there is no content attribute. - [ ] design a way for a keystroke to interrupt a long-running function. - [ ] extend Draw:measure protocol to allow constant-width-fonts to cannot-scale displays can be detected and measurement optimised for. diff --git a/core-doc.c b/core-doc.c index c08ca122..e4db60f7 100644 --- a/core-doc.c +++ b/core-doc.c @@ -550,6 +550,22 @@ DEF_CMD(doc_get_attr) return 1; } +DEF_CMD(doc_doc_get_attr) +{ + /* If the document doesn't provide the attribute for + * this location, see if there is a pane-attribute for + * the document. + */ + char *a; + + if (!ci->str) + return Enoarg; + a = pane_attr_get(ci->home, ci->str); + if (a) + comm_call(ci->comm2, "cb", ci->focus, 0, NULL, a); + return 1; +} + DEF_CMD(doc_set_name) { struct doc *d = ci->home->data; @@ -1241,6 +1257,7 @@ static void init_doc_cmds(void) key_add(doc_default_cmd, "doc:vmark-prev", &doc_vmarkprev); key_add(doc_default_cmd, "doc:vmark-new", &doc_vmarknew); key_add(doc_default_cmd, "get-attr", &doc_get_attr); + key_add(doc_default_cmd, "doc:get-attr", &doc_doc_get_attr); key_add(doc_default_cmd, "doc:set-name", &doc_set_name); key_add(doc_default_cmd, "doc:destroy", &doc_do_destroy); key_add(doc_default_cmd, "doc:drop-cache", &doc_drop_cache); diff --git a/doc-text.c b/doc-text.c index cfbd6cb6..1bf8ef41 100644 --- a/doc-text.c +++ b/doc-text.c @@ -2396,6 +2396,8 @@ DEF_CMD(text_doc_get_attr) return Enoarg; a = text_attrset(d, m, &o); val = attr_get_str(a, attr, o); + if (!val && !ci->num2) + return Efallthrough; comm_call(ci->comm2, "callback:get_attr", ci->focus, 0, m, val, 0, NULL, attr); if (ci->num2 == 1) { diff --git a/python/module-notmuch.py b/python/module-notmuch.py index 329a4b18..a06f0e3a 100644 --- a/python/module-notmuch.py +++ b/python/module-notmuch.py @@ -1684,7 +1684,8 @@ class notmuch_query(edlib.Doc): if not val is None: comm2("callback", focus, val, mark, attr) - return 1 + return 1 + return edlib.Efallthrough def handle_get_attr(self, key, focus, str, comm2, **a): "handle:get-attr" -- 2.39.5