I have this function which works perfectly in an uncompiled function. It should let-bind the variable
bibtex-completion-bibliography to the result of
(defun org-ref-valid-keys () "Return a list of valid bibtex keys for this buffer. This is used a lot in `org-ref-cite-activate' so it needs to be fast, but also up to date." ;; this seems to be needed, but we don't want to do this every time (unless bibtex-completion-display-formats-internal (bibtex-completion-init)) ;; I don't fully understand what is happening here. (let ((bibtex-completion-bibliography (org-ref-find-bibliography))) (cl-loop for entry in (bibtex-completion-candidates) collect (cdr (assoc "=key=" (cdr entry))))))
What should happen is (org-ref-find-bibliography) gets a list of bibliography files if they are defined in a buffer (it defaults to a variable setting if they are not), and then let-binds that list to bibtex-completion-bibliography, and the keys are extracted from (bibtex-completion-candidates) which uses bibtex-completion-bibliography to get keys from those files. This works fine when the function is not compiled.
When the function is compiled, the keys end up coming from the default list of bibtex files, and not from the list defined by (org-ref-find-bibliography) (which still does the right thing). It is as if the let binding does not work.
If I debug the function, or re-evaluate it, it works fine, it only does not work when called from the compiled function. It also works if I delete all the .elc files in the package.
All the bibtex-completion* functions and variables are defined in the external library bibtex-completion.
-*- lexical-binding: t; -*- in the first line of that file.
What could be causing this?
GNU Emacs 28.0.50 (build 1, x86_64-apple-darwin20.6.0, NS appkit-2022.60 Version 11.5 (Build 20G71)) of 2021-07-29