I’ve now migrated over to v2 of Org-roam. To do this, I needed to follow a number of steps.
- Make sure that
gcc
is in my path (follow the thread here). - Add new spacemacs leader keys and capture templates (below).
Similar to my org setup, we’d like some specific org-roam capture templates. For example, I’m going to have common tags, such as person, division, process, code. I’d like to have those pre-populated wherever possible. The following will create such capture templates.
(setq
;; Define custom org-roam capture templates
org-roam-capture-templates
'(
("p" "Permanent Note" plain "%?"
:if-new (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
:unnarrowed t
)
("i" "Ideas and Somedays" plain "%?"
:if-new (file+head "ideas/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
:unnarrowed t
)
("l" "Literature Note" plain "%?"
:if-new (file+head "literature/%<%Y%m%d%H%M%S>-${citar-citekey}.org" "#+title: ${note-title}. ${citar-citekey} (${citar-date}).\n#+created: %U\n\n")
:unnarrowed t
)
("m" "Meeting Note" plain "%?"
:if-new (file+head "meetings/%<%Y%m%d%H%M%S>-${slug}.org" "
#+ROAM_TAGS: %^G
#+title: ${title}
Date: %^{Meeting date}u
Time-stamp: <>
Attendees:
* Notes Prior
* Notes During
")
:unnarrowed t
)
)
)
(setq
;; Define custom org-roam capture templates
org-roam-capture-templates
'(
("p" "person" plain (function org-roam--capture-get-point)
"%?"
:file-name "%<%Y%m%d%H%M%S>-${slug}"
:head "#+title: ${title}
#+roam_tags: person\n"
:unnarrowed t)
("c" "code" plain (function org-roam--capture-get-point)
"%?"
:file-name "%<%Y%m%d%H%M%S>-${slug}"
:head "#+title: ${title}
#+roam_tags: code\n"
:unnarrowed t)
("P" "process" plain (function org-roam--capture-get-point)
"%?"
:file-name "%<%Y%m%d%H%M%S>-${slug}"
:head "#+title: ${title}
#+roam_tags: process\n"
:unnarrowed t)
)
)
Org-roam needs to be ‘started’ with v2. So we call the setup function to get it going:
;; start org roam
;; (org-roam-setup)
To make it a little easier to search, use ripgrep.
(defun sprazza/org-roam-search ()
"Search in the org-roam directory with `rg'."
(interactive)
(spacemacs/compleseus-search t org-roam-directory))
(progn
(spacemacs/set-leader-keys
"aors" 'sprazza/org-roam-search
)
(spacemacs/set-leader-keys-for-major-mode 'org-mode
"rs" 'sprazza/org-roam-search
)
)
These helpers come/are adapted from this link.
;; Make sure only to do these after org-roam is loaded
(with-eval-after-load 'org-roam
(cl-defmethod org-roam-node-directories ((node org-roam-node))
(if-let ((dirs (file-name-directory (file-relative-name (org-roam-node-file node) org-roam-directory))))
(format "(%s)" (car (split-string dirs "/")))
""))
(cl-defmethod org-roam-node-backlinkscount ((node org-roam-node))
(let* ((count (caar (org-roam-db-query
[:select (funcall count source)
:from links
:where (= dest $s1)
:and (= type "id")]
(org-roam-node-id node)))))
(format "[%d]" count)))
(cl-defmethod org-roam-node-date ((node org-roam-node))
(format-time-string "%Y-%m-%d" (org-roam-node-file-mtime node))
)
;; (setq org-roam-node-display-template "${directories:10} ${tags:20} ${title:100} ${backlinkscount:6}")
(setq
org-roam-node-display-template "${title:*} ${directories:20} ${tags:40} ${backlinkscount:6} ${date:10}"
org-roam-db-autosync-mode t
)
)