From cdf1fca4adb10bc0d2ff09343c74d576b118f699 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Wed, 20 Oct 2010 00:02:35 +0000 Subject: [PATCH] shr.el (shr-save-contents): New command and keystroke. --- lisp/gnus/ChangeLog | 1 + lisp/gnus/shr.el | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index 36b4bc4518e..4a7384a793e 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog @@ -2,6 +2,7 @@ * shr.el (shr-find-fill-point): Don't leave blanks at the start of some lines. + (shr-save-contents): New command and keystroke. * nndoc.el (nndoc-type-alist): Add git support. (nndoc-git-type-p): New function. diff --git a/lisp/gnus/shr.el b/lisp/gnus/shr.el index cdb6ea67d1d..98c473c1879 100644 --- a/lisp/gnus/shr.el +++ b/lisp/gnus/shr.el @@ -98,6 +98,7 @@ cid: URL as the argument.") (define-key map "I" 'shr-insert-image) (define-key map "u" 'shr-copy-url) (define-key map "v" 'shr-browse-url) + (define-key map "o" 'shr-save-contents) (define-key map "\r" 'shr-browse-url) map)) @@ -323,6 +324,23 @@ redirects somewhere else." (message "No link under point") (browse-url url)))) +(defun shr-save-contents (directory) + "Save the contents from URL in a file." + (interactive "DSave contents of URL to directory: ") + (let ((url (get-text-property (point) 'shr-url))) + (if (not url) + (message "No link under point") + (url-retrieve (shr-encode-url url) + 'shr-store-contents (list url directory))))) + +(defun shr-store-contents (status url directory) + (unless (plist-get status :error) + (when (or (search-forward "\n\n" nil t) + (search-forward "\r\n\r\n" nil t)) + (write-region (point) (point-max) + (expand-file-name (file-name-nondirectory url) + directory))))) + (defun shr-image-fetched (status buffer start end) (when (and (buffer-name buffer) (not (plist-get status :error))) -- 2.39.5