From 68e90c83d09da9904233dfa6f538f86f7da1e1bc Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Wed, 28 Nov 2012 17:34:50 +0900 Subject: [PATCH] add function download-file --- emacs.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/emacs.el b/emacs.el index 25bf5e4..395d023 100644 --- a/emacs.el +++ b/emacs.el @@ -68,6 +68,27 @@ otherwise the path where the library installed." (locate-library lib)) locate-p))) +(defun download-file (url path &optional ok-if-already-exists) + "Download file from URL and output to PATH." + (or (ignore-errors + (url-copy-file url + path + ok-if-already-exists) + path) + (ignore-errors + (let ((curl (executable-find "curl"))) + (when curl + (if (and (not ok-if-already-exists) + (file-exists-p path)) + nil + (eq 0 + (call-process curl + nil + nil + nil + "--output" + path)))))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; autoload