ORB: helm-bibtex -> `open notes` won't create new note

Hi guys,

while transitioning from org-ref to org-roam-bibtex I’ve encountered a problem. My issue is somewhat related to this one - open notes in org-roam-bibtex does not work - yet slightly different.

In his excellent video tutorial on the usage of ORB, @zaeph can be seen running M-x helm-bibtex, selecting a note and then running Edit notes. In theory (and in the video), this will either open the associated org-roam file or create a new one.

The problem I have is that Edit notes jumps to/adds a headline in my org-ref-bibliography-notes file instead (that used to be my old workflow). My understanding is that ORB is supposed to overwrite pre-existing configurations but I must have made a mistake in my setup.

As a spacemacs user (I haven’t mustered the courage yet to switch to doom emacs), please see my private layer file below.

Thanks in advance for your help!

(defconst org-roam-packages
  '(
    (org-roam :location
              (recipe :fetcher github :repo "jethrokuan/org-roam"))
    (company-org-roam :toggle (configuration-layer/package-used-p 'company))
    org-roam-bibtex))

(defun org-roam/init-org-roam ()
  (use-package org-roam
    :hook
    (after-init . org-roam-mode)
    ;; :custom
    ;; (org-roam-directory "~/org/roam/")
    :init
    (progn
      (spacemacs/declare-prefix "aR" "org-roam")
      (spacemacs/set-leader-keys
        "aRl" 'org-roam
        "aRt" 'org-roam-dailies-today
        "aRf" 'org-roam-find-file
        "aRg" 'org-roam-graph)

      (spacemacs/declare-prefix-for-mode 'org-mode "mr" "org-roam")
      (spacemacs/set-leader-keys-for-major-mode 'org-mode
        "rl" 'org-roam
        "rt" 'org-roam-dailies-today
        "rb" 'org-roam-switch-to-buffer
        "rf" 'org-roam-find-file
        "ri" 'org-roam-insert
        "rg" 'org-roam-graph))))

(defun org-roam/init-company-org-roam ()
  (use-package company-org-roam
    :defer t
    :init (spacemacs|add-company-backends
            :backends company-org-roam
            :modes org-roam-mode org-mode)))

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

Hi Hermann,

this could be some loading issues. How do you load org-ref?

Could you also check whether org-roam-bibtex-mode is active? If not, could you run org-roam-bibtex-mode and check whether the Helm problem persists?

1 Like

Thank you so much, running org-roam-bibtex-mode fixed it of course and pointed me in the right direction … for some reason, I thought that the layer itself would be enough but I had to add

(require 'org-roam-bibtex)
(add-hook 'after-init-hook #'org-roam-bibtex-mode)
(define-key org-roam-bibtex-mode-map (kbd "C-c n a") #'orb-note-actions)

to my .spacemacs.

All of this is actually very well documented here but since lines 2 and 3 of the snippet above look very similar to the :hook and :bind part in init-org-roam-bibtex, I thought that the entire snippet had to be redundant.

I see and understand now that (require 'org-roam-bibtex) is needed to activate org-roam-bibtex mode, but I would have expected the layer to take care of hooks and keybindings. Well, I guess I’ll just have to learn more about Elisp in general and spacemacs in particular. Again, thank you!

@hermann.westerholt You are absolutely right, the layer, as described in the README, should be enough. The fact that it does not work might indicate interference in your config. That’s why my question how you load org-ref, possibly also org and helm-bibtex.

Ah, snap! Once again, thank you for pointing me in the right direction. It all makes sense now! If only I had remembered this part at the very top of the org-layer for spacemacs documentation:

Since version 0.104, spacemacs uses the org version from the org ELPA repository instead of the one shipped with emacs. Then, any org related code should not be loaded before dotspacemacs/user-config , otherwise both versions will be loaded and will conflict.

Because of autoloading, calling to org functions will trigger the loading up of the org shipped with emacs which will induce conflicts. One way to avoid conflict is to wrap your org config code in a with-eval-after-load block like this:

(with-eval-after-load 'org
  ;; here goes your Org config :)
  ;; ....
  )

I nuked my config file a while ago and completely forgot about this crucial detail … the layer now works as expected and I have gotten rid of the additional clutter in my .spacemacs file. Essence of my story: RTFM

Thank you!

1 Like

I’m glad you’ve figured it out. Don’t worry about your story here, it will help others :slight_smile:

1 Like

I’m a bit confused about what types of org configuration options are supposed to be wrapped. Is it literally everything in dotspacemacs/user-config related to org? What about stuff like all the org-roam-bibtex configuration?

Here are some examples from my dotspacemacs/user-config:

  (add-hook 'org-mode-hook 'spacemacs/toggle-truncate-lines-off)
  (add-hook 'org-mode-hook 'hl-todo-mode)
  (customize-set-variable 'org-blank-before-new-entry  ;; disables org's magic decision making around new lines
                          '((heading . nil)
                            (plain-list-item . nil)))

  (use-package org
    :config
    (setq org-startup-indented t)
    (setq org-startup-with-latex-preview t)
    )
  ;; org-mode latex fragment configuration
  (setq org-format-latex-options (plist-put org-format-latex-options :scale 1.2))
  (setq org-preview-latex-default-process 'dvisvgm) ;; dvisvgm instead of dvipng for high resolution latex fragments
  (add-hook 'org-mode-hook 'org-fragtog-mode) ;; automatically toggle fragments
  (setq org-highlight-latex-and-related '(latex))  ;; need the parens around latex for some reason

  (add-hook 'org-mode-hook 'smartparens-mode)


  ;; org-roam-bibtex
  ;; note that init code is directly in private Spacemacs layer
  (add-hook 'org-mode-hook 'org-roam-bibtex-mode)
  (setq reftex-default-bibliography '("~/Dropbox/org/bibtex/ref.bib"))

  ;; see org-ref for use of these variables
  (setq org-ref-bibliography-notes "~/Dropbox/org/bibtex/org-ref-notes.org"
        org-ref-notes-directory "~/Dropbox/org/bibtex/helm-bibtex-notes"
        org-ref-default-bibliography '("~/Dropbox/org/bibtex/ref.bib")
        org-ref-pdf-directory "~/Dropbox/org/bibtex/pdf/")
  ;; helm-bibtex variables
  (setq bibtex-completion-bibliography "~/Dropbox/org/bibtex/ref.bib"
        bibtex-completion-library-path "~/Dropbox/org/bibtex/pdf"
        bibtex-completion-notes-path "~/Dropbox/org/bibtex/helm-bibtex-notes")

A couple specific questions:

  1. I’ve been loading org-roam-bibtex (and other modes) with (add-hook 'org-mode-hook 'org-roam-bibtex-mode) and it usually seems ok but sometimes seems buggy on Emacs startup. How is it supposed to be done?
  2. How much of that config should be wrapped inside with-eval-after-load 'org?

Although I’ve been using Spacemacs for quite a while, I’m not using it anymore, so my answer will lack certainty in Spacemacs specifics.

This is a common sense advice:

  1. You can safely put any simple setq's almost anywhere. Simple means your setq does not call any functions or uses any variables, just (setq my-var "my-value"). Otherwise, it’s better to put them into with-eval-after-load. Spacemacs recommends to wrap all Org config into with-eval-after-load. Note however, that some packages, Org including as far as I remember, may require some of their settings set before the package is loaded, unless they are set through Customize.

  2. You should better wrap add-to-list and add-hook into with-eval-after-load. This will ensure that the list and hook variables you are setting are initialized, or you’ll catch some undefined variable errors. It’s almost always safe to use with-eval-after-load with any kind of configuration stuff, unless things must be set/done before loading the package.

  3. You should probably not use use-package in your dotspacemacs/user-config function. You should not use use-package twice. Org layer has already done this for you once (I assume you are using Org layer). Actually, I think this is the offending piece that makes your Emacs buggy upon startup. Another problem with this use-package statement of yours is that it does not have any “deferring” statememts such as :hook, :after, :commands, or simply :defer t. Refer to use-package's docs for a clarification. But again, you do not need it here, you don’t need it at all. Spacemacs has taken care of it.

  4. Org Roam and ORB examples above in the topic refer to creating a private Spacemacs layer, which you put in $SPACEMACSDIR/layers or $SPACEMACSDIR/private/layers or something like that. Consult Spacemacs docs on how to create layers. Items 1–3 also apply to Org roam and ORB. But since you are creating a private layer, you can put all of their configuration in the layer inside the respective use-package statements. This is good for decluttering your dotspacemacs/user-config.