protesilaos / denote

Simple notes for Emacs with an efficient file-naming scheme
https://protesilaos.com/emacs/denote
GNU General Public License v3.0
541 stars 55 forks source link

Suggestion for manual: find previous and next journal entries #450

Closed brabalan closed 1 month ago

brabalan commented 1 month ago

I coded these small functions to navigate my journal entries. I’m posting them here in case they might be useful additions to the manual.

(defvar my-denote-journal-earliest-date (encode-time 0 0 0 1 1 2000))
(defvar my-denote-journal-longest-future-gap (days-to-time 30))

(defun my-denote-journal-previous-entry ()
  (interactive)
  (let* ((file (buffer-file-name))
         (id (denote-retrieve-filename-identifier file))
         (date (date-to-time id))
         (one-day (days-to-time 1))
         (found nil))
    (while (and (not found) (time-less-p my-denote-journal-earliest-date date))
      (setq date (time-subtract date one-day))
      (setq found (denote-journal-extra-path-to-new-or-existing-entry date)))
    (when found (find-file found))))

(defun my-denote-journal-next-entry ()
  (interactive)
  (let* ((file (buffer-file-name))
         (id (denote-retrieve-filename-identifier file))
         (date (date-to-time id))
         (one-day (days-to-time 1))
         (limit (time-add date my-denote-journal-longest-future-gap))
         (found nil))
    (while (and (not found) (time-less-p date limit))
      (setq date (time-add date one-day))
      (setq found (denote-journal-extra-path-to-new-or-existing-entry date)))
    (when found (find-file found))))
protesilaos commented 1 month ago

From: Alan Schmitt @.***> Date: Fri, 27 Sep 2024 09:09:56 -0700

I coded these small functions to navigate my journal entries.

Thank you!

I’m posting them here in case they might be useful additions to the manual.

[... 30 lines elided]

Sure, we can add them there. I am curious about the workflow as well. Do you find the need to go to the next/previous entry while checking your journal? Is it, perhaps, because you are searching for something and so you "flip through the pages", as it were?

-- Protesilaos Stavrou https://protesilaos.com

brabalan commented 1 month ago

Do you find the need to go to the next/previous entry while checking your journal? Is it, perhaps, because you are searching for something and so you "flip through the pages", as it were?

Exactly! I was using dired for that before, but I realized it could be useful to do it from the journal entry.

I realize this is incompatible with #451 as the denote-journal-extra-path-to-new-or-existing-entry function now always creates an entry… So this should probably be dropped and I should go back using dired (and maybe play with dired-preview for this).

protesilaos commented 1 month ago

From: Alan Schmitt @.***> Date: Fri, 4 Oct 2024 02:56:21 -0700

Do you find the need to go to the next/previous entry while checking your journal? Is it, perhaps, because you are searching for something and so you "flip through the pages", as it were?

Exactly! I was using dired for that before, but I realized it could be useful to do it from the journal entry. I realize this is incompatible with #451 as the denote-journal-extra-path-to-new-or-existing-entry function now always creates an entry…

I see. Since Emacs does not have such a mechanism in general, we will impose limitations on ourselves if we have that, just as you noticed with the new 'denote-journal-extra-path-to-new-or-existing-entry'.

So this should probably be dropped and I should go back using dired (and maybe play with dired-preview for this).

Depending on how long the journal files are, this should be good enough. I normally use the 'denote-sort-dired' command to get the initial listing I am interested in. Then "flip through the pages" with the 'dired-preview-mode' enabled. But even without the preview, you can type 'o' in Dired (or 'M-x dired-find-file-other-window') to open the file in the other window, which is a good option as well.

-- Protesilaos Stavrou https://protesilaos.com

brabalan commented 1 month ago

Thank you for theses suggestions! I will play with this (and close this issue, it was an interesting learning exercise).