From: Alex Schroeder Date: Mon, 20 Jul 2020 08:03:12 +0000 (+0200) Subject: Fixes for elpher-menu X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=63ad5dac98dcc2c19ba03bc333a84f641c7c5975;p=elpher.git Fixes for elpher-menu 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). --- diff --git a/elpher.el b/elpher.el index 0ca7cdb..6513ee7 100644 --- a/elpher.el +++ b/elpher.el @@ -2156,8 +2156,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) @@ -2171,63 +2171,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 ;;