[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: eww
From: |
Tom Tromey |
Subject: |
Re: eww |
Date: |
Tue, 18 Jun 2013 10:17:40 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
>> Here's a version that addresses your comments and adds doc strings and a
>> ChangeLog entry. Let me know what you think.
Lars> Looks good; applied.
I didn't see it in bzr.
Anyway here is a slightly better version.
Differences:
HTML seems to specify "prev", not "previous" (though texinfo still seems
to use "previous").
HTML specifies "start" as well as "contents"; but I noticed that Gtk is
using "home" here. So now it handles all 3 and picks the "best" one.
Finally, the "rel" value is supposed to be case-insensitive, so downcase it.
Tom
=== modified file 'lisp/gnus/ChangeLog'
--- lisp/gnus/ChangeLog 2013-06-18 11:24:16 +0000
+++ lisp/gnus/ChangeLog 2013-06-18 16:15:25 +0000
@@ -1,3 +1,17 @@
+2013-06-18 Tom Tromey <address@hidden>
+
+ * eww.el (eww-next-url, eww-previous-url, eww-up-url)
+ (eww-start-url, eww-home-url, eww-contents-url):
+ New defvars.
+ (eww-open-file): New defun.
+ (eww-render): Initialize new variables.
+ (eww-display-html): Handle "link" and "a".
+ (eww-handle-link, eww-tag-link, eww-tag-a): New defuns.
+ (eww-mode-map): Move "p" to "l". Bind "p", "n", "t", and "u".
+ (eww-back-url): Rename from eww-previous-url.
+ (eww-next-url, eww-previous-url, eww-up-url, eww-top-url): New
+ defuns.
+
2013-06-18 Lars Magne Ingebrigtsen <address@hidden>
* shr.el (shr-tag-table): Insert the images after the table, so that
=== modified file 'lisp/gnus/eww.el'
--- lisp/gnus/eww.el 2013-06-18 09:29:20 +0000
+++ lisp/gnus/eww.el 2013-06-18 16:14:31 +0000
@@ -56,6 +56,13 @@
"Title of current page.")
(defvar eww-history nil)
+(defvar eww-next-url nil)
+(defvar eww-previous-url nil)
+(defvar eww-up-url nil)
+(defvar eww-home-url nil)
+(defvar eww-start-url nil)
+(defvar eww-contents-url nil)
+
;;;###autoload
(defun eww (url)
"Fetch URL and render the page."
@@ -64,10 +71,22 @@
(setq url (concat "http://" url)))
(url-retrieve url 'eww-render (list url)))
+;;;###autoload
+(defun eww-open-file (file)
+ "Render a file using EWW."
+ (interactive "fFile: ")
+ (eww (concat "file://" (expand-file-name file))))
+
(defun eww-render (status url &optional point)
(let ((redirect (plist-get status :redirect)))
(when redirect
(setq url redirect)))
+ (set (make-local-variable 'eww-next-url) nil)
+ (set (make-local-variable 'eww-previous-url) nil)
+ (set (make-local-variable 'eww-up-url) nil)
+ (set (make-local-variable 'eww-home-url) nil)
+ (set (make-local-variable 'eww-start-url) nil)
+ (set (make-local-variable 'eww-contents-url) nil)
(let* ((headers (eww-parse-headers))
(shr-target-id
(and (string-match "#\\(.*\\)" url)
@@ -146,11 +165,45 @@
(input . eww-tag-input)
(textarea . eww-tag-textarea)
(body . eww-tag-body)
- (select . eww-tag-select))))
+ (select . eww-tag-select)
+ (link . eww-tag-link)
+ (a . eww-tag-a))))
(shr-insert-document document)
(eww-convert-widgets))
(goto-char (point-min))))
+(defun eww-handle-link (cont)
+ (let* ((rel (assq :rel cont))
+ (href (assq :href cont))
+ (where (assoc
+ ;; The text associated with :rel is case-insensitive.
+ (if rel (downcase (cdr rel)))
+ '(("next" . eww-next-url)
+ ;; Texinfo uses "previous", but HTML specifies
+ ;; "prev", so recognize both.
+ ("previous" . eww-previous-url)
+ ("prev" . eww-previous-url)
+ ;; HTML specifies "start" but also "contents",
+ ;; and Gtk seems to use "home". Recognize
+ ;; them all; but store them in different
+ ;; variables so that we can readily choose the
+ ;; "best" one.
+ ("start" . eww-start-url)
+ ("home" . eww-home-url)
+ ("contents" . eww-contents-url)
+ ("up" . eww-up-url)))))
+ (and href
+ where
+ (set (cdr where) (cdr href)))))
+
+(defun eww-tag-link (cont)
+ (eww-handle-link cont)
+ (shr-generic cont))
+
+(defun eww-tag-a (cont)
+ (eww-handle-link cont)
+ (shr-tag-a cont))
+
(defun eww-update-header-line-format ()
(if eww-header-line-format
(setq header-line-format (format-spec eww-header-line-format
@@ -218,8 +271,11 @@
(define-key map [delete] 'scroll-down-command)
(define-key map "\177" 'scroll-down-command)
(define-key map " " 'scroll-up-command)
+ (define-key map "l" 'eww-back-url)
+ (define-key map "n" 'eww-next-url)
(define-key map "p" 'eww-previous-url)
- ;;(define-key map "n" 'eww-next-url)
+ (define-key map "u" 'eww-up-url)
+ (define-key map "t" 'eww-top-url)
map))
(define-derived-mode eww-mode nil "eww"
@@ -240,7 +296,7 @@
(setq eww-history nil)
(kill-buffer (current-buffer)))
-(defun eww-previous-url ()
+(defun eww-back-url ()
"Go to the previously displayed page."
(interactive)
(when (zerop (length eww-history))
@@ -248,6 +304,45 @@
(let ((prev (pop eww-history)))
(url-retrieve (car prev) 'eww-render (list (car prev) (cadr prev)))))
+(defun eww-next-url ()
+ "Go to the page marked `next'.
+A page is marked `next' if rel=\"next\" appears in a <link>
+or <a> tag."
+ (interactive)
+ (if eww-next-url
+ (eww-browse-url (shr-expand-url eww-next-url eww-current-url))
+ (error "No `next' on this page")))
+
+(defun eww-previous-url ()
+ "Go to the page marked `previous'.
+A page is marked `previous' if rel=\"previous\" appears in a <link>
+or <a> tag."
+ (interactive)
+ (if eww-previous-url
+ (eww-browse-url (shr-expand-url eww-previous-url eww-current-url))
+ (error "No `previous' on this page")))
+
+(defun eww-up-url ()
+ "Go to the page marked `up'.
+A page is marked `up' if rel=\"up\" appears in a <link>
+or <a> tag."
+ (interactive)
+ (if eww-up-url
+ (eww-browse-url (shr-expand-url eww-up-url eww-current-url))
+ (error "No `up' on this page")))
+
+(defun eww-top-url ()
+ "Go to the page marked `top'.
+A page is marked `top' if rel=\"start\", rel=\"home\", or rel=\"contents\"
+appears in a <link> or <a> tag."
+ (interactive)
+ (let ((best-url (or eww-start-url
+ eww-contents-url
+ eww-home-url)))
+ (if best-url
+ (eww-browse-url (shr-expand-url best-url eww-current-url))
+ (error "No `top' for this page"))))
+
(defun eww-reload ()
"Reload the current page."
(interactive)
- Re: eww, (continued)
- Re: eww, Lars Magne Ingebrigtsen, 2013/06/19
- Re: eww, Christopher Schmidt, 2013/06/19
- Re: eww, Stefan Monnier, 2013/06/19
- Re: eww, Ted Zlatanov, 2013/06/19
- Re: eww, Lars Magne Ingebrigtsen, 2013/06/19
- Re: eww, chad, 2013/06/19
- Re: eww, Stefan Monnier, 2013/06/19
- Re: eww, Tom Tromey, 2013/06/19
- Re: eww,
Tom Tromey <=
- Re: eww, Christopher Schmidt, 2013/06/18
- Re: eww, Steinar Bang, 2013/06/18
- Re: eww, Lars Magne Ingebrigtsen, 2013/06/19
- Re: eww, Tom Tromey, 2013/06/19
- Re: eww, Lars Magne Ingebrigtsen, 2013/06/19
- Re: eww, Stefan Monnier, 2013/06/18
Re: eww, Lars Magne Ingebrigtsen, 2013/06/18
- Re: eww, Tom Tromey, 2013/06/18
- Re: eww, Lars Magne Ingebrigtsen, 2013/06/18
- Re: eww, Stefan Monnier, 2013/06/18