# Org-roam capture templates function to move to point in file

**URL:** <https://org-roam.discourse.group/t/org-roam-capture-templates-function-to-move-to-point-in-file/2784>\
**Category:** Troubleshooting\
**Created:** [September 27, 2022, 9:53pm UTC](https://org-roam.discourse.group/t/org-roam-capture-templates-function-to-move-to-point-in-file/2784 "2022-09-27T21:53:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dlucas](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@Dlucas](https://org-roam.discourse.group/u/Dlucas)\
**Post date:** [September 27, 2022, 9:53pm UTC](https://org-roam.discourse.group/t/org-roam-capture-templates-function-to-move-to-point-in-file/2784/1 "2022-09-27T21:53:26Z")

</div>

I am attempting to use the org-roam dailies capture templates to insert entries underneath a headline specified by the an org-roam-dailies-capture-templates key. I was hoping to get it to look something like this:

```auto
* 2022-09-25 Sunday
** logs
*** 20:00 Log Entry 01
This is a log entry

*** 23:00 Log Entry 02
This is also a log entry

** reflections
*** 22:00 Reflection Entry 01
This is a reflection entry

*** 23:30 Reflection Entry 02
This is also a reflection entry

```

So I tried to do this the way I would with `org-capture-templates`, by using a custom function with the `:target` property to move point to the respective headline and then insert my entry. However, it seems that `org-roam-capture-templates` and `org-roam-dailies-capture-templates` don’t accept the same arguments as regular `org-capture-templates`. In particular, custom functions to move the point within the file are not supported as far as I can tell.

A sample of the code that I hoped would achieve my purpose is

```lisp
org-roam-dailies-capture-templates
("l" "log entry" entry
      "* %<%H:%M>\n%?"
      :target (file+function "%(expand-file-name "%<%Y-%m>.org" org-roam-dailies-directory"
                             (function organum-capture-journal-target-heading))
      :journal-type "logs")

```

and the untested function to move to the heading is

```lisp
(defun organum-capture-journal-target-heading ()
  "Return a file target for a journal capture."
  (let ((date-heading (format-time-string "%Y-%m-%d %A"))
        (journal-heading (org-capture-get :journal-type)))
    (goto-char (point-min))
    (if (re-search-forward
         (format org-complex-heading-regexp-format
                 (regexp-quote date-heading))
         nil t)
        (beginning-of-line)
      (goto-char (point-max))
      (unless (bolp) (insert "\n"))
      (insert "* " date-heading "\n")
      (beginning-of-line 0))
    (if (re-search-forward
         (format org-complex-heading-regexp-format
                 (regexp-quote journal-heading))
         nil t)
        (beginning-of-line)
      (goto-char (point-max))
      (unless (bolp) (insert "\n"))
      (insert "* " journal-heading "\n")
      (beginning-of-line 0))))

```

i am not sure the above function works, but it hopefully captures the idea of what I am attempting to do. Is there any way for me to achieve this with org-roam’s capture templating system?

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [September 28, 2022, 7:06pm UTC](https://org-roam.discourse.group/t/org-roam-capture-templates-function-to-move-to-point-in-file/2784/2 "2022-09-28T19:06:49Z")

</div>

How about something simpler?

```auto
  (setq org-roam-dailies-capture-templates
        '(("l" "Logs" plain ""
           :target
           (file+head+olp "%<%Y-%m>.org" ""
                          ("%<%Y-%m-%d %A>" "logs" "%<%H:%M> log entry"))
           :empty-lines-after 2)
          ("r" "Reflections" plain ""
           :target
           (file+head+olp "%<%Y-%m>.org" ""
                          ("%<%Y-%m-%d %A>" "reflections" "%<%H:%M> reflection entry"))
           :empty-lines-after 2)))

```

The result is something like this image below. I believe it covers most of your requirements.

 ![image](https://global.discourse-cdn.com/free1/uploads/orgroam/original/2X/0/071fbc45510c1bc5aac0d9e13d52db6d4b872223.png)

I didn’t understand exactly what you wish to do in some details from the code. Here are some main assumptions I made and consequences of the approach. I trust that you can adjust the code above to your exact requirements. I don’t use Org-roam-dailies so I’m sure I have missed some important aspects for you.

- I take it that you would like “monthlies”  
This means one file per month and you want just one node (Org-ID per file). No headline nodes. I chose the `plain` option instead of `entry`. I believe that `entry` would result in creating a node for the headline of each day.

- You would need to manually control the sequence of logs and reflections  
There are two keys for selections `l` for `Logs` and `r` for `Reflections`. You can use `r` before `l`. If the sequence is very important for you, you would need to ensure to create logs first, or manually exchange the sequence (easy to do with Org)

- You may need to experiment with the `:empty-lines-after` property to get the spaces right for you  
I was not sure how important it is for you to get the blank spaces after each entry. You might need to get used to how the property works – I don’t fully understand it

- You have number sequence like “Log Entry 01, Log Entry 02, etc.”  
I disregarded it – I don’t know how to achieve this with the template. If it is important, I guess you could use some function with `%(sexp)` – as documented in `org-roam-capture-templates`.

---

<div class="post-metadata">

**Author:** ![Dlucas](https://avatars.discourse-cdn.com/v4/letter/d/c77e96/32.png) [@Dlucas](https://org-roam.discourse.group/u/Dlucas)\
**Post date:** [October 1, 2022, 9:56pm UTC](https://org-roam.discourse.group/t/org-roam-capture-templates-function-to-move-to-point-in-file/2784/3 "2022-10-01T21:56:38Z")

</div>

Sorry for the delay in responding, this achieves what I was looking for very well! The olp section of the target field was the key here. Thank you!!

---

<div class="post-metadata">

**Author:** ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)\
**Post date:** [October 2, 2022, 7:16am UTC](https://org-roam.discourse.group/t/org-roam-capture-templates-function-to-move-to-point-in-file/2784/4 "2022-10-02T07:16:52Z")

</div>

Thank you for coming back and confirming
