comparison lisp/textmodes/reftex-cite.el @ 46683:060f433ebf11

Updated to RefTeX 4.18
author Carsten Dominik <dominik@science.uva.nl>
date Thu, 25 Jul 2002 07:03:41 +0000
parents 7522419c4db0
children 11e08f9901ea
comparison
equal deleted inserted replaced
46682:7a836df2d686 46683:060f433ebf11
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 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.17 5 ;; Version: 4.18
6 6
7 ;; This file is part of GNU Emacs. 7 ;; This file is part of GNU Emacs.
8 8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify 9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by 10 ;; it under the terms of the GNU General Public License as published by
162 ;; BUFFERS is a list of buffers or file names. 162 ;; BUFFERS is a list of buffers or file names.
163 ;; Return list with entries." 163 ;; Return list with entries."
164 (let* (re-list first-re rest-re 164 (let* (re-list first-re rest-re
165 (buffer-list (if (listp buffers) buffers (list buffers))) 165 (buffer-list (if (listp buffers) buffers (list buffers)))
166 found-list entry buffer1 buffer alist 166 found-list entry buffer1 buffer alist
167 key-point start-point end-point) 167 key-point start-point end-point default)
168 168
169 ;; Read a regexp, completing on known citation keys. 169 ;; Read a regexp, completing on known citation keys.
170 (setq default (regexp-quote (reftex-get-bibkey-default)))
170 (setq re-list 171 (setq re-list
171 (split-string 172 (split-string
172 (completing-read 173 (completing-read
173 "RegExp [ && RegExp...]: " 174 (concat
175 "Regex { && Regex...}: "
176 "[" default "]: ")
174 (if reftex-mode 177 (if reftex-mode
175 (if (fboundp 'LaTeX-bibitem-list) 178 (if (fboundp 'LaTeX-bibitem-list)
176 (LaTeX-bibitem-list) 179 (LaTeX-bibitem-list)
177 (cdr (assoc 'bibview-cache 180 (cdr (assoc 'bibview-cache
178 (symbol-value reftex-docstruct-symbol)))) 181 (symbol-value reftex-docstruct-symbol))))
179 nil) 182 nil)
180 nil nil nil 'reftex-cite-regexp-hist) 183 nil nil nil 'reftex-cite-regexp-hist)
181 "[ \t]*&&[ \t]*")) 184 "[ \t]*&&[ \t]*"))
185
186 (if (or (null re-list ) (equal re-list '("")))
187 (setq re-list (list default)))
182 188
183 (setq first-re (car re-list) ; We'll use the first re to find things, 189 (setq first-re (car re-list) ; We'll use the first re to find things,
184 rest-re (cdr re-list)) ; the others to narrow down. 190 rest-re (cdr re-list)) ; the others to narrow down.
185 (if (string-match "\\`[ \t]*\\'" (or first-re "")) 191 (if (string-match "\\`[ \t]*\\'" (or first-re ""))
186 (error "Empty regular expression")) 192 (error "Empty regular expression"))
313 (defun reftex-extract-bib-entries-from-thebibliography (files) 319 (defun reftex-extract-bib-entries-from-thebibliography (files)
314 ;; Extract bib-entries from the \begin{thebibliography} environment. 320 ;; Extract bib-entries from the \begin{thebibliography} environment.
315 ;; Parsing is not as good as for the BibTeX database stuff. 321 ;; Parsing is not as good as for the BibTeX database stuff.
316 ;; The environment should be located in file FILE. 322 ;; The environment should be located in file FILE.
317 323
318 (let* (start end buf entries re re-list file) 324 (let* (start end buf entries re re-list file default)
319 (unless files 325 (unless files
320 (error "Need file name to find thebibliography environment")) 326 (error "Need file name to find thebibliography environment"))
321 (while (setq file (pop files)) 327 (while (setq file (pop files))
322 (setq buf (reftex-get-file-buffer-force 328 (setq buf (reftex-get-file-buffer-force
323 file (not reftex-keep-temporary-buffers))) 329 file (not reftex-keep-temporary-buffers)))
349 "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*")))))) 355 "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*"))))))
350 (goto-char end))))) 356 (goto-char end)))))
351 (unless entries 357 (unless entries
352 (error "No bibitems found")) 358 (error "No bibitems found"))
353 359
354 (setq re-list (split-string 360 ;; Read a regexp, completing on known citation keys.
355 (read-string "RegExp [ && RegExp...]: " 361 (setq default (regexp-quote (reftex-get-bibkey-default)))
356 nil 'reftex-cite-regexp-hist) 362 (setq re-list
357 "[ \t]*&&[ \t]*")) 363 (split-string
364 (completing-read
365 (concat
366 "Regex { && Regex...}: "
367 "[" default "]: ")
368 (if reftex-mode
369 (if (fboundp 'LaTeX-bibitem-list)
370 (LaTeX-bibitem-list)
371 (cdr (assoc 'bibview-cache
372 (symbol-value reftex-docstruct-symbol))))
373 nil)
374 nil nil nil 'reftex-cite-regexp-hist)
375 "[ \t]*&&[ \t]*"))
376
377 (if (or (null re-list ) (equal re-list '("")))
378 (setq re-list (list default)))
379
358 (if (string-match "\\`[ \t]*\\'" (car re-list)) 380 (if (string-match "\\`[ \t]*\\'" (car re-list))
359 (error "Empty regular expression")) 381 (error "Empty regular expression"))
360 382
361 (while (and (setq re (pop re-list)) entries) 383 (while (and (setq re (pop re-list)) entries)
362 (setq entries 384 (setq entries
372 (push (reftex-get-bib-field "&key" x) x) 394 (push (reftex-get-bib-field "&key" x) x)
373 x) 395 x)
374 entries)) 396 entries))
375 397
376 entries)) 398 entries))
399
400 (defun reftex-get-bibkey-default ()
401 ;; Return the word before the cursor. If the cursor is in a
402 ;; citation macro, return the word before the macro.
403 (let* ((macro (reftex-what-macro 1)))
404 (save-excursion
405 (if (and macro (string-match "cite" (car macro)))
406 (goto-char (cdr macro)))
407 (skip-chars-backward "^a-zA-Z0-9")
408 (reftex-this-word))))
377 409
378 ;; Parse and format individual entries 410 ;; Parse and format individual entries
379 411
380 (defun reftex-get-bib-names (field entry) 412 (defun reftex-get-bib-names (field entry)
381 ;; Return a list with the author or editor names in ENTRY 413 ;; Return a list with the author or editor names in ENTRY