* net/tramp-adb.el: Spell author name correctly.
[emacs.git] / lisp / textmodes / reftex-cite.el
bloba36fa17fca5ae3407b198c57022338ea02335b73
1 ;;; reftex-cite.el --- creating citations with RefTeX
3 ;; Copyright (C) 1997-2014 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <dominik@science.uva.nl>
6 ;; Maintainer: auctex-devel@gnu.org
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (eval-when-compile (require 'cl))
29 (require 'reftex)
31 ;;; Variables and constants
32 (defvar reftex-cite-regexp-hist nil
33 "The history list of regular expressions used for citations")
35 (defconst reftex-citation-prompt
36 "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more"
37 "Prompt and help string for citation selection")
39 (defconst reftex-citation-help
40 " n / p Go to next/previous entry (Cursor motion works as well).
41 g / r Start over with new regexp / Refine with additional regexp.
42 SPC Show full database entry in other window.
43 f Toggle follow mode: Other window will follow with full db entry.
44 . Show insertion point.
45 q Quit without inserting \\cite macro into buffer.
46 TAB Enter citation key with completion.
47 RET Accept current entry (also on mouse-2) and create \\cite macro.
48 m / u Mark/Unmark the entry.
49 e / E Create BibTeX file with all (marked/unmarked) entries
50 a / A Put all (marked) entries into one/many \\cite commands.")
52 ;;; Find bibtex files
53 (defmacro reftex-with-special-syntax-for-bib (&rest body)
54 `(let ((saved-syntax (syntax-table)))
55 (unwind-protect
56 (progn
57 (set-syntax-table reftex-syntax-table-for-bib)
58 ,@body)
59 (set-syntax-table saved-syntax))))
61 (defun reftex-default-bibliography ()
62 "Return the expanded value of variable `reftex-default-bibliography'.
63 The expanded value is cached."
64 (unless (eq (get 'reftex-default-bibliography :reftex-raw)
65 reftex-default-bibliography)
66 (put 'reftex-default-bibliography :reftex-expanded
67 (reftex-locate-bibliography-files
68 default-directory reftex-default-bibliography))
69 (put 'reftex-default-bibliography :reftex-raw
70 reftex-default-bibliography))
71 (get 'reftex-default-bibliography :reftex-expanded))
73 (defun reftex-bib-or-thebib ()
74 "Test if BibTeX or \begin{thebibliography} should be used for the citation.
75 Find the bof of the current file"
76 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
77 (rest (or (member (list 'bof (buffer-file-name)) docstruct)
78 docstruct))
79 (bib (assq 'bib rest))
80 (thebib (assq 'thebib rest))
81 (bibmem (memq bib rest))
82 (thebibmem (memq thebib rest)))
83 (when (not (or thebib bib))
84 (setq bib (assq 'bib docstruct)
85 thebib (assq 'thebib docstruct)
86 bibmem (memq bib docstruct)
87 thebibmem (memq thebib docstruct)))
88 (if (> (length bibmem) (length thebibmem))
89 (if bib 'bib nil)
90 (if thebib 'thebib nil))))
92 (defun reftex-get-bibfile-list ()
93 "Return list of bibfiles for current document.
94 When using the chapterbib or bibunits package you should either
95 use the same database files everywhere, or separate parts using
96 different databases into different files (included into the mater file).
97 Then this function will return the applicable database files."
99 ;; Ensure access to scanning info
100 (reftex-access-scan-info)
102 ;; Try inside this file (and its includes)
103 (cdr (reftex-last-assoc-before-elt
104 'bib (list 'eof (buffer-file-name))
105 (member (list 'bof (buffer-file-name))
106 (symbol-value reftex-docstruct-symbol))))
107 ;; Try after the beginning of this file
108 (cdr (assq 'bib (member (list 'bof (buffer-file-name))
109 (symbol-value reftex-docstruct-symbol))))
110 ;; Anywhere in the entire document
111 (cdr (assq 'bib (symbol-value reftex-docstruct-symbol)))
112 (error "\\bibliography statement missing or .bib files not found")))
114 ;;; Find a certain reference in any of the BibTeX files.
115 (defun reftex-pop-to-bibtex-entry (key file-list &optional mark-to-kill
116 highlight item return)
117 "Find BibTeX KEY in any file in FILE-LIST in another window.
118 If MARK-TO-KILL is non-nil, mark new buffer to kill.
119 If HIGHLIGHT is non-nil, highlight the match.
120 If ITEM in non-nil, search for bibitem instead of database entry.
121 If RETURN is non-nil, just return the entry and restore point."
122 (let* ((re
123 (if item
124 (concat "\\\\bibitem[ \t]*\\(\\[[^]]*\\]\\)?[ \t]*{"
125 (regexp-quote key) "}")
126 (concat "@\\(?:\\w\\|\\s_\\)+[ \t\n\r]*[{(][ \t\n\r]*"
127 (regexp-quote key) "[, \t\r\n}]")))
128 (buffer-conf (current-buffer))
129 file buf pos oldpos)
131 (catch 'exit
132 (while file-list
133 (setq file (car file-list)
134 file-list (cdr file-list))
135 (unless (setq buf (reftex-get-file-buffer-force file mark-to-kill))
136 (error "No such file %s" file))
137 (set-buffer buf)
138 (setq oldpos (point))
139 (widen)
140 (goto-char (point-min))
141 (if (not (re-search-forward re nil t))
142 (goto-char oldpos) ;; restore previous position of point
143 (goto-char (match-beginning 0))
144 (setq pos (point))
145 (when return
146 ;; Just return the relevant entry
147 (if item (goto-char (match-end 0)))
148 (setq return (buffer-substring
149 (point) (reftex-end-of-bib-entry item)))
150 (goto-char oldpos) ;; restore point.
151 (set-buffer buffer-conf)
152 (throw 'exit return))
153 (switch-to-buffer-other-window buf)
154 (goto-char pos)
155 (recenter 0)
156 (if highlight
157 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
158 (throw 'exit (selected-window))))
159 (set-buffer buffer-conf)
160 (if item
161 (error "No \\bibitem with citation key %s" key)
162 (error "No BibTeX entry with citation key %s" key)))))
164 (defun reftex-end-of-bib-entry (item)
165 (save-excursion
166 (condition-case nil
167 (if item
168 (progn (end-of-line)
169 (re-search-forward
170 "\\\\bibitem\\|\\end{thebibliography}")
171 (1- (match-beginning 0)))
172 (progn (forward-list 1) (point)))
173 (error (min (point-max) (+ 300 (point)))))))
175 ;;; Parse bibtex buffers
176 (defun reftex-extract-bib-entries (buffers)
177 "Extract bib entries which match regexps from BUFFERS.
178 BUFFERS is a list of buffers or file names.
179 Return list with entries."
180 (let* (re-list first-re rest-re
181 (buffer-list (if (listp buffers) buffers (list buffers)))
182 found-list entry buffer1 buffer alist
183 key-point start-point end-point default)
185 ;; Read a regexp, completing on known citation keys.
186 (setq default (regexp-quote (reftex-get-bibkey-default)))
187 (setq re-list
188 (split-string
189 (completing-read
190 (concat
191 "Regex { && Regex...}: "
192 "[" default "]: ")
193 (if reftex-mode
194 (if (fboundp 'LaTeX-bibitem-list)
195 (LaTeX-bibitem-list)
196 (cdr (assoc 'bibview-cache
197 (symbol-value reftex-docstruct-symbol))))
198 nil)
199 nil nil nil 'reftex-cite-regexp-hist)
200 "[ \t]*&&[ \t]*"))
202 (if (or (null re-list ) (equal re-list '("")))
203 (setq re-list (list default)))
205 (setq first-re (car re-list) ; We'll use the first re to find things,
206 rest-re (cdr re-list)) ; the others to narrow down.
207 (if (string-match "\\`[ \t]*\\'" (or first-re ""))
208 (error "Empty regular expression"))
210 (save-excursion
211 (save-window-excursion
213 ;; Walk through all bibtex files
214 (while buffer-list
215 (setq buffer (car buffer-list)
216 buffer-list (cdr buffer-list))
217 (if (and (bufferp buffer)
218 (buffer-live-p buffer))
219 (setq buffer1 buffer)
220 (setq buffer1 (reftex-get-file-buffer-force
221 buffer (not reftex-keep-temporary-buffers))))
222 (if (not buffer1)
223 (message "No such BibTeX file %s (ignored)" buffer)
224 (message "Scanning bibliography database %s" buffer1)
225 (unless (verify-visited-file-modtime buffer1)
226 (when (y-or-n-p
227 (format "File %s changed on disk. Reread from disk? "
228 (file-name-nondirectory
229 (buffer-file-name buffer1))))
230 (with-current-buffer buffer1 (revert-buffer t t)))))
232 (set-buffer buffer1)
233 (reftex-with-special-syntax-for-bib
234 (save-excursion
235 (goto-char (point-min))
236 (while (re-search-forward first-re nil t)
237 (catch 'search-again
238 (setq key-point (point))
239 (unless (re-search-backward "\\(\\`\\|[\n\r]\\)[ \t]*\
240 @\\(\\(?:\\w\\|\\s_\\)+\\)[ \t\n\r]*[{(]" nil t)
241 (throw 'search-again nil))
242 (setq start-point (point))
243 (goto-char (match-end 0))
244 (condition-case nil
245 (up-list 1)
246 (error (goto-char key-point)
247 (throw 'search-again nil)))
248 (setq end-point (point))
250 ;; Ignore @string, @comment and @c entries or things
251 ;; outside entries
252 (when (or (string= (downcase (match-string 2)) "string")
253 (string= (downcase (match-string 2)) "comment")
254 (string= (downcase (match-string 2)) "c")
255 (< (point) key-point)) ; this means match not in {}
256 (goto-char key-point)
257 (throw 'search-again nil))
259 ;; Well, we have got a match
260 ;;(setq entry (concat
261 ;; (buffer-substring start-point (point)) "\n"))
262 (setq entry (buffer-substring start-point (point)))
264 ;; Check if other regexp match as well
265 (setq re-list rest-re)
266 (while re-list
267 (unless (string-match (car re-list) entry)
268 ;; nope - move on
269 (throw 'search-again nil))
270 (pop re-list))
272 (setq alist (reftex-parse-bibtex-entry
273 nil start-point end-point))
274 (push (cons "&entry" entry) alist)
276 ;; check for crossref entries
277 (if (assoc "crossref" alist)
278 (setq alist
279 (append
280 alist (reftex-get-crossref-alist alist))))
282 ;; format the entry
283 (push (cons "&formatted" (reftex-format-bib-entry alist))
284 alist)
286 ;; make key the first element
287 (push (reftex-get-bib-field "&key" alist) alist)
289 ;; add it to the list
290 (push alist found-list)))))
291 (reftex-kill-temporary-buffers))))
292 (setq found-list (nreverse found-list))
294 ;; Sorting
295 (cond
296 ((eq 'author reftex-sort-bibtex-matches)
297 (sort found-list 'reftex-bib-sort-author))
298 ((eq 'year reftex-sort-bibtex-matches)
299 (sort found-list 'reftex-bib-sort-year))
300 ((eq 'reverse-year reftex-sort-bibtex-matches)
301 (sort found-list 'reftex-bib-sort-year-reverse))
302 (t found-list))))
304 (defun reftex-bib-sort-author (e1 e2)
305 "Compare bib entries E1 and E2 by author.
306 The name of the first different author/editor is used."
307 (let ((al1 (reftex-get-bib-names "author" e1))
308 (al2 (reftex-get-bib-names "author" e2)))
309 (while (and al1 al2 (string= (car al1) (car al2)))
310 (pop al1)
311 (pop al2))
312 (if (and (stringp (car al1))
313 (stringp (car al2)))
314 (string< (car al1) (car al2))
315 (not (stringp (car al1))))))
317 (defun reftex-bib-sort-year (e1 e2)
318 "Compare bib entries E1 and E2 by year in ascending order."
319 (< (string-to-number (or (cdr (assoc "year" e1)) "0"))
320 (string-to-number (or (cdr (assoc "year" e2)) "0"))))
322 (defun reftex-bib-sort-year-reverse (e1 e2)
323 "Compare bib entries E1 and E2 by year in descending order."
324 (> (string-to-number (or (cdr (assoc "year" e1)) "0"))
325 (string-to-number (or (cdr (assoc "year" e2)) "0"))))
327 (defun reftex-get-crossref-alist (entry)
328 "Return the alist from a crossref ENTRY."
329 (let ((crkey (cdr (assoc "crossref" entry)))
330 start)
331 (save-excursion
332 (save-restriction
333 (widen)
334 (if (re-search-forward
335 (concat "@\\w+[{(][ \t\n\r]*" (regexp-quote crkey)
336 "[ \t\n\r]*,") nil t)
337 (progn
338 (setq start (match-beginning 0))
339 (condition-case nil
340 (up-list 1)
341 (error nil))
342 (reftex-parse-bibtex-entry nil start (point)))
343 nil)))))
345 ;; Parse the bibliography environment
346 (defun reftex-extract-bib-entries-from-thebibliography (files)
347 "Extract bib-entries from the \begin{thebibliography} environment.
348 Parsing is not as good as for the BibTeX database stuff.
349 The environment should be located in FILES."
350 (let* (start end buf entries re re-list file default)
351 (unless files
352 (error "Need file name to find thebibliography environment"))
353 (while (setq file (pop files))
354 (setq buf (reftex-get-file-buffer-force
355 file (not reftex-keep-temporary-buffers)))
356 (unless buf
357 (error "No such file %s" file))
358 (message "Scanning thebibliography environment in %s" file)
360 (with-current-buffer buf
361 (save-excursion
362 (save-restriction
363 (widen)
364 (goto-char (point-min))
365 (while (re-search-forward
366 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t)
367 (beginning-of-line 2)
368 (setq start (point))
369 (if (re-search-forward
370 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t)
371 (progn
372 (beginning-of-line 1)
373 (setq end (point))))
374 (when (and start end)
375 (setq entries
376 (append entries
377 (mapcar 'reftex-parse-bibitem
378 (delete ""
379 (split-string
380 (buffer-substring-no-properties
381 start end)
382 "[ \t\n\r]*\\\\bibitem[ \t]*\
383 \\(\\[[^]]*]\\)*\[ \t]*"))))))
384 (goto-char end))))))
385 (unless entries
386 (error "No bibitems found"))
388 ;; Read a regexp, completing on known citation keys.
389 (setq default (regexp-quote (reftex-get-bibkey-default)))
390 (setq re-list
391 (split-string
392 (completing-read
393 (concat
394 "Regex { && Regex...}: "
395 "[" default "]: ")
396 (if reftex-mode
397 (if (fboundp 'LaTeX-bibitem-list)
398 (LaTeX-bibitem-list)
399 (cdr (assoc 'bibview-cache
400 (symbol-value reftex-docstruct-symbol))))
401 nil)
402 nil nil nil 'reftex-cite-regexp-hist)
403 "[ \t]*&&[ \t]*"))
405 (if (or (null re-list ) (equal re-list '("")))
406 (setq re-list (list default)))
408 (if (string-match "\\`[ \t]*\\'" (car re-list))
409 (error "Empty regular expression"))
411 (while (and (setq re (pop re-list)) entries)
412 (setq entries
413 (delq nil (mapcar
414 (lambda (x)
415 (if (string-match re (cdr (assoc "&entry" x)))
416 x nil))
417 entries))))
418 (setq entries
419 (mapcar
420 (lambda (x)
421 (push (cons "&formatted" (reftex-format-bibitem x)) x)
422 (push (reftex-get-bib-field "&key" x) x)
424 entries))
426 entries))
428 (defun reftex-get-bibkey-default ()
429 "Return the word before the cursor.
430 If the cursor is in a citation macro, return the word before the macro."
431 (let* ((macro (reftex-what-macro 1)))
432 (save-excursion
433 (if (and macro (string-match "cite" (car macro)))
434 (goto-char (cdr macro)))
435 (skip-chars-backward "^a-zA-Z0-9")
436 (reftex-this-word))))
438 ;;; Parse and format individual entries
439 (defun reftex-get-bib-names (field entry)
440 "Return a list with the author or editor names in ENTRY.
441 If FIELD is empty try \"editor\" field."
442 (let ((names (reftex-get-bib-field field entry)))
443 (if (equal "" names)
444 (setq names (reftex-get-bib-field "editor" entry)))
445 (while (string-match "\\band\\b[ \t]*" names)
446 (setq names (replace-match "\n" nil t names)))
447 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" names)
448 (setq names (replace-match "" nil t names)))
449 (while (string-match "^[ \t]+\\|[ \t]+$" names)
450 (setq names (replace-match "" nil t names)))
451 (while (string-match "[ \t][ \t]+" names)
452 (setq names (replace-match " " nil t names)))
453 (split-string names "\n")))
455 (defun reftex-parse-bibtex-entry (entry &optional from to raw)
456 "Parse BibTeX ENTRY.
457 If ENTRY is nil then parse the entry in current buffer between FROM and TO.
458 If RAW is non-nil, keep double quotes/curly braces delimiting fields."
459 (let (alist key start field)
460 (save-excursion
461 (save-restriction
462 (if entry
463 (progn
464 (set-buffer (get-buffer-create " *RefTeX-scratch*"))
465 (fundamental-mode)
466 (set-syntax-table reftex-syntax-table-for-bib)
467 (erase-buffer)
468 (insert entry))
469 (widen)
470 (if (and from to) (narrow-to-region from to)))
471 (goto-char (point-min))
473 (if (re-search-forward "@\\(\\(?:\\w\\|\\s_\\)+\\)[ \t\n\r]*\
474 \[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t)
475 (setq alist
476 (list
477 (cons "&type" (downcase (reftex-match-string 1)))
478 (cons "&key" (reftex-match-string 2)))))
479 (while (re-search-forward "\\(\\(?:\\w\\|-\\)+\\)[ \t\n\r]*=[ \t\n\r]*"
480 nil t)
481 (setq key (downcase (reftex-match-string 1)))
482 (cond
483 ((= (following-char) ?{)
484 (cond
485 (raw
486 (setq start (point))
487 (forward-char 1))
489 (forward-char 1)
490 (setq start (point))
491 (condition-case nil
492 (up-list 1)
493 (error nil)))))
494 ((= (following-char) ?\")
495 (cond
496 (raw
497 (setq start (point))
498 (forward-char 1))
500 (forward-char 1)
501 (setq start (point))))
502 (while (and (search-forward "\"" nil t)
503 (= ?\\ (char-after (- (point) 2))))))
505 (setq start (point))
506 (re-search-forward "[ \t]*[\n\r,}]" nil 1)))
507 ;; extract field value, ignore trailing comma if in RAW mode
508 (let ((stop (if (and raw (not (= (char-after (1- (point))) ?,)))
509 (point)
510 (1- (point))) ))
511 (setq field (buffer-substring-no-properties start stop)))
512 ;; remove extra whitespace
513 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field)
514 (setq field (replace-match " " nil t field)))
515 (push (cons key field) alist))))
516 alist))
518 (defun reftex-get-bib-field (fieldname entry &optional format)
519 "Extract the field FIELDNAME from ENTRY.
520 If FORMAT is non-nil `format' entry accordingly."
521 (let ((cell (assoc fieldname entry)))
522 (if cell
523 (if format
524 (format format (cdr cell))
525 (cdr cell))
526 "")))
528 (defun reftex-format-bib-entry (entry)
529 "Format a BibTeX ENTRY so that it is nice to look at."
530 (let*
531 ((auth-list (reftex-get-bib-names "author" entry))
532 (authors (mapconcat 'identity auth-list ", "))
533 (year (reftex-get-bib-field "year" entry))
534 (title (reftex-get-bib-field "title" entry))
535 (type (reftex-get-bib-field "&type" entry))
536 (key (reftex-get-bib-field "&key" entry))
537 (extra
538 (cond
539 ((equal type "article")
540 (concat (reftex-get-bib-field "journal" entry) " "
541 (reftex-get-bib-field "volume" entry) ", "
542 (reftex-get-bib-field "pages" entry)))
543 ((equal type "book")
544 (concat "book (" (reftex-get-bib-field "publisher" entry) ")"))
545 ((equal type "phdthesis")
546 (concat "PhD: " (reftex-get-bib-field "school" entry)))
547 ((equal type "mastersthesis")
548 (concat "Master: " (reftex-get-bib-field "school" entry)))
549 ((equal type "inbook")
550 (concat "Chap: " (reftex-get-bib-field "chapter" entry)
551 ", pp. " (reftex-get-bib-field "pages" entry)))
552 ((or (equal type "conference")
553 (equal type "incollection")
554 (equal type "inproceedings"))
555 (reftex-get-bib-field "booktitle" entry "in: %s"))
556 (t ""))))
557 (setq authors (reftex-truncate authors 30 t t))
558 (when (reftex-use-fonts)
559 (put-text-property 0 (length key) 'face reftex-label-face
560 key)
561 (put-text-property 0 (length authors) 'face reftex-bib-author-face
562 authors)
563 (put-text-property 0 (length year) 'face reftex-bib-year-face
564 year)
565 (put-text-property 0 (length title) 'face reftex-bib-title-face
566 title)
567 (put-text-property 0 (length extra) 'face reftex-bib-extra-face
568 extra))
569 (concat key "\n " authors " " year " " extra "\n " title "\n\n")))
571 (defun reftex-parse-bibitem (item)
572 "Parse a \bibitem entry in ITEM."
573 (let ((key "") (text ""))
574 (when (string-match "\\`{\\([^}]+\\)}\\([^\000]*\\)" item)
575 (setq key (match-string 1 item)
576 text (match-string 2 item)))
577 ;; Clean up the text a little bit
578 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text)
579 (setq text (replace-match " " nil t text)))
580 (if (string-match "\\`[ \t]+" text)
581 (setq text (replace-match "" nil t text)))
582 (list
583 (cons "&key" key)
584 (cons "&text" text)
585 (cons "&entry" (concat key " " text)))))
587 (defun reftex-format-bibitem (item)
588 "Format a \bibitem entry in ITEM so that it is (relatively) nice to look at."
589 (let ((text (reftex-get-bib-field "&text" item))
590 (key (reftex-get-bib-field "&key" item))
591 (lines nil))
593 ;; Wrap the text into several lines.
594 (while (and (> (length text) 70)
595 (string-match " " (substring text 60)))
596 (push (substring text 0 (+ 60 (match-beginning 0))) lines)
597 (setq text (substring text (+ 61 (match-beginning 0)))))
598 (push text lines)
599 (setq text (mapconcat 'identity (nreverse lines) "\n "))
601 (when (reftex-use-fonts)
602 (put-text-property 0 (length text) 'face reftex-bib-author-face text))
603 (concat key "\n " text "\n\n")))
605 ;;; Make a citation
607 ;;;###autoload
608 (defun reftex-citation (&optional no-insert format-key)
609 "Make a citation using BibTeX database files.
610 After prompting for a regular expression, scans the buffers with
611 bibtex entries (taken from the \\bibliography command) and offers the
612 matching entries for selection. The selected entry is formatted according
613 to `reftex-cite-format' and inserted into the buffer.
615 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
617 FORMAT-KEY can be used to pre-select a citation format.
619 When called with a `C-u' prefix, prompt for optional arguments in
620 cite macros. When called with a numeric prefix, make that many
621 citations. When called with point inside the braces of a `\\cite'
622 command, it will add another key, ignoring the value of
623 `reftex-cite-format'.
625 The regular expression uses an expanded syntax: && is interpreted as `and'.
626 Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'.
627 While entering the regexp, completion on knows citation keys is possible.
628 `=' is a good regular expression to match all entries in all files."
629 (interactive)
631 ;; check for recursive edit
632 (reftex-check-recursive-edit)
634 ;; This function may also be called outside reftex-mode.
635 ;; Thus look for the scanning info only if in reftex-mode.
637 (when reftex-mode
638 (reftex-access-scan-info nil))
640 ;; Call reftex-do-citation, but protected
641 (unwind-protect
642 (reftex-do-citation current-prefix-arg no-insert format-key)
643 (reftex-kill-temporary-buffers)))
645 (defun reftex-do-citation (&optional arg no-insert format-key)
646 "This really does the work of `reftex-citation'."
647 (let* ((format (reftex-figure-out-cite-format arg no-insert format-key))
648 (docstruct-symbol reftex-docstruct-symbol)
649 (selected-entries (reftex-offer-bib-menu))
650 (insert-entries selected-entries)
651 entry string cite-view)
653 (unless selected-entries (error "Quit"))
655 (if (stringp selected-entries)
656 ;; Nonexistent entry
657 (setq insert-entries (list (list selected-entries
658 (cons "&key" selected-entries)))
659 selected-entries nil)
660 ;; It makes sense to compute the cite-view strings.
661 (setq cite-view t))
663 (when (eq (car selected-entries) 'concat)
664 ;; All keys go into a single command - we need to trick a little
665 ;; FIXME: Unfortunately, this means that commenting does not work right.
666 (pop selected-entries)
667 (let ((concat-keys (mapconcat 'car selected-entries
668 reftex-cite-key-separator)))
669 (setq insert-entries
670 (list (list concat-keys (cons "&key" concat-keys))))))
672 (unless no-insert
674 ;; We shall insert this into the buffer...
675 (message "Formatting...")
677 (while (setq entry (pop insert-entries))
678 ;; Format the citation and insert it
679 (setq string (if reftex-format-cite-function
680 (funcall reftex-format-cite-function
681 (reftex-get-bib-field "&key" entry)
682 format)
683 (reftex-format-citation entry format)))
684 (when (or (eq reftex-cite-prompt-optional-args t)
685 (and reftex-cite-prompt-optional-args
686 (equal arg '(4))))
687 (let ((start 0) (nth 0) value)
688 (while (setq start (string-match "\\[\\]" string start))
689 (setq value (save-match-data
690 (read-string (format "Optional argument %d: "
691 (setq nth (1+ nth))))))
692 (setq string (replace-match (concat "[" value "]") t t string))
693 (setq start (1+ start)))))
694 ;; Should we cleanup empty optional arguments?
695 ;; if the first is empty, it can be removed. If the second is empty,
696 ;; it has to go. If there is only a single arg and empty, it can go
697 ;; as well.
698 (when reftex-cite-cleanup-optional-args
699 (cond
700 ((string-match "\\([a-zA-Z0-9]\\)\\[\\]{" string)
701 (setq string (replace-match "\\1{" nil nil string)))
702 ((string-match "\\[\\]\\(\\[[a-zA-Z0-9., ]+\\]\\)" string)
703 (setq string (replace-match "\\1" nil nil string)))
704 ((string-match "\\[\\]\\[\\]" string)
705 (setq string (replace-match "" t t string)))))
706 (insert string))
708 ;; Reposition cursor?
709 (when (string-match "\\?" string)
710 (search-backward "?")
711 (delete-char 1))
713 ;; Tell AUCTeX
714 (when (and reftex-mode
715 (fboundp 'LaTeX-add-bibitems)
716 reftex-plug-into-AUCTeX)
717 (apply 'LaTeX-add-bibitems (mapcar 'car selected-entries)))
719 ;; Produce the cite-view strings
720 (when (and reftex-mode reftex-cache-cite-echo cite-view)
721 (mapc (lambda (entry)
722 (reftex-make-cite-echo-string entry docstruct-symbol))
723 selected-entries))
725 (message ""))
727 (set-marker reftex-select-return-marker nil)
728 (reftex-kill-buffer "*RefTeX Select*")
730 ;; Check if the prefix arg was numeric, and call recursively
731 (when (integerp arg)
732 (if (> arg 1)
733 (progn
734 (skip-chars-backward "}")
735 (decf arg)
736 (reftex-do-citation arg))
737 (forward-char 1)))
739 ;; Return the citation key
740 (mapcar 'car selected-entries)))
742 (defun reftex-figure-out-cite-format (arg &optional no-insert format-key)
743 "Check if there is already a cite command at point and change cite format
744 in order to only add another reference in the same cite command."
745 (let ((macro (car (reftex-what-macro 1)))
746 (cite-format-value (reftex-get-cite-format))
747 key format)
748 (cond
749 (no-insert
750 ;; Format does not really matter because nothing will be inserted.
751 (setq format "%l"))
753 ((and (stringp macro)
754 (string-match "\\`\\\\cite\\|cite\\'" macro))
755 ;; We are already inside a cite macro
756 (if (or (not arg) (not (listp arg)))
757 (setq format
758 (concat
759 (if (member (preceding-char) '(?\{ ?,))
761 reftex-cite-key-separator)
762 "%l"
763 (if (member (following-char) '(?\} ?,))
765 reftex-cite-key-separator)))
766 (setq format "%l")))
768 ;; Figure out the correct format
769 (setq format
770 (if (and (symbolp cite-format-value)
771 (assq cite-format-value reftex-cite-format-builtin))
772 (nth 2 (assq cite-format-value reftex-cite-format-builtin))
773 cite-format-value))
774 (when (listp format)
775 (setq key
776 (or format-key
777 (reftex-select-with-char
778 "" (concat "SELECT A CITATION FORMAT\n\n"
779 (mapconcat
780 (lambda (x)
781 (format "[%c] %s %s" (car x)
782 (if (> (car x) 31) " " "")
783 (cdr x)))
784 format "\n")))))
785 (if (assq key format)
786 (setq format (cdr (assq key format)))
787 (error "No citation format associated with key `%c'" key)))))
788 format))
790 (defun reftex-citep ()
791 "Call `reftex-citation' with a format selector `?p'."
792 (interactive)
793 (reftex-citation nil ?p))
795 (defun reftex-citet ()
796 "Call `reftex-citation' with a format selector `?t'."
797 (interactive)
798 (reftex-citation nil ?t))
800 (defvar reftex-select-bib-map)
801 (defun reftex-offer-bib-menu ()
802 "Offer bib menu and return list of selected items."
803 (let ((bibtype (reftex-bib-or-thebib))
804 found-list rtn key data selected-entries)
805 (while
806 (not
807 (catch 'done
808 ;; Scan bibtex files
809 (setq found-list
810 (cond
811 ((eq bibtype 'bib)
812 ; ((assq 'bib (symbol-value reftex-docstruct-symbol))
813 ;; using BibTeX database files.
814 (reftex-extract-bib-entries (reftex-get-bibfile-list)))
815 ((eq bibtype 'thebib)
816 ; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
817 ;; using thebibliography environment.
818 (reftex-extract-bib-entries-from-thebibliography
819 (reftex-uniquify
820 (mapcar 'cdr
821 (reftex-all-assq
822 'thebib (symbol-value reftex-docstruct-symbol))))))
823 (reftex-default-bibliography
824 (message "Using default bibliography")
825 (reftex-extract-bib-entries (reftex-default-bibliography)))
826 (t (error "No valid bibliography in this document, and no default available"))))
828 (unless found-list
829 (error "Sorry, no matches found"))
831 ;; Remember where we came from
832 (setq reftex-call-back-to-this-buffer (current-buffer))
833 (set-marker reftex-select-return-marker (point))
835 ;; Offer selection
836 (save-window-excursion
837 (delete-other-windows)
838 (reftex-kill-buffer "*RefTeX Select*")
839 (switch-to-buffer-other-window "*RefTeX Select*")
840 (unless (eq major-mode 'reftex-select-bib-mode)
841 (reftex-select-bib-mode))
842 (let ((buffer-read-only nil))
843 (erase-buffer)
844 (reftex-insert-bib-matches found-list))
845 (setq buffer-read-only t)
846 (if (= 0 (buffer-size))
847 (error "No matches found"))
848 (setq truncate-lines t)
849 (goto-char 1)
850 (while t
851 (setq rtn
852 (reftex-select-item
853 reftex-citation-prompt
854 reftex-citation-help
855 reftex-select-bib-map
857 'reftex-bibtex-selection-callback nil))
858 (setq key (car rtn)
859 data (nth 1 rtn))
860 (unless key (throw 'done t))
861 (cond
862 ((eq key ?g)
863 ;; Start over
864 (throw 'done nil))
865 ((eq key ?r)
866 ;; Restrict with new regular expression
867 (setq found-list (reftex-restrict-bib-matches found-list))
868 (let ((buffer-read-only nil))
869 (erase-buffer)
870 (reftex-insert-bib-matches found-list))
871 (goto-char 1))
872 ((eq key ?A)
873 ;; Take all (marked)
874 (setq selected-entries
875 (if reftex-select-marked
876 (mapcar 'car (nreverse reftex-select-marked))
877 found-list))
878 (throw 'done t))
879 ((eq key ?a)
880 ;; Take all (marked), and push the symbol 'concat
881 (setq selected-entries
882 (cons 'concat
883 (if reftex-select-marked
884 (mapcar 'car (nreverse reftex-select-marked))
885 found-list)))
886 (throw 'done t))
887 ((eq key ?e)
888 ;; Take all (marked), and push the symbol 'concat
889 (reftex-extract-bib-file found-list reftex-select-marked)
890 (setq selected-entries "BibTeX database file created")
891 (throw 'done t))
892 ((eq key ?E)
893 ;; Take all (marked), and push the symbol 'concat
894 (reftex-extract-bib-file found-list reftex-select-marked
895 'complement)
896 (setq selected-entries "BibTeX database file created")
897 (throw 'done t))
898 ((or (eq key ?\C-m)
899 (eq key 'return))
900 ;; Take selected
901 (setq selected-entries
902 (if reftex-select-marked
903 (cons 'concat
904 (mapcar 'car (nreverse reftex-select-marked)))
905 (if data (list data) nil)))
906 (throw 'done t))
907 ((stringp key)
908 ;; Got this one with completion
909 (setq selected-entries key)
910 (throw 'done t))
912 (ding))))))))
913 selected-entries))
915 (defun reftex-restrict-bib-matches (found-list)
916 "Limit FOUND-LIST with more regular expressions."
917 (let ((re-list (split-string (read-string
918 "RegExp [ && RegExp...]: "
919 nil 'reftex-cite-regexp-hist)
920 "[ \t]*&&[ \t]*"))
921 (found-list-r found-list)
923 (while (setq re (pop re-list))
924 (setq found-list-r
925 (delq nil
926 (mapcar
927 (lambda (x)
928 (if (string-match
929 re (cdr (assoc "&entry" x)))
931 nil))
932 found-list-r))))
933 (if found-list-r
934 found-list-r
935 (ding)
936 found-list)))
938 (defun reftex-extract-bib-file (all &optional marked complement)
939 "Limit FOUND-LIST with more regular expressions."
940 (let ((file (read-file-name "File to create: ")))
941 (find-file-other-window file)
942 (if (> (buffer-size) 0)
943 (unless (yes-or-no-p
944 (format "Overwrite non-empty file %s? " file))
945 (error "Abort")))
946 (erase-buffer)
947 (setq all (delq nil
948 (mapcar
949 (lambda (x)
950 (if marked
951 (if (or (and (assoc x marked) (not complement))
952 (and (not (assoc x marked)) complement))
953 (cdr (assoc "&entry" x))
954 nil)
955 (cdr (assoc "&entry" x))))
956 all)))
957 (insert (mapconcat 'identity all "\n\n"))
958 (save-buffer)
959 (goto-char (point-min))))
961 (defun reftex-insert-bib-matches (list)
962 "Insert the bib matches and number them correctly."
963 (let ((mouse-face
964 (if (memq reftex-highlight-selection '(mouse both))
965 reftex-mouse-selected-face
966 nil))
967 tmp len)
968 (mapc
969 (lambda (x)
970 (setq tmp (cdr (assoc "&formatted" x))
971 len (length tmp))
972 (put-text-property 0 len :data x tmp)
973 (put-text-property 0 (1- len) 'mouse-face mouse-face tmp)
974 (insert tmp))
975 list))
976 (run-hooks 'reftex-display-copied-context-hook))
978 (defun reftex-format-names (namelist n)
979 (let (last (len (length namelist)))
980 (if (= n 0) (setq n len))
981 (cond
982 ((< len 1) "")
983 ((= 1 len) (car namelist))
984 ((> len n) (concat (car namelist) (nth 2 reftex-cite-punctuation)))
986 (setq n (min len n)
987 last (nth (1- n) namelist))
988 (setcdr (nthcdr (- n 2) namelist) nil)
989 (concat
990 (mapconcat 'identity namelist (nth 0 reftex-cite-punctuation))
991 (nth 1 reftex-cite-punctuation)
992 last)))))
994 (defun reftex-format-citation (entry format)
995 "Format a citation from the info in the BibTeX ENTRY according to FORMAT."
996 (unless (stringp format) (setq format "\\cite{%l}"))
998 (if (and reftex-comment-citations
999 (string-match "%l" reftex-cite-comment-format))
1000 (error "reftex-cite-comment-format contains invalid %%l"))
1002 (while (string-match
1003 "\\(\\`\\|[^%]\\)\\(\\(%\\([0-9]*\\)\\([a-zA-Z]\\)\\)[.,;: ]*\\)"
1004 format)
1005 (let ((n (string-to-number (match-string 4 format)))
1006 (l (string-to-char (match-string 5 format)))
1007 rpl b e)
1008 (save-match-data
1009 (setq rpl
1010 (cond
1011 ((= l ?l) (concat
1012 (reftex-get-bib-field "&key" entry)
1013 (if reftex-comment-citations
1014 reftex-cite-comment-format
1015 "")))
1016 ((= l ?a) (reftex-format-names
1017 (reftex-get-bib-names "author" entry)
1018 (or n 2)))
1019 ((= l ?A) (car (reftex-get-bib-names "author" entry)))
1020 ((= l ?b) (reftex-get-bib-field "booktitle" entry "in: %s"))
1021 ((= l ?B) (reftex-abbreviate-title
1022 (reftex-get-bib-field "booktitle" entry "in: %s")))
1023 ((= l ?c) (reftex-get-bib-field "chapter" entry))
1024 ((= l ?d) (reftex-get-bib-field "edition" entry))
1025 ((= l ?e) (reftex-format-names
1026 (reftex-get-bib-names "editor" entry)
1027 (or n 2)))
1028 ((= l ?E) (car (reftex-get-bib-names "editor" entry)))
1029 ((= l ?h) (reftex-get-bib-field "howpublished" entry))
1030 ((= l ?i) (reftex-get-bib-field "institution" entry))
1031 ((= l ?j) (reftex-get-bib-field "journal" entry))
1032 ((= l ?k) (reftex-get-bib-field "key" entry))
1033 ((= l ?m) (reftex-get-bib-field "month" entry))
1034 ((= l ?n) (reftex-get-bib-field "number" entry))
1035 ((= l ?N) (reftex-get-bib-field "note" entry))
1036 ((= l ?o) (reftex-get-bib-field "organization" entry))
1037 ((= l ?p) (reftex-get-bib-field "pages" entry))
1038 ((= l ?P) (car (split-string
1039 (reftex-get-bib-field "pages" entry)
1040 "[- .]+")))
1041 ((= l ?s) (reftex-get-bib-field "school" entry))
1042 ((= l ?u) (reftex-get-bib-field "publisher" entry))
1043 ((= l ?U) (reftex-get-bib-field "url" entry))
1044 ((= l ?r) (reftex-get-bib-field "address" entry))
1045 ((= l ?t) (reftex-get-bib-field "title" entry))
1046 ((= l ?T) (reftex-abbreviate-title
1047 (reftex-get-bib-field "title" entry)))
1048 ((= l ?v) (reftex-get-bib-field "volume" entry))
1049 ((= l ?y) (reftex-get-bib-field "year" entry)))))
1051 (if (string= rpl "")
1052 (setq b (match-beginning 2) e (match-end 2))
1053 (setq b (match-beginning 3) e (match-end 3)))
1054 (setq format (concat (substring format 0 b) rpl (substring format e)))))
1055 (while (string-match "%%" format)
1056 (setq format (replace-match "%" t t format)))
1057 (while (string-match "[ ,.;:]*%<" format)
1058 (setq format (replace-match "" t t format)))
1059 format)
1061 (defun reftex-make-cite-echo-string (entry docstruct-symbol)
1062 "Format a bibtex ENTRY for the echo area and cache the result."
1063 (let* ((key (reftex-get-bib-field "&key" entry))
1064 (string
1065 (let* ((reftex-cite-punctuation '(" " " & " " etal.")))
1066 (reftex-format-citation entry reftex-cite-view-format)))
1067 (cache (assq 'bibview-cache (symbol-value docstruct-symbol)))
1068 (cache-entry (assoc key (cdr cache))))
1069 (unless cache
1070 ;; This docstruct has no cache - make one.
1071 (set docstruct-symbol (cons (cons 'bibview-cache nil)
1072 (symbol-value docstruct-symbol))))
1073 (when reftex-cache-cite-echo
1074 (setq key (copy-sequence key))
1075 (set-text-properties 0 (length key) nil key)
1076 (set-text-properties 0 (length string) nil string)
1077 (if cache-entry
1078 (unless (string= (cdr cache-entry) string)
1079 (setcdr cache-entry string)
1080 (put reftex-docstruct-symbol 'modified t))
1081 (push (cons key string) (cdr cache))
1082 (put reftex-docstruct-symbol 'modified t)))
1083 string))
1085 (defun reftex-bibtex-selection-callback (data ignore no-revisit)
1086 "Callback function to be called from the BibTeX selection, in
1087 order to display context. This function is relatively slow and not
1088 recommended for follow mode. It works OK for individual lookups."
1089 (let ((win (selected-window))
1090 (key (reftex-get-bib-field "&key" data))
1091 bibfile-list item bibtype)
1093 (catch 'exit
1094 (with-current-buffer reftex-call-back-to-this-buffer
1095 (setq bibtype (reftex-bib-or-thebib))
1096 (cond
1097 ((eq bibtype 'bib)
1098 ; ((assq 'bib (symbol-value reftex-docstruct-symbol))
1099 (setq bibfile-list (reftex-get-bibfile-list)))
1100 ((eq bibtype 'thebib)
1101 ; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
1102 (setq bibfile-list
1103 (reftex-uniquify
1104 (mapcar 'cdr
1105 (reftex-all-assq
1106 'thebib (symbol-value reftex-docstruct-symbol))))
1107 item t))
1108 (reftex-default-bibliography
1109 (setq bibfile-list (reftex-default-bibliography)))
1110 (t (ding) (throw 'exit nil))))
1112 (when no-revisit
1113 (setq bibfile-list (reftex-visited-files bibfile-list)))
1115 (condition-case nil
1116 (reftex-pop-to-bibtex-entry
1117 key bibfile-list (not reftex-keep-temporary-buffers) t item)
1118 (error (ding))))
1120 (select-window win)))
1122 ;;; Global BibTeX file
1123 (defun reftex-all-used-citation-keys ()
1124 (reftex-access-scan-info)
1125 (let ((files (reftex-all-document-files)) file keys kk k)
1126 (save-current-buffer
1127 (while (setq file (pop files))
1128 (set-buffer (reftex-get-file-buffer-force file 'mark))
1129 (save-excursion
1130 (save-restriction
1131 (widen)
1132 (goto-char (point-min))
1133 (while (re-search-forward "\\(?:^\\|\\=\\)[^%\n\r]*?\\\\\\(bibentry\\|[a-zA-Z]*cite[a-zA-Z]*\\)\\(\\[[^]]*\\]\\)?{\\([^}]+\\)}" nil t)
1134 (setq kk (match-string-no-properties 3))
1135 (while (string-match "%.*\n?" kk)
1136 (setq kk (replace-match "" t t kk)))
1137 (setq kk (split-string kk "[, \t\r\n]+"))
1138 (while (setq k (pop kk))
1139 (or (member k keys)
1140 (setq keys (cons k keys)))))))))
1141 (reftex-kill-temporary-buffers)
1142 keys))
1144 (defun reftex-get-string-refs (alist)
1145 "Return a list of BibTeX @string references that appear as values in ALIST."
1146 (reftex-remove-if (lambda (x) (string-match "^\\([\"{]\\|[0-9]+$\\)" x))
1147 ;; get list of values, discard keys
1148 (mapcar 'cdr
1149 ;; remove &key and &type entries
1150 (reftex-remove-if (lambda (pair)
1151 (string-match "^&" (car pair)))
1152 alist))))
1154 (defun reftex-create-bibtex-file (bibfile)
1155 "Create a new BibTeX database BIBFILE with all entries referenced in document.
1156 The command prompts for a filename and writes the collected
1157 entries to that file. Only entries referenced in the current
1158 document with any \\cite-like macros are used. The sequence in
1159 the new file is the same as it was in the old database.
1161 Entries referenced from other entries must appear after all
1162 referencing entries.
1164 You can define strings to be used as header or footer for the
1165 created files in the variables `reftex-create-bibtex-header' or
1166 `reftex-create-bibtex-footer' respectively."
1167 (interactive "FNew BibTeX file: ")
1168 (let ((keys (reftex-all-used-citation-keys))
1169 (files (reftex-get-bibfile-list))
1170 file key entries beg end entry string-keys string-entries)
1171 (save-current-buffer
1172 (dolist (file files)
1173 (set-buffer (reftex-get-file-buffer-force file 'mark))
1174 (reftex-with-special-syntax-for-bib
1175 (save-excursion
1176 (save-restriction
1177 (widen)
1178 (goto-char (point-min))
1179 (while (re-search-forward "^[ \t]*@\\(?:\\w\\|\\s_\\)+[ \t\n\r]*\
1180 \[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t)
1181 (setq key (match-string 1)
1182 beg (match-beginning 0)
1183 end (progn
1184 (goto-char (match-beginning 1))
1185 (condition-case nil
1186 (up-list 1)
1187 (error (goto-char (match-end 0))))
1188 (point)))
1189 (when (member key keys)
1190 (setq entry (buffer-substring beg end)
1191 entries (cons entry entries)
1192 keys (delete key keys))
1194 ;; check for crossref entries
1195 (let* ((attr-list (reftex-parse-bibtex-entry nil beg end))
1196 (xref-key (cdr (assoc "crossref" attr-list))))
1197 (if xref-key (pushnew xref-key keys)))
1198 ;; check for string references
1199 (let* ((raw-fields (reftex-parse-bibtex-entry nil beg end t))
1200 (string-fields (reftex-get-string-refs raw-fields)))
1201 (dolist (skey string-fields)
1202 (unless (member skey string-keys)
1203 (push skey string-keys)))))))))))
1204 ;; second pass: grab @string references
1205 (if string-keys
1206 (save-current-buffer
1207 (dolist (file files)
1208 (set-buffer (reftex-get-file-buffer-force file 'mark))
1209 (reftex-with-special-syntax-for-bib
1210 (save-excursion
1211 (save-restriction
1212 (widen)
1213 (goto-char (point-min))
1214 (while (re-search-forward
1215 "^[ \t]*@[Ss][Tt][Rr][Ii][Nn][Gg][ \t]*{[ \t]*\\([^ \t\r\n]+\\)"
1216 nil t)
1217 (setq key (match-string 1)
1218 beg (match-beginning 0)
1219 end (progn
1220 (goto-char (match-beginning 1))
1221 (condition-case nil
1222 (up-list 1)
1223 (error (goto-char (match-end 0))))
1224 (point)))
1225 (when (member key string-keys)
1226 (setq entry (buffer-substring beg end)
1227 string-entries (cons entry string-entries)
1228 string-keys (delete key string-keys))))))))))
1229 (find-file-other-window bibfile)
1230 (if (> (buffer-size) 0)
1231 (unless (yes-or-no-p
1232 (format "Overwrite non-empty file %s? " bibfile))
1233 (error "Abort")))
1234 (erase-buffer)
1235 (if reftex-create-bibtex-header (insert reftex-create-bibtex-header "\n\n"))
1236 (insert (mapconcat 'identity (reverse string-entries) "\n\n"))
1237 (if string-entries (insert "\n\n\n"))
1238 (insert (mapconcat 'identity (reverse entries) "\n\n"))
1239 (if reftex-create-bibtex-footer (insert "\n\n" reftex-create-bibtex-footer))
1240 (goto-char (point-min))
1241 (save-buffer)
1242 (message "%d entries extracted and copied to new database"
1243 (length entries))))
1245 (provide 'reftex-cite)
1246 ;;; reftex-cite.el ends here