+(defun elpher-menu-refresh-current ()
+ "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)
+ (cond ((eq major-mode 'elpher-mode)
+ (vector "G"
+ (or (elpher-find-title)
+ (elpher-page-display-string elpher-current-page)
+ (buffer-name))
+ (or (elpher-address-to-url
+ (elpher-page-address elpher-current-page))
+ "none")))
+ ((eq major-mode 'gemini-mode)
+ (vector "E"
+ (or (elpher-page-display-string elpher-current-page)
+ (buffer-name))
+ (or (elpher-address-to-url
+ (elpher-page-address elpher-current-page))
+ "none")))
+ ((eq major-mode 'eww-mode)
+ (vector "W"
+ (or (plist-get eww-data :title)
+ (buffer-name))
+ (or (eww-current-url)
+ "none"))))))
+
+(defun elpher-menu-refresh-history ()
+ "Return current entries for `elpher-menu-refresh'.
+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'."
+ ;; Every section starts with the current page, followed by some
+ ;; history items, and ends with the separator.
+ (let ((separator (list nil
+ (vector "-"
+ (make-string 25 ?-)
+ (make-string 25 ?-)))))
+ (cond ((eq major-mode 'elpher-mode)
+ ;; A pair is (BUFFER-OR-DATA . PAGE) where BUFFER-OR-DTA is
+ ;; the current buffer, if possible, or list (BUFFER FUNC
+ ;; &rest ARGS) telling us which BUFFER to switch to, and
+ ;; what function to call. The last item of elpher-history
+ ;; has a nil page, so when that shows up, use the separator
+ (mapcar (lambda (pair)
+ (if (cdr pair)
+ (list (car pair)
+ (vector "G"
+ (or (elpher-page-display-string (cdr pair)) "?")
+ (or (elpher-address-to-url
+ (elpher-page-address (cdr pair))) "none")))
+ separator))
+ (cons (cons (current-buffer) elpher-current-page)
+ (mapcar (lambda (page)
+ (cons (list (current-buffer) 'elpher-visit-page page)
+ page))
+ elpher-history))))
+ ((eq major-mode 'gemini-mode)
+ ;; No history means a list of one item. Add a separator.
+ (list (list (current-buffer)
+ (vector "E"
+ (or (elpher-page-display-string elpher-current-page)
+ (buffer-name))
+ (or (elpher-address-to-url
+ (elpher-page-address elpher-current-page)))))
+ separator))
+ ((eq major-mode 'eww-mode)
+ ;; A pair is (BUFFER-OR-DATA . PAGE) where BUFFER-OR-DTA is
+ ;; the current buffer, if possible, or list (BUFFER FUNC
+ ;; &rest ARGS) telling us which BUFFER to switch to, and
+ ;; what function to call. Add the separator at the end.
+ (nconc (cons (list (current-buffer)
+ (vector "W"
+ (or (plist-get eww-data :title) "none")
+ (or (plist-get eww-data :url) "none")))
+ (mapcar (lambda (data)
+ (list
+ (list (current-buffer) 'eww-restore-history data)
+ (vector "W"
+ (or (plist-get data :title) "none")
+ (or (plist-get data :url) "none"))))
+ eww-history))
+ (list separator))))))
+