0

My org-capture setup:

(setq org-capture-templates
 '(("t" "Todo" entry (file+headline "~/org/gtd.org" "@computer")
        "* TODO %?\n %i\n")
   ("j" "Journal" entry (file+datetree "~/org/gtd.org" "Journal")
        "* %?\nEntered on %U\n %i\n")))

When I file a note via org-capture as a journal entry, it is not saved in the dateree below "Journal" but in the first "2014" node of the document (which does not have a "Journal" parent node).

Does anybody have an idea why this happens or how I can prevent this?

1
  • The Org doc implies that file+datetree only takes a file path, not a parent node. So you are seeing the expected behavior.
    – glucas
    Commented Nov 20, 2014 at 16:21

1 Answer 1

1

If it's the only one headline to host a datetree. You can set the DATE_TREE property in the Journal headline, and then there are placed.

But if you want to have more datetrees in the gtd.org file, you should use a file+function target.

Updated

I've been developing a solution for this problem taking in consideration multiple DATETREES for the same file and here is my function:

(defun test-capture-func ()
  (org-capture-put-target-region-and-position)
  (widen)
  (goto-char 1)
  (search-forward-regexp "^\\*+ Journal")
  (let* ((lvl (org-current-level))
         (org-datetree-base-level (+ 1 lvl)))
    (org-narrow-to-subtree)
    (move-end-of-line 1)
    (let* ((date (calendar-gregorian-from-absolute (org-today)))
           (year (nth 2 date))
           (month (car date))
           (day (nth 1 date)))
      (save-restriction
        (goto-char (point-min))
        (org-datetree-find-year-create year)
        (org-datetree-find-month-create year month)
        (org-datetree-find-day-create year month day)
        (goto-char (prog1 (point) (widen)))))
    (org-narrow-to-subtree)
    (org-capture-put :exact-position nil)))

But it's a problem the org implementation of the function org-capture-set-target-location, needs a small modification I'm going to propose to the org developers. The problem is that when you use the function or file+function target, it set the :exact-position property to (point) in the org-capture-plist, so you can't append the template as subheading of the current position heading.

The modification is in the function or file+function target, change the line:

(org-capture-put :exact-position (point))

for:

(unless (memq :exact-position org-capture-plist)
  (org-capture-put :exact-position (point)))

In this way now, you can set in your function :exact-position to nil, as I do in the function above, and then capture puts the templates inside the heading at point.

1
  • The problem I was monkeypatching is solved in the org mode git master. So after comes to packages, the last two lines of the function can be removed. Commented Nov 24, 2014 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.