1

If we have org file with datetree and repeating actions, how can I capture under last heading of some level. Let's say we have this:

* 2018 ** 2018-W47 *** 2018-11-21 Wednesday **** Gym Session ** 2018-W48 *** 2018-12-01 Saturday **** Running *** 2018-12-02 Sunday **** Gym Session 

I want to create org-capture template which would put entry under last "Gym Session" from Sunday. This means I can't use heading, because it's not guaranteed to be unique. Is there some function like "org-last-heading-of-level-4" or something similar maybe? Thanks!

2 Answers 2

1

From your description the selection of the heading you want to add to is quite random. At least, the description of your work flow is not detailed enough for someone else to create a function that always finds the correct header.

I suggest that you use org-mode's clocking functionality to log into the task of under the right heading and use the current task capture template from the howardism blog to add more text:

(add-to-list 'org-capture-templates `("c" "Item to Current Clocked Task" item (clock) "%i%?" :empty-lines 1)) 
1
  • Ok, this does seem interesting feature and I will dig further because it actually might be better approach to my problem than my own, but I wanted something that seamed way simpler than this. It's not really random, because I want something to go to the last existing heading of certain level. Commented Dec 9, 2018 at 11:59
0

Again, this might not again be exactly what you want, but gives the kind of functionality you need. In your example, you want to add text to the end of the file.

I am using this function myself to add comments to a last captured org note in an org datetree file. The function simply goes to the end of the file so that I can write whatever I want:

(defun my/last-captured-org-note () "Move to the last line of the last org capture note." (interactive) (find-file "~/Dropbox/org/notes.org") (goto-char (point-max))) 

If the header you want is not the last one, you can add approriate search-backward and forward-line forms to the function to get there.

3
  • Great, this can work with search-backward. Thanks! Commented Dec 11, 2018 at 9:54
  • It may be because I'm new on this site, but I can't mark your answer as accepted. If there is some option to do it that I don't see, please tell me. Thanks. Commented Dec 11, 2018 at 10:02
  • You might have to upvote the answer first before you can mark it accepted. Commented Dec 12, 2018 at 6:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.