From: Ivan Kanis <ivan@kanis.fr>
To: Lars Magne Ingebrigtsen <larsi@gnus.org>
Cc: Emacs Development List <emacs-devel@gnu.org>
Subject: Re: patches and one bug
Date: Tue, 25 Jun 2013 08:21:33 +0200 [thread overview]
Message-ID: <87bo6uww0i.fsf@kanis.fr> (raw)
In-Reply-To: <m361x370ll.fsf@stories.gnus.org> (Lars Magne Ingebrigtsen's message of "Mon, 24 Jun 2013 21:47:02 +0200")
[-- Attachment #1: Type: text/plain, Size: 236 bytes --]
June, 24 at 21:47 Lars Magne Ingebrigtsen wrote:
> Ivan Kanis <ivan@kanis.fr> writes:
>
>> Do you want a new patch?
>
> Yes, please.
Here you go. I have removed wget-api. Instead I use a variable that will
hold the function to call.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-use-url-retrieve-to-download-files.patch --]
[-- Type: text/x-diff, Size: 2337 bytes --]
From 8a251f6f85ffa9ba3cf48d2c95ac27eeda58ac4d Mon Sep 17 00:00:00 2001
From: Ivan Kanis <ivan@tao>
Date: Mon, 24 Jun 2013 18:15:05 +0200
Subject: [PATCH] use url-retrieve to download files
---
emacs/misc/eww.el | 38 +++++++++++++++++++++++++++++++++++++-
1 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/emacs/misc/eww.el b/emacs/misc/eww.el
index 7b37eda..96e70b1 100644
--- a/emacs/misc/eww.el
+++ b/emacs/misc/eww.el
@@ -50,6 +50,20 @@
:group 'eww
:type 'string)
+(defcustom eww-download-path "~"
+ "Path where files will downloaded."
+ :version "24.4"
+ :group 'eww
+ :type 'string)
+
+(defcustom eww-download-function nil
+ "Function used to download a link.
+The function takes one argument. It is the URL of the link. It is
+called in `shr-download'."
+ :version "24.4"
+ :group 'shr
+ :type 'function)
+
(defface eww-form-submit
'((((type x w32 ns) (class color)) ; Like default mode line
:box (:line-width 2 :style released-button)
@@ -323,6 +337,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))
@@ -845,6 +860,27 @@ The browser to used is specified by the `shr-external-browser' variable."
(interactive)
(message eww-current-url)
(kill-new eww-current-url))
+
+(defun eww-download ()
+ "Download URL under point.
+It calls `shr-dowload-function' with argument URL if it's non-nil."
+ (interactive)
+ (let ((url (get-text-property (point) 'shr-url)))
+ (if (not url)
+ (message "No URL under point")
+ (if eww-download-function
+ (funcall eww-download-function url)
+ (url-retrieve url 'eww-download-callback (list url))))))
+
+(defun eww-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 file eww-download-path))
+ (message (expand-file-name file eww-download-path))
+ (message "File %s saved." file))))
+
(provide 'eww)
-;;; eww.el ends here
--
1.7.1
next prev parent reply other threads:[~2013-06-25 6:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-24 9:58 patches and one bug Ivan Kanis
2013-06-24 13:36 ` Lars Magne Ingebrigtsen
2013-06-24 13:43 ` Lars Magne Ingebrigtsen
2013-06-24 14:05 ` Rüdiger Sonderfeld
2013-06-24 17:42 ` Lars Magne Ingebrigtsen
2013-06-24 16:18 ` Ivan Kanis
2013-06-24 17:36 ` Lars Magne Ingebrigtsen
2013-06-24 19:41 ` Ivan Kanis
2013-06-24 19:47 ` Lars Magne Ingebrigtsen
2013-06-25 6:21 ` Ivan Kanis [this message]
2013-06-25 19:51 ` Lars Magne Ingebrigtsen
2013-06-25 20:23 ` Ivan Kanis
2013-06-24 16:46 ` Ivan Kanis
2013-06-24 17:39 ` Lars Magne Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bo6uww0i.fsf@kanis.fr \
--to=ivan@kanis.fr \
--cc=emacs-devel@gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.