Fiddling with bookmarks display.
[elpher.git] / elpher.el
index 4e69967..0c4cd81 100644 (file)
--- a/elpher.el
+++ b/elpher.el
     (telnet elpher-get-telnet-page nil "tel" elpher-telnet)
     (other-url elpher-get-other-url-page nil "url" elpher-other-url)
     ((special start) elpher-get-start-page nil "E" elpher-index)
+    ((special bookmarks) elpher-get-bookmarks-page nil "E" elpher-index)
     ((special history) elpher-get-history-page nil "E" elpher-index)
     ((special visited-pages) elpher-get-visited-pages-page nil "E" elpher-index))
   "Association list from types to getters, renderers, margin codes and index faces.")
@@ -1758,7 +1759,7 @@ This is rendered using `elpher-get-visited-pages-page' via `elpher-type-map'."
                (elpher-insert-index-record display-string address))))
        (insert "No history items found.\n"))
      (insert "\n" footer-line "\n"
-             "Select and entry or press 'u' to return to the previous page.")
+             "Select an entry or press 'u' to return to the previous page.")
      (elpher-restore-pos))))
 
 
@@ -1798,9 +1799,19 @@ record for the current elpher page."
 
 ;;;###autoload
 (defun elpher-bookmark-jump (bookmark)
-  "Go to a particular BOOKMARK."
-  (let* ((url (cdr (assq 'location bookmark))))
-    (elpher-go url)))
+  "Handler used to open a bookmark using elpher.
+The argument BOOKMARK is a bookmark record passed to the function.
+This handler is responsible for loading the bookmark in some buffer,
+then making that buffer the current buffer.  It should not switch
+to the buffer."
+  (let* ((url (cdr (assq 'location bookmark)))
+         (cleaned-url (string-trim url))
+         (address (elpher-address-from-url cleaned-url))
+         (page (elpher-make-page cleaned-url address)))
+    (elpher-with-clean-buffer
+     (elpher-visit-page page))
+    (set-buffer (get-buffer elpher-buffer-name))
+    nil))
 
 (defun elpher-bookmark-link ()
   "Bookmark the link at point.
@@ -1851,6 +1862,36 @@ bookmark file and offer to import it."
       (rename-file old-bookmarks-file (concat old-bookmarks-file "-legacy"))))
   (call-interactively #'bookmark-bmenu-list))
 
+(defun elpher-get-bookmarks-page (renderer)
+  "Getter which displays the history page (RENDERER must be nil)."
+  (when renderer
+    (elpher-visit-previous-page)
+    (error "Command not supported for bookmarks page"))
+  (let* ((names (seq-filter (lambda (name)
+                              (let ((record (bookmark-get-bookmark-record name)))
+                                ;; record
+                                (eq (alist-get 'handler record) 'elpher-bookmark-jump)
+                                ))
+                            (bookmark-all-names))))
+    (elpher-with-clean-buffer
+     (insert " ---- Elpher Bookmarks ---- \n\n")
+     (if names
+         (dolist (name names)
+           (when names
+             (let* ((url (alist-get 'location (bookmark-get-bookmark-record name)))
+                    (address (elpher-address-from-url url)))
+               (elpher-insert-index-record name address))))
+       (insert "No bookmarked pages found.\n"))
+     (insert "\n --------------------------\n\n"
+             "Select an entry or press 'u' to return to the previous page.")
+     (elpher-restore-pos))))
+
+(defun elpher-show-bookmarks ()
+  "Show elpher bookmarks."
+  (interactive)
+  (elpher-visit-page
+   (elpher-make-page "Elpher Bookmarks"
+                    (elpher-make-special-address 'bookmarks))))
 
 ;;; Integrations
 ;;
@@ -2191,7 +2232,8 @@ When run interactively HOST-OR-URL is read from the minibuffer."
     (define-key map (kbd "C") 'elpher-copy-current-url)
     (define-key map (kbd "a") 'elpher-bookmark-link)
     (define-key map (kbd "A") 'elpher-bookmark-current)
-    (define-key map (kbd "B") 'elpher-open-bookmarks)
+    (define-key map (kbd "B") 'elpher-show-bookmarks)
+    ;; (define-key map (kbd "B") 'elpher-open-bookmarks)
     (define-key map (kbd "!") 'elpher-set-gopher-coding-system)
     (define-key map (kbd "F") 'elpher-forget-current-certificate)
     (when (fboundp 'evil-define-key*)
@@ -2223,7 +2265,8 @@ When run interactively HOST-OR-URL is read from the minibuffer."
        (kbd "C") 'elpher-copy-current-url
        (kbd "a") 'elpher-bookmark-link
        (kbd "A") 'elpher-bookmark-current
-       (kbd "B") 'elpher-open-bookmarks
+       ;; (kbd "B") 'elpher-open-bookmarks
+       (kbd "B") 'elpher-show-bookmarks
        (kbd "!") 'elpher-set-gopher-coding-system
        (kbd "F") 'elpher-forget-current-certificate))
     map)
@@ -2240,7 +2283,8 @@ functions which initialize the client, namely
   (setq-local elpher-history nil)
   (setq-local elpher-buffer-name (buffer-name))
   (setq-local bookmark-make-record-function #'elpher-bookmark-make-record)
-  (setq-local imenu-create-index-function (lambda () elpher--gemini-page-headings)))
+  (setq-local imenu-create-index-function (lambda () elpher--gemini-page-headings))
+  (setq-local xterm-color-preserve-properties t))
 
 (when (fboundp 'evil-set-initial-state)
   (evil-set-initial-state 'elpher-mode 'motion))