org-journal
org-journal copied to clipboard
Org journal doesn't cause Org-Roam data base syncs for some reason
Describe the bug I have my org-journal inside a sub-directory in org-roam. I use dailies for this. When I create a new org-journal file the org-roam-db-sync does not occur. Even after saving the file.
I have a potential fix below but it is kind of a hack.
To Reproduce
- Have org-journal directory inside an org-roam directory.
- Create a new org-journal. Save the file.
- Try to find the file with org-roam-node-find. It won't be there.
- Manually fun org-roam-db-sync, now you can repeat step 3. This should be automatically synced when the file is saved, but it's not.
Expected behavior When I save the org file inside the org-roam directory it should trigger the default behavior of my automatic org-roam-db-sync.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: Archlinux and Ubuntu (Tested on 2 separate machines)
- Emacs Version 27.1
Your Emacs Configuration
(add-hook 'org-journal-after-header-create-hook 'org-create-new-id-journal) (defun org-create-new-id-journal () (goto-char (point-min)) (org-id-get-create) (save-buffer) (org-roam-db-sync) (goto-char (point-max)))
Side note: The point min/max and org-id-get-create is used to make this a "Roam" file by adding an org-ID at the top of the file. It's kind of a hack, but it has worked up to this point. For this discussion I recently added the (save-buffer) and (org-roam-db-sync) to force the org-roam-db-sync to occur. This should automatically happen though when I save the file and it never does. I either have to manually run org-roam-db-sync, or add this hook.
Thank you for reporting your issue. I've run into a similar issue with org-roam. An alternative workaround is to create new journal files through roam. It's tantalizing how close the roam-dailies are to org-journal, yet they are not quite compatible.
Would you like to contribute a pull request that optionally hooks org-journal into org-roam dailies properly?
Thank you for reporting your issue. I've run into a similar issue with org-roam. An alternative workaround is to create new journal files through roam. It's tantalizing how close the roam-dailies are to org-journal, yet they are not quite compatible. Do you have any recommendations for that?
At the moment I use both org-roam "journals" and the org-journal for both of their sets of functionality, and just point them to the dame directory/files.
I started a discussion on the Vulpea discussion pages as that is where I initially found the problem. @d12frosted found some interesting things he reported here https://github.com/d12frosted/vulpea/discussions/133#discussioncomment-2115889. If this gives you any immediate ideas @bastibe for fixes let me know.
What d12frosted said:
The only hiccup that I faced - after-save-hook
and before-save-hook
are messed when org-journal
creates a new entry. They are fixed by re-visiting file though (e.g. save buffer, kill buffer, find file again). And this is why synchronization doesn't work.
So TL;DR - the problem is with messed up hooks. Trying to patch them by manually saving file, updating db is not going to lead you anywhere. You are fixing symptoms instead of the real issue.
Attempt to debug
I tried to debug it a little bit, but could not understand at what point it becomes corrupted. For example, I see that org-roam-db-autosync--setup-file-h
is being called and that it modifies after-save-hook from (1) to (2) by appending org-roam-db-autosync--try-update-on-save-h
:
(1): (vino-db-update-file flycheck-handle-save diff-hl-update org-journal-after-save-hook t ws-butler-after-save) (2): (org-roam-db-autosync--try-update-on-save-h vino-db-update-file flycheck-handle-save diff-hl-update org-journal-after-save-hook t ws-butler-after-save)
But then somehow after-save-hook
gets the following value (e.g. org-roam-db-autosync--try-update-on-save-h
and vino-db-update-file
are dropped):
(flycheck-handle-save diff-hl-update org-journal-after-save-hook t ws-butler-after-save)
Workaround
Obviously, you can restore these hooks in org-journal-after-entry-create-hook
:
(add-hook 'org-journal-after-entry-create-hook #'org-roam-db-autosync--setup-file-h)
(add-hook 'org-journal-after-entry-create-hook #'org-journal-restore-hooks)
(defun org-journal-restore-hooks ()
(add-hook 'find-file-hook #'vulpea-project-update-tag)
(add-hook 'before-save-hook #'vulpea-project-update-tag))
(Note the vulpea-project-uppdate-tag
is for a different feature independent of this issue.
But overall, it's a bad workaround, because it fixes only stuff that I noticed to be broken. Other things might be affected by this 'corruption'.
What a possible fix looks like
(add-hook 'org-journal-after-header-create-hook #'org-id-get-create)
(add-hook 'org-journal-after-entry-create-hook #'org-roam-db-autosync--setup-file-h)
(add-hook 'org-journal-after-entry-create-hook #'org-journal-restore-hooks)
(defun org-journal-restore-hooks ()
(add-hook 'find-file-hook #'vulpea-project-update-tag)
(add-hook 'before-save-hook #'vulpea-project-update-tag))
(Note the vulpea-project-uppdate-tag
is for a different feature independent of this issue.
And then once you save the buffer, everything should be synced.
For full details of what he said please see the link https://github.com/d12frosted/vulpea/discussions/133#discussioncomment-2115889.
If this turns out to work reliably, I'd be grateful for a pull request that documents it in the readme.
@bastibe while it works, it's just a lousy workaround. First of all, it doesn't cover full value of those hooks, so users have to figure that out. And secondly, we don't know which hooks are affected. I found 3 - find-file-hook
, before-save-hook
and after-save-hook
. It's tricky. Though the following lines should be kind of OK for most of the users of org-journal
and org-roam
combination, because it restores automatic db sync. Ideally users should check if auto sync mode is enabled, but that's prose.
(add-hook 'org-journal-after-header-create-hook #'org-id-get-create)
(add-hook 'org-journal-after-entry-create-hook #'org-roam-db-autosync--setup-file-h)
Even though I don't use org-journal
nowadays (as don't do journaling anymore), I am still curious why these hooks are corrupted.
not perfectly sure, but I think the org-journal files need the IDs?
org-journal does not require IDs. It needs the date tags for weekly and monthly journals (though not dailies), but nothing else.