commit 26c969703dbfc57da38359bb41c3f8720cf4d224
parent c8be2611786d1d8d666b7b4f73582de1093f25ac
Author: andsy10 <andsy1016@gmail.com>
Date: Mon, 12 Oct 2026 18:16:48 +0800
Allow org-download-image-dir to be a function
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/org-download.el b/org-download.el
@@ -91,10 +91,12 @@
(defcustom org-download-image-dir nil
"If set, images will be stored in this directory instead of \".\".
-See `org-download--dir-1' for more info."
+It can be a directory string, or a function that returns a directory
+string. See `org-download--dir-1' for more info."
:type '(choice
(const :tag "Default" nil)
- (string :tag "Directory")))
+ (string :tag "Directory")
+ (function :tag "Function returning directory")))
(make-variable-buffer-local 'org-download-image-dir)
(defcustom org-download-heading-lvl 0
@@ -245,8 +247,13 @@ For example:
(defun org-download--dir-1 ()
"Return the first part of the directory path for `org-download--dir'.
-It's `org-download-image-dir', unless it's nil. Then it's \".\"."
- (or org-download-image-dir "."))
+It's `org-download-image-dir', unless it's nil. Then it's \".\".
+If `org-download-image-dir' is a function, it is called with no
+arguments to obtain the directory."
+ (let ((dir org-download-image-dir))
+ (cond ((functionp dir) (or (funcall dir) "."))
+ (dir)
+ (t "."))))
(defun org-download--dir-2 ()
"Return the second part of the directory path for `org-download--dir'.