aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Magne Ingebrigtsen2013-06-25 17:39:13 +0200
committerLars Magne Ingebrigtsen2013-06-25 17:39:13 +0200
commitd3f0f918e9f2f20d27e129107a63e634d4e82814 (patch)
tree4f46cd370434698c95e7e1c2d60a334178b134fb
parent341881c044bae8941443901e0884ef23ab51213d (diff)
downloademacs-d3f0f918e9f2f20d27e129107a63e634d4e82814.tar.gz
emacs-d3f0f918e9f2f20d27e129107a63e634d4e82814.zip
(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"...
-rw-r--r--lisp/ChangeLog1
-rw-r--r--lisp/net/eww.el44
2 files changed, 35 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fc57dc2b163..c712e023c2a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -2,6 +2,7 @@
2 2
3 * net/eww.el (eww-back-url): Implement the history by stashing all 3 * net/eww.el (eww-back-url): Implement the history by stashing all
4 the data into a list. 4 the data into a list.
5 (eww-forward-url): Allow going forward in the history, too.
5 6
62013-06-25 Stefan Monnier <monnier@iro.umontreal.ca> 72013-06-25 Stefan Monnier <monnier@iro.umontreal.ca>
7 8
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 4663e25e6c9..a77bed52a96 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -86,6 +86,7 @@
86(defvar eww-current-title "" 86(defvar eww-current-title ""
87 "Title of current page.") 87 "Title of current page.")
88(defvar eww-history nil) 88(defvar eww-history nil)
89(defvar eww-history-position 0)
89 90
90(defvar eww-next-url nil) 91(defvar eww-next-url nil)
91(defvar eww-previous-url nil) 92(defvar eww-previous-url nil)
@@ -318,6 +319,7 @@ word(s) will be searched for via `eww-search-prefix'."
318 (define-key map "\177" 'scroll-down-command) 319 (define-key map "\177" 'scroll-down-command)
319 (define-key map " " 'scroll-up-command) 320 (define-key map " " 'scroll-up-command)
320 (define-key map "l" 'eww-back-url) 321 (define-key map "l" 'eww-back-url)
322 (define-key map "f" 'eww-forward-url)
321 (define-key map "n" 'eww-next-url) 323 (define-key map "n" 'eww-next-url)
322 (define-key map "p" 'eww-previous-url) 324 (define-key map "p" 'eww-previous-url)
323 (define-key map "u" 'eww-up-url) 325 (define-key map "u" 'eww-up-url)
@@ -336,13 +338,20 @@ word(s) will be searched for via `eww-search-prefix'."
336 ;;(setq buffer-read-only t) 338 ;;(setq buffer-read-only t)
337 ) 339 )
338 340
341(defun eww-save-history ()
342 (let ((elem (list :url eww-current-url
343 :point (point)
344 :text (buffer-string))))
345 (if (or (zerop eww-history-position)
346 (= eww-history-position (length eww-history)))
347 (push elem eww-history)
348 (setcdr (nthcdr eww-history-position eww-history)
349 (cons elem (nthcdr eww-history-position eww-history))))))
350
339(defun eww-browse-url (url &optional new-window) 351(defun eww-browse-url (url &optional new-window)
340 (when (and (equal major-mode 'eww-mode) 352 (when (and (equal major-mode 'eww-mode)
341 eww-current-url) 353 eww-current-url)
342 (push (list :url eww-current-url 354 (eww-save-history))
343 :point (point)
344 :text (buffer-string))
345 eww-history))
346 (eww url)) 355 (eww url))
347 356
348(defun eww-quit () 357(defun eww-quit ()
@@ -354,14 +363,29 @@ word(s) will be searched for via `eww-search-prefix'."
354(defun eww-back-url () 363(defun eww-back-url ()
355 "Go to the previously displayed page." 364 "Go to the previously displayed page."
356 (interactive) 365 (interactive)
357 (when (zerop (length eww-history)) 366 (when (>= eww-history-position (length eww-history))
358 (error "No previous page")) 367 (error "No previous page"))
359 (let ((prev (pop eww-history)) 368 (eww-restore-history
360 (inhibit-read-only t)) 369 (if (not (zerop eww-history-position))
370 (elt eww-history eww-history-position)
371 (eww-save-history)
372 (elt eww-history (1+ eww-history-position))))
373 (setq eww-history-position (1+ eww-history-position)))
374
375(defun eww-forward-url ()
376 "Go to the next displayed page."
377 (interactive)
378 (when (zerop eww-history-position)
379 (error "No next page"))
380 (eww-restore-history (elt eww-history (1- eww-history-position)))
381 (setq eww-history-position (1- eww-history-position)))
382
383(defun eww-restore-history (elem)
384 (let ((inhibit-read-only t))
361 (erase-buffer) 385 (erase-buffer)
362 (insert (plist-get prev :text)) 386 (insert (plist-get elem :text))
363 (goto-char (plist-get prev :point)) 387 (goto-char (plist-get elem :point))
364 (setq eww-current-url (plist-get prev :url)))) 388 (setq eww-current-url (plist-get elem :url))))
365 389
366(defun eww-next-url () 390(defun eww-next-url ()
367 "Go to the page marked `next'. 391 "Go to the page marked `next'.