From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/83370 Path: news.gmane.org!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel,gmane.emacs.gnus.general Subject: Re: eww Date: Tue, 18 Jun 2013 10:17:40 -0600 Message-ID: <874ncv8kbf.fsf@fleche.redhat.com> References: <87d2rkb1pi.fsf@fleche.redhat.com> <87fvwfa3ev.fsf@fleche.redhat.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1371572275 24158 80.91.229.3 (18 Jun 2013 16:17:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Jun 2013 16:17:55 +0000 (UTC) Cc: ding@gnus.org, emacs-devel To: Lars Magne Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 18 18:17:55 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UoybS-0004zx-PB for ged-emacs-devel@m.gmane.org; Tue, 18 Jun 2013 18:17:54 +0200 Original-Received: from localhost ([::1]:33606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoybS-0001Hx-BR for ged-emacs-devel@m.gmane.org; Tue, 18 Jun 2013 12:17:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45992) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoybN-0001EA-7W for emacs-devel@gnu.org; Tue, 18 Jun 2013 12:17:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UoybJ-0004Sv-3x for emacs-devel@gnu.org; Tue, 18 Jun 2013 12:17:49 -0400 Original-Received: from mx1.redhat.com ([209.132.183.28]:41868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoybI-0004Sp-Rq for emacs-devel@gnu.org; Tue, 18 Jun 2013 12:17:45 -0400 Original-Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5IGHhBJ023759 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Jun 2013 12:17:43 -0400 Original-Received: from barimba (ovpn-113-102.phx2.redhat.com [10.3.113.102]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5IGHfER025817 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 18 Jun 2013 12:17:41 -0400 X-Attribution: Tom In-Reply-To: (Lars Magne Ingebrigtsen's message of "Tue, 18 Jun 2013 17:14:14 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160583 gmane.emacs.gnus.general:83370 Archived-At: >> 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 + + * 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 * 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 +or 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 +or 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 +or 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 or 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)