;;;; citation.el -- show what is cited here ;;; Time-stamp: <2005-03-10 12:06:31 john> ;; This program is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by the ;; Free Software Foundation; either version 2 of the License, or (at your ;; option) any later version. ;; This program is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License along ;; with this program; if not, write to the Free Software Foundation, Inc., ;; 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA (provide 'citation) (defvar buffer-bibliographies nil "The bibliographies for the current buffer.") (make-variable-buffer-local 'buffer-bibliographies) (defun buffer-bibliographies () "Return the bibliography filenames for the current buffer." (if buffer-bibliographies buffer-bibliographies (setq buffer-bibliographies (save-excursion (goto-char (point-min)) (if (re-search-forward "\\\\bibliography{\\([^}]+\\)}" (point-max) t) (let ((names-string (match-string-no-properties 1))) (mapcar (lambda (name) (expand-file-name (concat name ".bib"))) (split-string names-string ","))) nil))))) ;;;###autoload (defun show-citation () "Show the citation at or before point. Return whether it was found." ;; done: make sure it works with multiple bibliographis ;; done: bury the bibliography buffer if it did not contain target (interactive) (let ((window (selected-window)) (citation (save-excursion (if (and (search-backward "\\") (looking-at "\\\\cite{\\([^}]+\\)}")) (match-string-no-properties 1) nil))) (bibliographies (buffer-bibliographies))) (if citation (let ((result (catch 'found (mapcar (lambda (bibliography) (if (and bibliography (file-readable-p bibliography)) (progn (find-file-other-window bibliography) (let ((found (save-excursion (goto-char (point-min)) (re-search-forward (concat "@[a-z]+{" citation ",") (point-max) t)))) (if found (progn (goto-char found) (throw 'found found)) (bury-buffer)))) nil)) bibliographies) nil))) (select-window window) result) nil))) ;;; end of citation.el