Lagrange [work/v1.10]

Home button opens a random "homepage" bookmark

=> 01b09cc3cf3cd25396c53e184563fbfdab74f8e7

diff --git a/src/app.c b/src/app.c
index 84e57ce2..2928522b 100644
--- a/src/app.c
+++ b/src/app.c
@@ -912,11 +912,30 @@ iBool handleCommand_App(const char *cmd) {
         setText_InputWidget(findChild_Widget(dlg, "prefs.proxy.gopher"),
                             schemeProxy_App(range_CStr("gopher")));
         setCommandHandler_Widget(dlg, handlePrefsCommands_);
-        postCommand_App("focus.set id:prefs.downloads");
     }
     else if (equal_Command(cmd, "navigate.home")) {
-        /* TODO: Look for bookmarks tagged homepage, or use the URL set in Preferences. */
-        postCommand_App("open url:about:lagrange");
+        /* Look for bookmarks tagged "homepage". */
+        iRegExp *pattern = iClob(new_RegExp("\\bhomepage\\b", caseInsensitive_RegExpOption));
+        const iPtrArray *homepages =
+            list_Bookmarks(d->bookmarks, NULL, filterTagsRegExp_Bookmarks, pattern);
+        if (isEmpty_PtrArray(homepages)) {
+            postCommand_App("open url:about:lagrange");
+        }
+        else {
+            iStringSet *urls = iClob(new_StringSet());
+            iConstForEach(PtrArray, i, homepages) {
+                const iBookmark *bm = i.ptr;
+                /* Try to switch to a different bookmark. */
+                if (cmpStringCase_String(url_DocumentWidget(document_App()), &bm->url)) {
+                    insert_StringSet(urls, &bm->url);
+                }
+            }
+            if (!isEmpty_StringSet(urls)) {
+                postCommandf_App(
+                    "open url:%s",
+                    cstr_String(constAt_StringSet(urls, iRandoms(0, size_StringSet(urls)))));
+            }
+        }
         return iTrue;
     }
     else if (equal_Command(cmd, "zoom.set")) {
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 8fe7d109..7e98fb27 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 #include 
 #include 
 #include 
+#include 
 
 void init_Bookmark(iBookmark *d) {
     init_String(&d->url);
@@ -166,6 +167,12 @@ iBookmark *get_Bookmarks(iBookmarks *d, uint32_t id) {
     return (iBookmark *) value_Hash(&d->bookmarks, id);
 }
 
+iBool filterTagsRegExp_Bookmarks(void *regExp, const iBookmark *bm) {
+    iRegExpMatch m;
+    init_RegExpMatch(&m);
+    return matchString_RegExp(regExp, &bm->tags, &m);
+}
+
 const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp,
                                 iBookmarksFilterFunc filter, void *context) {
     lock_Mutex(d->mtx);
diff --git a/src/bookmarks.h b/src/bookmarks.h
index aac83be1..4889e7b5 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -55,6 +55,8 @@ iBookmark *get_Bookmarks    (iBookmarks *, uint32_t id);
 typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *);
 typedef int   (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **);
 
+iBool   filterTagsRegExp_Bookmarks  (void *regExp, const iBookmark *);
+
 /**
  * Lists all or a subset of the bookmarks in a sorted array of Bookmark pointers.
  *
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.10/cdiff/01b09cc3cf3cd25396c53e184563fbfdab74f8e7
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
60.787984 milliseconds
Gemini-to-HTML Time
0.251283 milliseconds

This content has been proxied by September (ba2dc).