From 14a34a626b6684cce34d25800df4bd9765794376 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Thu, 19 Feb 2015 22:59:16 -0500 Subject: 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. --- bog.el | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'bog.el') 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) -- cgit v1.2.3