Fixes for elpher-menu
authorAlex Schroeder <alex@gnu.org>
Mon, 20 Jul 2020 08:03:12 +0000 (10:03 +0200)
committerAlex Schroeder <alex@gnu.org>
Mon, 20 Jul 2020 08:03:12 +0000 (10:03 +0200)
Make URL wider in the display.

Refactor elpher-menu-refresh-current to be easier to read.

Fix elpher-menu-refresh-current such that Gemini Mode entries aren't
shown as type "W" (EWW).

elpher.el

index dc83212..1da26a6 100644 (file)
--- a/elpher.el
+++ b/elpher.el
@@ -2151,8 +2151,8 @@ With an optional argument, add all the history items, too."
     ;; Set up `tabulated-list-format'.
     (setq tabulated-list-format
          (vector '("T" 1 t)
-                 '("URL" 35 t)
-                 '("Name" 35 t))
+                 '("URL" 40 t)
+                 '("Name" 30 t))
          tabulated-list-sort-key nil)
     ;; Collect info for each buffer we're interested in.
     (let (entries)
@@ -2166,63 +2166,78 @@ With an optional argument, add all the history items, too."
     (tabulated-list-init-header))
 
 (defun elpher-menu-refresh-current ()
-  "Return current entries for `elpher-menu-refresh'.
-If we're only interested in the current entries, then this
-function can only return a list of a single item per buffer."
+  "Returns an item for `elpher-menu-refresh'
+based on the current buffer.
+
+An item is a list (BUFFER VECTOR) where BUFFER is the buffer this
+item refers to and VECTOR is what to display in the tabulated
+list established by `elpher-menu-refresh'. See
+`tabulated-list-format'."
   (list (current-buffer)
-       (vector
-        (cond ((eq major-mode 'elpher-mode) "G")
-              ((eq major-mode 'gemini-mode) "E")
-              ((eq major-mode 'eww-mode) "W"))
-        (cond ((eq major-mode 'elpher-mode)
-               (or (elpher-address-to-url
-                    (elpher-page-address elpher-current-page))
-                   "none"))
-              ((eq major-mode 'gemini-mode)
-               (or (elpher-address-to-url
-                    (elpher-page-address elpher-current-page))
-                   "none"))
-              ((eq major-mode 'eww-mode)
-               (eww-current-url)))
-        (cond ((eq major-mode 'elpher-mode)
-               (or (elpher-find-title)
-                   (elpher-page-display-string elpher-current-page)))
-              ((eq major-mode 'gemini-mode)
-               (or (elpher-page-display-string elpher-current-page)
-                   (buffer-name)))
-              ((eq major-mode 'eww-mode)
-               (plist-get eww-data :title))))))
+       (cond ((eq major-mode 'elpher-mode)
+              (vector "G"
+                      (or (elpher-address-to-url
+                           (elpher-page-address elpher-current-page))
+                          "none")
+                      (or (elpher-find-title)
+                          (elpher-page-display-string elpher-current-page)
+                          (buffer-name))))
+             ((eq major-mode 'gemini-mode)
+              (vector "E"
+                      (or (elpher-address-to-url
+                           (elpher-page-address elpher-current-page))
+                          "none")
+                      (or (elpher-page-display-string elpher-current-page)
+                          (buffer-name))))
+             ((eq major-mode 'eww-mode)
+              (vector "W"
+                      (or (eww-current-url)
+                          "none")
+                      (or (plist-get eww-data :title)
+                          (buffer-name)))))))
 
 (defun elpher-menu-refresh-history ()
   "Return current entries for `elpher-menu-refresh'.
-If we're only interested in the current entries, then this
-function can only return a list of a single item per buffer."
+This returns a list of items for the current buffer, based on the
+buffer's history.
+
+An item is a list (BUFFER VECTOR) where BUFFER is the buffer this
+item refers to and VECTOR is what to display in the tabulated
+list established by `elpher-menu-refresh'. See
+`tabulated-list-format'."
   (let ((separator (list (current-buffer)
                         (vector
-                         "E"
+                         "-"
                          (make-string 25 ?-)
                          (make-string 25 ?-)))))
-    (if (eq major-mode 'elpher-mode)
-       ;; every section starts with the current page and ends with
-       ;; the separator
-       (mapcar (lambda (page)
-                 (if page
-                     (list (current-buffer)
-                           (vector
-                            "E"
-                            (or (elpher-address-to-url
-                                 (elpher-page-address page)) "none")
-                            (or (elpher-page-display-string page) "?")))
-                   separator))
-               (cons elpher-current-page elpher-history))
-      (nconc (mapcar (lambda (data)
-                      (list (current-buffer)
-                            (vector
-                             "W"
-                             (plist-get data :url)
-                             (plist-get data :title))))
-                    (cons eww-data eww-history))
-            (list separator)))))
+    (cond ((eq major-mode 'elpher-mode)
+          ;; every section starts with the current page and ends with
+          ;; the separator
+          (mapcar (lambda (page)
+                    (if page
+                        (list (current-buffer)
+                              (vector "G"
+                                      (or (elpher-address-to-url
+                                           (elpher-page-address page)) "none")
+                                      (or (elpher-page-display-string page) "?")))
+                      separator))
+                  (cons elpher-current-page elpher-history)))
+         ((eq major-mode 'gemini-mode)
+          ;; no history means a list of one item
+          (list (list (current-buffer)
+                      (vector "E"
+                              (or (elpher-address-to-url
+                                   (elpher-page-address elpher-current-page)))
+                              (or (elpher-page-display-string elpher-current-page)
+                                  (buffer-name))))))
+          ((eq major-mode 'eww-mode)
+           (nconc (mapcar (lambda (data)
+                            (list (current-buffer)
+                                  (vector "W"
+                                          (or (plist-get data :url) "none")
+                                          (or (plist-get data :title) "none"))))
+                          (cons eww-data eww-history))
+                  (list separator))))))
 
 ;;; Main start procedure
 ;;