diff options
author | Kyle Meyer <kyle@kyleam.com> | 2015-02-19 22:59:16 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2015-02-19 22:59:16 -0500 |
commit | 14a34a626b6684cce34d25800df4bd9765794376 (patch) | |
tree | 4a9b9b789f8ff84f0d43410e6469012ff061c7b2 /bog.el | |
parent | 13ed41952162b0bb1ecd9217df2260f98d1b61d6 (diff) | |
download | bog-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.
Diffstat (limited to 'bog.el')
-rw-r--r-- | bog.el | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -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) |