From 8308f184984d5c10fee62990d8a01abcec7f2160 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Wed, 26 Jun 2013 00:24:43 +0200 Subject: [PATCH] * net/eww.el: Rework history traversal. When going forward/back, put these actions into the history, too, so that they can be replayed. --- lisp/ChangeLog | 6 ++++++ lisp/net/eww.el | 33 +++++++++++++++------------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index d65ffc0cf5c..10b5daaac04 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-06-25 Lars Magne Ingebrigtsen + + * net/eww.el: Rework history traversal. When going forward/back, + put these actions into the history, too, so that they can be + replayed. + 2013-06-25 Juri Linkov * files-x.el (modify-dir-local-variable): Change the header comment diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 2d6fe9a08dc..eaff1a1b985 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -118,6 +118,7 @@ word(s) will be searched for via `eww-search-prefix'." (unless (string-match-p "\\'file:" url) (setq url (concat eww-search-prefix (replace-regexp-in-string " " "+" url))))) + (setq eww-history-position 0) (url-retrieve url 'eww-render (list url))) ;;;###autoload @@ -309,10 +310,11 @@ word(s) will be searched for via `eww-search-prefix'." (defun eww-setup-buffer () (pop-to-buffer (get-buffer-create "*eww*")) - (remove-overlays) (let ((inhibit-read-only t)) + (remove-overlays) (erase-buffer)) - (eww-mode)) + (unless (eq major-mode 'eww-mode) + (eww-mode))) (defvar eww-mode-map (let ((map (make-sparse-keymap))) @@ -342,18 +344,16 @@ word(s) will be searched for via `eww-search-prefix'." (set (make-local-variable 'eww-current-url) 'author) (set (make-local-variable 'browse-url-browser-function) 'eww-browse-url) (set (make-local-variable 'after-change-functions) 'eww-process-text-input) + (set (make-local-variable 'eww-history) nil) + (set (make-local-variable 'eww-history-position) 0) ;;(setq buffer-read-only t) ) (defun eww-save-history () - (let ((elem (list :url eww-current-url - :point (point) - :text (buffer-string)))) - (if (or (zerop eww-history-position) - (= eww-history-position (length eww-history))) - (push elem eww-history) - (setcdr (nthcdr eww-history-position eww-history) - (cons elem (nthcdr eww-history-position eww-history)))))) + (push (list :url eww-current-url + :point (point) + :text (buffer-string)) + eww-history)) (defun eww-browse-url (url &optional new-window) (when (and (equal major-mode 'eww-mode) @@ -372,20 +372,17 @@ word(s) will be searched for via `eww-search-prefix'." (interactive) (when (>= eww-history-position (length eww-history)) (error "No previous page")) - (eww-restore-history - (if (not (zerop eww-history-position)) - (elt eww-history eww-history-position) - (eww-save-history) - (elt eww-history (1+ eww-history-position)))) - (setq eww-history-position (1+ eww-history-position))) + (eww-save-history) + (setq eww-history-position (+ eww-history-position 2)) + (eww-restore-history (elt eww-history (1- eww-history-position)))) (defun eww-forward-url () "Go to the next displayed page." (interactive) (when (zerop eww-history-position) (error "No next page")) - (eww-restore-history (elt eww-history (1- eww-history-position))) - (setq eww-history-position (1- eww-history-position))) + (eww-save-history) + (eww-restore-history (elt eww-history (1- eww-history-position)))) (defun eww-restore-history (elem) (let ((inhibit-read-only t)) -- 2.39.2