On Mon, May 05 2025, Kristoffer Balintona wrote:

> It would be nice if the top-level datetree in <file-spec> would simply
> be used if the function supplied for function-returning-list-of-strings
> returns nil.

Seems like the attached diff can accomplish this, though I'm not sure if
it's the most elegant solution.

-- 
Best,
Kristoffer
 lisp/org-capture.el | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 6d395406c..674504165 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1086,12 +1086,15 @@ Store them in the capture property list."
 	   (setq target-entry-p
 		 (and (derived-mode-p 'org-mode) (org-at-heading-p)))))
 	(`(file+olp+datetree ,path . ,outline-path)
-	 (let ((m (if outline-path
-		      (let ((expanded-file-path (org-capture-expand-file path)))
-                        (org-find-olp (cons expanded-file-path
-					    (apply #'org-capture-expand-olp expanded-file-path outline-path))))
-		    (set-buffer (org-capture-target-buffer path))
-		    (point-marker))))
+	 (let* ((expanded-file-path (org-capture-expand-file path))
+                (outline-path (if (functionp (car outline-path))
+                                  (funcall (car outline-path))
+                                outline-path))
+                (m (if outline-path
+                       (org-find-olp (cons expanded-file-path
+                                           (apply #'org-capture-expand-olp expanded-file-path outline-path)))
+                     (set-buffer (org-capture-target-buffer expanded-file-path))
+                     (point-marker))))
 	   (set-buffer (marker-buffer m))
 	   (org-capture-put-target-region-and-position)
 	   (widen)

Reply via email to