On Mon, May 05 2025, Ihor Radchenko wrote: > Kristoffer Balintona <krisbalint...@gmail.com> writes: > >> 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. Alternatively, a target specification like >> (file+olp+datetree function-returning-file-path-and-olp) >> or >> (file+olp+datetree list-of-file-path-and-olp) >> would suffice. >> >> Are such changes desirable? If they are, I could try preparing a patch, >> but looking at org-capture-set-target-location, I'm not sure how easy >> this would be easy. > > That would be logical, I think. > Not just for file+olp+datetree, but then also for file+headline and file+olp.
I agree. But I've written a few thoughts about that below. >> Seems like the attached diff can accomplish this, though I'm not sure if >> it's the most elegant solution. >> ... >> - (apply #'org-capture-expand-olp >> expanded-file-path outline-path)))) >> ... >> + (outline-path (if (functionp (car outline-path)) >> + (funcall (car outline-path)) >> + outline-path)) > > We should keep outline path processing inside > `org-capture-expand-olp'. Duplicating logic is a bad idea. I agree that duplicating logic isn't ideal; that "solution" was just a quick fix. But the reason I hadn't suggested something else was that it wasn't clear to me which parts of the code is best to change. Currently, `org-find-olp' assumes that it is being passed a file path + an outline path, but when the olp function returns nil, only a file path is returned, so `org-find-olp' ends up returning nil when `org-capture-set-target-location' expects it to return a marker. Since `org-find-olp' is always run when the outline-path parameter is provided, we run into issues when it is a function returning nil. Taking a look at the code, it seems like file+olp+datetree and file+olp both behave like this. So my question is: which parts of the code should handle an outline-path function returning nil? Should we change the behavior of `org-find-olp' and/or `'org-capture-expand-olp', or should we change things just in `org-capture-set-target-location'? With respect to file+headline: I think a similar dilemma applies there. It looks like the relevant function is `org-capture-expand-headline': should we change that function to handle the case of its argument being a function that returns nil or have that handling in `org-capture-set-target-location'? -- Best, Kristoffer