summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bog-tests.el14
-rw-r--r--bog.el20
2 files changed, 29 insertions, 5 deletions
diff --git a/bog-tests.el b/bog-tests.el
index 506cd27..f83c3af 100644
--- a/bog-tests.el
+++ b/bog-tests.el
@@ -1,5 +1,6 @@
(require 'ert)
(require 'org)
+(require 'dash)
(require 'bog)
;; Modified from magit-tests.el.
@@ -169,6 +170,19 @@
(should-not (file-exists-p (expand-file-name
(concat "one.pdf") bog-pdf-directory))))))
+(ert-deftest bog-pdf-citekeys-multiple-variants ()
+ (bog-tests--with-temp-dir
+ (let* ((bog-pdf-directory (expand-file-name "pdfs"))
+ (citekey "name2010word")
+ (variants (--map (concat citekey it ".pdf")
+ '("" "_0" "-supplement")))
+ found-files)
+ (make-directory bog-pdf-directory)
+ (--each variants
+ (write-region "" nil (expand-file-name it bog-pdf-directory)))
+ (setq files-found (bog-citekey-pdfs citekey))
+ (should (= (length files-found) 3)))))
+
;;; BibTeX functions
diff --git a/bog.el b/bog.el
index 987087c..67af286 100644
--- a/bog.el
+++ b/bog.el
@@ -144,6 +144,12 @@ alternative is `ido-completing-read'."
:group 'bog
:type 'string)
+(defcustom bog-pdf-file-name-separators '("-" "_")
+ "Characters allowed to follow the citekey in PDF file names.
+When `bog-find-citekey-pdf' is run on <citekey>, it will find
+files with the format <citekey><sep>*.pdf, where <sep> is one of
+the characters in `bog-pdf-file-name-separators'.")
+
(defcustom bog-web-search-url
"http://scholar.google.com/scholar?q=%s"
"URL to use for CITEKEY search.
@@ -244,11 +250,7 @@ text under point if it matches `bog-citekey-format' or using
(defun bog-open-citekey-pdf (citekey)
(let* (citekey-pdf
- (citekey-pdfs
- (--mapcat (file-expand-wildcards
- (concat (file-name-as-directory bog-pdf-directory)
- citekey it ".pdf"))
- '("" "-*")))
+ (citekey-pdfs (bog-citekey-pdfs citekey))
(choices (-map 'file-name-nondirectory citekey-pdfs))
(num-choices (length choices)))
(cond
@@ -263,6 +265,14 @@ text under point if it matches `bog-citekey-format' or using
bog-pdf-directory))))
(start-process "bog-pdf" nil bog-pdf-opener citekey-pdf)))
+(defun bog-citekey-pdfs (citekey)
+ (let* ((patterns (--map (concat it "*") bog-pdf-file-name-separators))
+ (patterns (cons "" patterns)))
+ (--mapcat (file-expand-wildcards
+ (concat (file-name-as-directory bog-pdf-directory)
+ citekey it ".pdf"))
+ patterns)))
+
;;;###autoload
(defun bog-rename-staged-pdf-to-citekey ()
"Rename PDF in `bog-stage-directory' to `bog-pdf-directory'/<citekey>.pdf.