diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-03-14 00:36:01 -0400 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-03-14 01:04:50 -0400 |
commit | b08b66f33ea11c9d6218cd26f7a636d972a7b0f2 (patch) | |
tree | 289501d7451439fc3d217b405fc369194b6ed3cb | |
parent | be0c58a1dcdf78b636b1115b0bf4e867d289c222 (diff) | |
download | bog-b08b66f33ea11c9d6218cd26f7a636d972a7b0f2.tar.gz |
ENH: Allow customization of PDF file separator
-rw-r--r-- | bog-tests.el | 14 | ||||
-rw-r--r-- | bog.el | 20 |
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 @@ -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. |