From: NeilBrown Date: Fri, 29 Sep 2023 23:14:09 +0000 (+1000) Subject: Change return value of docs:byeach X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=4ae81582a37188fd103b6cfad2fc05729dee800e;p=edlib.git Change return value of docs:byeach Rather than 0 for continue and non-zero for stop, use Efalse for don't continue, Errors for abort, and normal values for continue. This makes it similar to event handlers which stop being called after Efalse. Also cause a False return from python code to be Efalse. Signed-off-by: NeilBrown --- diff --git a/doc-docs.c b/doc-docs.c index 68cde8d4..e420c5fd 100644 --- a/doc-docs.c +++ b/doc-docs.c @@ -302,14 +302,19 @@ DEF_CMD(docs_callback_byeach) { struct docs *doc = ci->home->doc_data; struct pane *p; + int ret = 1; list_for_each_entry(p, &doc->collection->children, siblings) { int r; r = comm_call(ci->comm2, "callback:doc", p); - if (r) + if (r > ret) + ret = r; + if (r == Efalse) + return ret; + if (r < Efalse) return r; } - return 1; + return ret; } DEF_CMD(docs_callback_choose) diff --git a/lang-python.c b/lang-python.c index 1afdf27f..084f7643 100644 --- a/lang-python.c +++ b/lang-python.c @@ -533,7 +533,7 @@ REDEF_CB(python_call) else if (PyLong_Check(ret)) rv = PyLong_AsLong(ret); else if (PyBool_Check(ret)) - rv = (ret == Py_True); + rv = (ret == Py_True) ? 1 : Efalse; else if (PyUnicode_Check(ret) && PyUnicode_GET_LENGTH(ret) >= 1) rv = CHAR_RET(PyUnicode_READ_CHAR(ret, 0)); else diff --git a/mode-emacs.c b/mode-emacs.c index cd287e56..ca958559 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -940,39 +940,39 @@ DEF_CB(find_helper) * So return this one and keep looking. */ h->ret = p; - return 0; + return 1; } else { /* Want the pane that is after nothing, so * the first. This one. All done. */ h->ret = p; - return 1; + return Efalse; } } name = pane_attr_get(ci->focus, "doc-name"); if (!name) - return 0; + return 1; if (strcmp(name, h->name) == 0) { if (h->want_prev) { /* Want the previous one, which is * already in ->ret */ - return 1; + return Efalse; } else { /* Want the next one, so clear name * and keep going. */ h->name = NULL; - return 0; + return 1; } } else { if (h->want_prev) { /* This might be what I want - keep it in case */ h->ret = p; - return 0; + return 1; } else { /* Don't want this - just keep going */ - return 0; + return 1; } } } diff --git a/python/lib-abbrev.py b/python/lib-abbrev.py index 67b13635..d2733656 100644 --- a/python/lib-abbrev.py +++ b/python/lib-abbrev.py @@ -182,14 +182,14 @@ class AbbrevPane(edlib.Pane): def each_doc(self, key, focus, **a): if self.docs_scanned > 5: # already handle 5 docs - stop now - return 1 + return False if focus['doc-name'] == self['doc-name']: - return 0 + return 1 if "text" not in focus["doc-type"]: - return 0 + return 1 self.docs_scanned += 1 self.gather_completions(focus, None) - return 0 + return 1 def next_completion(self, dir): if self.current < 0: diff --git a/python/lib-server.py b/python/lib-server.py index 295e278d..41438a05 100755 --- a/python/lib-server.py +++ b/python/lib-server.py @@ -276,8 +276,8 @@ if sys.argv[0] == "": focus = a['focus'] if focus.notify("doc:done", "test") > 0: choice.append(focus) - return 1 - return 0 + return False + return 1 focus.call("docs:byeach", lambda key,**a:choose(choice, a)) if len(choice): par = focus.call("ThisPane", ret='pane') diff --git a/python/module-notmuch.py b/python/module-notmuch.py index f0e7b627..ce0dec1d 100644 --- a/python/module-notmuch.py +++ b/python/module-notmuch.py @@ -1990,8 +1990,8 @@ class notmuch_master_view(edlib.Pane): focus = a['focus'] if focus['email-sent'] == 'no': choice.append(focus) - return 1 - return 0 + return False + return 1 focus.call("docs:byeach", lambda key,**a:choose(choice, a)) if len(choice): par = focus.call("PopupTile", "MD3tsa", ret='pane') @@ -3798,8 +3798,8 @@ def notmuch_compose(key, focus, **a): focus = a['focus'] if focus['email-sent'] == 'no': choice.append(focus) - return 1 - return 0 + return False + return 1 focus.call("docs:byeach", lambda key,**a:choose(choice, a)) if len(choice): par = focus.call("ThisPane", ret='pane')