How to use brackets to create org-roam nodes

Posted May 29, 2023

I’m giving org-roam a try, and the other day I came across this need: Can [[ ]​] be used to create a new node?. The answer, which is in the post itself, is to write roam: after the opening brackets, like this: [[roam:Hello World!]]. This way, if you try to open that link, org-roam will attempt to create it for you.

Since I would prefer to not have to add roam: manually, I added this following piece of code to my .emacs:

(use-package org-roam
  ;; ...
  :hook
  (post-self-insert . (lambda ()
                        (when (looking-back "\\[\\[" 2)
                          (insert "roam:]")
                          (backward-char)))))