Gnus development mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Lars Magne Ingebrigtsen <larsi@gnus.org>
Cc: ding@gnus.org, emacs-devel <emacs-devel@gnu.org>
Subject: Re: eww
Date: Tue, 18 Jun 2013 10:17:40 -0600	[thread overview]
Message-ID: <874ncv8kbf.fsf@fleche.redhat.com> (raw)
In-Reply-To: <m3li67fo3d.fsf@stories.gnus.org> (Lars Magne Ingebrigtsen's message of "Tue, 18 Jun 2013 17:14:14 +0200")

>> 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  <tromey@barimba>
+
+	* 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  <larsi@gnus.org>
 
 	* 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)




  reply	other threads:[~2013-06-18 16:17 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-16 14:53 eww Lars Magne Ingebrigtsen
2013-06-16 15:21 ` eww Adam Sjøgren
2013-06-16 15:29   ` eww Lars Magne Ingebrigtsen
2013-06-16 15:46     ` eww Lars Magne Ingebrigtsen
2013-06-16 17:01       ` eww Dmitry Gutov
2013-06-16 17:06         ` eww Lars Magne Ingebrigtsen
2013-06-17 21:00           ` eww Lars Magne Ingebrigtsen
2013-06-17 23:35             ` eww Ted Zlatanov
2013-06-18  0:01               ` eww Lars Magne Ingebrigtsen
2013-07-09 13:20                 ` eww Ted Zlatanov
2013-08-01 14:39                   ` eww Lars Magne Ingebrigtsen
2013-07-09 10:23               ` eww Julien Cubizolles
2013-07-09 10:42                 ` eww David Edmondson
2013-06-16 23:42 ` eww lee
2013-06-17  5:57   ` eww Lars Magne Ingebrigtsen
2013-06-17 18:46     ` eww lee
2013-06-18  2:19 ` eww Tom Tromey
2013-06-18 11:23   ` eww Lars Magne Ingebrigtsen
2013-06-18 14:34     ` eww Tom Tromey
2013-06-18 15:01       ` eww Lars Magne Ingebrigtsen
2013-06-18 15:43         ` eww Tom Tromey
2013-06-18 14:39     ` eww Tom Tromey
2013-06-18 15:14       ` eww Lars Magne Ingebrigtsen
2013-06-18 16:17         ` Tom Tromey [this message]
2013-06-18 19:06           ` eww Steinar Bang
2013-06-18 19:07     ` eww Stefan Monnier
2013-06-18 11:31   ` eww Lars Magne Ingebrigtsen
2013-06-18 14:42     ` eww Tom Tromey
2013-06-18 15:04       ` eww Lars Magne Ingebrigtsen
2013-06-18 19:13         ` eww Stefan Monnier
2013-06-18 19:17           ` eww Eli Zaretskii
2013-06-18 20:21             ` eww Stefan Monnier
2013-06-18 23:34               ` eww James Cloos
2013-06-19  2:50               ` eww Eli Zaretskii
2013-06-19  4:49                 ` eww Stefan Monnier
2013-06-18 23:03             ` eww Xue Fuqiao
2013-06-19  3:03               ` eww Eli Zaretskii
2013-06-18 19:27           ` eww Tom Tromey
2013-06-18 23:40     ` eww Juri Linkov
2013-06-19  0:51       ` eww Stefan Monnier
2013-06-19  1:08         ` eww Russ Allbery
2013-06-19 10:14           ` eww Rasmus
2013-06-19 10:34         ` eww Christopher Schmidt
2013-06-25  7:43       ` eww lee
2013-06-25  9:05         ` eww Tassilo Horn
2013-06-25 13:27           ` eww Steinar Bang
2013-06-27  9:05           ` eww lee
2013-06-18 11:32 ` eww joakim
2013-06-18 12:16   ` eww Andreas Schwab
2013-06-18 13:57   ` eww Lars Magne Ingebrigtsen
2013-06-18 14:01     ` eww joakim
2013-06-19 10:21 ` eww Ivan Kanis
2013-06-19 11:52   ` eww Steinar Bang
2013-06-19 12:14   ` eww Ivan Kanis
2013-08-01 11:59 ` eww John Williams
2013-08-02  0:20   ` eww John Williams
2013-08-02  0:27     ` eww Lars Magne Ingebrigtsen
2013-08-02 19:48       ` eww Richard Stallman
2013-08-03 11:30         ` eww Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874ncv8kbf.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=ding@gnus.org \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).