summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-12-13 01:10:06 -0500
committerKyle Meyer <kyle@kyleam.com>2014-12-13 01:10:06 -0500
commit248f8a8e81dc161401dc50a3a84ebe41abb23f07 (patch)
treea28cb569c7c01f09876e78406feae2f503f3139e /bog.el
parent447ac23d28fb7d5f2fc94a6924eb3f48a4243ab2 (diff)
downloadbog-248f8a8e81dc161401dc50a3a84ebe41abb23f07.tar.gz
Support creating combined bib from multiple files
Before, bog-create-combined-bib only collected citekeys from a single buffer. Extend it so that it also works with marked files in Dired. In addition - Rename combined bib buffer so that it includes "Bog" in the name. - Offer to skip missing bib files instead of failing. - Remove bog-collect-references and bog-collect-unique-references, which overlap with the newer bog-citekeys-in-buffer [1] and should have been removed when that function was added. [1] ce74785920d6234072eb2ebef63bd140a25534c2
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el52
1 files changed, 26 insertions, 26 deletions
diff --git a/bog.el b/bog.el
index 89bba91..6fce190 100644
--- a/bog.el
+++ b/bog.el
@@ -587,32 +587,32 @@ one entry per BibTeX file."
(defun bog-create-combined-bib ()
"Create buffer that has entries for all citekeys in buffer."
(interactive)
- (let ((bib-buffer (get-buffer-create "*Bib*"))
- (refs (-map 'bog-citekey-as-bib (bog-collect-unique-references))))
- (--each refs (unless (file-exists-p it) (user-error "%s does not exist" it)))
- (switch-to-buffer-other-window bib-buffer)
- (--each refs
- (insert "\n")
- (insert-file-contents it)
- (goto-char (point-max)))
- (bibtex-mode)
- (goto-char (point-min))))
-
-(defun bog-collect-unique-references ()
- "Return names in buffer that match `bog-citekey-format'.
-Duplicates are removed and the entries are sorted
-alphabetically."
- (-distinct (--sort (string-lessp it other) (bog-collect-references))))
-
-(defun bog-collect-references ()
- "Return names in buffer that match `bog-citekey-format'."
- (let (refs
- case-fold-search)
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward bog-citekey-format nil t)
- (push (match-string-no-properties 0) refs))
- refs)))
+ (let ((bib-buffer-name "*Bog combined bib*")
+ citekeys
+ bib-files)
+ (if (derived-mode-p 'dired-mode)
+ (--each (dired-get-marked-files)
+ (with-temp-buffer
+ (insert-file-contents it)
+ (setq citekeys (append (bog-citekeys-in-buffer) citekeys))))
+ (setq citekeys (bog-citekeys-in-buffer)))
+ (setq bib-files
+ (-map #'bog-citekey-as-bib
+ (-distinct (--sort (string-lessp it other) citekeys))))
+ (with-current-buffer (get-buffer-create bib-buffer-name)
+ (delete-region (point-min) (point-max))
+ (--each bib-files
+ (cond
+ ((file-exists-p it)
+ (insert "\n")
+ (insert-file-contents it)
+ (goto-char (point-max)))
+ ((not (y-or-n-p (format "%s does not exist. Skip it?" it)))
+ (kill-buffer bib-buffer)
+ (user-error "Aborting"))))
+ (bibtex-mode)
+ (goto-char (point-min)))
+ (switch-to-buffer-other-window bib-buffer-name)))
(defun bog-citekey-as-bib (citekey)
"Return file name `bog-bib-directory'/CITEKEY.bib."