link-hint.el icon indicating copy to clipboard operation
link-hint.el copied to clipboard

[citation] link cannot open properly

Open randomwangran opened this issue 2 years ago • 0 comments

If the point is not under a cite link, link-hint-open-link can open a link cite:somekey, which will result in the following hydra command panel org-ref-citation-hydra/body It is a function in org-ref/org-ref-citation-links.el.

image

However, further input from the user will result in a failed message: Wrong type argument: stringp, nil. For example, pressing p will result in a message: Wrong type argument: stringp, nil.

Here's my initial investigation.

Taking open an pdf as example. In the following function, org-ref-citation-hydra/org-ref-open-pdf-at-point-and-exit

(defun org-ref-open-pdf-at-point ()
  "Open the pdf for bibtex key under point if it exists."
  (interactive)
  (let* ((bibtex-completion-bibliography (org-ref-find-bibliography))
         (results (org-ref-get-bibtex-key-and-file))
         (key (car results))
         (pdf-file (bibtex-completion-find-pdf key t)))
    (pcase (length pdf-file)
      (0
       (message "no pdf found for %s" key))
      (1
       (org-open-file (car pdf-file)))
      (_
       (org-open-file (completing-read "pdf: " pdf-file))))))

(org-ref-get-bibtex-key-and-file) use the the value returned by (org-ref-get-bibtex-key-under-cursor) to get key and pdf file. If the cursor is not under the citation link, then there is no result returned, which will cause the error message. However, if the cursor is on the citation link, the pdfs will be opened properly.

I am trying to figure out how to pass the key to org-ref-open-pdf-at-point.

randomwangran avatar Mar 25 '22 20:03 randomwangran