summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-02-02 23:54:49 -0500
committerKyle Meyer <kyle@kyleam.com>2014-02-03 00:50:18 -0500
commit96e5ef57785a05d9a7b618ac4985fbcea53344d7 (patch)
tree3947dd3312f84c99a1b1bf0f3def8ea0a342123b
parentba4e43b1c4693635d83072d9e67f4eb4ea7f76d7 (diff)
downloadbog-96e5ef57785a05d9a7b618ac4985fbcea53344d7.tar.gz
Add function to find citekey bib
-rw-r--r--bog.el37
1 files changed, 37 insertions, 0 deletions
diff --git a/bog.el b/bog.el
index 6eb3b27..9e4cea4 100644
--- a/bog.el
+++ b/bog.el
@@ -58,6 +58,12 @@ rename."
:group 'bog
:type 'string)
+(defcustom bog-bib-directory
+ (expand-file-name "bibs" bog-notes-directory)
+ "The name of the directory that BibTeX 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
@@ -202,6 +208,37 @@ matches `bog-citekey-format'."
(file-name-as-directory bog-pdf-directory)
"*.pdf"))))
+
+;;; BibTeX-related
+
+;;;###autoload
+(defun bog-find-citekey-bib (arg)
+ "Open BibTeX 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-bib
+ '(lambda () (bog-select-citekey (bog-bib-citekeys)))
+ arg))
+
+(defun bog-open-citekey-bib (citekey)
+ (let ((bib-file (bog-citekey-as-bib citekey)))
+ (unless (file-exists-p bib-file)
+ (error "%s does not exist" bib-file))
+ (find-file-other-window bib-file)))
+
+(defun bog-citekey-as-bib (citekey)
+ (expand-file-name (concat citekey ".bib") bog-bib-directory))
+
+(defun bog-bib-citekeys ()
+ "Return a list citekeys for all BibTeX files in `bog-bib-directory'."
+ (-map 'file-name-base
+ (file-expand-wildcards (concat
+ (file-name-as-directory bog-bib-directory)
+ "*.bib"))))
+
(provide 'bog)
;; bog.el ends here