bastibe / org-journal

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

Small documentation issue for Journal Capture Template (and suggestion of an addition) #302

Closed brabalan closed 4 years ago

brabalan commented 4 years ago

When implementing https://github.com/bastibe/org-journal#journal-capture-template in my configuration, I was getting errors of the form before the first headline. I narrowed it down to the call to org-narrow-subtree. Indeed, in some cases (daily journal with org-journal-date-prefix set to something other that *, it's #+TITLE: in my case), there is no subtree.

As this line is only useful for entries that are not in daily format, I suggest to change this line to

    (unless (eq org-journal-file-type 'daily)
      (org-narrow-to-subtree))

In addition, I have adapted the code to work for a future entry. Here it is:

(defun org-journal-date-location (&optional scheduled-time)
  (let ((scheduled-time (or scheduled-time (org-read-date nil nil nil "Date:"))))
    (setq as/org-journal-date-location-scheduled-time scheduled-time)
    (org-journal-new-entry t (org-time-string-to-time scheduled-time))
    (unless (eq org-journal-file-type 'daily)
      (org-narrow-to-subtree))
    (goto-char (point-max))))

and

          ("J" "Scheduled Journal Entry" plain (function org-journal-date-location)
                               "* TODO %?\n <%(princ as/org-journal-date-location-scheduled-time)>\n %U"
                               :jump-to-captured t)
casch-at commented 4 years ago
    (unless (eq org-journal-file-type 'daily)
      (org-narrow-to-subtree))

Right!

    (setq as/org-journal-date-location-scheduled-time scheduled-time)

Why didn't you reuse the variable scheduled-time instead of creating a new global variable as/org-journal-date-location-scheduled-time which is available even after let. Is there a reason?

Please create a PR.

brabalan commented 4 years ago

Why didn't you reuse the variable scheduled-time instead of creating a new global variable as/org-journal-date-location-scheduled-time which is available even after let. Is there a reason?

I need the scheduled time to be available in the org-capture template. I know it's ugly to use side effects like this, but I don't have another solution.