multiple org-roam notebases
Table of Contents
multiple org-roam notebases could be implemented in 2 seperate measures:
.dir-locals.el
to overload variables in files(or buffer that opens the files) in specific directory- elisp function with
let*
Those 2 works seperately and are both nice to have.
1. Objective: overload org-roam-directory
and org-roam-db-location
These 2 are used to refer to the nodebases
org-roam-directory
is the root directory of the notebase, which would be scanned whenorg-roam-db-sync
is called and create asqlite
db for searchorg-roam-db-location
points to the db used to search your notes. If you manually setorg-roam-directory
to another dir, say from~/main/
to~/project/robotics/
, and did not runorg-roam-db-sync
, yourorg-roam-node-find
would return nodes from~/main/
but not~/project/robotics/
2. .dir-locals.el
Place a .dir-locals.el
file with the following content to the root of the project notebase(in here ~/project/robotics/
):
((nil . ((org-roam-directory . "~/project/robotics/") ;;don't forget the trailing "/", otherwise ;;org-roam-node-find would not find anything (org-roam-db-location . "~/project/robotics/org-roam.db") (org-roam-node-display-template . "${title} ${doom-type:12} ${doom-tags:42}") )))
- on
org-roam-node-display-template
I tend to use a large notes.org
file with headings and luhmann id structure to organize project notes, so titles get very long if use doom-hierarchy
if the id be 1b2a3
(displaying 1
, 1b
, 1b2
1b2a
and 1b2a3 whell encoder
)
- effect
- after setting up this file, each time you open a file under this directory, emacs would prompt you to load file-specific variables on our 2 objectives, and
org-roam-node-find/insert
would default to the directory, which makes sense: you’d want to visit zettels in the same zettelkasten.
3. overloading find
and insert
The most frequently used zettelkasten primitives.
Here I used a messy wrapper function, whose job may be better done with macro.
(setq org-roam-dirs '(("main" (org-roam-directory . "~/main/") (org-roam-db-location . "~/emacs-distros/doomemacs/.local/cache/org-roam.db") ) ("comp329" (org-roam-directory . "~/projects/robotics/" ) (org-roam-db-location . "~/projects/robotics/org-roam.db"))) ) ;; wrap org-roam-node-find and org-roam-node-insert (defun hermanhelf-org-roam-multidir (func arg ) (interactive "p") (cond ;; no prefix ((eq arg 1) (funcall func)) ;; C-u ((eq arg 4) (let* ((profile (completing-read "org-roam note base" (mapcar 'car org-roam-dirs))) (profile (car (-filter (lambda (item) (equal (car item) profile)) org-roam-dirs))) (org-roam-directory (cdr (second profile))) ;; (org-roam-db-location (cdr (third profile))) ) (funcall func) ;; org-roam-db-location ) ) ) ) (defun hermanhelf-org-roam-multidir-node-find (arg) (interactive "p") (hermanhelf-org-roam-multidir 'org-roam-node-find arg) ) (defun hermanhelf-org-roam-multidir-node-insert (arg) (interactive "p") (hermanhelf-org-roam-multidir 'org-roam-node-insert arg) ) (map! :map doom-leader-notes-map "r f" #'hermanhelf-org-roam-multidir-node-find )
org-roam-dirs
- store a list of directory, db location together with a string label. The format is almost trivial with the example above
hermanhel-org-roam-multidir func arg
- is a wrapper function that calls func with a selected set of directory and db location when
C-u
prefix is pressed, and call it directly(which would conform to.dir-locals.el
or global setting) when no prefix is provided.
Backlinks
In the old days this is the main way to go: to have a zettelkasten for each project, and according to wikipedia. Nowadays software make a lifelong main zettelkasten not as enormous, space consuming and labour heavy as they used to be, but project zettelkasten is still good practice.
- setting up multiple org-roam notebases
org-roam
org-roam is a package implementing behaviours of a Zettelkasten note system into a specified org-roam-directory
.