TransWikia.com

org-journal sort entries by date at insert time

Emacs Asked by user57623 on November 27, 2020

I want to switch from daily files to monthly (or even yearly). The problem I’m facing is: org-journal-new-entry and org-journal-new-scheduled-entry simply append at the bottom of a file. This can result in unsorted days – can this be sorted?.

(extreme) example:
config

(use-package org-journal
  :ensure t
  :defer t
  :bind
  ("C-c n j" . org-journal-new-entry)
  ("C-c n s" . org-journal-new-scheduled-entry)
  :custom
  (org-journal-file-format "%Y-%m.org")
  (org-journal-enable-agenda-integration t)
  :config
  (setq org-journal-dir org-journal-directory)
  (setq org-journal-file-type 'monthly)
  (setq org-journal-date-format " %d/%m/%y - %A")
  (setq org-journal-file-header "#+title: %B Journal")

Then:

  1. Add new scheduled in the future
  2. Add new entry today
  3. Add new entry in the past

Result:

#+title: October Journal
*  08/10/20 - Thursday
  :PROPERTIES:
  :CREATED:  20201008
  :END:
** First: New Scheduled
<2020-10-08>
*  06/10/20 - Tuesday
  :PROPERTIES:
  :CREATED:  20201006
  :END:
** 12:46 Second: new Entry
*  05/10/20 - Monday
  :PROPERTIES:
  :CREATED:  20201005
  :END:
** Third: new scheduled in past
<2020-10-05>

my goal
would be to have entries in the file correctly sorted from top to bottom (basically the oppositve of my result)

One Answer

I'm not sure how this is handled in org-journal, by base orgmode provides datetree as an option for capture templates. These are created and inserted in sorted order. This allows you to define an appropriate capture element to add entries to your journal.org file.

From the org manual, (org) Template elements:

 ‘(file+olp+datetree "filename" [ "Level 1 heading" ...])’
      This target(1) creates a heading in a date tree(2) for today’s
      date.  If the optional outline path is given, the tree will be
      built under the node it is pointing to, instead of at top
      level.  Check out the ‘:time-prompt’ and ‘:tree-type’
      properties below for additional options.


(2) A date tree is an outline structure with years on the highest
level, months or ISO weeks as sublevels and then dates on the lowest
level.  Tags are allowed in the tree structure.

Answered by Tyler on November 27, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP