jkitchin / org-ref

org-mode modules for citations, cross-references, bibliographies in org-mode and useful bibtex tools to go with it.
GNU General Public License v3.0
1.37k stars 243 forks source link

`org-ref` gives "Wrong type argument: listp, 771" #1121

Open sprig opened 2 months ago

sprig commented 2 months ago

Hi, Thanks for org-ref!

Running org-ref in an org buffer in emacs 29.2 gives the above messages. I traced the code and found the error originating in this function from org-ref:

;;** bad citations, labels, refs and files in orgfile
;;  These are used i
(defvar bibtex-files)
(defvar bibtex-file-path)
(defun org-ref-bad-cite-candidates ()
  "Return a list of conses (key . marker) where key does not exist in the known bibliography files, and marker points to the key."
  (let* ((cp (point))           ; save to return to later
         (bibtex-files (cl-loop for f in (org-ref-find-bibliography)
                if (file-exists-p f)
                collect (file-truename f)))
         (bibtex-file-path (mapconcat
                            (lambda (x)
                              (file-name-directory (file-truename x)))
                            bibtex-files ":"))
         (bibtex-keys (mapcar (lambda (x) (car x))
                              (bibtex-global-key-alist)))
         (bad-citations '()))

    (org-element-map (org-ref-parse-buffer) 'link
      (lambda (link)
        (let ((plist (nth 1 link)))
          (when (assoc (plist-get plist :type) org-ref-cite-types)
        (when (not (string= "*" (plist-get plist :path)))
          (cl-loop for ref in (plist-get (org-ref-parse-cite-path (plist-get plist :path)) :references)
               do
               (when (not (member (plist-get ref :key) bibtex-keys))
             (goto-char (org-element-property :begin link))
             (re-search-forward (plist-get ref :key))
             (push (cons (plist-get ref :key) (point-marker)) bad-citations)))))))
      ;; add with-affiliates to get cites in caption
      nil nil nil t)
    (goto-char cp)
    bad-citations))

Specifically in this sexp:

         (mapcar (lambda (x) (car x))
                              (bibtex-global-key-alist))

It seems that the result from (bibtex-global-key-alist) is some function reference, rather than an alist.

Result: #f(compiled-function (string pred action) #<bytecode 0x1dfcf93f30d2e84b>)

Seems like a bug in bibtex, although I'm not sure - other functionality seems to work correctly, e.g. org-ref-insert-link. On the other hand, it seems that the only places this function is used inside bibtex is in bibtex-completion-at-point-function as well as bibtex-read-key which I assume helm overrides.

Any idea what's going on?

jkitchin commented 2 months ago

I can't reproduce this on Emacs 30. For me, bibtex-global-key-alist is a function that returns an alist. It seems weird it would return a function.

I guess what is happening is that code gets run in a bibtex file. Then, it looks like bibtex-global-key-alist returns bibtex-reference-keys, which does have the results you showed. I don't know why that would happen though.

Can you run this elisp block in an org file successfully?

#+BEGIN_SRC emacs-lisp
(org-ref-bad-cite-candidates)
#+END_SRC

#+RESULTS:
: ((not-today . #<marker at 96 in 2024-09-01.org>))

[[cite:&not-today]]
sprig commented 2 months ago

Hi!

Thanks for your response.

I cannot right now test on emacs above 29.2 because network connections there (such as in package.el) lead to hangs. I saw a similar bug report and apparently a fix for future versions but I'm not sure it's out yet.

The code above raises the same message as in the title...