From: NeilBrown Date: Sat, 9 Sep 2023 03:55:48 +0000 (+1000) Subject: Discard DocLeaf - use new pane_leaf() instead. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=2cb960d941dfd8055a0c03bb6e3bed3a7241b122;p=edlib.git Discard DocLeaf - use new pane_leaf() instead. pane_leaf() follows children of the pane as long as there is only one with ->z==0. Returns the final pane found. Use this together with DocPane instead the hackish DocLeaf. Possible some pane_focus() should be changed to pane_leaf(). Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 6fbb9ae7..7525cca1 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -138,7 +138,7 @@ Core features - [ ] send warning message when recursive notification is prohibited. editor:notify:Message:broadcast - [ ] Make DEF_CB really different from DEF_CMD and ensure it is used properly. -- [ ] is DocLeaf really a good idea? Maybe panes should have 'leafward' +- [X] is DocLeaf really a good idea? Maybe panes should have 'leafward' pointer separate to 'focus'? Maybe panes could have optional 'child' method which returns main child - pane_focus() calls that. Maybe pane_focus() find a pane with z=0 and matching w,h ?? @@ -149,6 +149,7 @@ Core features messageline_msg which wants to allow fallthrough, but needs to acknowledge. How can I resolve this? Use Efallthrough as -1. - [ ] make a doc read-only if dir doesn't exist or isn't writable +- [ ] change some pane_focus() to pane_leaf() where appropriate. - [ ] account all mem allocation types separately, and (optionally) report stats regularly - [ ] document the use of doc:replaced. What are the two diff --git a/core-pane.c b/core-pane.c index b1da57dc..4594c7ed 100644 --- a/core-pane.c +++ b/core-pane.c @@ -893,6 +893,34 @@ struct pane *pane_my_child(struct pane *p, struct pane *c) return c; } +struct pane * safe pane_leaf(struct pane *p safe) +{ + /* Find the only child with ->z of zero, + * and recurse on that. + * This ignores popups and stops when a pane + * splits. + */ + struct pane *l = p; + + while (l) { + struct pane *c; + p = l; + l = NULL; + list_for_each_entry(c, &p->children, siblings) { + if (c->z) + continue; + if (!l) { + l = c; + continue; + } + /* Two candidates, so further leaf - stop here */ + l = NULL; + break; + } + } + return p; +} + DEF_CB(take_simple) { struct call_return *cr = container_of(ci->comm, struct call_return, c); diff --git a/core.h b/core.h index c166973a..af62ada0 100644 --- a/core.h +++ b/core.h @@ -508,6 +508,7 @@ static inline int pane_attr_get_int(struct pane *p safe, const char *key safe, return rv; } void pane_free(struct pane *p safe); +struct pane * safe pane_leaf(struct pane *p safe); /* Inlines */ diff --git a/lang-python.c b/lang-python.c index ecd746e5..2152dcd7 100644 --- a/lang-python.c +++ b/lang-python.c @@ -1626,6 +1626,8 @@ static Pane *pane_getpane(Pane *p safe, char *which safe) new = pane_root(p->pane); if (*which == 'F') new = pane_focus(p->pane); + if (*which == 'L') + new = pane_leaf(p->pane); if (new == NULL) { Py_INCREF(Py_None); newpane = (Pane*)Py_None; @@ -1713,7 +1715,10 @@ static const PyGetSetDef pane_getseters[] = { "Root pane", "r"}, {"final_focus", (getter)pane_getpane, (setter)pane_nosetpane, - "Leaf pane", "F"}, + "Final focus pane", "F"}, + {"leaf", + (getter)pane_getpane, (setter)pane_nosetpane, + "Leaf pane", "L"}, {NULL} /* Sentinel */ }; diff --git a/lib-tile.c b/lib-tile.c index b48f1466..e5c85c70 100644 --- a/lib-tile.c +++ b/lib-tile.c @@ -942,6 +942,8 @@ DEF_CMD(tile_doc) } /* Find where 'focus' is open */ name = pane_attr_get(ci->focus, "doc-name"); + if (!name) + return Efallthrough; if (!ti->leaf) ti = tile_first(ti); t = ti; @@ -951,12 +953,11 @@ DEF_CMD(tile_doc) t = list_next_entry(t, tiles); f = t->content; if (f) { - f = pane_focus(f); + f = pane_leaf(f); n = pane_attr_get(f, "doc-name"); - if (name && n && strcmp(n, name) == 0) + if (n && strcmp(n, name) == 0) return comm_call(ci->comm2, "callback:pane", - strcmp(ci->key, "DocLeaf") == 0 - ? f : t->p, + t->p, 0, NULL, t->name); } } while (t != ti); @@ -1052,7 +1053,6 @@ void edlib_init(struct pane *ed safe) key_add(tile_map, "OtherPane", &tile_other); key_add(tile_map, "ThisPane", &tile_this); key_add(tile_map, "DocPane", &tile_doc); - key_add(tile_map, "DocLeaf", &tile_doc); key_add(tile_map, "RootPane", &tile_root); key_add(tile_map, "Clone", &tile_clone); key_add(tile_map, "Child-Notify", &tile_child_notify); diff --git a/python/lib-diff.py b/python/lib-diff.py index 08cb60dc..ff427673 100644 --- a/python/lib-diff.py +++ b/python/lib-diff.py @@ -304,7 +304,9 @@ class DiffPane(edlib.Pane): focus.call("Message", "File %s not found" % fname) return edlib.Efail - par = focus.call("DocLeaf", d, ret='pane') + par = focus.call("DocPane", d, ret='pane') + if par: + par = par.leaf if not par: par = focus.call("OtherPane", d, ret='pane') if not par: diff --git a/python/lib-make.py b/python/lib-make.py index ed9ea341..6725d3ac 100644 --- a/python/lib-make.py +++ b/python/lib-make.py @@ -466,9 +466,9 @@ class MakePane(edlib.Pane): else: in_popup = True if where in ['OtherPane', 'AnyPane']: - par = focus.call("DocLeaf", d, ret='pane') + par = focus.call("DocPane", d, ret='pane') if par: - pass + par = par.leaf elif where == 'OtherPane': pane = focus.call(where, ret='pane') else: