From e04c0fcc7bd57fb36ced8539e56db4ab652ff468 Mon Sep 17 00:00:00 2001 From: Peng Li Date: Tue, 13 Sep 2016 21:30:23 +0800 Subject: [PATCH] emacs - add download function --- emacs.d/config.org | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/emacs.d/config.org b/emacs.d/config.org index df43076..8bb6d51 100644 --- a/emacs.d/config.org +++ b/emacs.d/config.org @@ -1471,6 +1471,28 @@ brew install the-silver-searcher (add-hook 'text-mode-hook 'table-recognize) #+END_SRC +** url-download +Refer [[http://stackoverflow.com/questions/4448055/download-a-file-with-emacs-lisp][download-a-file-with-emacs-lisp]] +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + (defun sd/download-file (&optional url download-dir download-name) + (interactive) + (let ((url (or url + (read-string "Enter download URL: "))) + (download-dir (or (read-string "Save to (~/Downloads): ") "~/Downloads"))) + (let ((download-buffer (url-retrieve-synchronously url))) + (save-excursion + (set-buffer download-buffer) + ;; we may have to trim the http response + (goto-char (point-min)) + (re-search-forward "^$" nil 'move) + (forward-char) + (delete-region (point-min) (point)) + (write-file (concat (or download-dir + "~/Downloads/") + (or download-name + (car (last (split-string url "/" t)))))))))) +#+END_SRC + * Dired ** Dired bindings =C-o= is defined as a global key for window operation, here unset it in dired mode -- 2.11.0