summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--bog-tests.el8
-rw-r--r--bog-todo2
-rw-r--r--bog.el52
4 files changed, 30 insertions, 35 deletions
diff --git a/NEWS b/NEWS
index c11a25c..2052161 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,9 @@
- New command =bog-list-orphan-citekeys= finds citekeys that are
referred to in the notes but don't have their own heading.
+- =bog-create-combined-bib= now supports collecting citekeys from
+ marked files in a Dired buffer.
+
** Other changes
- =bog-goto-citekey-heading-in-buffer= and
diff --git a/bog-tests.el b/bog-tests.el
index c454da7..0532fc9 100644
--- a/bog-tests.el
+++ b/bog-tests.el
@@ -433,14 +433,6 @@ some text"
(kill-buffer new-buffer)
(delete-file new-file)))))
-;; `bog-collect-references'
-
-(ert-deftest bog-collect-unique-references ()
- (with-temp-buffer
- (insert "abc1900word\nhij2000word\nefg1800word\n")
- (should (equal (bog-collect-unique-references)
- '("abc1900word" "efg1800word" "hij2000word")))))
-
;; `bog-sort-topic-headings-in-buffer'
(ert-deftest bog-sort-topic-headings-in-buffer ()
diff --git a/bog-todo b/bog-todo
index 7309776..452f302 100644
--- a/bog-todo
+++ b/bog-todo
@@ -40,7 +40,7 @@ as a heading, not a property.
* BibTeX files
-** ENH Create combined bib from a suffix glob
+** DONE Create combined bib from a suffix glob
For documents generated from multiple files
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."