(defun my/org-ref-open-pdf-at-point ()
"Open the pdf for bibtex key under point if it exists."
(interactive)
(let* ((results (org-ref-get-bibtex-key-and-file))
(key (car results))
(pdf-file (concat org-ref-pdf-directory "/" key ".pdf")))
(if (file-exists-p pdf-file)
(w32-shell-execute "open" pdf-file)
(progn
(message "results:[%s]" results)
(message "key file:[%s]" key)
(message "No PDF found for %s" pdf-file)))))
(setq org-ref-open-pdf-function 'my/org-ref-open-pdf-at-point)
(defun kimim/org-ref-get-pdf-filename (key)
"Return the pdf filename associated with a bibtex KEY.
This searches recursively for the pattern KEY*.pdf. If one result
is found it is returned, but if multiple results are found,
e.g. there are related files to the KEY you are prompted for
which one you want."
(if org-ref-pdf-directory
(let ((pdfs
(-flatten
(--map (file-expand-wildcards
(f-join it (format "%s*.pdf" key)))
(-flatten
(append (list org-ref-pdf-directory)
(directory-files-recursively
org-ref-pdf-directory "" t)))))))
(cond
((= 0 (length pdfs))
(expand-file-name (format "%s.pdf" key) org-ref-pdf-directory))
((= 1 (length pdfs))
(car pdfs))
((> (length pdfs) 1)
(completing-read "Choose: " pdfs))))
;; No org-ref-pdf-directory defined so return just a file name.
(format "%s.pdf" key)))
(setq org-ref-get-pdf-filename-function 'kimim/org-ref-get-pdf-filename))