Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding top-of-file metadata? #182

Closed
ndw opened this issue Jan 9, 2020 · 4 comments
Closed

Adding top-of-file metadata? #182

ndw opened this issue Jan 9, 2020 · 4 comments

Comments

@ndw
Copy link
Contributor

@ndw ndw commented Jan 9, 2020

I've been creating daily journals for a while now, but in practice, I create a summary for every week. On the one hand, that's a good opportunity to synthesize the work of the week. On the other hand, I wouldn't have to cut and paste quite so much if I just kept a weekly journal.

So I'm thinking of switching to weekly.

But if I did that, I think I'd want to have a preamble:

#+TITLE: Some title, probably generated by a format-time-string or a function
#+OPTION: some option
#+HEADER: maybe other headers

* 6 January 2020
** 09:00 stuff I did
** 12:00 more stuff I did
* 7 January 2020
** 07:30 yet more stuff
...

On a casual inspection of the code, it didn't seem like this was configurable today. It's also not entirely clear if the extra headers would introduce any problems. I don't think they would, but...

Is this something you think could be made to work?

@bastibe

This comment has been minimized.

Copy link
Owner

@bastibe bastibe commented Jan 10, 2020

Excellent idea!

One would have to change org-journal-new-entry to check if the file is empty, and insert the contents of a new custom variable in that case.

Would you like to try implementing it yourself?

@cslux

This comment has been minimized.

Copy link
Collaborator

@cslux cslux commented Jan 10, 2020

Hmm. Actually, this can already be done with org-journal-data-format, but the name of the variable is a bit misleading.

(defun org-journal-date-format-func (time)
      "Custom function to insert journal date header,
  and some custom text on a newly created journal file."
      (concat (when (= (buffer-size) 0)
                (concat
                 (format-time-string
                  (pcase org-journal-file-type
                    (`daily "#+TITLE: Daily Journal, %A, %x")
                    (`weekly "#+TITLE: Weekly Journal No. %V, %Y")
                    (`monthly "#+TITLE: %B Journal, %Y")
                    (`yearly "#+TITLE: %Y Journal")))
                 "\n"))
              org-journal-date-prefix
              (format-time-string "%A, %x" time)))

(setq org-journal-date-format #'org-journal-date-format-func)

In your case.

(defun ndw/org-journal-monday (&optional time)
  "Return the TIME cast back to the previous Monday.
If TIME isn’t specified, the (current-time) is assumed.
If today is Monday, return today."
  (let* ((now    (if time time (current-time)))
         (dow    (string-to-number (format-time-string "%u" now)))
         (delta  (if (= dow 1)
                     0
                   (* (- dow 1) (* 24 3600)))))
    (seconds-to-time (- (time-to-seconds now) delta))))

(setq org-journal-date-format
      (lambda ()
        (concat (when (= (buffer-size) 0)
                  (let ((monday (ndw/org-journal-monday)))
                    (insert "#+TITLE: ")
                    (insert (format-time-string org-journal-date-format monday))
                    (insert "\n#+STARTUP: showeverything\n#+FILETAGS: :Journal:\n\n")))
                org-journal-date-prefix
                (format-time-string "%A, %x" time))))
@cslux

This comment has been minimized.

Copy link
Collaborator

@cslux cslux commented Jan 11, 2020

@bastibe Separating the file header from the org-journal-date-format is a good idea. We had this discussion already once. This change makes it clear what variable does what.

@cslux cslux closed this in 0f383d0 Jan 11, 2020
@bastibe

This comment has been minimized.

Copy link
Owner

@bastibe bastibe commented Jan 13, 2020

Thank you very much @ndw for your contribution, and @cslux for integrating it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.