all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* org-bibtex-yank failing with error Wrong type argument: stringp, nil
       [not found] <1939460027.3272000.1691771671040.ref@mail.yahoo.com>
@ 2023-08-11 16:34 ` J. G.
  2023-08-12  4:15   ` J. G.
  0 siblings, 1 reply; 7+ messages in thread
From: J. G. @ 2023-08-11 16:34 UTC (permalink / raw)
  To: Org-Mode Mailing List

Hi, I'm trying to figure out why I'm getting consistent failures using org-bibtex-yank. This appears to be identical to the problem posted here:

https://stackoverflow.com/questions/31174281/org-bibtex-yank-fails-with-wrong-type-argument-stringp-nil

On my system I am using a fresh Ubuntu 23.04 VM with the following emacs and org-mode build info:

GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.37, cairo version 1.16.0) of 2023-08-11

Org mode version 9.7-pre (release_9.6.7-652-gcfea24 @ /home/test/org-mode/lisp/)

My backtrace is very similar to that posted in the stackoverflow thread:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  looking-at(nil)
  bibtex-parse-entry()
  org-bibtex-read()
  org-bibtex-yank()
  funcall-interactively(org-bibtex-yank)
  call-interactively(org-bibtex-yank record nil)
  command-execute(org-bibtex-yank record)
  execute-extended-command(nil "org-bibtex-yank" nil)
  funcall-interactively(execute-extended-command nil "org-bibtex-yank" nil)
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)

My steps to reproduce, with this as my init.el file:

(add-to-list 'load-path "~/org-mode/lisp")
(require 'org-loaddefs)

1. Open test.org in emacs.

2. Copy a bibtex entry in Firefox, for example this entry from Google Scholar:

@article{dominik2004org,
  title={Org Mode Manual},
  author={Dominik, Carsten},
  year={2004}
}

3. In the org file call M-x org-bibtex-yank.

After that I experience the failure above 100% of the time.

Attempts to troubleshoot:

One of the comments in the stackoverflow thread mentioned that a reason this could have failed was that the variable "bibtex-dialect" wasn't set. C-h v confirms it was set in my case (to "BibTeX"), but the problem was still present. I added a line in my init.el file "(setq bibtex-dialect 'biblatex)" just to double check and the problem was still present.

As described in the same comment, with my original 2 line init.el file above,

1. simply opening a new file "dummy.bib" (doing nothing with it),

2. then opening "test.org",

3. copying a bibtex entry in Firefox,

4. calling org-bibtex-yank

caused org-bibtex-yank to correctly function. I did not need to call bibtex-set-dialect as the comment described.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-bibtex-yank failing with error Wrong type argument: stringp, nil
  2023-08-11 16:34 ` org-bibtex-yank failing with error Wrong type argument: stringp, nil J. G.
@ 2023-08-12  4:15   ` J. G.
  2023-08-13  7:57     ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: J. G. @ 2023-08-12  4:15 UTC (permalink / raw)
  To: Org-Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]

On Friday, August 11, 2023 at 09:34:31 AM PDT, J. G. <jerzor@pacbell.net> wrote: 
> Hi, I'm trying to figure out why I'm getting consistent failures using org-bibtex-yank. This appears to be identical to the problem posted here:
On further investigation I have pinpointed the precise error as referenced by the comment in the Stackoverflow thread. One of the nested function calls stemming from org-bibtex-yank is to bibtex-parse-entry in bibtex.el, and that in turn attempts to make use of the internal variable bibtex-entry-maybe-empty-head. That variable, among others, has documentation that they are nil until initialized by bibtex-set-dialect, which sets a number of other internal variables along with bibtex-dialect. That default nil value bubbles up to cause the error I am experiencing. The solution in my original email of opening a dummy.bib file works because it calls bibtex-mode and that calls bibtex-set-dialect.
Adding the following two lines to my init fixes the error in my case:
(require 'bibtex)(bibtex-set-dialect 'biblatex nil)
where the first line seems to be necessary in my barebones case because bibtex isn't yet loaded, and the second line sets my dialect of choice (biblatex) and sets the internal variables for bibtex globally (nil), not locally (t).
Given the disconnect between the error and the solution (as I understand it at least), and the absence of this necessity in the documentation (I have read through at least ol-bibtex.el), perhaps a small mention of this in the documentation in ol-bibtex.el is in order, and I can submit a patch for review?

[-- Attachment #2: Type: text/html, Size: 2358 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-bibtex-yank failing with error Wrong type argument: stringp, nil
  2023-08-12  4:15   ` J. G.
@ 2023-08-13  7:57     ` Ihor Radchenko
  2023-08-13 15:30       ` Jeremias Gonzalez
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2023-08-13  7:57 UTC (permalink / raw)
  To: J. G.; +Cc: Org-Mode Mailing List

"J. G." <jerzor@pacbell.net> writes:

> Adding the following two lines to my init fixes the error in my case:
> (require 'bibtex)(bibtex-set-dialect 'biblatex nil)

Do I understand correctly that you attempted to run org-bibtex-read from
a non-bibtex buffer?

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-bibtex-yank failing with error Wrong type argument: stringp, nil
  2023-08-13  7:57     ` Ihor Radchenko
@ 2023-08-13 15:30       ` Jeremias Gonzalez
  2023-08-13 15:44         ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremias Gonzalez @ 2023-08-13 15:30 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org-Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 692 bytes --]

On Sun, Aug 13, 2023 at 12:57 AM Ihor Radchenko <yantar92@posteo.net> wrote:

> "J. G." <jerzor@pacbell.net> writes:
>
> > Adding the following two lines to my init fixes the error in my case:
> > (require 'bibtex)(bibtex-set-dialect 'biblatex nil)
>
> 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.

[-- Attachment #2: Type: text/html, Size: 1063 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-bibtex-yank failing with error Wrong type argument: stringp, nil
  2023-08-13 15:30       ` Jeremias Gonzalez
@ 2023-08-13 15:44         ` Ihor Radchenko
  2023-08-13 16:15           ` Jeremias Gonzalez
  0 siblings, 1 reply; 7+ messages in thread
From: Ihor Radchenko @ 2023-08-13 15:44 UTC (permalink / raw)
  To: Jeremias Gonzalez; +Cc: Org-Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 528 bytes --]

Jeremias Gonzalez <jerzor@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?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-bibtex-yank-Fix-bibtex-parser-not-initialized-in.patch --]
[-- Type: text/x-patch, Size: 1354 bytes --]

From 67c15a645f98f25af4db37830d632e9daf875e5e Mon Sep 17 00:00:00 2001
Message-ID: <67c15a645f98f25af4db37830d632e9daf875e5e.1691941444.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@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. <jerzor@pacbell.net>
Link: https://orgmode.org/list/1939460027.3272000.1691771671040@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


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: org-bibtex-yank failing with error Wrong type argument: stringp, nil
  2023-08-13 15:44         ` Ihor Radchenko
@ 2023-08-13 16:15           ` Jeremias Gonzalez
  2023-08-13 16:25             ` Ihor Radchenko
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremias Gonzalez @ 2023-08-13 16:15 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Org-Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 176 bytes --]

On Sun, Aug 13, 2023 at 8:44 AM Ihor Radchenko <yantar92@posteo.net> wrote:

> Does the attached patch fix the problem?
>

The patch works for me, thank you very much!

[-- Attachment #2: Type: text/html, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org-bibtex-yank failing with error Wrong type argument: stringp, nil
  2023-08-13 16:15           ` Jeremias Gonzalez
@ 2023-08-13 16:25             ` Ihor Radchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Ihor Radchenko @ 2023-08-13 16:25 UTC (permalink / raw)
  To: Jeremias Gonzalez; +Cc: Org-Mode Mailing List

Jeremias Gonzalez <jerzor@pacbell.net> writes:

> On Sun, Aug 13, 2023 at 8:44 AM Ihor Radchenko <yantar92@posteo.net> wrote:
>
>> Does the attached patch fix the problem?
>>
>
> The patch works for me, thank you very much!

Thanks for testing!
Applied, onto bugfix.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=99cc9619c
Fixed.

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-08-13 16:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1939460027.3272000.1691771671040.ref@mail.yahoo.com>
2023-08-11 16:34 ` org-bibtex-yank failing with error Wrong type argument: stringp, nil J. G.
2023-08-12  4:15   ` J. G.
2023-08-13  7:57     ` Ihor Radchenko
2023-08-13 15:30       ` Jeremias Gonzalez
2023-08-13 15:44         ` Ihor Radchenko
2023-08-13 16:15           ` Jeremias Gonzalez
2023-08-13 16:25             ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.