[emacs] Organize org-roam slipboxes under a common directory

This commit is contained in:
Correl Roush 2023-08-30 22:26:07 -04:00
parent 4eb17fb1ac
commit 5a6781214d

View file

@ -911,10 +911,6 @@ Powerful cross-linked note-taking.
https://orgroam.com https://orgroam.com
#+begin_src emacs-lisp
(setq org-roam-directory (file-truename (if (f-dir? "~/org-roam") "~/org-roam"
"~/org/roam")))
#+end_src
**** Capture templates **** Capture templates
#+begin_src emacs-lisp #+begin_src emacs-lisp
(setq org-roam-capture-templates (setq org-roam-capture-templates
@ -974,42 +970,41 @@ Makes for a much nicer note-taking experience.
(add-hook! 'org-mode-hook #'my/org-roam-writeroom) (add-hook! 'org-mode-hook #'my/org-roam-writeroom)
#+end_src #+end_src
**** Provide seamless switching between org-roam slipboxes **** Provide seamless switching between org-roam slipboxes
When we visit a buffer in a different slip box (different =org-roam-directory=) I keep multiple slipboxes under a common directory, some of which may or may not
than we were visiting previously, ensure the cache is updated. be available on different machines (e.g. a work slipbox vs a personal one). This
gives me an interface for easily switching between them and resyncing their
databases. The databases are kept out of the slipbox directories themselves to
keep them tidy.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defvar my/org-roam-directory-cache (list (defvar my/org-roam-slipbox-directory (expand-file-name "~/roam"))
(cons (expand-file-name org-roam-directory)
(expand-file-name org-roam-db-location))))
(after! savehist (defun my/org-roam-slipbox-node-find ()
(add-to-list 'savehist-additional-variables
'my/org-roam-directory-cache))
(defun my/org-roam-directory--lookup (path)
(alist-get path my/org-roam-directory-cache nil nil #'s-equals?))
(defun my/org-roam-directory--update ()
(setq my/org-roam-directory-cache
(cons (cons org-roam-directory org-roam-db-location)
(seq-filter
(lambda (x) (not (s-equals? org-roam-directory (car x))))
my/org-roam-directory-cache))))
(add-hook! 'org-roam-buffer-prepare-hook #'my/org-roam-directory--update)
(defun my/org-roam-find-in-directory ()
(interactive) (interactive)
(let* ((org-roam-directory (completing-read "Roam Directory" (let* ((slipbox (completing-read "Slipbox" (-map #'f-filename (f-directories my/org-roam-slipbox-directory))))
(mapcar #'car my/org-roam-directory-cache))) (org-roam-directory (f-join my/org-roam-slipbox-directory slipbox))
(org-roam-db-location (my/org-roam-directory--lookup (org-roam-db-location (f-join my/org-roam-slipbox-directory (s-concat slipbox ".db"))))
org-roam-directory))) (unless (f-exists? org-roam-db-location)
(org-roam-find-file))) (org-roam-db-sync))
(org-roam-node-find)))
(defun my/org-roam-slipbox-db-sync ()
(interactive)
(-each (-map #'f-filename (f-directories my/org-roam-slipbox-directory))
(lambda (slipbox)
(let ((org-roam-directory (f-join my/org-roam-slipbox-directory slipbox))
(org-roam-db-location (f-join my/org-roam-slipbox-directory (s-concat slipbox ".db"))))
(org-roam-db-sync)))))
(map! :leader (map! :leader
(:prefix-map ("n" . "notes") (:prefix-map ("n" . "notes")
(:prefix ("r" . "roam") (:prefix ("r" . "roam")
:desc "Find file in slipbox" "F" #'my/org-roam-find-in-directory))) :desc "Find file in slipbox" "F" #'my/org-roam-slipbox-node-find)))
(map! :leader
(:prefix-map ("n" . "notes")
(:prefix ("r" . "roam")
:desc "Synchronize all slipbox databases" "S" #'my/org-roam-slipbox-db-sync)))
#+end_src #+end_src
When setting up additional slipboxes, be sure to set both =org-roam-directory= When setting up additional slipboxes, be sure to set both =org-roam-directory=