all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / 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)




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

Thread overview: 185+ 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 21:13             ` eww Stefan Monnier
2013-06-17 21:30               ` eww Lars Magne Ingebrigtsen
2013-06-17 22:04                 ` eww Lars Magne Ingebrigtsen
2013-06-17 22:39                   ` eww Rasmus
2013-06-17 22:43                     ` eww Lars Magne Ingebrigtsen
2013-06-17 23:35             ` eww Ted Zlatanov
2013-06-18 12:09             ` eww Thomas Fitzsimmons
2013-06-18 14:57               ` eww Lars Magne Ingebrigtsen
2013-06-18 17:02                 ` eww Thomas Fitzsimmons
2013-06-19  8:59                   ` eww Lars Magne Ingebrigtsen
2013-06-18 17:21               ` eww Tom Tromey
2013-06-19  6:53                 ` eww Lars Magne Ingebrigtsen
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 15:48         ` eww Lars Magne Ingebrigtsen
2013-06-18 17:40           ` eww Eli Zaretskii
2013-06-19  1:14             ` eww Stephen J. Turnbull
2013-06-19  6:58             ` eww Lars Magne Ingebrigtsen
2013-06-19 14:50               ` eww Eli Zaretskii
2013-06-18 18:04           ` eww Karl Fogel
2013-06-18 18:29             ` eww Eli Zaretskii
2013-06-19  7:13               ` eww Lars Magne Ingebrigtsen
2013-06-19  8:43                 ` eww Andreas Schwab
2013-06-19  9:03                   ` eww Lars Magne Ingebrigtsen
2013-06-19  9:13                     ` eww Andreas Schwab
2013-06-19 12:27                 ` eww Stefan Monnier
2013-06-19 13:50                   ` eww Stefan Monnier
2013-06-19 14:02                   ` eww Lars Magne Ingebrigtsen
2013-06-21 14:03                     ` eww Stefan Monnier
2013-06-25 19:57                       ` eww Lars Magne Ingebrigtsen
2013-06-19 14:55                 ` eww Eli Zaretskii
2013-06-19 19:46                   ` eww Lars Magne Ingebrigtsen
2013-06-19 19:59                     ` eww Eli Zaretskii
2013-06-19 20:13                       ` eww Lars Magne Ingebrigtsen
2013-06-19 22:12                       ` eww Johan Bockgård
2013-06-19 20:22                     ` eww Stefan Monnier
2013-06-18 19:00           ` eww Ted Zlatanov
2013-06-18 20:19             ` eww Stefan Monnier
2013-06-18 21:37               ` eww Ted Zlatanov
2013-06-18 23:21                 ` eww Stefan Monnier
2013-06-19  4:15                   ` eww Ted Zlatanov
2013-06-19  7:22               ` eww Lars Magne Ingebrigtsen
2013-06-19 10:38               ` eww Christopher Schmidt
2013-06-19 12:35                 ` eww Stefan Monnier
2013-06-20  7:17                   ` eww Lars Magne Ingebrigtsen
2013-06-20 20:10                     ` eww Stefan Monnier
2013-06-21  6:58                       ` eww Lars Magne Ingebrigtsen
2013-06-28 15:12                         ` eww Ted Zlatanov
2013-07-06 15:17                           ` eww Lars Ingebrigtsen
2013-06-25 23:11                       ` eww Lars Magne Ingebrigtsen
2013-06-26  6:49                         ` eww Daimrod
2013-06-26 11:55                           ` eww Lars Magne Ingebrigtsen
2013-06-19  4:21           ` eww Ted Zlatanov
2013-06-19  7:25             ` eww Lars Magne Ingebrigtsen
2013-06-19 22:45               ` eww Ted Zlatanov
2013-06-20  9:01                 ` eww Lars Magne Ingebrigtsen
2013-07-01 22:48                   ` eww Ted Zlatanov
2013-07-02  6:03                     ` eww Thierry Volpiatto
2013-07-06 15:19                     ` eww Lars Ingebrigtsen
2013-07-06 22:32                       ` eww Xue Fuqiao
2013-07-06 22:57                         ` eww Lars Ingebrigtsen
2013-07-08 12:34                       ` eww Ted Zlatanov
2013-07-08 12:55                         ` eww Lars Magne Ingebrigtsen
2013-06-19  8:21             ` eww chad
2013-06-19 12:32               ` eww Stefan Monnier
2013-06-19 20:55               ` eww Juri Linkov
2013-06-19 21:16                 ` eww Tom Tromey
2013-06-19 13:50           ` eww Tom Tromey
2013-06-18 16:17         ` Tom Tromey [this message]
2013-06-18 16:45           ` eww Christopher Schmidt
2013-06-18 19:06           ` eww Steinar Bang
2013-06-19  6:50           ` eww Lars Magne Ingebrigtsen
2013-06-19 17:13             ` eww Tom Tromey
2013-06-19 19:31               ` eww Lars Magne Ingebrigtsen
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-19  8:17               ` eww Stephen Leake
2013-06-18 23:03             ` eww Xue Fuqiao
2013-06-18 23:56               ` eww Paul Eggert
2013-06-19  7:52                 ` eww Xue Fuqiao
2013-06-19 15:03                   ` eww Eli Zaretskii
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 10:34         ` eww Christopher Schmidt
2013-06-19  7:34       ` eww Lars Magne Ingebrigtsen
2013-06-20 22:52         ` eww Juri Linkov
2013-06-21  6:56           ` eww Lars Magne Ingebrigtsen
2013-06-19 14:06     ` eww Drew Adams
2013-06-19 15:36       ` eww Jambunathan K
2013-06-20  4:10         ` eww Richard Stallman
2013-06-20  4:28           ` eww Paul Eggert
2013-06-20  7:18           ` eww Lars Magne Ingebrigtsen
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  0:46       ` eww John Williams
2013-08-02 12:27         ` eww Lars Magne Ingebrigtsen
2013-08-02 21:39           ` eww John Williams
2013-08-03 11:08             ` eww Lars Magne Ingebrigtsen
2013-08-04  3:59               ` eww John Williams
2013-08-05  2:10                 ` eww Lars Magne Ingebrigtsen
2013-08-05  3:29                   ` eww John Williams
2013-08-07  0:46                   ` eww John Williams
2013-08-07  1:24                     ` eww Lars Magne Ingebrigtsen
2013-08-02 19:48       ` eww Richard Stallman
2013-08-03 11:30         ` eww Lars Magne Ingebrigtsen
  -- strict thread matches above, loose matches on Subject: below --
2014-01-12 13:46 eww Richard Stallman
2014-01-12 13:50 ` eww Juanma Barranquero
2014-01-13 11:20   ` eww Bastien
2014-01-13 17:44     ` eww Davis Herring
2014-01-13 22:19       ` eww Bastien
2014-01-13 19:36     ` eww Richard Stallman
2014-01-13 22:29       ` eww Bastien
2014-01-14 17:06         ` eww Richard Stallman
2014-01-14 20:22           ` eww Bastien
2014-01-15 12:29             ` eww Richard Stallman
2014-01-13 19:36     ` eww Richard Stallman
2014-01-13 22:25       ` eww Bastien
2014-01-14  0:00         ` eww Stefan Monnier
2014-01-14  9:43           ` eww Bastien
2014-01-14 11:09             ` eww Nicolas Richard
2014-01-14 16:39               ` eww Bastien
2014-01-14 16:57                 ` eww Nicolas Richard
2014-01-14 18:21                   ` eww Bastien
2014-01-14 21:31                     ` eww Nicolas Richard
2014-01-14 22:36                       ` eww Bastien
2014-01-15 12:29                     ` eww Richard Stallman
2014-01-15 14:07                       ` eww Andreas Schwab
2014-01-15 16:10                         ` eww Nicolas Richard
2014-01-16 17:56                           ` eww Richard Stallman
2014-01-16 18:19                             ` eww Andreas Schwab
2014-01-17 14:10                               ` eww Richard Stallman
2014-01-17 15:04                                 ` eww Stefan Monnier
2014-01-17 15:28                                   ` eww Eli Zaretskii
2014-01-17 16:04                                     ` eww Stefan Monnier
2014-01-18 12:33                                   ` eww Richard Stallman
2014-01-19  2:12                                     ` eww Stefan Monnier
2014-01-19 11:35                                       ` eww Francesco Potortì
2014-01-20  9:14                                       ` eww Richard Stallman
2014-01-17 15:06                                 ` eww Andreas Schwab
2014-01-17 15:23                                 ` eww Francesco Potortì
2014-01-17 13:06                             ` eww Bastien
2014-01-17 14:22                               ` eww Stefan Monnier
2014-01-17 14:59                                 ` eww Bastien
2014-01-18  6:12                               ` eww Richard Stallman
2014-01-16 17:57                         ` eww Richard Stallman
2014-01-14 17:58             ` eww Stefan Monnier
2014-01-14 18:22               ` eww Bastien
2014-01-14 17:06           ` eww Richard Stallman
2014-01-13 22:18     ` eww Bastien
2014-01-14  0:45       ` eww Juanma Barranquero
2014-01-13 15:41   ` eww Richard Stallman
2014-01-13 18:05     ` eww Lars Magne Ingebrigtsen
2014-01-14 17:05       ` eww Richard Stallman
2014-01-14 19:39         ` eww Bastien
2014-01-15 12:29           ` eww Richard Stallman

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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.