Skip to content

Latest commit

 

History

History
151 lines (123 loc) · 5.07 KB

org-roam-setup.org

File metadata and controls

151 lines (123 loc) · 5.07 KB

Org-roam setup

Introduction

I’ve now migrated over to v2 of Org-roam. To do this, I needed to follow a number of steps.

  1. Make sure that gcc is in my path (follow the thread here).
  2. Add new spacemacs leader keys and capture templates (below).

Capture templates

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.

Template definitions

(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
    )
   )
 )

Template definitions

(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)
   )
 )

Starting org-roam

Org-roam needs to be ‘started’ with v2. So we call the setup function to get it going:

;; start org roam
;; (org-roam-setup)

Searching through your notes

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
    )
  )

Helper Functions

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
   )
)