>From 3168367eed8a388efe7bf934cb3d626b9c98e44c Mon Sep 17 00:00:00 2001 From: Ivan Kanis Date: Mon, 24 Jun 2013 18:15:05 +0200 Subject: [PATCH] use url-retrieve to download files --- emacs/misc/eww.el | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/emacs/misc/eww.el b/emacs/misc/eww.el index 5359925..0db84ab 100644 --- a/emacs/misc/eww.el +++ b/emacs/misc/eww.el @@ -50,6 +50,12 @@ :group 'eww :type 'string) +(defcustom eww-download-path "~" + "Path where files will downloaded." + :version "24.4" + :group 'eww + :type 'string) + (defface eww-form-submit '((((type x w32 ns) (class color)) ; Like default mode line :box (:line-width 2 :style released-button) @@ -319,6 +325,7 @@ word(s) will be searched for via `eww-search-prefix'." (define-key map "u" 'eww-up-url) (define-key map "t" 'eww-top-url) (define-key map "w" 'eww-browse-with-external-browser) + (define-key map "d" 'eww-download) (define-key map "y" 'eww-yank-page-url) map)) @@ -841,6 +848,26 @@ The browser to used is specified by the `shr-external-browser' variable." (interactive) (message eww-current-url) (kill-new eww-current-url)) + +(defun shr-download () + "Download URL under point." + (interactive) + (let ((url (get-text-property (point) 'shr-url))) + (if (not url) + (message "No URL under point") + (if (fboundp 'wget-api) + (wget-api url nil) + (url-retrieve url 'shr-download-callback (list url)))))) + +(defun shr-download-callback (status url) + "Download callback." + (unless (plist-get status :error) + (let* ((obj (url-generic-parse-url url)) + (path (car (url-path-and-query obj))) + (file (file-name-nondirectory path))) + (write-file (expand-file-name (concat eww-download-path "/" file))) + (message "File %s saved." file)))) + (provide 'eww) ;;; eww.el ends here -- 1.7.1