0

I use org-expiry to insert the CREATED date in properties drawer by default. When I created second level headlines with my org-capture template and press C-c C-c when my cursor is at second level headline, org-expiry create the properties drawer at second level headline.

I want the properties drawer to be added to top level headline no matter where my cursor is when I finish the capture.

    * Top
    :PROPERTIES:
    :CREATED:  [2023-03-07 Tue 00:14]
    :END:
    ** Second 
    I finish my capture with my cursor being here.

Instead I got this:

    * Top
    ** Second 
    :PROPERTIES:
    :CREATED:  [2023-03-07 Tue 00:14]
    :END:
    I finish my capture with my cursor here.  

I tried to add :prepare-finalize (beginning-of-buffer) to the capture template but it doesn't work.

(setq org-capture-templates '(("f" "fleeting notes"
                                     entry
                                     (file+datetree org-fleeting-note-file)
                                     "* Top \n** Second %?"
                                     :tree-type month
                                     :prepare-finalize  (beginning-of-buffer)
                                     ))
3
  • org-expiry does that and there is no provision for it to insert the CREATED property somewhere else. Since it's an orphaned package, you might want to adopt it, fix it and support it. If so, see How to contribute.
    – NickD
    Mar 6, 2023 at 18:26
  • I should have asked: how have you configured org-expiry to do what it does to the capture? If you are doing it manually, then just call org-expiry-insert-created at the top level headline.
    – NickD
    Mar 6, 2023 at 18:28
  • I added the org-expiry-insert-created to org-capture-before-finalize-hook (add-hook 'org-capture-before-finalize-hook 'org-expiry-insert-created)
    – Le0
    Mar 7, 2023 at 6:48

1 Answer 1

1

I end up writing a new function that wrap org-expiry-insert-created to achieve this. For anyone who has the same problem, this is what I do:

    (defun my/org-insert-time-top-level-headline ()
      (save-excursion
        (goto-char (point-min))
        (org-expiry-insert-created)))

    (add-hook 'org-capture-prepare-finalize-hook #'my/org-insert-time-top-level-headline)

Feel free to comment if anyone has a cleaner solution.

2
  • This is as clean a solution as any. Nicely done!
    – NickD
    Mar 8, 2023 at 18:19
  • Thanks, I still have no idea why :prepare-finalize (beginning-of-buffer) does not work though. Would have been nice if I don't need to write an extra function.
    – Le0
    Mar 10, 2023 at 3:44

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.