aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2003-05-13 20:39:27 +0000
committerStefan Monnier2003-05-13 20:39:27 +0000
commitcc311d2bbb82175d36ecb8b8103261b00e9ee0f6 (patch)
treee6139d4fdd0fd0365ca21bdfb0de5a66b71c9968
parentc64a682caf00ec84b5f490c15cc255fadf2929b0 (diff)
downloademacs-cc311d2bbb82175d36ecb8b8103261b00e9ee0f6.tar.gz
emacs-cc311d2bbb82175d36ecb8b8103261b00e9ee0f6.zip
(reftex-extract-bib-entries, reftex-extract-bib-entries-from-thebibliography):
New arg re-list. (reftex-extract-bib-entries): Use ^ rather than \(\`\|[\n\r]\). Use member-ignore-case. Don't add unnecessary trailing \n. (reftex-offer-bib-menu): Consolidate duplicated code from reftex-extract-bib-entries and reftex-extract-bib-entries-from-thebibliography.
-rw-r--r--lisp/textmodes/reftex-cite.el107
1 files changed, 40 insertions, 67 deletions
diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el
index 3a71ad2117e..acd33f3d62a 100644
--- a/lisp/textmodes/reftex-cite.el
+++ b/lisp/textmodes/reftex-cite.el
@@ -1,5 +1,5 @@
1;;; reftex-cite.el --- creating citations with RefTeX 1;;; reftex-cite.el --- creating citations with RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.18 5;; Version: 4.18
@@ -177,39 +177,15 @@
177 177
178;; Parse bibtex buffers 178;; Parse bibtex buffers
179 179
180(defun reftex-extract-bib-entries (buffers) 180(defun reftex-extract-bib-entries (buffers re-list)
181 ;; Extract bib entries which match regexps from BUFFERS. 181 ;; Extract bib entries which match regexps from BUFFERS.
182 ;; BUFFERS is a list of buffers or file names. 182 ;; BUFFERS is a list of buffers or file names.
183 ;; Return list with entries." 183 ;; Return list with entries."
184 (let* (re-list first-re rest-re 184 (let* ((buffer-list (if (listp buffers) buffers (list buffers)))
185 (buffer-list (if (listp buffers) buffers (list buffers))) 185 (first-re (car re-list)) ; We'll use the first re to find things,
186 found-list entry buffer1 buffer alist 186 (rest-re (cdr re-list)) ; the others to narrow down.
187 key-point start-point end-point default) 187 found-list entry buffer1 buffer alist
188 188 key-point start-point end-point default)
189 ;; Read a regexp, completing on known citation keys.
190 (setq default (regexp-quote (reftex-get-bibkey-default)))
191 (setq re-list
192 (split-string
193 (completing-read
194 (concat
195 "Regex { && Regex...}: "
196 "[" default "]: ")
197 (if reftex-mode
198 (if (fboundp 'LaTeX-bibitem-list)
199 (LaTeX-bibitem-list)
200 (cdr (assoc 'bibview-cache
201 (symbol-value reftex-docstruct-symbol))))
202 nil)
203 nil nil nil 'reftex-cite-regexp-hist)
204 "[ \t]*&&[ \t]*"))
205
206 (if (or (null re-list ) (equal re-list '("")))
207 (setq re-list (list default)))
208
209 (setq first-re (car re-list) ; We'll use the first re to find things,
210 rest-re (cdr re-list)) ; the others to narrow down.
211 (if (string-match "\\`[ \t]*\\'" (or first-re ""))
212 (error "Empty regular expression"))
213 189
214 (save-excursion 190 (save-excursion
215 (save-window-excursion 191 (save-window-excursion
@@ -235,7 +211,7 @@
235 (catch 'search-again 211 (catch 'search-again
236 (setq key-point (point)) 212 (setq key-point (point))
237 (unless (re-search-backward 213 (unless (re-search-backward
238 "\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t) 214 "^[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t)
239 (throw 'search-again nil)) 215 (throw 'search-again nil))
240 (setq start-point (point)) 216 (setq start-point (point))
241 (goto-char (match-end 0)) 217 (goto-char (match-end 0))
@@ -247,17 +223,15 @@
247 223
248 ;; Ignore @string, @comment and @c entries or things 224 ;; Ignore @string, @comment and @c entries or things
249 ;; outside entries 225 ;; outside entries
250 (when (or (string= (downcase (match-string 2)) "string") 226 (when (or (member-ignore-case (match-string 1)
251 (string= (downcase (match-string 2)) "comment") 227 '("string" "comment" "c"))
252 (string= (downcase (match-string 2)) "c")
253 (< (point) key-point)) ; this means match not in {} 228 (< (point) key-point)) ; this means match not in {}
254 (goto-char key-point) 229 (goto-char key-point)
255 (throw 'search-again nil)) 230 (throw 'search-again nil))
256 231
257 ;; Well, we have got a match 232 ;; Well, we have got a match
258 (setq entry (concat 233 (setq entry (buffer-substring start-point (point)))
259 (buffer-substring start-point (point)) "\n")) 234
260
261 ;; Check if other regexp match as well 235 ;; Check if other regexp match as well
262 (setq re-list rest-re) 236 (setq re-list rest-re)
263 (while re-list 237 (while re-list
@@ -336,12 +310,12 @@
336 nil))))) 310 nil)))))
337 311
338;; Parse the bibliography environment 312;; Parse the bibliography environment
339(defun reftex-extract-bib-entries-from-thebibliography (files) 313(defun reftex-extract-bib-entries-from-thebibliography (files re-list)
340 ;; Extract bib-entries from the \begin{thebibliography} environment. 314 ;; Extract bib-entries from the \begin{thebibliography} environment.
341 ;; Parsing is not as good as for the BibTeX database stuff. 315 ;; Parsing is not as good as for the BibTeX database stuff.
342 ;; The environment should be located in file FILE. 316 ;; The environment should be located in file FILE.
343 317
344 (let* (start end buf entries re re-list file default) 318 (let* (start end buf entries re file default)
345 (unless files 319 (unless files
346 (error "Need file name to find thebibliography environment")) 320 (error "Need file name to find thebibliography environment"))
347 (while (setq file (pop files)) 321 (while (setq file (pop files))
@@ -377,29 +351,6 @@
377 (unless entries 351 (unless entries
378 (error "No bibitems found")) 352 (error "No bibitems found"))
379 353
380 ;; Read a regexp, completing on known citation keys.
381 (setq default (regexp-quote (reftex-get-bibkey-default)))
382 (setq re-list
383 (split-string
384 (completing-read
385 (concat
386 "Regex { && Regex...}: "
387 "[" default "]: ")
388 (if reftex-mode
389 (if (fboundp 'LaTeX-bibitem-list)
390 (LaTeX-bibitem-list)
391 (cdr (assoc 'bibview-cache
392 (symbol-value reftex-docstruct-symbol))))
393 nil)
394 nil nil nil 'reftex-cite-regexp-hist)
395 "[ \t]*&&[ \t]*"))
396
397 (if (or (null re-list ) (equal re-list '("")))
398 (setq re-list (list default)))
399
400 (if (string-match "\\`[ \t]*\\'" (car re-list))
401 (error "Empty regular expression"))
402
403 (while (and (setq re (pop re-list)) entries) 354 (while (and (setq re (pop re-list)) entries)
404 (setq entries 355 (setq entries
405 (delq nil (mapcar 356 (delq nil (mapcar
@@ -757,17 +708,37 @@ While entering the regexp, completion on knows citation keys is possible.
757 ;; Offer bib menu and return list of selected items 708 ;; Offer bib menu and return list of selected items
758 709
759 (let ((bibtype (reftex-bib-or-thebib)) 710 (let ((bibtype (reftex-bib-or-thebib))
760 found-list rtn key data selected-entries) 711 found-list rtn key data selected-entries re-list)
761 (while 712 (while
762 (not 713 (not
763 (catch 'done 714 (catch 'done
715 ;; Get the search regexps, completing on known citation keys.
716 (setq re-list
717 (let ((default (regexp-quote (reftex-get-bibkey-default))))
718 (split-string
719 (completing-read
720 (concat
721 "Regex { && Regex...}: "
722 "[" default "]: ")
723 (if reftex-mode
724 (if (fboundp 'LaTeX-bibitem-list)
725 (LaTeX-bibitem-list)
726 (cdr (assoc 'bibview-cache
727 (symbol-value reftex-docstruct-symbol))))
728 nil)
729 nil nil nil 'reftex-cite-regexp-hist default)
730 "[ \t]*&&[ \t]*")))
731
732 (if (string-match "\\`[ \t]*\\'" (car re-list))
733 (error "Empty regular expression"))
734
764 ;; Scan bibtex files 735 ;; Scan bibtex files
765 (setq found-list 736 (setq found-list
766 (cond 737 (cond
767 ((eq bibtype 'bib) 738 ((eq bibtype 'bib)
768; ((assq 'bib (symbol-value reftex-docstruct-symbol)) 739; ((assq 'bib (symbol-value reftex-docstruct-symbol))
769 ;; using BibTeX database files. 740 ;; using BibTeX database files.
770 (reftex-extract-bib-entries (reftex-get-bibfile-list))) 741 (reftex-extract-bib-entries (reftex-get-bibfile-list) re-list))
771 ((eq bibtype 'thebib) 742 ((eq bibtype 'thebib)
772; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) 743; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
773 ;; using thebibliography environment. 744 ;; using thebibliography environment.
@@ -775,10 +746,12 @@ While entering the regexp, completion on knows citation keys is possible.
775 (reftex-uniquify 746 (reftex-uniquify
776 (mapcar 'cdr 747 (mapcar 'cdr
777 (reftex-all-assq 748 (reftex-all-assq
778 'thebib (symbol-value reftex-docstruct-symbol)))))) 749 'thebib (symbol-value reftex-docstruct-symbol))))
750 re-list))
779 (reftex-default-bibliography 751 (reftex-default-bibliography
780 (message "Using default bibliography") 752 (message "Using default bibliography")
781 (reftex-extract-bib-entries (reftex-default-bibliography))) 753 (reftex-extract-bib-entries (reftex-default-bibliography)
754 re-list))
782 (t (error "No valid bibliography in this document, and no default available")))) 755 (t (error "No valid bibliography in this document, and no default available"))))
783 756
784 (unless found-list 757 (unless found-list