summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-02-02 23:53:05 -0500
committerKyle Meyer <kyle@kyleam.com>2014-02-03 00:50:13 -0500
commitd90c0d8417fcc8dc93a5745825be7af3fec8e905 (patch)
treecae7fe67979807e6825a3938821cf8bcdceb305a /bog.el
parent2626b234016d3a826dde5b11c321512c98e12214 (diff)
downloadbog-d90c0d8417fcc8dc93a5745825be7af3fec8e905.tar.gz
Add function to find citekey PDF
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el43
1 files changed, 43 insertions, 0 deletions
diff --git a/bog.el b/bog.el
index 971b811..aa52749 100644
--- a/bog.el
+++ b/bog.el
@@ -44,6 +44,12 @@
:group 'bog
:type 'string)
+(defcustom bog-pdf-directory
+ (expand-file-name "pdfs" bog-notes-directory)
+ "The name of the directory that PDF files are stored in."
+ :group 'bog
+ :type 'string)
+
(defcustom bog-read-file-name 'read-file-name
"A function that will be used to promtp for file name.
The function should accept one arguments, a string to use for the
@@ -59,6 +65,11 @@ alternative is `ido-completing-read'."
:group 'bog
:type 'function)
+(defcustom bog-pdf-opener "xdg-open"
+ "Program to open PDF files with."
+ :group 'bog
+ :type 'string)
+
(defcustom bog-citekey-format
"\\([0-9]*[a-z]+[-a-z]*\\)\\([0-9]\\{4\\}\\)\\([a-z]+\\)"
"Regex used to match study citekey.
@@ -121,6 +132,38 @@ ACTION will be called with the resulting citekey as an argument."
(when (equal (length text) (match-end 0))
t))
+
+;;; PDF-related
+
+;;;###autoload
+(defun bog-find-citekey-pdf (arg)
+ "Open PDF file for a citekey.
+If a prefix argument is given, a prompt will open to select from
+available citekeys. Otherwise, the citekey will be taken from the
+text under point if it matches `bog-citekey-format' or from the
+first parent heading that matches `bog-citekey-format'."
+ (interactive "P")
+ (bog-citekey-action 'bog-open-citekey-pdf
+ '(lambda () (bog-select-citekey (bog-pdf-citekeys)))
+ arg))
+
+(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)))
+
+(defun bog-citekey-as-pdf (citekey)
+ (expand-file-name (concat citekey ".pdf") bog-pdf-directory))
+
+(defun bog-pdf-citekeys ()
+ "Return a list citekeys for all pdf files in
+`bog-pdf-directory'."
+ (-map 'file-name-base
+ (file-expand-wildcards (concat
+ (file-name-as-directory bog-pdf-directory)
+ "*.pdf"))))
+
(provide 'bog)
;; bog.el ends here