org-roam / org-roam-bibtex

Org Roam integration with bibliography management software
GNU General Public License v3.0
568 stars 47 forks source link

orb-edit-notes caught an error during capture: Capture template ‘r’: Invalid search bound (wrong side of point) #188

Closed sdh0618 closed 3 years ago

sdh0618 commented 3 years ago

Describe the bug The above error shows when orb-edit-notes is used to create a new note. A new buffer will be created in the background with the correct orb-templates but the error will prompt first.

Expected behavior When orb-edit-notes is called and if the note hasn't been created yet, a new buffer will appear based on the orb-templates and without showing the error.

ORB configuration

;;;; Org-ref
(use-package org-ref
  :init
  ;; (setq org-ref-completion-library 'org-ref-ivy-cite)
  (setq org-ref-notes-function 'orb-edit-notes)
  :config
  (setq reftex-default-bibliography '("~/Dropbox/Bibtex/main.bib"))
  (setq org-ref-bibliography-notes "~/Dropbox/Bibtex/notes.org"
    org-ref-default-bibliography "~/Dropbox/Bibtex/main.bib"
    org-ref-pdf-directory "~/Dropbox/Bibtex/pdf/"))
(use-package bibtex-completion
  :config
  (setq bibtex-completion-bibliography "~/Dropbox/Bibtex/main.bib"
    bibtex-completion-library-path "~/Dropbox/Bibtex/pdf/"
    bibtex-completion-notes-path "~/Dropbox/Bibtex/notes.org"))
;; Org-roam
(use-package org-roam
  :hook
  (after-init . org-roam-mode)
  :custom
  (org-roam-directory "~/Documents/Roam-Notes")
  :bind (:map org-roam-mode-map
              (("C-c n l" . org-roam)
               ("C-c n f" . org-roam-find-file)
               ("C-c n g" . org-roam-graph))
          :map org-mode-map
              (("C-c n i" . org-roam-insert))
              (("C-c n I" . org-roam-insert-immediate))))
(use-package org-roam-bibtex
  :after org-roam
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :config
  (require 'org-ref))

Environment (please complete the following information):

myshevchuk commented 3 years ago

Hi, so how exactly do you trigger orb-edit-notes, through following an Org-ref cite:citation?

Anyway, there are several places in your config that may cause problems, although I'm not sure they are responsible for this issue. Maybe they are!

  1. (setq org-ref-notes-function 'orb-edit-notes) Don't do that. Instead, make sure org-roam-bibtex-mode is on. It sets the correct function. If you absolutely want to do it yourself, you should (setq org-ref-notes-function 'orb-notes-fn)
  2. org-ref-default-bibliography "~/Dropbox/Bibtex/main.bib" This variable should be a list, e.g. org-ref-default-bibliography '("~/Dropbox/Bibtex/main.bib")
  3. (after-init . org-roam-mode) can cause loading issues for Org-roam and Org-related packages, you should make it (org-load . org-roam-mode) instead.

Try fixing these, restart Emacs and see if the issue persists. If it does, please report in more detail what you actually do. E.g. I call this function, then this function, then I get this error.

sdh0618 commented 3 years ago

Hi @myshevchuk , thanks for your comments. Unfortunately the error's still there after I applied them.

The orb-edit-notes is triggered by either using the orb-insert in a org file, or trying to add notes to an Org-ref cite:citation. Both cases, the error shows up when the note is first created (if the note doesn't exist before calling the orb-edit-notes).

As I described, the note will be created properly, but in the background buffers. The error blocked the switching buffer which is annoying.

myshevchuk commented 3 years ago

@sdh0618 I cannot reproduce this issue, which means something must be wrong in your configuration. Something you didn't share here because it did not seem relevant. Most probably, something related to Org or Org-capture. You can try to debug it with Edebug. Try instrumenting orb--edit-notes: go to org-roam-bibtex.el source file in your installation location, find the function orb--edit-notes and call M-x edebug-defun. Then trigger orb-edit-notes and step through the function until the error is thrown.

You may also want to make sure that there are no stale .elc files in your installation. This happens sometimes after an upgrade. You should look for Org, Org-roam and Org-roam-bibtex installation directories, remove all the .elc files and reinstall/rebuild the packages.

sdh0618 commented 3 years ago

@myshevchuk Thanks! It turns out everything is .elc in the Org directory, which is the one install with emacs. I guess the emacs in my system just prefer the .elc files.

Now I installed the Org manually from their website and the error disappeared.

myshevchuk commented 3 years ago

@sdh0618 Good that you have it fixed. Emacs comes with precompiled .elc files, the source files are distributed as .el.gz archives. Thanks for reporting this. I will investigate why Org-roam-bibtex does not work with Org 9.3, although it should.

artpelling commented 3 years ago

had the exact same issue wit Emacs 27.1 and stock Org 9.3, can confirm that installing newer Org (9.4.6) version fixes it.

myshevchuk commented 3 years ago

I've just tested it on a clean Emacs 27.2 installation, which ships with Org 9.4.4 and I can't reproduce this error. So perhaps this is specific to Emacs <27.1 and Org <9.4. I will update the ORB's dependencies accordingly. Emacs 27.2 is the current stable version and ORB supports official stable versions of Emacs.

Thank you for brining it to my attention!