]> git.neil.brown.name Git - edlib.git/commitdiff
doc: add default doc:get-attr which returns pane attribute.
authorNeilBrown <neil@brown.name>
Thu, 25 May 2023 23:47:35 +0000 (09:47 +1000)
committerNeilBrown <neil@brown.name>
Fri, 26 May 2023 22:18:43 +0000 (08:18 +1000)
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 <neil@brown.name>
DOC/TODO.md
core-doc.c
doc-text.c
python/module-notmuch.py

index d46bc6e2c8c2f2ce2d01ba5a2c10972f1dd497b0..129313a8282b19d0d855fa1083f58f7e18b6d640 100644 (file)
@@ -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.
index c08ca12208d1d36d1396dca03eb8a4e3d1dff40c..e4db60f7cc37abae1698bcfab5c290882d00d026 100644 (file)
@@ -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);
index cfbd6cb623890ff6a3c91b7e2ad52827b28bf9e3..1bf8ef4117ffe8372496e5abe3b5e6171ac1e06e 100644 (file)
@@ -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) {
index 329a4b183195071bcbae51f56b4d2b54b3bc4ca0..a06f0e3a2a216cbb43cacc8be893540837f2a074 100644 (file)
@@ -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"