summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el18
1 files changed, 10 insertions, 8 deletions
diff --git a/bog.el b/bog.el
index d3f6f92..15ece92 100644
--- a/bog.el
+++ b/bog.el
@@ -529,7 +529,7 @@ one entry per BibTeX file."
"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-references))))
+ (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
@@ -539,18 +539,20 @@ one entry per BibTeX file."
(bibtex-mode)
(goto-char (point-min))))
-(defun bog-collect-references (&optional no-sort)
+(defun bog-collect-unique-references ()
"Return names in buffer that match `bog-citekey-format'.
-If NO-SORT, citekeys are returned in reverse order that they
-occur in buffer instead of alphabetical order."
+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)
(save-excursion
(goto-char (point-min))
(while (re-search-forward bog-citekey-format nil t)
- (add-to-list 'refs (match-string-no-properties 0)))
- (if no-sort
- refs
- (--sort (string-lessp it other) refs)))))
+ (push (match-string-no-properties 0) refs))
+ refs)))
(defun bog-citekey-as-bib (citekey)
(expand-file-name (concat citekey ".bib") bog-bib-directory))