kris
October 26, 2021, 8:18pm
7
For me the most important feature of org-journal is the second one you mentioned.
And I still use org-roam-dailies for its file can be included in org-roam database and shown in org-roam buffer.
So, I put my journal files into a directory in my org-roam-directory
to get both mode’s advantage.
A compatibility problem exists though, and I managed to solve it.
opened 09:47PM - 06 Sep 21 UTC
### Description
When using org-journal-mode in a org-roam-dailies file (more pr… ecisely, a file in `org-roam-directory`), after running `save-buffer`, org-journal-mode is turned off and evil shortcuts do not work.
Used edebug to find that this is caused by macro `org-roam-with-file`, if current buffer is not equal to org-mode (like org-journal-mode), the macro will `delay-mode-hooks` and run `(org-mode)`. Because of delaying of hooks, org-journal-mode is not activated, neither do evil key-bindings. [See related code](https://github.com/org-roam/org-roam/blob/1795039ab93ef19611dbb3fca21c4211c4e655a9/org-roam-utils.el#L78-L83).
#### Steps to Reproduce
1. set `org-journal-dir` and `org-roam-dailies-directory` to be the same and the latter should be in `org-roam-directory`, of course. (I think just make `org-journal-dir` to be inside of `org-roam-directory` should be enough to reproduce, since the problem is caused by `org-roam-with-file`.)
2. open a journal by `org-journal-new-entry`.
3. Make the buffer modified and save-buffer.
4. You can see org-journal-mode is turned off and evil shortcuts not working.
#### Backtrace
The following backtrace is generated by inserting `(edebug)` after [this line](https://github.com/org-roam/org-roam/blob/1795039ab93ef19611dbb3fca21c4211c4e655a9/org-roam-utils.el#L83).
```
Debugger entered: nil
edebug()
(save-current-buffer (set-buffer buf) (if (equal major-mode 'org-mode) nil (progn (make-local-variable 'delay-mode-hooks) (let ((delay-mode-hooks t)) (let ((org-inhibit-startup t) (org-agenda-files nil)) (org-mode))))) (edebug) (setq res (progn (let ((emacsql--connection (org-roam-db)) (emacsql--completed nil) (emacsql--transaction-level (1+ emacsql--transaction-level)) (emacsql--result)) (unwind-protect (while (not emacsql--completed) (condition-case nil (progn ... ...) (emacsql-locked ... ...))) (if (and (= 1 emacsql--transaction-level) (not emacsql--completed)) (progn (emacsql emacsql--connection ...)))) emacsql--result))) (if (and new-buf (not nil)) nil (save-buffer)))
(let* (new-buf (auto-mode-alist nil) (buf (or (and (not file-path) (current-buffer)) (find-buffer-visiting file-path) (progn (setq new-buf t) (find-file-noselect file-path)))) res) (save-current-buffer (set-buffer buf) (if (equal major-mode 'org-mode) nil (progn (make-local-variable 'delay-mode-hooks) (let ((delay-mode-hooks t)) (let ((org-inhibit-startup t) (org-agenda-files nil)) (org-mode))))) (edebug) (setq res (progn (let ((emacsql--connection (org-roam-db)) (emacsql--completed nil) (emacsql--transaction-level (1+ emacsql--transaction-level)) (emacsql--result)) (unwind-protect (while (not emacsql--completed) (condition-case nil ... ...)) (if (and ... ...) (progn ...))) emacsql--result))) (if (and new-buf (not nil)) nil (save-buffer))) (if (and new-buf (not nil)) (if (find-buffer-visiting file-path) (progn (kill-buffer (find-buffer-visiting file-path))))) res)
(if (string= content-hash db-hash) nil (let* (new-buf (auto-mode-alist nil) (buf (or (and (not file-path) (current-buffer)) (find-buffer-visiting file-path) (progn (setq new-buf t) (find-file-noselect file-path)))) res) (save-current-buffer (set-buffer buf) (if (equal major-mode 'org-mode) nil (progn (make-local-variable 'delay-mode-hooks) (let ((delay-mode-hooks t)) (let (... ...) (org-mode))))) (edebug) (setq res (progn (let ((emacsql--connection ...) (emacsql--completed nil) (emacsql--transaction-level ...) (emacsql--result)) (unwind-protect (while ... ...) (if ... ...)) emacsql--result))) (if (and new-buf (not nil)) nil (save-buffer))) (if (and new-buf (not nil)) (if (find-buffer-visiting file-path) (progn (kill-buffer (find-buffer-visiting file-path))))) res))
(let ((content-hash (org-roam-db--file-hash file-path)) (db-hash (car (car (org-roam-db-query [:select hash :from files :where (= file $s1)] file-path)))) info) (if (string= content-hash db-hash) nil (let* (new-buf (auto-mode-alist nil) (buf (or (and (not file-path) (current-buffer)) (find-buffer-visiting file-path) (progn (setq new-buf t) (find-file-noselect file-path)))) res) (save-current-buffer (set-buffer buf) (if (equal major-mode 'org-mode) nil (progn (make-local-variable 'delay-mode-hooks) (let (...) (let ... ...)))) (edebug) (setq res (progn (let (... ... ... ...) (unwind-protect ... ...) emacsql--result))) (if (and new-buf (not nil)) nil (save-buffer))) (if (and new-buf (not nil)) (if (find-buffer-visiting file-path) (progn (kill-buffer (find-buffer-visiting file-path))))) res)))
org-roam-db-update-file()
(progn (org-roam-db-update-file))
(if org-roam-db-update-on-save (progn (org-roam-db-update-file)))
org-roam-db-autosync--try-update-on-save-h()
funcall(org-roam-db-autosync--try-update-on-save-h)
(condition-case e (funcall hook) ((debug error) (signal 'doom-hook-error (list hook e))))
doom-run-hook(org-roam-db-autosync--try-update-on-save-h)
run-hook-wrapped(doom-run-hook org-roam-db-autosync--try-update-on-save-h)
(condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car (cdr e))) (symbol-name (car (cdr e))) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e)))))
(let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car ...)) (symbol-name (car ...)) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--)))
(while --dolist-tail-- (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp ...) (symbol-name ...) (car ...)) (car (cdr ...)))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--))))
(let ((--dolist-tail-- hooks)) (while --dolist-tail-- (let ((hook (car --dolist-tail--))) (condition-case e (run-hook-wrapped hook #'doom-run-hook) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if ... ... ...) (car ...))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
doom-run-hooks(after-save-hook)
apply(doom-run-hooks after-save-hook)
run-hooks(after-save-hook)
basic-save-buffer()
```
#### My solution
Change code [here](https://github.com/org-roam/org-roam/blob/1795039ab93ef19611dbb3fca21c4211c4e655a9/org-roam-utils.el#L78-L83) from `(equal major-mode 'org-mode)` to `(derived-mode-p 'org-mode)`:
```emacs-lisp
(with-current-buffer buf
(unless (derived-mode-p 'org-mode)
(delay-mode-hooks
(let ((org-inhibit-startup t)
(org-agenda-files nil))
(org-mode))))
```
then, this block of code will not run in org-journal-mode, and the issue is avoided.
### Environment
- Emacs: GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.29, cairo version 1.17.4)
of 2021-06-12
- Framework: Doom
- Org: Org mode version 9.5 (9.5-b83ae59 @ /home/user/doom-emacs/.local/straight/build-28.0.50/org/)
- Org-roam: v2.1.0-16-g1795039-dirty
- Org-roam commit: https://github.com/org-roam/org-roam/commit/1795039ab