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:

(use-package org-journal
  :ensure t
  :defer t
  ("C-c n j" . org-journal-new-entry)
  ("C-c n s" . org-journal-new-scheduled-entry)
  (org-journal-file-format "")
  (org-journal-enable-agenda-integration t)
  (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")


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


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

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 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 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP