From: Tim Vaughan Date: Sun, 10 Nov 2019 22:54:24 +0000 (+0100) Subject: New simplified history implementation in place. X-Git-Tag: v2.5.0~6 X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=98b62fff557b13235be5c39aa0f183494b389b32;p=elpher.git New simplified history implementation in place. --- diff --git a/elpher.el b/elpher.el index 3a11487..c3e311f 100644 --- a/elpher.el +++ b/elpher.el @@ -181,6 +181,7 @@ allows switching from an encrypted channel back to plain text without user input "Specifies the number of seconds to wait for a network connection to time out." :type '(integer)) + ;;; Model ;; @@ -308,8 +309,6 @@ If no address is defined, returns 0. (This is for compatibility with the URL li "" (substring (url-filename address) 2))) -;; Page - ;; Cache @@ -332,18 +331,18 @@ If no address is defined, returns 0. (This is for compatibility with the URL li "Set the cursor position cache for ADDRESS to POS." (puthash address pos elpher-pos-cache)) + ;; Page -(defun elpher-make-page (address display-string) - (list address display-string)) +(defun elpher-make-page (display-string address) + (list display-string address)) -(defun elpher-page-address (page) +(defun elpher-page-display-string (page) (elt page 0)) -(defun elpher-page-display-string (page) +(defun elpher-page-address (page) (elt page 1)) - (defvar elpher-current-page nil) (defvar elpher-history nil) @@ -353,8 +352,10 @@ Additionally, push PAGE onto the stack of previously-visited pages, unless NO-HISTORY is non-nil." (elpher-save-pos) (elpher-process-cleanup) - (unless no-history - (push page elpher-history)) + (unless (or no-history + (equal (elpher-page-address elpher-current-page) + (elpher-page-address page))) + (push elpher-current-page elpher-history)) (setq elpher-current-page page) (let* ((address (elpher-page-address page)) (type (elpher-address-type address)) @@ -376,8 +377,9 @@ unless NO-HISTORY is non-nil." (defun elpher-visit-previous-page () "Visit the previous page in the history." (let ((previous-page (pop elpher-history))) - (when previous-page - (elpher-visit-page previous-page nil t)))) + (if previous-page + (elpher-visit-page previous-page nil t) + (error "No previous page.")))) (defun elpher-reload-current-page () "Reload the current page, discarding any existing cached content." @@ -1255,16 +1257,12 @@ If ADDRESS is already bookmarked, update the label only." (defun elpher-redraw () "Redraw current page." (interactive) - (if elpher-current-page - (elpher-visit-page elpher-current-page) - (message "No current site."))) + (elpher-visit-page elpher-current-page)) (defun elpher-reload () "Reload current page." (interactive) - (if elpher-current-page - (elpher-reload-current-page) - (message "No current site."))) + (elpher-reload-current-page)) (defun elpher-toggle-tls () "Toggle TLS encryption mode for gopher." @@ -1280,19 +1278,15 @@ If ADDRESS is already bookmarked, update the label only." (defun elpher-view-raw () "View raw server response for current page." (interactive) - (if elpher-current-page - (if (elpher-address-special-p (elpher-page-address elpher-current-page)) - (error "This page was not generated by a server") - (elpher-visit-page elpher-current-page - #'elpher-render-raw)) - (message "No current site."))) + (if (elpher-address-special-p (elpher-page-address elpher-current-page)) + (error "This page was not generated by a server") + (elpher-visit-page elpher-current-page + #'elpher-render-raw))) (defun elpher-back () "Go to previous site." (interactive) - (if elpher-history - (error "No previous site") - (elpher-visit-previous-page))) + (elpher-visit-previous-page)) (defun elpher-download () "Download the link at point."