From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/78567 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.gnus.general Subject: Re: shr-map keymap issues Date: Thu, 21 Apr 2011 19:14:23 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87mxjjm9b4.fsf@lifelogs.com> References: <8739ljfij1.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1303431329 22738 80.91.229.12 (22 Apr 2011 00:15:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 22 Apr 2011 00:15:29 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M26870@lists.math.uh.edu Fri Apr 22 02:15:26 2011 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QD41q-0005Ul-Oc for ding-account@gmane.org; Fri, 22 Apr 2011 02:15:23 +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 1QD419-0004us-UR; Thu, 21 Apr 2011 19:14:39 -0500 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1QD417-0004uh-Uw for ding@lists.math.uh.edu; Thu, 21 Apr 2011 19:14:37 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1QD416-0007Yz-B1 for ding@lists.math.uh.edu; Thu, 21 Apr 2011 19:14:37 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1QD415-0006WH-1l for ding@gnus.org; Fri, 22 Apr 2011 02:14:35 +0200 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QD414-00051A-EC for ding@gnus.org; Fri, 22 Apr 2011 02:14:34 +0200 Original-Received: from 38.98.147.130 ([38.98.147.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Apr 2011 02:14:34 +0200 Original-Received: from tzz by 38.98.147.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 22 Apr 2011 02:14:34 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 145 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 38.98.147.130 X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6;d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" User-Agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:epl2HvGv7+XJi6ayFOsF3xWRGrk= X-Spam-Score: -0.7 (/) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:78567 Archived-At: --=-=-= Content-Type: text/plain On Fri, 15 Apr 2011 13:58:58 -0500 Ted Zlatanov wrote: TZ> 1) `c' should copy the URL, like Info does TZ> 2) `i' and `I' are OK, but we should also have a way to hide images and TZ> to copy their URL. It would be nice to also provide "insert all images" TZ> and "hide all images". TZ> 3) `h' should show the source HTML in a temporary popup buffer, using TZ> html-helper-mode. Ideally the cursor should be placed on the element TZ> you were browsing in the shr buffer. TZ> 4) `?' should show a help message (I know about `C-h m', this would be short). TZ> 5) `+' and `-' should expand and collaps the current element. TZ> I think there's a lot more shr.el could use from emacs-w3m, but these TZ> are the things I'd really like. I can probably implement some of them. Lars, I implemented a few of these. Please see the attached patch and see if you can add it (and fix the two TODO items). I don't know shr.el well so please tell me if I did something stupid. Thanks Ted --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=shr-keys.patch diff --git a/lisp/mm-decode.el b/lisp/mm-decode.el index f543920..e87cdcb 100644 --- a/lisp/mm-decode.el +++ b/lisp/mm-decode.el @@ -1690,6 +1690,7 @@ If RECURSIVE, search recursively." (start end &optional base-url)) (declare-function shr-insert-document "shr" (dom)) (defvar shr-blocked-images) +(defvar shr-original-content) (defvar gnus-inhibit-images) (autoload 'gnus-blocked-images "gnus-art") @@ -1717,15 +1718,16 @@ If RECURSIVE, search recursively." (narrow-to-region (point) (point)) (shr-insert-document (mm-with-part handle - (insert (prog1 - (if (and charset - (setq charset - (mm-charset-to-coding-system charset)) - (not (eq charset 'ascii))) - (mm-decode-coding-string (buffer-string) charset) - (mm-string-as-multibyte (buffer-string))) - (erase-buffer) - (mm-enable-multibyte))) + (insert (setq shr-original-content + (prog1 + (if (and charset + (setq charset + (mm-charset-to-coding-system charset)) + (not (eq charset 'ascii))) + (mm-decode-coding-string (buffer-string) charset) + (mm-string-as-multibyte (buffer-string))) + (erase-buffer) + (mm-enable-multibyte)))) (goto-char (point-min)) (setq case-fold-search t) (while (re-search-forward diff --git a/lisp/shr.el b/lisp/shr.el index 401ac1a..6a5ca33 100644 --- a/lisp/shr.el +++ b/lisp/shr.el @@ -87,6 +87,10 @@ used." This is used for cid: URLs, and the function is called with the cid: URL as the argument.") +(defvar shr-original-content nil + "When set, this is the original HTML content we are rendering") +(make-variable-buffer-local 'shr-original-content) + ;;; Internal variables. (defvar shr-folding-mode nil) @@ -110,10 +114,27 @@ cid: URL as the argument.") (define-key map "v" 'shr-browse-url) (define-key map "o" 'shr-save-contents) (define-key map "\r" 'shr-browse-url) + (define-key map "\C-c\C-ss" 'shr-show-source) + (define-key map "\C-c\C-s?" 'shr-show-mini-help) + (define-key map "\C-c\C-si" 'shr-insert-images) + (define-key map "\C-c\C-sI" 'shr-hide-images) + (define-key map "\C-c\C-sc" 'shr-copy-url) map)) ;; Public functions and commands. +(defun shr-show-source () + "Show original source. +TODO: pop up a help-mode buffer." + (interactive) + shr-original-content) + +(defun shr-show-mini-help () + "Describe shr mode commands briefly." + (interactive) + (gnus-message 6 "%s" (substitute-command-keys "\\\\[shr-show-source]:Show source \\[shr-insert-images]:Insert all images \\[shr-hide-images]:Hide all images \\[shr-copy-url]:Copy URL \\[shr-show-mini-help]:This help"))) + + (defun shr-visit-file (file) (interactive "fHTML file name: ") (pop-to-buffer "*html*") @@ -191,6 +212,28 @@ redirects somewhere else." (list (current-buffer) (1- (point)) (point-marker)) t)))) +(defun shr-hide-images () + "Hide all the images in the buffer. +TODO: make it work." + (interactive) + (remove-images (point-min) (point-max))) + +(defun shr-insert-images () + "Insert all the unique images into the buffer." + (interactive) + (let (urls) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (let ((url (get-text-property (point) 'image-url))) + (when (and url (not (member url urls))) + (add-to-list 'urls url) + (message "Inserting %s..." url) + (url-retrieve url 'shr-image-fetched + (list (current-buffer) (1- (point)) (point-marker)) + t)) + (forward-word)))))) + ;;; Utility functions. (defun shr-transform-dom (dom) --=-=-=--