From d3f0f918e9f2f20d27e129107a63e634d4e82814 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Tue, 25 Jun 2013 17:39:13 +0200 Subject: [PATCH] (eww-forward-url) Allow going forward in the history, too. This may not be the most intuitive way to implement this. Perhaps following links should flush "forwards"... --- lisp/ChangeLog | 1 + lisp/net/eww.el | 44 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fc57dc2b16..c712e023c2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -2,6 +2,7 @@ * net/eww.el (eww-back-url): Implement the history by stashing all the data into a list. + (eww-forward-url): Allow going forward in the history, too. 2013-06-25 Stefan Monnier diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 4663e25e6c..a77bed52a9 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -86,6 +86,7 @@ (defvar eww-current-title "" "Title of current page.") (defvar eww-history nil) +(defvar eww-history-position 0) (defvar eww-next-url nil) (defvar eww-previous-url nil) @@ -318,6 +319,7 @@ word(s) will be searched for via `eww-search-prefix'." (define-key map "\177" 'scroll-down-command) (define-key map " " 'scroll-up-command) (define-key map "l" 'eww-back-url) + (define-key map "f" 'eww-forward-url) (define-key map "n" 'eww-next-url) (define-key map "p" 'eww-previous-url) (define-key map "u" 'eww-up-url) @@ -336,13 +338,20 @@ word(s) will be searched for via `eww-search-prefix'." ;;(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)))))) + (defun eww-browse-url (url &optional new-window) (when (and (equal major-mode 'eww-mode) eww-current-url) - (push (list :url eww-current-url - :point (point) - :text (buffer-string)) - eww-history)) + (eww-save-history)) (eww url)) (defun eww-quit () @@ -354,14 +363,29 @@ word(s) will be searched for via `eww-search-prefix'." (defun eww-back-url () "Go to the previously displayed page." (interactive) - (when (zerop (length eww-history)) + (when (>= eww-history-position (length eww-history)) (error "No previous page")) - (let ((prev (pop eww-history)) - (inhibit-read-only t)) + (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))) + +(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))) + +(defun eww-restore-history (elem) + (let ((inhibit-read-only t)) (erase-buffer) - (insert (plist-get prev :text)) - (goto-char (plist-get prev :point)) - (setq eww-current-url (plist-get prev :url)))) + (insert (plist-get elem :text)) + (goto-char (plist-get elem :point)) + (setq eww-current-url (plist-get elem :url)))) (defun eww-next-url () "Go to the page marked `next'. -- 2.20.1