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.36k stars 243 forks source link

org-ref-get-bibtex-key-under-cursor returns nil instead of a list of keys #1097

Open mlemerre opened 11 months ago

mlemerre commented 11 months ago

Hello,

First, thanks for org-ref!

I have investigated a problem that bugged me for a while, which is that when I click on a reference, I have a hydra menu that gets opened, but most commands fails with a "wrong argument nil".

I have investigated the problem which seems to be that the org-ref-get-bibtex-key-under-cursor returns nil (as it ends execution with a prog1) instead of a list of keys, as expected e.g. by its caller org-ref-open-notes-at-point.

It seems quite easy to fix the code but I wonder how this problem has been unnoticed for so long; maybe for most people the (get-text-property 'cite-key) function gets triggered, so maybe there is a problem in my config? Or do people never use there mouses to click on citations?

mlemerre commented 11 months ago

As a temporary workaround I replaced (prog1 (get-text-property (point) 'cite-key)

with (prog1 (car keys)

but I guess this will fail when I use multiple citations. There seems to be a problem with this code, but I fail to understand the overall architecture.

mlemerre commented 11 months ago

I found out that I add (setq org-ref-activate-cite-links nil) in my config, which explains why in general the bug is not triggered. Still, the bug remains if this option is set.

jkitchin commented 11 months ago

(setq org-ref-activate-cite-links nil) will make this problem happen because it relies on (get-text-property (point) 'cite-key) to work, and this is set during activation.

I think the way this works is the following. You can click on different parts of the link that have to be handled. First, if there is a 'cite-key property then you are on an activated citation. If not, it could mean you click on the cite type, then it gets the keys, and if there is one, searches forward to it, and if there are many, it prompts you to choose one, then searches forward to what you select. Then, it tries to get the 'cite-key property (which should exist if it was activated). org-ref-activate-cite-links should default to t, and you would only turn it off for performance reasons if there are so many cites you see things slow down.

jkitchin commented 11 months ago

see e8518f4ad6e5adc6081386339fdd5f394b4822c9, I think it makes this a little more robust.