diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-03-04 00:46:02 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-03-04 00:49:41 -0500 |
commit | 95e0215211f8663c0da17ef23049a65b7be47f54 (patch) | |
tree | 5ce78fe5dcb20cef7c3e84d2ed9492c219475798 | |
parent | f2460c249794138f57aee50337771c80120f541f (diff) | |
download | bog-95e0215211f8663c0da17ef23049a65b7be47f54.tar.gz |
ENH: Allow citekey to have multiple PDFs
Match any PDF files named '<citekey.pdf' or '<citekey>-*.pdf'. When
finding a PDF for a citekey, complete read to deterimine which file to
open.
-rw-r--r-- | bog-todo.org | 3 | ||||
-rw-r--r-- | bog.el | 23 |
2 files changed, 21 insertions, 5 deletions
diff --git a/bog-todo.org b/bog-todo.org index ec72a62..f4b047f 100644 --- a/bog-todo.org +++ b/bog-todo.org @@ -64,7 +64,8 @@ Avoid filtering all bib file names. * PDF files -** ENH Better handling of multiple PDFs +** DONE Better handling of multiple PDFs + CLOSED: [2014-03-04 Tue 00:49] If multiple PDFs for a citekey, complete read. @@ -243,10 +243,25 @@ text under point if it matches `bog-citekey-format' or using (bog-open-citekey-pdf citekey))) (defun bog-open-citekey-pdf (citekey) - (let ((pdf-file (bog-citekey-as-pdf citekey))) - (unless (file-exists-p pdf-file) - (error "%s does not exist" pdf-file)) - (start-process "bog-pdf" nil bog-pdf-opener pdf-file))) + (let* (citekey-pdf + (citekey-pdfs + (--mapcat (file-expand-wildcards + (concat (file-name-as-directory bog-pdf-directory) + citekey it ".pdf")) + '("" "-*"))) + (choices (-map 'file-name-nondirectory citekey-pdfs)) + (num-choices (length choices))) + (cond + ((= 0 num-choices) + (error "No PDF found for %s" citekey)) + ((= 1 num-choices) + (setq citekey-pdf (car citekey-pdfs))) + (t + (setq citekey-pdf + (expand-file-name (funcall bog-completing-read + "Select PDF file: " choices) + bog-pdf-directory)))) + (start-process "bog-pdf" nil bog-pdf-opener citekey-pdf))) ;;;###autoload (defun bog-rename-staged-pdf-to-citekey () |