mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-04-27 08:43:40 -07:00
* 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.
This commit is contained in:
parent
16f74f10ba
commit
bfbc93a1de
2 changed files with 50 additions and 0 deletions
|
|
@ -1,3 +1,12 @@
|
|||
2013-06-25 Lars Magne Ingebrigtsen <larsi@gnus.org>
|
||||
|
||||
* net/eww.el (eww-make-unique-file-name): Create a unique file
|
||||
name before saving to entering `y' accidentally asynchronously.
|
||||
|
||||
2013-06-25 Ivan Kanis <ivan@kanis.fr>
|
||||
|
||||
* net/eww.el (eww-download): New command and keystroke.
|
||||
|
||||
2013-06-25 Lars Magne Ingebrigtsen <larsi@gnus.org>
|
||||
|
||||
* net/eww.el (eww-copy-page-url): Changed name of command.
|
||||
|
|
|
|||
|
|
@ -50,6 +50,12 @@
|
|||
:group 'eww
|
||||
:type 'string)
|
||||
|
||||
(defcustom eww-download-path "~/Downloads/"
|
||||
"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)
|
||||
|
|
@ -325,6 +331,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 "&" 'eww-browse-with-external-browser)
|
||||
(define-key map "d" 'eww-download)
|
||||
(define-key map "w" 'eww-copy-page-url)
|
||||
map))
|
||||
|
||||
|
|
@ -876,6 +883,40 @@ The browser to used is specified by the `shr-external-browser' variable."
|
|||
(message "%s" eww-current-url)
|
||||
(kill-new eww-current-url))
|
||||
|
||||
(defun eww-download ()
|
||||
"Download URL under point to `eww-download-directory'."
|
||||
(interactive)
|
||||
(let ((url (get-text-property (point) 'shr-url)))
|
||||
(if (not url)
|
||||
(message "No URL under point")
|
||||
(url-retrieve url 'eww-download-callback (list url)))))
|
||||
|
||||
(defun eww-download-callback (status url)
|
||||
(unless (plist-get status :error)
|
||||
(let* ((obj (url-generic-parse-url url))
|
||||
(path (car (url-path-and-query obj)))
|
||||
(file (eww-make-unique-file-name (file-name-nondirectory path)
|
||||
eww-download-path)))
|
||||
(write-file file)
|
||||
(message "Saved %s" file))))
|
||||
|
||||
(defun eww-make-unique-file-name (file directory)
|
||||
(cond
|
||||
((zerop (length file))
|
||||
(setq file "!"))
|
||||
((string-match "\\`[.]" file)
|
||||
(setq file (concat "!" file))))
|
||||
(let ((base file)
|
||||
(count 1))
|
||||
(while (file-exists-p (expand-file-name file directory))
|
||||
(setq file
|
||||
(if (string-match "\\`\\(.*\\)\\([.][^.]+\\)" file)
|
||||
(format "%s(%d)%s" (match-string 1 file)
|
||||
count (match-string 2 file))
|
||||
(format "%s(%d)" file count)))
|
||||
(setq count (1+ count)))
|
||||
(expand-file-name file directory)))
|
||||
|
||||
(provide 'eww)
|
||||
|
||||
;;; eww.el ends here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue