Hi Prot and friends,
I recently switched to denote from org-roam and so far am very happy.
A key part of my workflow with org-roam (and with Roam Research,
Obsidian, Logseq and other tools, some custom-made) was the daily
journal. I was very used to hitting a key combo and having the journal
pop up (the journal file, in the case of tools using vim or Emacs).
Following the documentation, it was easy to set up the daily journal in
denote, but I didn't want to create duplicate files, therefore I needed
some basic functions in my .emacs to do detect whether the journal file
for that day already existed, and if so, just to open that one instead
of creating a new file. The elisp below is what achieves that - I
thought someone might find it useful.
Please note - I am quite an experienced coder (Python, mainly, but also
other languages) but am new to Emacs Lisp! There is a bit of redundancy
and poor practice in here when it comes to the regexes, but the gist of
it should be clear enough. I'm sure there a million better ways to do
this!
I'm also new to sourcehut (which is great, by the way!), so I may take a
bit of time to get things looking ok...
(defun mrl/is-todays-journal? (f)
"If f is today's journal in denote, f is returned"
(let* ((month-regexp (car (calendar-current-date)))
(day-regexp (nth 1 (calendar-current-date)))
(year-regexp (nth 2 (calendar-current-date)))
(journal-files (directory-files (denote-directory) nil "_journal"))
(day-match? (string-match-p (concat "^......" (format "%02d" day-regexp)) f))
(year-match? (string-match-p (concat "^" (number-to-string year-regexp)) f))
(month-match? (string-match-p (concat (number-to-string month-regexp) "..T") f)))
(when (and day-match? year-match? month-match?)
f)))
(defun mrl/denote-journal ()
"Create an entry tagged 'journal' with the date as its title."
(interactive)
(let* ((journal-dir (concat (denote-directory) "journals"))
(today-journal
(car (-non-nil
(mapcar #'mrl/is-todays-journal? (directory-files journal-dir nil "_journal"))))))
(if today-journal
(find-file (concat journal-dir "/" today-journal))
(denote
(format-time-string "%A %e %B %Y")
'("journal") nil journal-dir)))))
Thanks.
--
Matthew
Hello,
On 2022-12-14 15:01, matt@matthewlemon.com writes:
> A key part of my workflow with org-roam (and with Roam Research,> Obsidian, Logseq and other tools, some custom-made) was the daily> journal. I was very used to hitting a key combo and having the journal> pop up (the journal file, in the case of tools using vim or Emacs).>> Following the documentation, it was easy to set up the daily journal in> denote, but I didn't want to create duplicate files, therefore I needed> some basic functions in my .emacs to do detect whether the journal file> for that day already existed, and if so, just to open that one instead> of creating a new file. The elisp below is what achieves that - I> thought someone might find it useful.
Thanks a lot for sharing, this is very nice.
I have a similar workflow, but sometimes I need to open a journal entry
for another day (to copy down something that was written on paper). Here
is my function to do that:
(defun my-denote-journal-open ()
(interactive)
(let* ((date (org-read-date))
(time (org-time-string-to-time date))
(title (format-time-string "%A %d %B %Y" time))
(initial (denote-sluggify title))
(target (read-file-name "Select note: " (denote-directory) nil nil initial
(lambda (f)
(or (denote-file-has-identifier-p f)
(file-directory-p f))))))
(if (file-exists-p target)
(find-file target)
(denote title '("journal") 'org nil date))))
It has some extra steps: one has to choose the date, and one has to
confirm the file when it exists. In most cases, it’s just a question of
hitting Enter twice.
Best,
Alan
> From: matt@matthewlemon.com> Date: Wed, 14 Dec 2022 15:01:11 +0000>> Hi Prot and friends,
Hello Matthew!
> I recently switched to denote from org-roam and so far am very happy.>> A key part of my workflow with org-roam (and with Roam Research,> Obsidian, Logseq and other tools, some custom-made) was the daily> journal. I was very used to hitting a key combo and having the journal> pop up (the journal file, in the case of tools using vim or Emacs).>> Following the documentation, it was easy to set up the daily journal in> denote, but I didn't want to create duplicate files, therefore I needed> some basic functions in my .emacs to do detect whether the journal file> for that day already existed, and if so, just to open that one instead> of creating a new file. The elisp below is what achieves that - I> thought someone might find it useful.
Yes, this is useful and thank you for taking the time to share it here.
We can expand the manual accordingly. In general, I think those
practical tweaks are helpful for users. Plus, they are consistent with
the hackability of Emacs and Denote.
On Friday I plan to prepare Denote's version 1.2.0. If you want to
contribute your custom code to the manual, we can do it right after.
This will give us plenty of time to test the code and, perhaps, think of
ways to expand on it.
> Please note - I am quite an experienced coder (Python, mainly, but also> other languages) but am new to Emacs Lisp! There is a bit of redundancy> and poor practice in here when it comes to the regexes, but the gist of> it should be clear enough. I'm sure there a million better ways to do> this!
It loooks good to me. A simple optimisation is to avoid calling the
same function multiple times to fetch data. Here is the gist:
(defun mrl/is-todays-journal? (f)
"If f is today's journal in denote, f is returned"
(let* ((date (calendar-current-date))
(month-regexp (car date))
(day-regexp (nth 1 date))
(year-regexp (nth 2 date))
...)))
All the best,
Prot
--
Protesilaos Stavrou
https://protesilaos.com
> From: Alan Schmitt <alan.schmitt@petitepomme.net>> Date: Wed, 14 Dec 2022 16:44:06 +0100>> Hello,
Hello Alan,
> On 2022-12-14 15:01, matt@matthewlemon.com writes:>>> A key part of my workflow with org-roam (and with Roam Research,>> Obsidian, Logseq and other tools, some custom-made) was the daily>> journal. I was very used to hitting a key combo and having the journal>> pop up (the journal file, in the case of tools using vim or Emacs).>>>> Following the documentation, it was easy to set up the daily journal in>> denote, but I didn't want to create duplicate files, therefore I needed>> some basic functions in my .emacs to do detect whether the journal file>> for that day already existed, and if so, just to open that one instead>> of creating a new file. The elisp below is what achieves that - I>> thought someone might find it useful.>> Thanks a lot for sharing, this is very nice.>> I have a similar workflow, but sometimes I need to open a journal entry> for another day (to copy down something that was written on paper). Here> is my function to do that:>> (defun my-denote-journal-open ()> (interactive)> (let* ((date (org-read-date))> (time (org-time-string-to-time date))> (title (format-time-string "%A %d %B %Y" time))> (initial (denote-sluggify title))> (target (read-file-name "Select note: " (denote-directory) nil nil initial> (lambda (f)> (or (denote-file-has-identifier-p f)> (file-directory-p f))))))> (if (file-exists-p target)> (find-file target)> (denote title '("journal") 'org nil date))))>> It has some extra steps: one has to choose the date, and one has to> confirm the file when it exists. In most cases, it’s just a question of> hitting Enter twice.
To repeat what I just wrote to Matthew in the other message to this
thread:
Yes, this is useful and thank you for taking the time to share it here.
We can expand the manual accordingly. In general, I think those
practical tweaks are helpful for users. Plus, they are consistent with
the hackability of Emacs and Denote.
On Friday I plan to prepare Denote's version 1.2.0. If you want to
contribute your custom code to the manual, we can do it right after.
This will give us plenty of time to test the code and, perhaps, think of
ways to expand on it.
All the best,
Prot
--
Protesilaos Stavrou
https://protesilaos.com
--
Protesilaos Stavrou <info@protesilaos.com> writes:
> On Friday I plan to prepare Denote's version 1.2.0. If you want to> contribute your custom code to the manual, we can do it right after.> This will give us plenty of time to test the code and, perhaps, think of> ways to expand on it.
Happy to look at that - look forward to version 1.2.0.
> It loooks good to me. A simple optimisation is to avoid calling the> same function multiple times to fetch data. Here is the gist:>> (defun mrl/is-todays-journal? (f)> "If f is today's journal in denote, f is returned"> (let* ((date (calendar-current-date))> (month-regexp (car date))> (day-regexp (nth 1 date))> (year-regexp (nth 2 date))> ...)))
Of course - rather obvious and makes sense. Thank you.
PS Trying this from my new sourcehut email address - I have registered
an account. Not sure how confused the mailing list is going to be with
that, but I am also the same Matthew using matt@matthewlemon.com. Will
try to keep things consistent in future!
--
Matthew