emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r113177: * net/eww.el (eww-download): New command an


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] trunk r113177: * net/eww.el (eww-download): New command and keystroke.
Date: Tue, 25 Jun 2013 19:50:08 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113177
revision-id: address@hidden
parent: address@hidden
author: Ivan Kanis <address@hidden>
committer: Lars Magne Ingebrigtsen <address@hidden>
branch nick: trunk
timestamp: Tue 2013-06-25 21:50:05 +0200
message:
  * 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.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/net/eww.el                eww.el-20130610114603-80ap3gwnw4x4m5ix-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-06-25 19:25:14 +0000
+++ b/lisp/ChangeLog    2013-06-25 19:50:05 +0000
@@ -1,5 +1,14 @@
 2013-06-25  Lars Magne Ingebrigtsen  <address@hidden>
 
+       * 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  <address@hidden>
+
+       * net/eww.el (eww-download): New command and keystroke.
+
+2013-06-25  Lars Magne Ingebrigtsen  <address@hidden>
+
        * net/eww.el (eww-copy-page-url): Changed name of command.
 
        * net/shr.el (shr-map): Change `shr-copy-url' from `u' to `w' to

=== modified file 'lisp/net/eww.el'
--- a/lisp/net/eww.el   2013-06-25 19:25:14 +0000
+++ b/lisp/net/eww.el   2013-06-25 19:50:05 +0000
@@ -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 @@
     (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 @@
   (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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]