X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/b03f96dc5a6651d1dc84b81b2a15cad6908b9809..77ab81d0545e980c57c0a35510ade29a9e43b4cd:/lisp/textmodes/reftex-cite.el diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el index e160db307d..19663f81bd 100644 --- a/lisp/textmodes/reftex-cite.el +++ b/lisp/textmodes/reftex-cite.el @@ -1,18 +1,19 @@ ;;; reftex-cite.el --- creating citations with RefTeX ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, -;; 2006, 2007, 2008 Free Software Foundation, Inc. +;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. ;; Author: Carsten Dominik ;; Maintainer: auctex-devel@gnu.org ;; Version: 4.31 +;; Package: reftex ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs 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 3, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,9 +21,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -358,29 +357,31 @@ (error "No such file %s" file)) (message "Scanning thebibliography environment in %s" file) - (save-excursion - (set-buffer buf) - (save-restriction - (widen) - (goto-char (point-min)) - (while (re-search-forward - "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) - (beginning-of-line 2) - (setq start (point)) - (if (re-search-forward - "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t) - (progn - (beginning-of-line 1) - (setq end (point)))) - (when (and start end) - (setq entries - (append entries - (mapcar 'reftex-parse-bibitem - (delete "" - (split-string - (buffer-substring-no-properties start end) - "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*")))))) - (goto-char end))))) + (with-current-buffer buf + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (while (re-search-forward + "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) + (beginning-of-line 2) + (setq start (point)) + (if (re-search-forward + "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t) + (progn + (beginning-of-line 1) + (setq end (point)))) + (when (and start end) + (setq entries + (append entries + (mapcar 'reftex-parse-bibitem + (delete "" + (split-string + (buffer-substring-no-properties + start end) + "[ \t\n\r]*\\\\bibitem[ \t]*\ +\\(\\[[^]]*]\\)*\[ \t]*")))))) + (goto-char end)))))) (unless entries (error "No bibitems found")) @@ -687,7 +688,7 @@ While entering the regexp, completion on knows citation keys is possible. ;; it has to go. If there is only a single arg and empty, it can go ;; as well. (when reftex-cite-cleanup-optional-args - (cond + (cond ((string-match "\\([a-zA-Z0-9]\\)\\[\\]{" string) (setq string (replace-match "\\1{" nil nil string))) ((string-match "\\[\\]\\(\\[[a-zA-Z0-9., ]+\\]\\)" string) @@ -726,7 +727,7 @@ While entering the regexp, completion on knows citation keys is possible. (decf arg) (reftex-do-citation arg)) (forward-char 1))) - + ;; Return the citation key (car (car selected-entries)))) @@ -740,7 +741,7 @@ While entering the regexp, completion on knows citation keys is possible. (no-insert ;; Format does not really matter because nothing will be inserted. (setq format "%l")) - + ((and (stringp macro) (string-match "\\`\\\\cite\\|cite\\'" macro)) ;; We are already inside a cite macro @@ -761,7 +762,7 @@ While entering the regexp, completion on knows citation keys is possible. (when (listp format) (setq key (or format-key - (reftex-select-with-char + (reftex-select-with-char "" (concat "SELECT A CITATION FORMAT\n\n" (mapconcat (lambda (x) @@ -790,8 +791,8 @@ While entering the regexp, completion on knows citation keys is possible. (let ((bibtype (reftex-bib-or-thebib)) found-list rtn key data selected-entries) - (while - (not + (while + (not (catch 'done ;; Scan bibtex files (setq found-list @@ -806,31 +807,30 @@ While entering the regexp, completion on knows citation keys is possible. (reftex-extract-bib-entries-from-thebibliography (reftex-uniquify (mapcar 'cdr - (reftex-all-assq + (reftex-all-assq 'thebib (symbol-value reftex-docstruct-symbol)))))) (reftex-default-bibliography (message "Using default bibliography") (reftex-extract-bib-entries (reftex-default-bibliography))) (t (error "No valid bibliography in this document, and no default available")))) - + (unless found-list (error "Sorry, no matches found")) - + ;; Remember where we came from (setq reftex-call-back-to-this-buffer (current-buffer)) (set-marker reftex-select-return-marker (point)) - + ;; Offer selection (save-window-excursion (delete-other-windows) - (let ((default-major-mode 'reftex-select-bib-mode)) - (reftex-kill-buffer "*RefTeX Select*") - (switch-to-buffer-other-window "*RefTeX Select*") - (unless (eq major-mode 'reftex-select-bib-mode) - (reftex-select-bib-mode)) - (let ((buffer-read-only nil)) - (erase-buffer) - (reftex-insert-bib-matches found-list))) + (reftex-kill-buffer "*RefTeX Select*") + (switch-to-buffer-other-window "*RefTeX Select*") + (unless (eq major-mode 'reftex-select-bib-mode) + (reftex-select-bib-mode)) + (let ((buffer-read-only nil)) + (erase-buffer) + (reftex-insert-bib-matches found-list)) (setq buffer-read-only t) (if (= 0 (buffer-size)) (error "No matches found")) @@ -860,15 +860,15 @@ While entering the regexp, completion on knows citation keys is possible. (goto-char 1)) ((eq key ?A) ;; Take all (marked) - (setq selected-entries + (setq selected-entries (if reftex-select-marked (mapcar 'car (nreverse reftex-select-marked)) found-list)) (throw 'done t)) ((eq key ?a) ;; Take all (marked), and push the symbol 'concat - (setq selected-entries - (cons 'concat + (setq selected-entries + (cons 'concat (if reftex-select-marked (mapcar 'car (nreverse reftex-select-marked)) found-list))) @@ -887,9 +887,9 @@ While entering the regexp, completion on knows citation keys is possible. ((or (eq key ?\C-m) (eq key 'return)) ;; Take selected - (setq selected-entries + (setq selected-entries (if reftex-select-marked - (cons 'concat + (cons 'concat (mapcar 'car (nreverse reftex-select-marked))) (if data (list data) nil))) (throw 'done t)) @@ -929,7 +929,7 @@ While entering the regexp, completion on knows citation keys is possible. (let ((file (read-file-name "File to create: "))) (find-file-other-window file) (if (> (buffer-size) 0) - (unless (yes-or-no-p + (unless (yes-or-no-p (format "Overwrite non-empty file %s? " file)) (error "Abort"))) (erase-buffer) @@ -1049,7 +1049,7 @@ While entering the regexp, completion on knows citation keys is possible. (defun reftex-make-cite-echo-string (entry docstruct-symbol) ;; Format a bibtex entry for the echo area and cache the result. (let* ((key (reftex-get-bib-field "&key" entry)) - (string + (string (let* ((reftex-cite-punctuation '(" " " & " " etal."))) (reftex-format-citation entry reftex-cite-view-format))) (cache (assq 'bibview-cache (symbol-value docstruct-symbol))) @@ -1079,8 +1079,7 @@ While entering the regexp, completion on knows citation keys is possible. bibfile-list item bibtype) (catch 'exit - (save-excursion - (set-buffer reftex-call-back-to-this-buffer) + (with-current-buffer reftex-call-back-to-this-buffer (setq bibtype (reftex-bib-or-thebib)) (cond ((eq bibtype 'bib) @@ -1091,7 +1090,7 @@ While entering the regexp, completion on knows citation keys is possible. (setq bibfile-list (reftex-uniquify (mapcar 'cdr - (reftex-all-assq + (reftex-all-assq 'thebib (symbol-value reftex-docstruct-symbol)))) item t)) (reftex-default-bibliography @@ -1102,17 +1101,17 @@ While entering the regexp, completion on knows citation keys is possible. (setq bibfile-list (reftex-visited-files bibfile-list))) (condition-case nil - (reftex-pop-to-bibtex-entry + (reftex-pop-to-bibtex-entry key bibfile-list (not reftex-keep-temporary-buffers) t item) (error (ding)))) - + (select-window win))) ;;; Global BibTeX file (defun reftex-all-used-citation-keys () (reftex-access-scan-info) (let ((files (reftex-all-document-files)) file keys kk k) - (save-excursion + (save-current-buffer (while (setq file (pop files)) (set-buffer (reftex-get-file-buffer-force file 'mark)) (save-excursion @@ -1134,13 +1133,13 @@ While entering the regexp, completion on knows citation keys is possible. "Create a new BibTeX database file with all entries referenced in document. The command prompts for a filename and writes the collected entries to that file. Only entries referenced in the current document with -any \\cite-like macros are used. +any \\cite-like macros are used. The sequence in the new file is the same as it was in the old database." (interactive "FNew BibTeX file: ") (let ((keys (reftex-all-used-citation-keys)) (files (reftex-get-bibfile-list)) file key entries beg end entry) - (save-excursion + (save-current-buffer (while (setq file (pop files)) (set-buffer (reftex-get-file-buffer-force file 'mark)) (reftex-with-special-syntax-for-bib @@ -1148,9 +1147,8 @@ The sequence in the new file is the same as it was in the old database." (save-restriction (widen) (goto-char (point-min)) - (while (re-search-forward - "^[ \t]*@[a-zA-Z]+[ \t]*{\\([^ \t\r\n]+\\)," - nil t) + (while (re-search-forward "^[ \t]*@\\(?:\\w\\|\\s_\\)+[ \t\n\r]*\ +\[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t) (setq key (match-string 1) beg (match-beginning 0) end (progn @@ -1165,7 +1163,7 @@ The sequence in the new file is the same as it was in the old database." keys (delete key keys))))))))) (find-file-other-window bibfile) (if (> (buffer-size) 0) - (unless (yes-or-no-p + (unless (yes-or-no-p (format "Overwrite non-empty file %s? " bibfile)) (error "Abort"))) (erase-buffer) @@ -1176,5 +1174,5 @@ The sequence in the new file is the same as it was in the old database." (length entries)))) -;;; arch-tag: d53d0a5a-ab32-4b52-a846-2a7c3527cd89 +;; arch-tag: d53d0a5a-ab32-4b52-a846-2a7c3527cd89 ;;; reftex-cite.el ends here