Jeremias Gonzalez <jer...@pacbell.net> writes:

>> Do I understand correctly that you attempted to run org-bibtex-read from
>> a non-bibtex buffer?
>>
>
> At a top level, I was using org-bibtex-yank with an org buffer (and in my
> ideal case with no bibtex buffers whatsoever) as the documentation for that
> function only requires bibtex to be in the kill ring. However, yes,
> org-bibtex-yank calls org-bibtex-read, and I was doing so (in the ideal
> case) with a non-bibtex buffer.

Does the attached patch fix the problem?

>From 67c15a645f98f25af4db37830d632e9daf875e5e Mon Sep 17 00:00:00 2001
Message-ID: <67c15a645f98f25af4db37830d632e9daf875e5e.1691941444.git.yanta...@posteo.net>
From: Ihor Radchenko <yanta...@posteo.net>
Date: Sun, 13 Aug 2023 18:41:59 +0300
Subject: [PATCH] org-bibtex-yank: Fix bibtex parser not initialized in temp
 buffer

* lisp/ol-bibtex.el (org-bibtex-yank): Make sure that we parse bibtex
entry from the kill ring in a `bibtex-mode' buffer.  Otherwise,
calling `org-bibtex-read' (that calls `bibtex-parse-entry') may err
because some Bibtex parser variables are not initialized.

Reported-by: J. G. <jer...@pacbell.net>
Link: https://orgmode.org/list/1939460027.3272000.1691771671...@mail.yahoo.com
---
 lisp/ol-bibtex.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/ol-bibtex.el b/lisp/ol-bibtex.el
index 4308424a3..17fbb9fbd 100644
--- a/lisp/ol-bibtex.el
+++ b/lisp/ol-bibtex.el
@@ -765,7 +765,10 @@ (defun org-bibtex-yank ()
   "If kill ring holds a bibtex entry yank it as an Org headline."
   (interactive)
   (let (entry)
-    (with-temp-buffer (yank 1) (setf entry (org-bibtex-read)))
+    (with-temp-buffer
+      (yank 1)
+      (bibtex-mode)
+      (setf entry (org-bibtex-read)))
     (if entry
 	(org-bibtex-write)
       (error "Yanked text does not appear to contain a BibTeX entry"))))
-- 
2.41.0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to