diff options
| author | Ivan Kanis | 2013-06-25 21:50:05 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2013-06-25 21:50:05 +0200 |
| commit | bfbc93a1de51de1707092339156aa909c0bdfdb4 (patch) | |
| tree | 243e279fac2bf46afd835606ff08f7cfbcb821c7 | |
| parent | 16f74f10ba890564e6d93b221ec38091af781bf3 (diff) | |
| download | emacs-bfbc93a1de51de1707092339156aa909c0bdfdb4.tar.gz emacs-bfbc93a1de51de1707092339156aa909c0bdfdb4.zip | |
* net/eww.el (eww-download): New command and keystroke.
* net/eww.el (eww-make-unique-file-name): Create a unique file
name before saving to entering `y' accidentally asynchronously.
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/net/eww.el | 41 |
2 files changed, 50 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2f6f2df3221..1cba40dc90e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,14 @@ | |||
| 1 | 2013-06-25 Lars Magne Ingebrigtsen <larsi@gnus.org> | 1 | 2013-06-25 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 2 | ||
| 3 | * net/eww.el (eww-make-unique-file-name): Create a unique file | ||
| 4 | name before saving to entering `y' accidentally asynchronously. | ||
| 5 | |||
| 6 | 2013-06-25 Ivan Kanis <ivan@kanis.fr> | ||
| 7 | |||
| 8 | * net/eww.el (eww-download): New command and keystroke. | ||
| 9 | |||
| 10 | 2013-06-25 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 11 | |||
| 3 | * net/eww.el (eww-copy-page-url): Changed name of command. | 12 | * net/eww.el (eww-copy-page-url): Changed name of command. |
| 4 | 13 | ||
| 5 | * net/shr.el (shr-map): Change `shr-copy-url' from `u' to `w' to | 14 | * net/shr.el (shr-map): Change `shr-copy-url' from `u' to `w' to |
diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 9d6e42792ec..2d6fe9a08dc 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el | |||
| @@ -50,6 +50,12 @@ | |||
| 50 | :group 'eww | 50 | :group 'eww |
| 51 | :type 'string) | 51 | :type 'string) |
| 52 | 52 | ||
| 53 | (defcustom eww-download-path "~/Downloads/" | ||
| 54 | "Path where files will downloaded." | ||
| 55 | :version "24.4" | ||
| 56 | :group 'eww | ||
| 57 | :type 'string) | ||
| 58 | |||
| 53 | (defface eww-form-submit | 59 | (defface eww-form-submit |
| 54 | '((((type x w32 ns) (class color)) ; Like default mode line | 60 | '((((type x w32 ns) (class color)) ; Like default mode line |
| 55 | :box (:line-width 2 :style released-button) | 61 | :box (:line-width 2 :style released-button) |
| @@ -325,6 +331,7 @@ word(s) will be searched for via `eww-search-prefix'." | |||
| 325 | (define-key map "u" 'eww-up-url) | 331 | (define-key map "u" 'eww-up-url) |
| 326 | (define-key map "t" 'eww-top-url) | 332 | (define-key map "t" 'eww-top-url) |
| 327 | (define-key map "&" 'eww-browse-with-external-browser) | 333 | (define-key map "&" 'eww-browse-with-external-browser) |
| 334 | (define-key map "d" 'eww-download) | ||
| 328 | (define-key map "w" 'eww-copy-page-url) | 335 | (define-key map "w" 'eww-copy-page-url) |
| 329 | map)) | 336 | map)) |
| 330 | 337 | ||
| @@ -876,6 +883,40 @@ The browser to used is specified by the `shr-external-browser' variable." | |||
| 876 | (message "%s" eww-current-url) | 883 | (message "%s" eww-current-url) |
| 877 | (kill-new eww-current-url)) | 884 | (kill-new eww-current-url)) |
| 878 | 885 | ||
| 886 | (defun eww-download () | ||
| 887 | "Download URL under point to `eww-download-directory'." | ||
| 888 | (interactive) | ||
| 889 | (let ((url (get-text-property (point) 'shr-url))) | ||
| 890 | (if (not url) | ||
| 891 | (message "No URL under point") | ||
| 892 | (url-retrieve url 'eww-download-callback (list url))))) | ||
| 893 | |||
| 894 | (defun eww-download-callback (status url) | ||
| 895 | (unless (plist-get status :error) | ||
| 896 | (let* ((obj (url-generic-parse-url url)) | ||
| 897 | (path (car (url-path-and-query obj))) | ||
| 898 | (file (eww-make-unique-file-name (file-name-nondirectory path) | ||
| 899 | eww-download-path))) | ||
| 900 | (write-file file) | ||
| 901 | (message "Saved %s" file)))) | ||
| 902 | |||
| 903 | (defun eww-make-unique-file-name (file directory) | ||
| 904 | (cond | ||
| 905 | ((zerop (length file)) | ||
| 906 | (setq file "!")) | ||
| 907 | ((string-match "\\`[.]" file) | ||
| 908 | (setq file (concat "!" file)))) | ||
| 909 | (let ((base file) | ||
| 910 | (count 1)) | ||
| 911 | (while (file-exists-p (expand-file-name file directory)) | ||
| 912 | (setq file | ||
| 913 | (if (string-match "\\`\\(.*\\)\\([.][^.]+\\)" file) | ||
| 914 | (format "%s(%d)%s" (match-string 1 file) | ||
| 915 | count (match-string 2 file)) | ||
| 916 | (format "%s(%d)" file count))) | ||
| 917 | (setq count (1+ count))) | ||
| 918 | (expand-file-name file directory))) | ||
| 919 | |||
| 879 | (provide 'eww) | 920 | (provide 'eww) |
| 880 | 921 | ||
| 881 | ;;; eww.el ends here | 922 | ;;; eww.el ends here |