diff --git a/Hitchhiker's-Rough-Guide-to-Org-roam-V2.org b/Hitchhiker's-Rough-Guide-to-Org-roam-V2.org index 1b2aac3..131dcdc 100644 --- a/Hitchhiker's-Rough-Guide-to-Org-roam-V2.org +++ b/Hitchhiker's-Rough-Guide-to-Org-roam-V2.org @@ -388,4 +388,34 @@ For example, to use dashes rather than underscores in your slugs: You should place this in your =init.el= somewhere that is evaluated after org-roam has been loaded. -For more discussion, see [[https://github.com/org-roam/org-roam/pull/1544][#1544]]. \ No newline at end of file +For more discussion, see [[https://github.com/org-roam/org-roam/pull/1544][#1544]].\ + +** Run =org-roam-db-sync= when Emacs is idle + +Refer to [#1939](https://github.com/org-roam/org-roam/issues/1939). + +You can turn off automatic db update when you save a buffer by turning off =org-roam-db-update-on-save=; e.g. when you have a large Org file and do not want the delay on save. + +In this case, you may like to set an idle-timer to automatically run =org-roam-db-sync= to update the db when Emacs is idle. +You can create your own global minor mode and toggle it on/off as you like (so that you can remove the timer). + +Adjust the interval to your liking. + +If you are Windows, you will see Error running timer ‘org-roam-db-sync’: (error "Selecting deleted buffer") every second time. That has been the way it is for Windows but works for every odd number of times. + +#+begin_src emacs-lisp +(defvar my/auto-org-roam-db-sync--timer nil) +(defvar my/auto-org-roam-db-sync--timer-interval 5) + +(define-minor-mode my/auto-org-roam-db-sync-mode + "Toggle automatic `org-roam-db-sync' when Emacs is idle. +Referece: `auto-save-visited-mode'" + :group 'org-roam + :global t + (when my/auto-org-roam-db-sync--timer (cancel-timer my/auto-org-roam-db-sync--timer)) + (setq my/auto-org-roam-db-sync--timer + (when my/auto-org-roam-db-sync-mode + (run-with-idle-timer + my/auto-org-roam-db-sync--timer-interval :repeat + #'org-roam-db-sync)))) +#+end_src