bastibe / org-journal

A simple org-mode based journaling mode
BSD 3-Clause "New" or "Revised" License
1.24k stars 124 forks source link

"Before first heading" error in heading-free files #440

Open meedstrom opened 2 months ago

meedstrom commented 2 months ago

Describe the bug I get a "Before first heading" error message when I call org-journal-new-entry.

To Reproduce

Set these settings:

(progn
  (setq org-journal-file-type 'daily)
  (setq org-journal-file-format "%F.org")
  (setq org-journal-date-prefix "#+title: ")
  (setq org-journal-date-format "%F")
  (setq org-journal-time-prefix "")
  (setq org-journal-time-format ""))

Now do M-x org-journal-new-entry.

Desktop (please complete the following information):

meedstrom commented 2 months ago

It is because org-journal-new-entry calls outline-show-entry at the end.

Simple workaround may be to add Beginning-of-String "\\`" to the outline-regexp in org-journal buffers.

Like

(add-hook 'org-journal-mode-hook
            (lambda ()
              (setq outline-regexp (rx (or bos (seq (+ "*") " "))))))
bastibe commented 2 months ago

Is this caused by your customizations, or always a problem?

meedstrom commented 2 months ago

It wasn't a problem when I went with a non-blank time prefix:

(setq org-journal-time-prefix "* ")

so I inferred that it has to do with some Org code not behaving as expected when point is before the first heading (a common problem).

I'm actually gonna use a homegrown system rather than org-journal, so it's not important to me to fix this, but let me know if you don't get the error with the reproduction steps suggested in OP. I will be surprised (is your value of outline-regexp the default?), but then I might try to track down the real issue with emacs -Q.

bastibe commented 2 months ago

I guess this is expected behavior, in some sense.