summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-02-19 22:59:16 -0500
committerKyle Meyer <kyle@kyleam.com>2015-02-19 22:59:16 -0500
commit14a34a626b6684cce34d25800df4bd9765794376 (patch)
tree4a9b9b789f8ff84f0d43410e6469012ff061c7b2
parent13ed41952162b0bb1ecd9217df2260f98d1b61d6 (diff)
downloadbog-14a34a626b6684cce34d25800df4bd9765794376.tar.gz
Rewrite bog-create-combined-bib
- Add numerical argument to pass to dired-get-marked-files. - Expand docstring. - When missing citekey bib, prompt with citekey instead of file name.
-rw-r--r--bog.el32
1 files changed, 17 insertions, 15 deletions
diff --git a/bog.el b/bog.el
index d71ef14..59e5860 100644
--- a/bog.el
+++ b/bog.el
@@ -678,30 +678,32 @@ one entry per BibTeX file."
(delete-file file)))
;;;###autoload
-(defun bog-create-combined-bib ()
- "Create buffer that has entries for all citekeys in buffer."
- (interactive)
+(defun bog-create-combined-bib (&optional arg)
+ "Create buffer that has entries for all citekeys in buffer.
+If in Dired, collect citekeys from marked (or next ARG) files.
+Otherwise, collect citekeys the current buffer."
+ (interactive "p")
+ (setq arg (and current-prefix-arg arg))
(let ((bib-buffer-name "*Bog combined bib*")
citekeys
- bib-files)
+ bib-citekeys)
(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
+ (-distinct (-mapcat #'bog-citekeys-in-file
+ (dired-get-marked-files nil arg))))
(setq citekeys (bog-citekeys-in-buffer)))
- (setq bib-files
- (-map #'bog-citekey-as-bib
- (-distinct (sort citekeys #'string-lessp))))
+ (setq bib-citekeys (-annotate #'bog-citekey-as-bib
+ (sort citekeys #'string-lessp)))
(with-current-buffer (get-buffer-create bib-buffer-name)
(erase-buffer)
- (--each bib-files
+ (dolist (bib-citekey bib-citekeys)
(cond
- ((file-exists-p it)
+ ((file-exists-p (car bib-citekey))
(insert "\n")
- (insert-file-contents it)
+ (insert-file-contents (car bib-citekey))
(goto-char (point-max)))
- ((not (y-or-n-p (format "%s does not exist. Skip it?" it)))
+ ((not (y-or-n-p (format "No BibTeX entry found for %s. Skip it?"
+ (cdr bib-citekey))))
(kill-buffer bib-buffer-name)
(user-error "Aborting"))))
(bibtex-mode)