I wanted to verify with the community if that is the expected behaviour of org-roam.
Each time I launch Emacs I need to run M-x org-roam-db-sync in order for Buffer/Nodes to appear on org-roam-node-find
Is that how it should work? Or maybe I am missing some configuration option. I am using Doom mode and this is my Roam section:
;; ORG-ROAM
(use-package! org-roam
:init
;; Override a couple of keybinding to have quicker access to things
(map! :leader
:prefix "n"
:desc "org-roam-node-find" "f" #'org-roam-node-find ;originnaly mapped to find-file-in-notes
:desc "org-roam-node-insert" "i" #'org-roam-node-insert ;; originally not mapped
)
:config
(org-roam-db-autosync-enable)
(setq org-roam-directory org-directory
org-roam-graph-exclude-matcher '("private" "repeaters" "dailies")
; org-id-link-to-org-use-id t
;org-roam-index-file "index.org"
org-roam-node-display-template "${doom-hierarchy:*} ${tags:45}"
)
(setq org-roam-capture-templates '(
("d" "default" plain "%?"
:target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
"#+title: ${title}\n")
:unnarrowed t)
("c" "concept" plain "%?"
:target (file+head "concepts/${slug}.org"
"#+title: ${title}\n")
:unnarrowed t)
("r" "ref" plain "%?" :target
(file+head "references/${slug}.org"
"#+title: ${title}")
:unnarrowed t)))
)
No, you should not have to manually do it every launch.
org-roam-db-autosync-enable does it for you.
How do you load org-roam? In your config excerpt above, you have (use-package! org-roam but what requires/loads org-roam? Does map! macro (I believe it’s Doom-specific) set autoloading so that when you call either “f” or “i”, Doom requires/loads org-roam? If that’s the intention, it does not seem to be working that way.
If I understand use-package and use-package! correctly, as org-roam-db-autosync-enable is in the :config part, it won’t be called until you require/load org-roam.
Hi @nobiot
Thanks a lot for your reply! somehow got buried in my inbox.
I think doom loads it in a module here is the code:
use-package! org-roam
:hook (org-load . +org-init-roam-h)
:preface
;; Set this to nil so we can later detect if the user has set custom values
;; for these variables. If not, default values will be set in the :config
;; section.
(defvar org-roam-directory nil)
(defvar org-roam-db-location nil)
:init
(doom-load-packages-incrementally
'(ansi-color dash f rx seq magit-section emacsql emacsql-sqlite))
;; Don't display warning message dedicated for v1 users. Need to be set early.
(setq org-roam-v2-ack t)
(defadvice! +org-roam-suppress-sqlite-build-a (fn &rest args)
"Suppress automatic building of sqlite3 binary when loading `org-roam'.
This is a blocking operation that can take a while to complete
and better be deferred when there will be an actual demand for
the database. See `+org-init-roam-h' for the launch process."
:around #'emacsql-sqlite-ensure-binary
(if (not (boundp 'org-roam-db-version))
(apply fn args)
(advice-remove #'emacsql-sqlite-ensure-binary #'+org-roam-suppress-sqlite-build-a)
nil))
:config
(defun +org-init-roam-h ()
"Setup `org-roam' but don't immediately initialize its database.
Instead, initialize it when it will be actually needed."
(letf! ((#'org-roam-db-sync #'ignore))
(org-roam-setup))
(defadvice! +org-roam-try-init-db-a (&rest _)
"Try to initialize org-roam database at the last possible safe moment.
In case of failure, fail gracefully."
:before #'org-roam-db-query
(message "Initializing org-roam database...")
(let ((run-cleanup-p t))
(unwind-protect
;; Try to build the binary if it doesn't exist. In case of failure
;; this will error, run the cleanup and exit, and in case of success
;; this will return nil and sync the database.
(setq run-cleanup-p (emacsql-sqlite-ensure-binary))
(when run-cleanup-p
(setq org-roam--sqlite-available-p nil)
(org-roam-teardown)
(message (concat "EmacSQL failied to build SQLite binary for org-roam; "
"see *Compile-Log* buffer for details.\n"
"To try reinitialize org-roam, run \"M-x org-roam-setup\"")))))
(advice-remove 'org-roam-db-query #'+org-roam-try-init-db-a)
(org-roam-db-sync)))
I think the interesting part is the +org-init-roam-h that I believe tries to make roam runs on the last moment just when org-roam-db-query is called but it does not work (maybe due to my config) - my elips is very basic though!
I tried a couple of things but it does not work. Somehow +org-init-roam-h never gets called
I get this might be more of doom issue than a roam issue
Doom pulls in the bleeding-edge development version of Org. Do you have org-load-hook? (It should be a variable). It might not be present or not called in the Org version you have.
By the way… The “module” you refer to: Do you use the +roam2 switch to tell Doom you want to use it? Then your custom settings might be redundant?
I do have +roam2 selected in packages.el and my config is there to override some defaults I do not like… and I also put it there becase well the sync thingy was not working and to add some capture temnplates.
I think I found the issue, I think the :init section was causing the problem! if I moved the map! declarations to :config it works!!
So now when I call org-roam-node-find for the first time the index is created!!
I take this has to be rebuilt once each time I open Emacs.