org-roam / org-roam-bibtex

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

Doom configuration persistence after restart #66

Closed visini closed 4 years ago

visini commented 4 years ago

I'm trying to set up my system with your fantastic workflow integration between org-roam, org-noter and org-ref. First of all, thank you for your great work.

I'm running into a strange issue with my configuration. I'm running emacs-doom. My config does not seem to persist after I run M-x doom/reload.

My ~/doom.d/config.el:

;; From hleissner private config
;;; :lang org
(setq org-directory "~/org/"
      ;;org-archive-location (concat org-directory ".archive/%s::")
      ;;org-roam-directory (concat org-directory "notes/")
      ;;org-journal-encrypt-journal t
      org-ellipsis " ▼ "
      org-superstar-headline-bullets-list '("◆"))
(after! org
  (add-to-list 'org-modules 'org-habit t))

;; This allows typing ALT+5/6 for square brackets using iso-de keyboard layout
(setq mac-option-modifier nil
      mac-command-modifier 'meta
      select-enable-clipboard t)

;; Org-ref
;; https://github.com/hlissner/doom-emacs/issues/1573
(use-package! org-ref
    :after org
    :init
    ; code to run before loading org-ref
    :config
    ; code to run after loading org-ref
    )

(setq reftex-default-bibliography '("~/Dropbox/bibliography/references.bib"))

;; see org-ref for use of these variables
(setq org-ref-default-bibliography '("~/Dropbox/_sync/Zotero/zotero-better-bibtex-all.bib")
      org-ref-bibliography-notes "~/org/org-ref/all.org"
      org-ref-pdf-directory "~/Dropbox/_sync/Zotero/ZotFileExport/")
(setq bibtex-completion-bibliography "~/Dropbox/_sync/Zotero/zotero-better-bibtex-all.bib"
      bibtex-completion-library-path "~/Dropbox/_sync/Zotero/ZotFileExport"
      bibtex-completion-notes-path "~/org/org-ref/helm-bibtex-notes")
;; open pdf with system pdf viewer (works on mac)
(setq bibtex-completion-pdf-open-function
  (lambda (fpath)
    (start-process "open" "*open*" "open" fpath)))

(use-package! org-noter)

(setq org-roam-directory "~/org-roam")

;; Org-roam-bibtex
(use-package org-roam-bibtex
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :bind (:map org-mode-map
         (("C-c n a" . orb-note-actions))))

(setq orb-preformat-keywords
   '(("citekey" . "=key=") "title" "url" "file" "author-or-editor" "keywords"))

(setq orb-templates
      '(("r" "ref" plain (function org-roam-capture--get-point)
         ""
         :file-name "${slug}"
         :head "#+TITLE: ${citekey}: ${title}\n#+ROAM_KEY: ${ref}

- tags ::
- keywords :: ${keywords}

* ORG-NOTER
:PROPERTIES:
:Custom_ID: ${citekey}
:URL: ${url}
:AUTHOR: ${author-or-editor}
:NOTER_DOCUMENT: %(orb-process-file-field \"${citekey}\")
:NOTER_PAGE:
:END:")))

;; Test capture template
;; http://pragmaticemacs.com/emacs/org-mode-basics-vii-a-todo-list-with-schedules-and-deadlines/
(setq org-capture-templates
      '(("t" "Todo" entry (file+headline "~/org/todo.org" "Inbox")
         "* TODO %?\nSCHEDULED: %(org-insert-time-stamp (org-read-date nil t \"+0d\"))\n")));; 

Steps to reproduce:

  1. Restart doom emacs
  2. Try to follow a cite:xyz link from within a org-roam document (select in org-ref buffer: 3. Add notes) by pressing Enter
  3. org-ref buffer closes, error bibtex-parse-entry: Wrong type argument: stringp, nil, no redirect to the respective document occurs
  4. Run M-x doom/reload
  5. Everything works, I can follow all cite:xyz links
  6. After I restart doom emacs, following links doesn't work anymore, back to step 2...

Conclusion

I tried out multiple different bibtex entries, or even create new ones. I suspect a collision in my private emacs doom config.el between any of these packages: org-roam, org-ref, org-roam-bibtex, or even org-noter...

visini commented 4 years ago

Possibly related to: https://github.com/org-roam/org-roam-bibtex/issues/63#issuecomment-634292471

Will try to reproduce...

myshevchuk commented 4 years ago

Hi, thank you for using our package!

Indeed, you'll probably find the solution in #63. If things work, then do not work, then work again as you described, the reason is most likely stale *.elc files. So try wiping doom-private-dir/.local/straight/build or even doom-private-dir/.local/straight, then doom sync.

Unfortunately, Org-mode and packages that depend on it, org-roam-bibtex including, often suffer from "strange" issues. There are usually two different versions of Org-mode installed in user's Emacs environment. The stable one shipped with Emacs itself and the development version installed through MELPA by the user or user's configuration framework such as Doom or Spacemacs. Having two versions of one package installed in the system can cause the "wrong" built-in version to be loaded during compilation which would result then in strange issues.

Not that it changes anything in your case, just a word of advice: when using use-package, one usually puts all configuration for the package after :config keyword like this:

(use-package! org-ref
    :after org
    :init
    ; code to run before loading org-ref
    :config
    (setq org-ref-default-bibliography '("~/Dropbox/_sync/Zotero/zotero-better-bibtex-all.bib")
    ...)
    )

(use-package! org-roam-bibtex
  :hook (org-roam-mode . org-roam-bibtex-mode)
  :bind (:map org-mode-map
         (("C-c n a" . orb-note-actions)))
  :config
  (setq orb-preformat-keywords
     '(("citekey" . "=key=") "title" "url" "file" "author-or-editor" "keywords"))
  (setq orb-templates
  ...)
  (setq ...))

You can also consider unpinning org-roam in Doom's packages: (unpin! org-roam company-org-roam)

Sometimes, quite rarely though, we introduce changes into org-roam-bibtex that depend on some changes in org-roam, but the new org-roam version would not make it into Doom for another couple of days, so org-roam-bibtex might seem broken. This is, however, definitely not your case unless you haven't upgraded Doom for months.

visini commented 4 years ago

Thank you for your thorough explanation. Purging stale *.elc files did not fix the issue, but heavily borrowing from and considering the order of this private emacs config.el, I managed to get it to work: https://github.com/theianjones/dotfiles/tree/master/.doom.d

myshevchuk commented 4 years ago

@visini Normally, the order of use-package statements does not matter. What matters, however, is when you declare the package to be loaded, e.g. the :after statement, which was missing from your previous config. Anyway, I am glad your issue is fixed.

visini commented 4 years ago

Thank you for your stellar work. I will continue to explore orb for my workflow! All the best