From dc7806b748effca4ea57a165df0fff33b1f83ef3 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 7 Feb 2014 01:23:35 -0500 Subject: ENH: Make compatible with single BibTeX file --- README.org | 14 ++++++++------ bog-todo.org | 3 ++- bog.el | 32 +++++++++++++++++++++++++++++--- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/README.org b/README.org index ba2dc9c..110632d 100644 --- a/README.org +++ b/README.org @@ -98,13 +98,15 @@ heading that is a study. ** Opening a BibTeX file -All BibTeX files are kept in a single directory and are named as -.bib. The function =bog-find-citekey-bib= will open the BibTeX -file associated with a citekey. The citekey is obtained in the same way -as the [[Opening a PDF file][PDF citekey]]. +The function =bog-find-citekey-bib= will open the BibTeX entry +associated with a citekey. -Although I prefer the above setup, using a single for all entries is -more common, so I plan to add support for this (see [[./bog-todo.org][bog-todo.org]]). +The citekey is obtained in the same way as the [[Opening%20a%20PDF%20file][PDF citekey]]. + +BibTeX entries can be stored in one of two ways: + +1. As a single file with many entries +2. As single-entry files named .bib within a common directory ** Searching citekey on the web diff --git a/bog-todo.org b/bog-todo.org index 067f3a7..fd4a0ae 100644 --- a/bog-todo.org +++ b/bog-todo.org @@ -45,7 +45,8 @@ Redefine org refile targets. * BibTeX files -** ENH [#A] Make `bog-find-citekey-bib' compatible with a single BibTeX file +** DONE [#A] Make `bog-find-citekey-bib' compatible with a single BibTeX file + CLOSED: [2014-02-07 Fri 01:16] ** ENH Create combined bib from a suffix glob diff --git a/bog.el b/bog.el index 14777bc..596a65b 100644 --- a/bog.el +++ b/bog.el @@ -88,9 +88,29 @@ rename." :group 'bog :type 'string) +(defcustom bog-find-citekey-bib-func 'bog-find-citekey-bib-file + "Function used to find BibTeX entry for citekey. + +Default is `bog-find-citekey-bib-file' that locates single entry +BibTeX files in `bog-bib-directory'. + +The other option is `bog-find-citekey-entry' that searches within +a single BibTeX file, `bog-bib-file', for the citekey entry." + :group 'bog + :type 'function) + (defcustom bog-bib-directory (expand-file-name "bibs" bog-notes-directory) - "The name of the directory that BibTeX files are stored in." + "The name of the directory that BibTeX files are stored in. +This is only meaningful if `bog-find-citekey-bib-func' set to +`bog-find-citekey-bib-file'." + :group 'bog + :type 'string) + +(defcustom bog-bib-file nil + "BibTeX file name. +This is only meaningful if `bog-find-citekey-bib-func' set to +`bog-find-citekey-entry'." :group 'bog :type 'string) @@ -273,16 +293,22 @@ available citekeys. Otherwise, the citekey will be taken from the text under point if it matches `bog-citekey-format' or using `bog-citekey-func'." (interactive "P") - (bog-citekey-action 'bog-open-citekey-bib + (bog-citekey-action bog-find-citekey-bib-func '(lambda () (bog-select-citekey (bog-bib-citekeys))) arg)) -(defun bog-open-citekey-bib (citekey) +(defun bog-find-citekey-bib-file (citekey) + "Open BibTeX file of CITEKEY contained in `bog-bib-directory'." (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-find-citekey-entry (citekey) + "Search for CITEKEY in `bog-bib-file'." + (find-file-other-window bog-bib-file) + (bibtex-search-entry citekey)) + ;;;###autoload (defun bog-rename-and-clean-new-bib-files () "Prepare new BibTeX files. -- cgit v1.2.3