diff --git a/modules/lang/org/contrib/roam2.el b/modules/lang/org/contrib/roam2.el index c1ea3a3a8..b741693b1 100644 --- a/modules/lang/org/contrib/roam2.el +++ b/modules/lang/org/contrib/roam2.el @@ -24,7 +24,7 @@ of org-mode to properly utilize ID links.") :init (doom-load-packages-incrementally - '(ansi-color dash f rx seq magit-section)) + '(ansi-color dash f rx seq magit-section emacsql emacsql-sqlite)) (map! :after org :map org-mode-map @@ -65,17 +65,41 @@ of org-mode to properly utilize ID links.") ;; 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 (orig-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-location)) + (apply orig-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-init-db-a (&rest _) - "Initialize org-roam database when it's first time queried to." + (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 - (advice-remove 'org-roam-db-query #'+org-roam-init-db-a) (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))) (setq org-roam-directory diff --git a/modules/lang/org/doctor.el b/modules/lang/org/doctor.el index d8a5261f8..d96e1c721 100644 --- a/modules/lang/org/doctor.el +++ b/modules/lang/org/doctor.el @@ -5,10 +5,11 @@ (unless (executable-find "gnuplot") (warn! "Couldn't find gnuplot. org-plot/gnuplot will not work"))) +(when (featurep! +roam) + (unless (executable-find "sqlite3") + (warn! "Couldn't find the sqlite3 executable. org-roam will not work."))) (when (or (featurep! +roam) (featurep! +roam2)) - (unless (executable-find "sqlite3") - (warn! "Couldn't find the sqlite3 executable. org-roam will not work.")) (unless (executable-find "dot") (warn! "Couldn't find the dot executable (from graphviz). org-roam will not be able to generate graph visualizations.")))