# Multiple blank lines in head of capture template

**URL:** <https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488>\
**Category:** Troubleshooting\
**Created:** [March 1, 2022, 9:51pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488 "2022-03-01T21:51:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![apc](https://avatars.discourse-cdn.com/v4/letter/a/9fc29f/32.png) [@apc](https://org-roam.discourse.group/u/apc)\
**Post date:** [March 1, 2022, 9:51pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/1 "2022-03-01T21:51:28Z")

</div>

I’m trying to have my capture templates insert an extra line before the content of the entry and the head. From what I understand after looking at the definition of `org-roam-capture--fill-template`, when using the template line breaks are essentially ignored. So, effectively, these two bits of code are treated the same

```auto
(setq org-roam-capture-templates
   '(("d" "default" plain "%?" :target
      (file+head "%<%Y%m%d%H%M%S>.org" "#+title: ${title}\n#+filetags: :draft:\n")
      :unnarrowed t)))

```

```auto
(setq org-roam-capture-templates
   '(("d" "default" plain "%?" :target
      (file+head "%<%Y%m%d%H%M%S>.org" "#+title: ${title}\n#+filetags: :draft:\n\n")
      :unnarrowed t)))

```

Has anyone managed to find a way around this? (I don’t want to insert a bunch of blank lines after capture, so in general I’m OK with the default behavior in most situations, but I’d like the ability to have that extra space after the header (or is is the head?)

---

<div class="post-metadata">

**Author:** ![deerpig](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/deerpig/32/662_2.png) [@deerpig](https://org-roam.discourse.group/u/deerpig)\
**Post date:** [March 5, 2022, 10:24am UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/2 "2022-03-05T10:24:02Z")

</div>

Use \n to insert a line break, so \n\n would insert a blank line.

---

<div class="post-metadata">

**Author:** ![artelse](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@artelse](https://org-roam.discourse.group/u/artelse)\
**Post date:** [March 6, 2022, 9:59am UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/3 "2022-03-06T09:59:25Z")

</div>

@apc This indeed doesn’t work, line breaks `\n` are ignored at the end of the header. I am having the same problem. I also tried adding a blank line at the start of the template file, but it is ignored as well. Any ideas?  
Edit: corrected typo.

---

<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:** [March 6, 2022, 4:10pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/4 "2022-03-06T16:10:44Z")

</div>

Refer to the comments and following lines of code around [here](https://github.com/org-roam/org-roam/blob/master/org-roam-capture.el#L776-L791).

I believe you’d need to override the function locally (I am not certain which line exactly). I’d `edebug` and see how the code removes the additional empty lines added in the template.

---

<div class="post-metadata">

**Author:** ![artelse](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@artelse](https://org-roam.discourse.group/u/artelse)\
**Post date:** [March 6, 2022, 6:27pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/5 "2022-03-06T18:27:50Z")

</div>

Have looked at the code comments. It makes sense to strip trailing new lines from the header, but I would suggest not touching anything people define in the template file; i.e. leave that up to the user.

---

<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:** [March 6, 2022, 6:44pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/6 "2022-03-06T18:44:53Z")

</div>

I suggest you report this to the project as an issue.

---

<div class="post-metadata">

**Author:** ![artelse](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@artelse](https://org-roam.discourse.group/u/artelse)\
**Post date:** [March 6, 2022, 7:27pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/7 "2022-03-06T19:27:42Z")

</div>

Done, see [here](https://github.com/org-roam/org-roam/issues/2115). Thanks!

---

<div class="post-metadata">

**Author:** ![lyndhurst](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@lyndhurst](https://org-roam.discourse.group/u/lyndhurst)\
**Post date:** [May 1, 2024, 5:59am UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/8 "2024-05-01T05:59:08Z")

</div>

> [@artelse](#):
>
> Done, see [here](https://github.com/org-roam/org-roam/issues/2115). Thanks!

I know this thread is old, and it seems to be fixed, but I found it while trying to overcome the same problem of inserting a blank line between the ‘head’ and the cursor.

So far, all my attempts have failed, I followed the link to github you provided, and tried to look at the commit which is supposed to have fixed the issue where I can see a reassuring `(insert (org-roam-capture--fill-template head 'ensure-newline)))` added to the code.

Since inserting `\n` or `\n\n` has no effect on my end, I looked for some `ensure-newline` or `fill-template` kind of variable but did not find any. I cannot find anything related in the `org-roam-capture-template` help.

Is there anything in particular to do to prevent blank lines from being stripped off the `org-roam-templates` ?

---

<div class="post-metadata">

**Author:** ![wilya](https://avatars.discourse-cdn.com/v4/letter/w/94ad74/32.png) [@wilya](https://org-roam.discourse.group/u/wilya)\
**Post date:** [August 16, 2024, 2:49pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/9 "2024-08-16T14:49:16Z")

</div>

See my reply in a new thread: [How to have a sequence of more than two newlines in a capture template? - #2 by wilya](https://org-roam.discourse.group/t/how-to-have-a-sequence-of-more-than-two-newlines-in-a-capture-template/3555/2)

TLDR: Only trailing whitespace are preserved.

To answer your question, if you comment out this line:

```auto
(defun org-roam-capture--fill-template (template &optional ensure-newline)
  ;; ... (other parts of the function) ...
  
  ;; Comment out or remove the following line to preserve newlines
  ;; (setq template (replace-regexp-in-string "[\n]*\\'" "" (org-capture-fill-template template))) 

  (when (and ensure-newline               
             (string-equal template-whitespace-content ""))
    (setq template-whitespace-content "\n"))
  (setq template (concat template template-whitespace-content))
  template)

```

it should change the behavior of the function. However, I have no idea if this could have unpleasant second order effects (also called bugs).

You can redefine the `org-roam-capture--fill-template` function in your Emacs configuration file.

```auto
(defun org-roam-capture--fill-template (template &optional ensure-newline)
  ;; ... (copy the original function definition here) ...

  ;; Comment out or remove the newline collapsing line
  ;; (setq template (replace-regexp-in-string "[\n]*\\'" "" (org-capture-fill-template template))) 

  ;; ... (rest of the original function definition) ...
)

```

This approach effectively overrides the original function definition with your modified version. Keep in mind that when redefining functions from packages, it can lead to conflicts if the package’s implementation changes in the future.

---

<div class="post-metadata">

**Author:** ![lyndhurst](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@lyndhurst](https://org-roam.discourse.group/u/lyndhurst)\
**Post date:** [October 13, 2024, 2:36pm UTC](https://org-roam.discourse.group/t/multiple-blank-lines-in-head-of-capture-template/2488/10 "2024-10-13T14:36:34Z")

</div>

I could not get around to it earlier, but thank you for taking the time to provide these detailled additional explanations.
