org-roam / org-roam-bibtex

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

orb-insert does not create new note #153

Closed kasteph closed 3 years ago

kasteph commented 3 years ago

Describe the bug orb-insert does not create a new note when one does not exist already.

To Reproduce Steps to reproduce the behavior:

  1. Create a new bibtex entry in .bib file set with bibtex-completion-library.
  2. Create a new note in org-mode.
  3. Run C-c ) i (or M-x then selecting orb-insert).
  4. Nothing happens.

Expected behavior Mini-buffer (? not sure of the right term, just started using emacs 😅 ) to capture note should show up.

ORB configuration

  1. How the package is loaded.
    (use-package! org-roam-bibtex
    :after (org-roam)
    :hook (org-roam-mode . org-roam-bibtex-mode))
  2. ORB options set to non-default values (e.g. orb-templates)
    (setq orb-preformat-keywords '("citekey" "author" "date"))
    (setq orb-templates
        '(("r" "ref" plain (function org-roam-capture--get-point)
           ""
           :file-name "lit/${slug}"
           :head ,(concat
                   "#+title: ${title}\n"
                   "#+roam_key: cite:${citekey}\n\n"
                   "* ${title}\n"
                   "  :PROPERTIES:\n"
                   "  :AUTHOR: ${author}\n"
                   "  :NOTER_DOCUMENT: %(orb-process-file-field \"${=key=}\")\n"
                   "  :NOTER_PAGE: \n"
                   "  :END:\n")
           :unnarrowed t))

Environment (please complete the following information):

Screenshots orb bug demo

kasteph commented 3 years ago

It seems that I've managed to fix it. The issue was in my orb-templates:

(setq orb-templates
        '(("r" "ref" plain (function org-roam-capture--get-point)

when it should be:

(setq orb-templates
       `(("r" "ref" plain (function org-roam-capture--get-point)
myshevchuk commented 3 years ago

Great! The backquote syntax is Emacs' blessing but easy to overlook.

A few friendly suggestions. You can use template files for larger templates, see the docstring of org-capture-templates for more information. This may be especially useful for decluttering your init.el if you have more than one template. In short, it'd look like this:

;; init.el
(setq orb-templates
        '(("r" "ref" plain (function org-roam-capture--get-point)
           (file "path/to/ref.template")
           :file-name "lit/${slug}"
           :head "#+title: ${title}\n"
           :unnarrowed t)

           ("q" "another template" (function org-roam-capture--get-point) 
           (file "path/to/another.template")
            ...)

Contents of ref.template

#+roam_key: cite:%^{citekey}

* %^{title}
 :PROPERTIES:
 :AUTHOR: %^{author}
 :NOTER_DOCUMENT: %(orb-process-file-field \"%^{=key=}\")
 :NOTER_PAGE: 
 :END:

Note, however, that only Org capture-style wildcards %^{} will work here.

Also, you can use a special %^{file} wildcard (or ${file} outside of a template file) with the same effect as %(orb-process-file-field \"${=key=}\"), i.e. if more than one file exists for a given entry, you'll be prompted to make a choice. The "file" keyword as well as the "=key=" keyword should be added to orb-preformat-keywords, if you plan to use them, though.

kasteph commented 3 years ago

@myshevchuk Thanks so much for taking the effort to follow up 🙏🏽 These are really helpful tips for an Emacs newbie like me :)

mbosley commented 3 years ago

I'm having the exact same problem. Changing from a ' to a ` while defining the orb-templates variable doesn't help.

myshevchuk commented 3 years ago

@mbosley this means that the cause of your problem is different.