V2 and spacemacs

I am just wondering if anyone knows how to make v2 to work in spacemacs?


Searching this Discourse with “Spacemacs v2” hits two other items. One is about installation, the other, configuration. You might like to try this yourself and see they help you.

1 Like

I use this The Org-roam v2 Great Migration - #19 by nickanderson with succuss

After several attempts, I finally make org-roam (currently v2) in Spacemacs work by creating a private layer.

First off, Spacemacs’ org layer includes the org-roam package, so we need to exclude it from org layer in dotspacemacs-configuration-layers:

(org :packeges (not org-roam))

Then M-x configuration-layer/create-layer, and follow the instruction to name the layer, e.g. org-roam. This will create a layer folder with a file named “packages.el”.

Delete the content in the packages.el, and paste the following (my org-roam layer):

(defconst org-roam-packages
    (org-roam :location
              (recipe :fetcher github :repo "org-roam/org-roam"))
    (org-roam-bibtex :location
                     (recipe :fetcher github :repo "org-roam/org-roam-bibtex"))))

(defun org-roam/init-org-roam ()
  (use-package org-roam
    :defer t
    :hook (after-init . org-roam-mode)
    (setq org-roam-v2-ack t)
    (org-roam-directory "~/org/roam") ;; please change it to your path
      (spacemacs/declare-prefix "aor" "org-roam")
      (spacemacs/declare-prefix "aord" "org-roam-dailies")
      (spacemacs/declare-prefix "aort" "org-roam-tags")
        "aordy" 'org-roam-dailies-goto-yesterday
        "aordt" 'org-roam-dailies-goto-today
        "aordT" 'org-roam-dailies-goto-tomorrow
        "aordd" 'org-roam-dailies-goto-date
        "aor/" 'org-roam-node-find
        "aorc" 'org-roam-capture
        ;; "aorg" 'org-roam-graph
        "aori" 'org-roam-node-insert
        "aorl" 'org-roam-buffer-toggle
        "aorta" 'org-roam-tag-add
        "aortd" 'org-roam-tag-delete
        "aora" 'org-roam-alias-add)

      (spacemacs/declare-prefix-for-mode 'org-mode "mr" "org-roam")
      (spacemacs/declare-prefix-for-mode 'org-mode "mrd" "org-roam-dailies")
      (spacemacs/declare-prefix-for-mode 'org-mode "mrt" "org-roam-tags")
      (spacemacs/set-leader-keys-for-major-mode 'org-mode
        "rb" 'org-roam-switch-to-buffer
        "rdy" 'org-roam-dailies-goto-yesterday
        "rdt" 'org-roam-dailies-goto-today
        "rdT" 'org-roam-dailies-goto-tomorrow
        "rdd" 'org-roam-dailies-goto-date
        "r/" 'org-roam-node-find
        "rc" 'org-roam-capture
        ;; "rg" 'org-roam-graph
        "ri" 'org-roam-node-insert
        "rl" 'org-roam-buffer-toggle
        "rta" 'org-roam-tag-add
        "rtd" 'org-roam-tag-delete
        "ra" 'org-roam-alias-add))
    (setq org-roam-mode-sections
          (list #'org-roam-backlinks-insert-section
    (setq org-roam-file-extensions '("org"))

    ;; templates
    (setq org-roam-capture-templates
            ("d" "default" plain
             :if-new (file+head "${slug}.org"
                                "#+title: ${title}\n")
             :immediate-finish t
             :unnarrowed t)
            ("r" "ref" plain
             :if-new (file+head "./ref_notes/${slug}.org"
                                "#+title: ${title}\n")
             :unnarrowed t)))
    (setq org-roam-dailies-directory "daily/")
    (setq org-roam-dailies-capture-templates
          '(("d" "default" entry
             "* %?"
             :if-new (file+head "%<%Y-%m-%d>.org"
                                "#+title: %<%Y-%m-%d>\n"))))

(defun org-roam/init-org-roam-bibtex ()
  (use-package org-roam-bibtex
    :after org-roam
    :hook (org-roam-mode . org-roam-bibtex-mode)
    :bind (:map org-mode-map
                (("C-c n a" . orb-note-actions)))))

Let me know if this works.


Thank you very much indeed gnohz!

I spent hours without success in the configuration until I came across your post. I configured org-roam totally manually with use-package instead of creating a private layer, but org-roam was mysteriously not loaded until I added this line of code:

I did not know that Spacemacs’ org layer includes the org-roam package, so we need to exclude it from org layer; maybe you discovered this by digging into the source code.

Also the suggested configuration for org-roam in the official Spacemacs documentation (4.16. Org-roam support ) was a disaster for me, I was even unable to run emacs in daemon mode. By the way, by configuring org-roam manually with use-package, everything is working fine so far.

For the benefit of other users, I share my .spacemacs conf, with org-roam-ui also already configured and working:

(defun dotspacemacs/layers ()
  "Layer configuration:
This function should only modify configuration layer settings."
     (org :packages (not org-roam))
   dotspacemacs-additional-packages '(
                                      ( simple-httpd )
                                      ( websocket )
                                      (org-roam-ui :location (recipe :fetcher github :repo "org-roam/org-roam-ui" :branch "main" :files ("*.el" "out")))

(defun dotspacemacs/user-config ()

(require 'org)
(setq org-enable-roam-support t)

(use-package org-roam
  :after org
  :ensure t
  :init (setq org-roam-v2-ack t) ;; Acknowledge V2 upgrade
  (org-roam-directory  (file-truename "~/orgRoam") )
  (org-roam-completion-everywhere t)
  ;; If using org-roam-protocol
  ;;(require 'org-roam-protocol)
  :bind (("C-c n f" . org-roam-node-find)
         ("C-c n g" . org-roam-graph)
         ("C-c n r" . org-roam-node-random)
         (:map org-mode-map
               (("C-c n i" . org-roam-node-insert)
                ("C-c n o" . org-id-get-create)
                ("C-c n t" . org-roam-tag-add)
                ("C-c n a" . org-roam-alias-add)
                ("C-c n l" . org-roam-buffer-toggle))))
(use-package org-roam-ui
  :after org-roam
  ;;:hook (after-init . org-roam-ui-mode)
  (setq org-roam-ui-sync-theme t
        org-roam-ui-follow t
        org-roam-ui-update-on-save t
        org-roam-ui-open-on-start t))

PS: do not forget to check that you have the path to gcc.exe and git.exe in your emacs exe-path variable.

1 Like

My pleasure. Yes, I tried it very hard too.

If we didn’t exclude the org-roam package from the org layer in Spacemacs, we will have initiation problem, specifically, that there will be two “init” by use-package. If you read the Spacemacs documentation, you will see it mentions “init”, “pre-init”, and “post-init”.

1 Like

Out of interest, what’s the problem with the built-in org-roam layer in Spacemacs? It has recently been updated to work with v2, and seems to be working fine for me.

Not checked recently, but it did not include orb before.

1 Like

There are some file/folder re-structure in the org-roam repository. For example, they put org-dailies into “extensions”, so accordingly, I changed the org-roam location as follows:

(org-roam :location
              (recipe :fetcher github
                      :repo "org-roam/org-roam"
                      :files (:defaults "extensions/*"))

You might need to manually delete org-roam package first.

When enabling the org-roam layer (org-enable-roam-support t), I was no more able to run Spacemacs in daemon mode. Similar bugs have been are already reported on github (Emacs hangs when started in daemon mode #14477)

1 Like

Which version of spacemacs are you using?

v.0.300.0 develop branch

Hmm, it works for me with a fresh clone of latest spacemacs develop and no customization other than enabling org-enable-roam-support. You may want to try that and then adding your customizations back in little by little to see what happens. What are your OS and emacs version?

That GH issue linked to is from a time before spacemacs worked with org-roam v2, so it may not be relevant anymore. Both org-roam and the spacemacs layer code for it have changed a lot since then.

I am using Emacs 27.1 under Win 10. I will try with no customization other than enabling org-enable-roam-support.

Thank you very much gnohz.

When I use you above configure.

It does NOT work on my spacemacs.
There are two Warnings show when I start up the spacemacs. The configure also did not take effect.

Do you know the reason why? Thanks
- package org-roam not initialized in layer Boyang-research, you may consider
removing this package from the package list or use the :toggle keyword instead
of a when' form. - package org-roam-bibtex not initialized in layer Boyang-research, you may consider removing this package from the package list or use the :toggle keyword instead of a when’ form.

This is my configuration.

Did you “remove” the org-roam package from the org-layer in spacemacs?

(org :packeges (not org-roam))

Adding to @gnohz ,

  • I would suggest to remove usage (I see two locations) of org-roam-mode in hooks. It does not do what you probably mean.

  • I’d move org-roam-setup from init to config.

  • Review the latest README of Org-roam and ORB to learn what both projects recommend for configuration with use-package — e.g. you would not use org-roam-setup and ORB should be required in config of org-roam, etc.

Hi gnohz,

Thanks for your reply and good day to you.

I found one of my issues.
We have different layers name, so I need to change:
defun org-roam/init-org-roam ()
defun my layer name/init-org-roam ()

However, There is one Error show when I start up the spacemacs.
Error (use-package): org-roam/:config: Key sequence r d starts with non-prefix key r

Do you face the same Error msg?

Also, I found this part of the configure(at the below) did not take effect.
(spacemacs/set-leader-keys-for-major-mode 'org-mode
“rb” 'org-roam-switch-to-buffer
“rdy” 'org-roam-dailies-goto-yesterday
“rdt” 'org-roam-dailies-goto-today
“rdT” 'org-roam-dailies-goto-tomorrow
“rdd” 'org-roam-dailies-goto-date
“r/” 'org-roam-node-find
“rc” 'org-roam-capture
;; “rg” 'org-roam-graph
“rh” 'org-id-get-create
“ri” 'org-roam-node-insert
“rl” 'org-roam-buffer-toggle
“rta” 'org-roam-tag-add
“rtd” 'org-roam-tag-delete
“ra” 'org-roam-alias-add))