]> git.neil.brown.name Git - edlib.git/commitdiff
Change return value of docs:byeach
authorNeilBrown <neil@brown.name>
Fri, 29 Sep 2023 23:14:09 +0000 (09:14 +1000)
committerNeilBrown <neil@brown.name>
Fri, 29 Sep 2023 23:47:43 +0000 (09:47 +1000)
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 <neil@brown.name>
doc-docs.c
lang-python.c
mode-emacs.c
python/lib-abbrev.py
python/lib-server.py
python/module-notmuch.py

index 68cde8d48cafce77e9789784de2ba02bdc0a1697..e420c5fd7c13e53f1afb0c46a108f92e24686211 100644 (file)
@@ -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)
index 1afdf27f92c71c9ee0feefde914ae5668591a944..084f76434674fcd520ce9a06e6dbcba4e82e3926 100644 (file)
@@ -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
index cd287e566376f0bf4bd6b787149e4e46ac78b5a6..ca9585594ced68507ad5c11f697efbb199b09d7d 100644 (file)
@@ -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;
                }
        }
 }
index 67b136357ded49017bc51244ecdef5882d079b0d..d27336563038b145300b3e3b4bff87e51e214cf3 100644 (file)
@@ -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:
index 295e278deb0a3f3363dfaed4a19f6b3ee9809002..41438a05bbf45984ad60f78fca8a6d1e9a5e0b40 100755 (executable)
@@ -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')
index f0e7b627fddbc977c19e3400e3dac8399efd6a7f..ce0dec1d45e1802573c07180696f70de28451621 100644 (file)
@@ -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')