summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-07-29 07:13:56 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-07-29 07:13:56 +0200
commit76f71e39f583b7f8bb47a47b315f49af6f23886e (patch)
tree31051d5b9022192ecb6bf11d4d64731ca24ff7d2 /lisp
parentbcf486c6043ba5f862c164f618f5b1017a1e0637 (diff)
downloademacs-76f71e39f583b7f8bb47a47b315f49af6f23886e.tar.gz
Make eww use the XDG download directory
* lisp/net/eww.el (erc--download-directory): New function (bug#41030). (eww-download-directory): Use it. (eww-download): Use it. (eww-download-callback): Adjust parameters.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/net/eww.el43
1 files changed, 30 insertions, 13 deletions
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index f4e3aa36c55..edb2f729c8b 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -32,6 +32,7 @@
(require 'thingatpt)
(require 'url)
(require 'url-queue)
+(require 'xdg)
(eval-when-compile (require 'subr-x))
(defgroup eww nil
@@ -55,11 +56,24 @@
:group 'eww
:type 'string)
-(defcustom eww-download-directory "~/Downloads/"
- "Directory where files will downloaded."
- :version "24.4"
+(defun erc--download-directory ()
+ "Return the name of the download directory.
+If ~/Downloads/ exists, that will be used, and if not, the
+DOWNLOAD XDG user directory will be returned. If that's
+undefined, ~/Downloads/ is returned anyway."
+ (or (and (file-exists-p "~/Downloads/")
+ "~/Downloads/")
+ (when-let ((dir (xdg-user-dir "DOWNLOAD")))
+ (file-name-as-directory dir))
+ "~/Downloads/"))
+
+(defcustom eww-download-directory 'erc--download-directory
+ "Directory where files will downloaded.
+This should either be a directory name or a function (called with
+no parameters) that returns a directory name."
+ :version "28.1"
:group 'eww
- :type 'directory)
+ :type '(choice directory function))
;;;###autoload
(defcustom eww-suggest-uris
@@ -1632,20 +1646,23 @@ Differences in #targets are ignored."
"Download URL to `eww-download-directory'.
Use link at point if there is one, else the current page's URL."
(interactive)
- (access-file eww-download-directory "Download failed")
- (let ((url (or (get-text-property (point) 'shr-url)
- (eww-current-url))))
- (if (not url)
- (message "No URL under point")
- (url-retrieve url #'eww-download-callback (list url)))))
-
-(defun eww-download-callback (status url)
+ (let ((dir (if (stringp eww-download-directory)
+ eww-download-directory
+ (funcall eww-download-directory))))
+ (access-file dir "Download failed")
+ (let ((url (or (get-text-property (point) 'shr-url)
+ (eww-current-url))))
+ (if (not url)
+ (message "No URL under point")
+ (url-retrieve url #'eww-download-callback (list url dir))))))
+
+(defun eww-download-callback (status url dir)
(unless (plist-get status :error)
(let* ((obj (url-generic-parse-url url))
(path (directory-file-name (car (url-path-and-query obj))))
(file (eww-make-unique-file-name
(eww-decode-url-file-name (file-name-nondirectory path))
- eww-download-directory)))
+ dir)))
(goto-char (point-min))
(re-search-forward "\r?\n\r?\n")
(let ((coding-system-for-write 'no-conversion))