1

I would like to setup an org-capture template for my journal entries that mimics org-journal.el. The difference is, I want my journal to live in one file.

Here is an excerpt from the github page to see what it looks like:

* Tuesday, 06/04/13
** 10:28 Company meeting
Endless discussions about projects. Not much progress

** 11:33 Work on org-journal
For the longest time, I wanted to have a cool diary app on my
computer. However, I simply lacked the right tool for that job. After
many hours of searching, I finally found PersonalDiary on EmacsWiki.
PersonalDiary is a very simple diary system based on the emacs
calendar. It works pretty well, but I don't really like that it only
uses unstructured text.

Thus, I spent the last two hours making that diary use org-mode
and represent every entry as an org-mode headline. Very cool!

** 15:33 Work on org-journal

Here is what I have so far:

;; org-capture settings.
  (setq org-capture-templates
        `(("j" "Journal entry" entry
           (file+headline "~/org/journal.org"
                          ,(format "%s"
                                   (format-time-string "%A, %y/%m/%d")))
           ,(concat "* " (format-time-string "%H:%M") " %^{Title}\n%?")
           )))

This has three problems:

  1. I can't figure out how to add a blank link in between entries.
  2. Org-capture keeps adding a blank space to the left of %?. No idea what is causing this
  3. The time stamp does not increment after the first time I run this?

Any ideas?

1

This is the best I get:

      ("j" "Journal" entry (file+olp+datetree "~/org/journal.org")
       "** %<%H:%M> %?\n")

It generates entries like this

* 2018
** 2018-03 March
*** 2018-03-20 Tuesday
**** 20:45 test 1
**** 20:46 test 2

It solves the 3rd problem. Seems like using %<...> is the cleanest way to get a time-related string format. See https://orgmode.org/manual/Template-expansion.html#Template-expansion

The answer from @kshenoy might be problematic for you since it will add a line for before and after the captured content (refer to this), therefore effectively separate each entry with 2 empty lines. I don't have a solution to that.

0

Try setting :empty-lines 1 as described here.

0

You can try the empty-lines option, but that didn't work for me. I had a related problem. If I went to the end of the capture buffer and typed, then the newline character would be lost. This was a problem because the next line in the file was a header - and this header now appeared at the end of the last line of whatever I captured when it saved it to the file.

I solved this by this hook:

  (defun add-newline-at-end-if-none ()
    "Add a newline at the end of the buffer if there isn't any."
    (save-excursion
      (save-restriction
        (goto-char (1- (point-max)))
        (if (not (looking-at "\n"))
          (progn
            (goto-char (point-max))
            (insert "\n"))))))

  (add-hook 'org-capture-prepare-finalize-hook 'add-newline-at-end-if-none)

In your case, you may need to check/add two new lines to ensure a blank line.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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