From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.gnus.general,gmane.emacs.devel Subject: Re: eww Date: Tue, 18 Jun 2013 08:39:52 -0600 Message-ID: <87fvwfa3ev.fsf@fleche.redhat.com> References: <87d2rkb1pi.fsf@fleche.redhat.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1371566477 18388 80.91.229.3 (18 Jun 2013 14:41:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 18 Jun 2013 14:41:17 +0000 (UTC) Cc: ding@gnus.org, emacs-devel To: Lars Magne Ingebrigtsen Original-X-From: ding-owner+M31625@lists.math.uh.edu Tue Jun 18 16:41:13 2013 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Uox5j-0001hI-SL for ding-account@gmane.org; Tue, 18 Jun 2013 16:41:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1Uox4w-0005FE-6i; Tue, 18 Jun 2013 09:40:14 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1Uox4u-0005F2-Sd for ding@lists.math.uh.edu; Tue, 18 Jun 2013 09:40:12 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1Uox4h-0001nS-4A for ding@lists.math.uh.edu; Tue, 18 Jun 2013 09:40:12 -0500 Original-Received: from mx1.redhat.com ([209.132.183.28]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1Uox4f-0000jk-Do; Tue, 18 Jun 2013 16:39:57 +0200 Original-Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5IEdt90006620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Jun 2013 10:39:55 -0400 Original-Received: from barimba (ovpn-113-102.phx2.redhat.com [10.3.113.102]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5IEdrC6003122 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 18 Jun 2013 10:39:54 -0400 X-Attribution: Tom In-Reply-To: (Lars Magne Ingebrigtsen's message of "Tue, 18 Jun 2013 13:23:02 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Spam-Score: -9.1 (---------) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:83364 gmane.emacs.devel:160571 Archived-At: Lars> Supporting and is a good idea. The code looks good, but Lars> here's a couple of comments: Thanks. Here's a version that addresses your comments and adds doc strings and a ChangeLog entry. Let me know what you think. Tom === modified file 'lisp/gnus/ChangeLog' --- lisp/gnus/ChangeLog 2013-06-18 11:24:16 +0000 +++ lisp/gnus/ChangeLog 2013-06-18 14:39:03 +0000 @@ -1,3 +1,16 @@ +2013-06-18 Tom Tromey + + * eww.el (eww-next-url, eww-previous-url, eww-up-url, eww-top-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 14:39:01 +0000 @@ -56,6 +56,11 @@ "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-top-url nil) + ;;;###autoload (defun eww (url) "Fetch URL and render the page." @@ -64,10 +69,20 @@ (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-top-url) nil) (let* ((headers (eww-parse-headers)) (shr-target-id (and (string-match "#\\(.*\\)" url) @@ -146,11 +161,33 @@ (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 (cdr rel) + '(("next" . eww-next-url) + ("previous" . eww-previous-url) + ("start" . eww-top-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 +255,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 +280,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 +288,42 @@ (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\" appears in a +or tag." + (interactive) + (if eww-top-url + (eww-browse-url (shr-expand-url eww-top-url eww-current-url)) + (error "No `top' on this page"))) + (defun eww-reload () "Reload the current page." (interactive)