From: Alexis Date: Fri, 4 Sep 2020 07:57:47 +0000 (+1000) Subject: Cache links in gemini pages. X-Git-Tag: bookmarks~32^2 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=elpher.git;a=commitdiff_plain;h=42b70bca5bd23de3de35ec95a196d00cdf88dc61 Cache links in gemini pages. This patch is based on the patch_add-link-numbering branch. By caching gemini page links, visiting numbered links now works when one returns to a previously-visited page (e.g. via `u`). --- diff --git a/elpher.el b/elpher.el index 8940f08..8230377 100644 --- a/elpher.el +++ b/elpher.el @@ -106,6 +106,8 @@ (defvar elpher--gemini-page-links '() "Internal variable containing list of links on page.") +(defvar elpher--gemini-page-links-cache (make-hash-table :test 'equal) + "Internal variable containing hash of addresses and page links.") ;;; Customization group ;; @@ -469,12 +471,17 @@ unless NO-HISTORY is non-nil." (setq elpher-current-page page) (let* ((address (elpher-page-address page)) (type (elpher-address-type address)) - (type-record (cdr (assoc type elpher-type-map)))) + (type-record (cdr (assoc type elpher-type-map))) + (page-links nil)) (if type-record - (funcall (car type-record) - (if renderer - renderer - (cadr type-record))) + (progn + (funcall (car type-record) + (if renderer + renderer + (cadr type-record))) + (setq page-links (gethash address elpher--gemini-page-links-cache)) + (if page-links + (setq elpher--gemini-page-links page-links))) (elpher-visit-previous-page) (pcase type (`(gopher ,type-char) @@ -1435,7 +1442,11 @@ width defined by elpher-gemini-max-fill-width." (t (elpher-gemini-insert-text line))))) (elpher-cache-content (elpher-page-address elpher-current-page) - (buffer-string)))) + (buffer-string)) + (puthash + (elpher-page-address elpher-current-page) + elpher--gemini-page-links + elpher--gemini-page-links-cache))) (defun elpher-render-gemini-plain-text (data _parameters) "Render DATA as plain text file. PARAMETERS is currently unused."