annotate lisp/textmodes/reftex-cite.el @ 109107:06fb882320aa

* config.nt (__P): Remove.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 02 Jul 2010 16:46:22 +0200
parents 1d1d5d9bd884
children 280c8ae2476d 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
1 ;;; reftex-cite.el --- creating citations with RefTeX
74509
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73804
diff changeset
2
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73804
diff changeset
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105813
diff changeset
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
5
46612
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 46131
diff changeset
6 ;; Author: Carsten Dominik <dominik@science.uva.nl>
76672
690423f53b08 * textmodes/reftex.el: Add maintainer address.
David Kastrup <dak@gnu.org>
parents: 75347
diff changeset
7 ;; Maintainer: auctex-devel@gnu.org
69094
bfd5c5e60410 Version number change only
Carsten Dominik <dominik@science.uva.nl>
parents: 68648
diff changeset
8 ;; Version: 4.31
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
9
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
10 ;; This file is part of GNU Emacs.
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
11
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; (at your option) any later version.
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
16
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
20 ;; GNU General Public License for more details.
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
21
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
24
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
25 ;;; Commentary:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
26
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
27 ;;; Code:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
28
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
29 (eval-when-compile (require 'cl))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
30 (provide 'reftex-cite)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
31 (require 'reftex)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
32 ;;;
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
33
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
34 ;; Variables and constants
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
35
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
36 ;; The history list of regular expressions used for citations
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
37 (defvar reftex-cite-regexp-hist nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
38
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
39 ;; Prompt and help string for citation selection
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
40 (defconst reftex-citation-prompt
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
41 "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
42
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
43 (defconst reftex-citation-help
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
44 " n / p Go to next/previous entry (Cursor motion works as well).
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
45 g / r Start over with new regexp / Refine with additional regexp.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
46 SPC Show full database entry in other window.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
47 f Toggle follow mode: Other window will follow with full db entry.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
48 . Show insertion point.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
49 q Quit without inserting \\cite macro into buffer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
50 TAB Enter citation key with completion.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
51 RET Accept current entry (also on mouse-2) and create \\cite macro.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
52 m / u Mark/Unmark the entry.
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
53 e / E Create BibTeX file with all (marked/unmarked) entries
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
54 a / A Put all (marked) entries into one/many \\cite commands.")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
55
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
56 ;; Find bibtex files
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
57
46612
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 46131
diff changeset
58 (defmacro reftex-with-special-syntax-for-bib (&rest body)
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 46131
diff changeset
59 `(let ((saved-syntax (syntax-table)))
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 46131
diff changeset
60 (unwind-protect
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
61 (progn
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
62 (set-syntax-table reftex-syntax-table-for-bib)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
63 ,@body)
46612
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 46131
diff changeset
64 (set-syntax-table saved-syntax))))
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 46131
diff changeset
65
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
66 (defun reftex-default-bibliography ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
67 ;; Return the expanded value of `reftex-default-bibliography'.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
68 ;; The expanded value is cached.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
69 (unless (eq (get 'reftex-default-bibliography :reftex-raw)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
70 reftex-default-bibliography)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
71 (put 'reftex-default-bibliography :reftex-expanded
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
72 (reftex-locate-bibliography-files
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
73 default-directory reftex-default-bibliography))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
74 (put 'reftex-default-bibliography :reftex-raw
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
75 reftex-default-bibliography))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
76 (get 'reftex-default-bibliography :reftex-expanded))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
77
46973
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
78 (defun reftex-bib-or-thebib ()
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
79 ;; Tests if BibTeX or \begin{tehbibliography} should be used for the
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
80 ;; citation
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
81 ;; Find the bof of the current file
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
82 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
83 (rest (or (member (list 'bof (buffer-file-name)) docstruct)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
84 docstruct))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
85 (bib (assq 'bib rest))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
86 (thebib (assq 'thebib rest))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
87 (bibmem (memq bib rest))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
88 (thebibmem (memq thebib rest)))
46973
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
89 (when (not (or thebib bib))
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
90 (setq bib (assq 'bib docstruct)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
91 thebib (assq 'thebib docstruct)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
92 bibmem (memq bib docstruct)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
93 thebibmem (memq thebib docstruct)))
46973
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
94 (if (> (length bibmem) (length thebibmem))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
95 (if bib 'bib nil)
46973
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
96 (if thebib 'thebib nil))))
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
97
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
98 (defun reftex-get-bibfile-list ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
99 ;; Return list of bibfiles for current document.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
100 ;; When using the chapterbib or bibunits package you should either
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
101 ;; use the same database files everywhere, or separate parts using
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
102 ;; different databases into different files (included into the mater file).
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
103 ;; Then this function will return the applicable database files.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
104
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
105 ;; Ensure access to scanning info
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
106 (reftex-access-scan-info)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
107 (or
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
108 ;; Try inside this file (and its includes)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
109 (cdr (reftex-last-assoc-before-elt
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
110 'bib (list 'eof (buffer-file-name))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
111 (member (list 'bof (buffer-file-name))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
112 (symbol-value reftex-docstruct-symbol))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
113 ;; Try after the beginning of this file
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
114 (cdr (assq 'bib (member (list 'bof (buffer-file-name))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
115 (symbol-value reftex-docstruct-symbol))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
116 ;; Anywhere in the entire document
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
117 (cdr (assq 'bib (symbol-value reftex-docstruct-symbol)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
118 (error "\\bibliography statement missing or .bib files not found")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
119
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
120 ;; Find a certain reference in any of the BibTeX files.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
121
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
122 (defun reftex-pop-to-bibtex-entry (key file-list &optional mark-to-kill
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
123 highlight item return)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
124 ;; Find BibTeX KEY in any file in FILE-LIST in another window.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
125 ;; If MARK-TO-KILL is non-nil, mark new buffer to kill.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
126 ;; If HIGHLIGHT is non-nil, highlight the match.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
127 ;; If ITEM in non-nil, search for bibitem instead of database entry.
73804
ad5c0d302d05 (reftex-pop-to-bibtex-entry): Preserve point when displaying a bibtex
Carsten Dominik <dominik@science.uva.nl>
parents: 69094
diff changeset
128 ;; If RETURN is non-nil, just return the entry and restore point.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
129
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
130 (let* ((re
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
131 (if item
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
132 (concat "\\\\bibitem\\(\\[[^]]*\\]\\)?{" (regexp-quote key) "}")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
133 (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
134 "[, \t\r\n}]")))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
135 (buffer-conf (current-buffer))
73804
ad5c0d302d05 (reftex-pop-to-bibtex-entry): Preserve point when displaying a bibtex
Carsten Dominik <dominik@science.uva.nl>
parents: 69094
diff changeset
136 file buf pos oldpos)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
137
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
138 (catch 'exit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
139 (while file-list
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
140 (setq file (car file-list)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
141 file-list (cdr file-list))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
142 (unless (setq buf (reftex-get-file-buffer-force file mark-to-kill))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
143 (error "No such file %s" file))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
144 (set-buffer buf)
73804
ad5c0d302d05 (reftex-pop-to-bibtex-entry): Preserve point when displaying a bibtex
Carsten Dominik <dominik@science.uva.nl>
parents: 69094
diff changeset
145 (setq oldpos (point))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
146 (widen)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
147 (goto-char (point-min))
73804
ad5c0d302d05 (reftex-pop-to-bibtex-entry): Preserve point when displaying a bibtex
Carsten Dominik <dominik@science.uva.nl>
parents: 69094
diff changeset
148 (if (not (re-search-forward re nil t))
ad5c0d302d05 (reftex-pop-to-bibtex-entry): Preserve point when displaying a bibtex
Carsten Dominik <dominik@science.uva.nl>
parents: 69094
diff changeset
149 (goto-char oldpos) ;; restore previous position of point
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
150 (goto-char (match-beginning 0))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
151 (setq pos (point))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
152 (when return
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
153 ;; Just return the relevant entry
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
154 (if item (goto-char (match-end 0)))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
155 (setq return (buffer-substring
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
156 (point) (reftex-end-of-bib-entry item)))
73804
ad5c0d302d05 (reftex-pop-to-bibtex-entry): Preserve point when displaying a bibtex
Carsten Dominik <dominik@science.uva.nl>
parents: 69094
diff changeset
157 (goto-char oldpos) ;; restore point.
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
158 (set-buffer buffer-conf)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
159 (throw 'exit return))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
160 (switch-to-buffer-other-window buf)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
161 (goto-char pos)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
162 (recenter 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
163 (if highlight
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
164 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
165 (throw 'exit (selected-window))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
166 (set-buffer buffer-conf)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
167 (if item
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
168 (error "No \\bibitem with citation key %s" key)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
169 (error "No BibTeX entry with citation key %s" key)))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
170
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
171 (defun reftex-end-of-bib-entry (item)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
172 (save-excursion
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
173 (condition-case nil
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
174 (if item
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
175 (progn (end-of-line)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
176 (re-search-forward
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
177 "\\\\bibitem\\|\\end{thebibliography}")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
178 (1- (match-beginning 0)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
179 (progn (forward-list 1) (point)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
180 (error (min (point-max) (+ 300 (point)))))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
181
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
182 ;; Parse bibtex buffers
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
183
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
184 (defun reftex-extract-bib-entries (buffers)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
185 ;; Extract bib entries which match regexps from BUFFERS.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
186 ;; BUFFERS is a list of buffers or file names.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
187 ;; Return list with entries."
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
188 (let* (re-list first-re rest-re
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
189 (buffer-list (if (listp buffers) buffers (list buffers)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
190 found-list entry buffer1 buffer alist
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
191 key-point start-point end-point default)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
192
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
193 ;; Read a regexp, completing on known citation keys.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
194 (setq default (regexp-quote (reftex-get-bibkey-default)))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
195 (setq re-list
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
196 (split-string
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
197 (completing-read
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
198 (concat
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
199 "Regex { && Regex...}: "
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
200 "[" default "]: ")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
201 (if reftex-mode
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
202 (if (fboundp 'LaTeX-bibitem-list)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
203 (LaTeX-bibitem-list)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
204 (cdr (assoc 'bibview-cache
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
205 (symbol-value reftex-docstruct-symbol))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
206 nil)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
207 nil nil nil 'reftex-cite-regexp-hist)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
208 "[ \t]*&&[ \t]*"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
209
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
210 (if (or (null re-list ) (equal re-list '("")))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
211 (setq re-list (list default)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
212
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
213 (setq first-re (car re-list) ; We'll use the first re to find things,
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
214 rest-re (cdr re-list)) ; the others to narrow down.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
215 (if (string-match "\\`[ \t]*\\'" (or first-re ""))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
216 (error "Empty regular expression"))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
217
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
218 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
219 (save-window-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
220
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
221 ;; Walk through all bibtex files
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
222 (while buffer-list
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
223 (setq buffer (car buffer-list)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
224 buffer-list (cdr buffer-list))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
225 (if (and (bufferp buffer)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
226 (buffer-live-p buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
227 (setq buffer1 buffer)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
228 (setq buffer1 (reftex-get-file-buffer-force
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
229 buffer (not reftex-keep-temporary-buffers))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
230 (if (not buffer1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
231 (message "No such BibTeX file %s (ignored)" buffer)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
232 (message "Scanning bibliography database %s" buffer1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
233
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
234 (set-buffer buffer1)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
235 (reftex-with-special-syntax-for-bib
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
236 (save-excursion
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
237 (goto-char (point-min))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
238 (while (re-search-forward first-re nil t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
239 (catch 'search-again
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
240 (setq key-point (point))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
241 (unless (re-search-backward
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
242 "\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
243 (throw 'search-again nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
244 (setq start-point (point))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
245 (goto-char (match-end 0))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
246 (condition-case nil
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
247 (up-list 1)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
248 (error (goto-char key-point)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
249 (throw 'search-again nil)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
250 (setq end-point (point))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
251
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
252 ;; Ignore @string, @comment and @c entries or things
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
253 ;; outside entries
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
254 (when (or (string= (downcase (match-string 2)) "string")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
255 (string= (downcase (match-string 2)) "comment")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
256 (string= (downcase (match-string 2)) "c")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
257 (< (point) key-point)) ; this means match not in {}
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
258 (goto-char key-point)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
259 (throw 'search-again nil))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
260
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
261 ;; Well, we have got a match
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
262 ;;(setq entry (concat
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
263 ;; (buffer-substring start-point (point)) "\n"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
264 (setq entry (buffer-substring start-point (point)))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
265
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
266 ;; Check if other regexp match as well
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
267 (setq re-list rest-re)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
268 (while re-list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
269 (unless (string-match (car re-list) entry)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
270 ;; nope - move on
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
271 (throw 'search-again nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
272 (pop re-list))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
273
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
274 (setq alist (reftex-parse-bibtex-entry
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
275 nil start-point end-point))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
276 (push (cons "&entry" entry) alist)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
277
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
278 ;; check for crossref entries
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
279 (if (assoc "crossref" alist)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
280 (setq alist
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
281 (append
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
282 alist (reftex-get-crossref-alist alist))))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
283
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
284 ;; format the entry
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
285 (push (cons "&formatted" (reftex-format-bib-entry alist))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
286 alist)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
287
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
288 ;; make key the first element
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
289 (push (reftex-get-bib-field "&key" alist) alist)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
290
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
291 ;; add it to the list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
292 (push alist found-list)))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
293 (reftex-kill-temporary-buffers))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
294 (setq found-list (nreverse found-list))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
295
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
296 ;; Sorting
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
297 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
298 ((eq 'author reftex-sort-bibtex-matches)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
299 (sort found-list 'reftex-bib-sort-author))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
300 ((eq 'year reftex-sort-bibtex-matches)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
301 (sort found-list 'reftex-bib-sort-year))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
302 ((eq 'reverse-year reftex-sort-bibtex-matches)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
303 (sort found-list 'reftex-bib-sort-year-reverse))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
304 (t found-list))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
305
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
306 (defun reftex-bib-sort-author (e1 e2)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
307 (let ((al1 (reftex-get-bib-names "author" e1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
308 (al2 (reftex-get-bib-names "author" e2)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
309 (while (and al1 al2 (string= (car al1) (car al2)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
310 (pop al1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
311 (pop al2))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
312 (if (and (stringp (car al1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
313 (stringp (car al2)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
314 (string< (car al1) (car al2))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
315 (not (stringp (car al1))))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
316
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
317 (defun reftex-bib-sort-year (e1 e2)
62402
a7e02ef1e3d6 Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 60918
diff changeset
318 (< (string-to-number (or (cdr (assoc "year" e1)) "0"))
a7e02ef1e3d6 Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 60918
diff changeset
319 (string-to-number (or (cdr (assoc "year" e2)) "0"))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
320
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
321 (defun reftex-bib-sort-year-reverse (e1 e2)
62402
a7e02ef1e3d6 Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 60918
diff changeset
322 (> (string-to-number (or (cdr (assoc "year" e1)) "0"))
a7e02ef1e3d6 Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 60918
diff changeset
323 (string-to-number (or (cdr (assoc "year" e2)) "0"))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
324
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
325 (defun reftex-get-crossref-alist (entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
326 ;; return the alist from a crossref entry
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
327 (let ((crkey (cdr (assoc "crossref" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
328 start)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
329 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
330 (save-restriction
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
331 (widen)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
332 (if (re-search-forward
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
333 (concat "@\\w+[{(][ \t\n\r]*" (regexp-quote crkey)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
334 "[ \t\n\r]*,") nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
335 (progn
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
336 (setq start (match-beginning 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
337 (condition-case nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
338 (up-list 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
339 (error nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
340 (reftex-parse-bibtex-entry nil start (point)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
341 nil)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
342
45318
b80d723ad7cc Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 38422
diff changeset
343 ;; Parse the bibliography environment
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
344 (defun reftex-extract-bib-entries-from-thebibliography (files)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
345 ;; Extract bib-entries from the \begin{thebibliography} environment.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
346 ;; Parsing is not as good as for the BibTeX database stuff.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
347 ;; The environment should be located in file FILE.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
348
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
349 (let* (start end buf entries re re-list file default)
25801
8f6d4157f700 (reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents: 25280
diff changeset
350 (unless files
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
351 (error "Need file name to find thebibliography environment"))
25801
8f6d4157f700 (reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents: 25280
diff changeset
352 (while (setq file (pop files))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
353 (setq buf (reftex-get-file-buffer-force
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
354 file (not reftex-keep-temporary-buffers)))
25801
8f6d4157f700 (reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents: 25280
diff changeset
355 (unless buf
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
356 (error "No such file %s" file))
25801
8f6d4157f700 (reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents: 25280
diff changeset
357 (message "Scanning thebibliography environment in %s" file)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
358
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104768
diff changeset
359 (with-current-buffer buf
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
360 (save-restriction
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
361 (widen)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
362 (goto-char (point-min))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
363 (while (re-search-forward
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
364 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
365 (beginning-of-line 2)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
366 (setq start (point))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
367 (if (re-search-forward
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
368 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
369 (progn
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
370 (beginning-of-line 1)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
371 (setq end (point))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
372 (when (and start end)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
373 (setq entries
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
374 (append entries
25801
8f6d4157f700 (reftex-pop-to-bibtex-entry): Fixed bug with recentering window.
Carsten Dominik <dominik@science.uva.nl>
parents: 25280
diff changeset
375 (mapcar 'reftex-parse-bibitem
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
376 (delete ""
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
377 (split-string
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
378 (buffer-substring-no-properties start end)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
379 "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*"))))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
380 (goto-char end)))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
381 (unless entries
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
382 (error "No bibitems found"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
383
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
384 ;; Read a regexp, completing on known citation keys.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
385 (setq default (regexp-quote (reftex-get-bibkey-default)))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
386 (setq re-list
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
387 (split-string
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
388 (completing-read
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
389 (concat
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
390 "Regex { && Regex...}: "
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
391 "[" default "]: ")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
392 (if reftex-mode
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
393 (if (fboundp 'LaTeX-bibitem-list)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
394 (LaTeX-bibitem-list)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
395 (cdr (assoc 'bibview-cache
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
396 (symbol-value reftex-docstruct-symbol))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
397 nil)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
398 nil nil nil 'reftex-cite-regexp-hist)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
399 "[ \t]*&&[ \t]*"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
400
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
401 (if (or (null re-list ) (equal re-list '("")))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
402 (setq re-list (list default)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
403
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
404 (if (string-match "\\`[ \t]*\\'" (car re-list))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
405 (error "Empty regular expression"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
406
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
407 (while (and (setq re (pop re-list)) entries)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
408 (setq entries
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
409 (delq nil (mapcar
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
410 (lambda (x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
411 (if (string-match re (cdr (assoc "&entry" x)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
412 x nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
413 entries))))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
414 (setq entries
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
415 (mapcar
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
416 (lambda (x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
417 (push (cons "&formatted" (reftex-format-bibitem x)) x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
418 (push (reftex-get-bib-field "&key" x) x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
419 x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
420 entries))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
421
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
422 entries))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
423
46683
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
424 (defun reftex-get-bibkey-default ()
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
425 ;; Return the word before the cursor. If the cursor is in a
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
426 ;; citation macro, return the word before the macro.
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
427 (let* ((macro (reftex-what-macro 1)))
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
428 (save-excursion
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
429 (if (and macro (string-match "cite" (car macro)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
430 (goto-char (cdr macro)))
46683
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
431 (skip-chars-backward "^a-zA-Z0-9")
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
432 (reftex-this-word))))
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
433
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
434 ;; Parse and format individual entries
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
435
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
436 (defun reftex-get-bib-names (field entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
437 ;; Return a list with the author or editor names in ENTRY
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
438 (let ((names (reftex-get-bib-field field entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
439 (if (equal "" names)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
440 (setq names (reftex-get-bib-field "editor" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
441 (while (string-match "\\band\\b[ \t]*" names)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
442 (setq names (replace-match "\n" nil t names)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
443 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" names)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
444 (setq names (replace-match "" nil t names)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
445 (while (string-match "^[ \t]+\\|[ \t]+$" names)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
446 (setq names (replace-match "" nil t names)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
447 (while (string-match "[ \t][ \t]+" names)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
448 (setq names (replace-match " " nil t names)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
449 (split-string names "\n")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
450
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
451 (defun reftex-parse-bibtex-entry (entry &optional from to)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
452 (let (alist key start field)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
453 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
454 (save-restriction
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
455 (if entry
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
456 (progn
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
457 (set-buffer (get-buffer-create " *RefTeX-scratch*"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
458 (fundamental-mode)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
459 (set-syntax-table reftex-syntax-table-for-bib)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
460 (erase-buffer)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
461 (insert entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
462 (widen)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
463 (narrow-to-region from to))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
464 (goto-char (point-min))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
465
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
466 (if (re-search-forward
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
467 "@\\(\\w+\\)[ \t\n\r]*[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
468 (setq alist
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
469 (list
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
470 (cons "&type" (downcase (reftex-match-string 1)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
471 (cons "&key" (reftex-match-string 2)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
472 (while (re-search-forward "\\(\\w+\\)[ \t\n\r]*=[ \t\n\r]*" nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
473 (setq key (downcase (reftex-match-string 1)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
474 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
475 ((= (following-char) ?{)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
476 (forward-char 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
477 (setq start (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
478 (condition-case nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
479 (up-list 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
480 (error nil)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
481 ((= (following-char) ?\")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
482 (forward-char 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
483 (setq start (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
484 (while (and (search-forward "\"" nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
485 (= ?\\ (char-after (- (point) 2))))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
486 (t
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
487 (setq start (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
488 (re-search-forward "[ \t]*[\n\r,}]" nil 1)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
489 (setq field (buffer-substring-no-properties start (1- (point))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
490 ;; remove extra whitespace
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
491 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
492 (setq field (replace-match " " nil t field)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
493 ;; remove leading garbage
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
494 (if (string-match "^[ \t{]+" field)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
495 (setq field (replace-match "" nil t field)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
496 ;; remove trailing garbage
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
497 (if (string-match "[ \t}]+$" field)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
498 (setq field (replace-match "" nil t field)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
499 (push (cons key field) alist))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
500 alist))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
501
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
502 (defun reftex-get-bib-field (fieldname entry &optional format)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
503 ;; Extract the field FIELDNAME from an ENTRY
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
504 (let ((cell (assoc fieldname entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
505 (if cell
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
506 (if format
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
507 (format format (cdr cell))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
508 (cdr cell))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
509 "")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
510
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
511 (defun reftex-format-bib-entry (entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
512 ;; Format a BibTeX ENTRY so that it is nice to look at
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
513 (let*
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
514 ((auth-list (reftex-get-bib-names "author" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
515 (authors (mapconcat 'identity auth-list ", "))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
516 (year (reftex-get-bib-field "year" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
517 (title (reftex-get-bib-field "title" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
518 (type (reftex-get-bib-field "&type" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
519 (key (reftex-get-bib-field "&key" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
520 (extra
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
521 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
522 ((equal type "article")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
523 (concat (reftex-get-bib-field "journal" entry) " "
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
524 (reftex-get-bib-field "volume" entry) ", "
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
525 (reftex-get-bib-field "pages" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
526 ((equal type "book")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
527 (concat "book (" (reftex-get-bib-field "publisher" entry) ")"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
528 ((equal type "phdthesis")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
529 (concat "PhD: " (reftex-get-bib-field "school" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
530 ((equal type "mastersthesis")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
531 (concat "Master: " (reftex-get-bib-field "school" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
532 ((equal type "inbook")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
533 (concat "Chap: " (reftex-get-bib-field "chapter" entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
534 ", pp. " (reftex-get-bib-field "pages" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
535 ((or (equal type "conference")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
536 (equal type "incollection")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
537 (equal type "inproceedings"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
538 (reftex-get-bib-field "booktitle" entry "in: %s"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
539 (t ""))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
540 (setq authors (reftex-truncate authors 30 t t))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
541 (when (reftex-use-fonts)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
542 (put-text-property 0 (length key) 'face
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
543 (reftex-verified-face reftex-label-face
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
544 'font-lock-constant-face
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
545 'font-lock-reference-face)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
546 key)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
547 (put-text-property 0 (length authors) 'face reftex-bib-author-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
548 authors)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
549 (put-text-property 0 (length year) 'face reftex-bib-year-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
550 year)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
551 (put-text-property 0 (length title) 'face reftex-bib-title-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
552 title)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
553 (put-text-property 0 (length extra) 'face reftex-bib-extra-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
554 extra))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
555 (concat key "\n " authors " " year " " extra "\n " title "\n\n")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
556
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
557 (defun reftex-parse-bibitem (item)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
558 ;; Parse a \bibitem entry
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
559 (let ((key "") (text ""))
37998
706af946b1e7 * reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents: 34402
diff changeset
560 (when (string-match "\\`{\\([^}]+\\)}\\([^\000]*\\)" item)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
561 (setq key (match-string 1 item)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
562 text (match-string 2 item)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
563 ;; Clean up the text a little bit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
564 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
565 (setq text (replace-match " " nil t text)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
566 (if (string-match "\\`[ \t]+" text)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
567 (setq text (replace-match "" nil t text)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
568 (list
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
569 (cons "&key" key)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
570 (cons "&text" text)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
571 (cons "&entry" (concat key " " text)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
572
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
573 (defun reftex-format-bibitem (item)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
574 ;; Format a \bibitem entry so that it is (relatively) nice to look at.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
575 (let ((text (reftex-get-bib-field "&text" item))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
576 (key (reftex-get-bib-field "&key" item))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
577 (lines nil))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
578
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
579 ;; Wrap the text into several lines.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
580 (while (and (> (length text) 70)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
581 (string-match " " (substring text 60)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
582 (push (substring text 0 (+ 60 (match-beginning 0))) lines)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
583 (setq text (substring text (+ 61 (match-beginning 0)))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
584 (push text lines)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
585 (setq text (mapconcat 'identity (nreverse lines) "\n "))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
586
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
587 (when (reftex-use-fonts)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
588 (put-text-property 0 (length text) 'face reftex-bib-author-face text))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
589 (concat key "\n " text "\n\n")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
590
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
591 ;; Make a citation
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
592
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
593 ;;;###autoload
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
594 (defun reftex-citation (&optional no-insert format-key)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
595 "Make a citation using BibTeX database files.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
596 After prompting for a regular expression, scans the buffers with
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
597 bibtex entries (taken from the \\bibliography command) and offers the
46131
7255ef8cf60f (reftex-citation): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 45318
diff changeset
598 matching entries for selection. The selected entry is formatted according
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
599 to `reftex-cite-format' and inserted into the buffer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
600
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
601 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
602
59579
a588c86a429c Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-40
Miles Bader <miles@gnu.org>
parents: 59534
diff changeset
603 FORMAT-KEY can be used to pre-select a citation format.
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
604
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
605 When called with a `C-u' prefix, prompt for optional arguments in
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
606 cite macros. When called with a numeric prefix, make that many
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
607 citations. When called with point inside the braces of a `\\cite'
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
608 command, it will add another key, ignoring the value of
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
609 `reftex-cite-format'.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
610
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
611 The regular expression uses an expanded syntax: && is interpreted as `and'.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
612 Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
613 While entering the regexp, completion on knows citation keys is possible.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
614 `=' is a good regular expression to match all entries in all files."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
615
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
616 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
617
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
618 ;; check for recursive edit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
619 (reftex-check-recursive-edit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
620
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
621 ;; This function may also be called outside reftex-mode.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
622 ;; Thus look for the scanning info only if in reftex-mode.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
623
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
624 (when reftex-mode
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
625 (reftex-access-scan-info nil))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
626
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
627 ;; Call reftex-do-citation, but protected
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
628 (unwind-protect
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
629 (reftex-do-citation current-prefix-arg no-insert format-key)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
630 (reftex-kill-temporary-buffers)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
631
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
632 (defun reftex-do-citation (&optional arg no-insert format-key)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
633 ;; This really does the work of reftex-citation.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
634
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
635 (let* ((format (reftex-figure-out-cite-format arg no-insert format-key))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
636 (docstruct-symbol reftex-docstruct-symbol)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
637 (selected-entries (reftex-offer-bib-menu))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
638 (insert-entries selected-entries)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
639 entry string cite-view)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
640
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
641 (when (stringp selected-entries)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
642 (error selected-entries))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
643 (unless selected-entries (error "Quit"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
644
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
645 (if (stringp selected-entries)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
646 ;; Nonexistent entry
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
647 (setq selected-entries nil
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
648 insert-entries (list (list selected-entries
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
649 (cons "&key" selected-entries))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
650 ;; It makes sense to compute the cite-view strings.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
651 (setq cite-view t))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
652
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
653 (when (eq (car selected-entries) 'concat)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
654 ;; All keys go into a single command - we need to trick a little
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
655 ;; FIXME: Unfortunately, this meens that commenting does not work right.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
656 (pop selected-entries)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
657 (let ((concat-keys (mapconcat 'car selected-entries ",")))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
658 (setq insert-entries
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
659 (list (list concat-keys (cons "&key" concat-keys))))))
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
660
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
661 (unless no-insert
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
662
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
663 ;; We shall insert this into the buffer...
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
664 (message "Formatting...")
59579
a588c86a429c Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-40
Miles Bader <miles@gnu.org>
parents: 59534
diff changeset
665
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
666 (while (setq entry (pop insert-entries))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
667 ;; Format the citation and insert it
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
668 (setq string (if reftex-format-cite-function
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
669 (funcall reftex-format-cite-function
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
670 (reftex-get-bib-field "&key" entry)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
671 format)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
672 (reftex-format-citation entry format)))
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
673 (when (or (eq reftex-cite-prompt-optional-args t)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
674 (and reftex-cite-prompt-optional-args
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
675 (equal arg '(4))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
676 (let ((start 0) (nth 0) value)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
677 (while (setq start (string-match "\\[\\]" string start))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
678 (setq value (read-string (format "Optional argument %d: "
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
679 (setq nth (1+ nth)))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
680 (setq string (replace-match (concat "[" value "]") t t string))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
681 (setq start (1+ start)))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
682 ;; Should we cleanup empty optional arguments?
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
683 ;; if the first is empty, it can be removed. If the second is empty,
60056
978d83f0a49f (reftex-do-citation): Cleanup single
Carsten Dominik <dominik@science.uva.nl>
parents: 59579
diff changeset
684 ;; it has to go. If there is only a single arg and empty, it can go
62467
35f6599373fc * textmodes/reftex-vars.el (reftex-cite-format-builtin): Support
Carsten Dominik <dominik@science.uva.nl>
parents: 62402
diff changeset
685 ;; as well.
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
686 (when reftex-cite-cleanup-optional-args
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
687 (cond
60056
978d83f0a49f (reftex-do-citation): Cleanup single
Carsten Dominik <dominik@science.uva.nl>
parents: 59579
diff changeset
688 ((string-match "\\([a-zA-Z0-9]\\)\\[\\]{" string)
978d83f0a49f (reftex-do-citation): Cleanup single
Carsten Dominik <dominik@science.uva.nl>
parents: 59579
diff changeset
689 (setq string (replace-match "\\1{" nil nil string)))
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
690 ((string-match "\\[\\]\\(\\[[a-zA-Z0-9., ]+\\]\\)" string)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
691 (setq string (replace-match "\\1" nil nil string)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
692 ((string-match "\\[\\]\\[\\]" string)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
693 (setq string (replace-match "" t t string)))))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
694 (insert string))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
695
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
696 ;; Reposition cursor?
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
697 (when (string-match "\\?" string)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
698 (search-backward "?")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
699 (delete-char 1))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
700
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
701 ;; Tell AUCTeX
85198
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
702 (when (and reftex-mode
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
703 (fboundp 'LaTeX-add-bibitems)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
704 reftex-plug-into-AUCTeX)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
705 (apply 'LaTeX-add-bibitems (mapcar 'car selected-entries)))
85198
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
706
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
707 ;; Produce the cite-view strings
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
708 (when (and reftex-mode reftex-cache-cite-echo cite-view)
85198
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
709 (mapc (lambda (entry)
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
710 (reftex-make-cite-echo-string entry docstruct-symbol))
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
711 selected-entries))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
712
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
713 (message ""))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
714
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
715 (set-marker reftex-select-return-marker nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
716 (reftex-kill-buffer "*RefTeX Select*")
85198
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
717
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
718 ;; Check if the prefix arg was numeric, and call recursively
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
719 (when (integerp arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
720 (if (> arg 1)
85198
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
721 (progn
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
722 (skip-chars-backward "}")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
723 (decf arg)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
724 (reftex-do-citation arg))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
725 (forward-char 1)))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
726
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
727 ;; Return the citation key
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
728 (car (car selected-entries))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
729
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
730 (defun reftex-figure-out-cite-format (arg &optional no-insert format-key)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
731 ;; Check if there is already a cite command at point and change cite format
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
732 ;; in order to only add another reference in the same cite command.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
733 (let ((macro (car (reftex-what-macro 1)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
734 (cite-format-value (reftex-get-cite-format))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
735 key format)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
736 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
737 (no-insert
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
738 ;; Format does not really matter because nothing will be inserted.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
739 (setq format "%l"))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
740
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
741 ((and (stringp macro)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
742 (string-match "\\`\\\\cite\\|cite\\'" macro))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
743 ;; We are already inside a cite macro
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
744 (if (or (not arg) (not (listp arg)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
745 (setq format
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
746 (concat
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
747 (if (member (preceding-char) '(?\{ ?,)) "" ",")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
748 "%l"
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
749 (if (member (following-char) '(?\} ?,)) "" ",")))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
750 (setq format "%l")))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
751 (t
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
752 ;; Figure out the correct format
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
753 (setq format
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
754 (if (and (symbolp cite-format-value)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
755 (assq cite-format-value reftex-cite-format-builtin))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
756 (nth 2 (assq cite-format-value reftex-cite-format-builtin))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
757 cite-format-value))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
758 (when (listp format)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
759 (setq key
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
760 (or format-key
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
761 (reftex-select-with-char
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
762 "" (concat "SELECT A CITATION FORMAT\n\n"
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
763 (mapconcat
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
764 (lambda (x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
765 (format "[%c] %s %s" (car x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
766 (if (> (car x) 31) " " "")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
767 (cdr x)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
768 format "\n")))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
769 (if (assq key format)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
770 (setq format (cdr (assq key format)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
771 (error "No citation format associated with key `%c'" key)))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
772 format))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
773
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
774 (defun reftex-citep ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
775 "Call `reftex-citation' with a format selector `?p'."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
776 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
777 (reftex-citation nil ?p))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
778
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
779 (defun reftex-citet ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
780 "Call `reftex-citation' with a format selector `?t'."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
781 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
782 (reftex-citation nil ?t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
783
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
784 (defvar reftex-select-bib-map)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
785 (defun reftex-offer-bib-menu ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
786 ;; Offer bib menu and return list of selected items
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
787
46973
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
788 (let ((bibtype (reftex-bib-or-thebib))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
789 found-list rtn key data selected-entries)
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
790 (while
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
791 (not
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
792 (catch 'done
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
793 ;; Scan bibtex files
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
794 (setq found-list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
795 (cond
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
796 ((eq bibtype 'bib)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
797 ; ((assq 'bib (symbol-value reftex-docstruct-symbol))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
798 ;; using BibTeX database files.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
799 (reftex-extract-bib-entries (reftex-get-bibfile-list)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
800 ((eq bibtype 'thebib)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
801 ; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
802 ;; using thebibliography environment.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
803 (reftex-extract-bib-entries-from-thebibliography
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
804 (reftex-uniquify
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
805 (mapcar 'cdr
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
806 (reftex-all-assq
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
807 'thebib (symbol-value reftex-docstruct-symbol))))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
808 (reftex-default-bibliography
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
809 (message "Using default bibliography")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
810 (reftex-extract-bib-entries (reftex-default-bibliography)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
811 (t (error "No valid bibliography in this document, and no default available"))))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
812
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
813 (unless found-list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
814 (error "Sorry, no matches found"))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
815
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
816 ;; Remember where we came from
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
817 (setq reftex-call-back-to-this-buffer (current-buffer))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
818 (set-marker reftex-select-return-marker (point))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
819
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
820 ;; Offer selection
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
821 (save-window-excursion
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
822 (delete-other-windows)
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
823 (reftex-kill-buffer "*RefTeX Select*")
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
824 (switch-to-buffer-other-window "*RefTeX Select*")
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
825 (unless (eq major-mode 'reftex-select-bib-mode)
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
826 (reftex-select-bib-mode))
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
827 (let ((buffer-read-only nil))
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
828 (erase-buffer)
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
829 (reftex-insert-bib-matches found-list))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
830 (setq buffer-read-only t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
831 (if (= 0 (buffer-size))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
832 (error "No matches found"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
833 (setq truncate-lines t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
834 (goto-char 1)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
835 (while t
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
836 (setq rtn
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
837 (reftex-select-item
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
838 reftex-citation-prompt
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
839 reftex-citation-help
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
840 reftex-select-bib-map
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
841 nil
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
842 'reftex-bibtex-selection-callback nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
843 (setq key (car rtn)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
844 data (nth 1 rtn))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
845 (unless key (throw 'done t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
846 (cond
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
847 ((eq key ?g)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
848 ;; Start over
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
849 (throw 'done nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
850 ((eq key ?r)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
851 ;; Restrict with new regular expression
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
852 (setq found-list (reftex-restrict-bib-matches found-list))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
853 (let ((buffer-read-only nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
854 (erase-buffer)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
855 (reftex-insert-bib-matches found-list))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
856 (goto-char 1))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
857 ((eq key ?A)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
858 ;; Take all (marked)
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
859 (setq selected-entries
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
860 (if reftex-select-marked
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
861 (mapcar 'car (nreverse reftex-select-marked))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
862 found-list))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
863 (throw 'done t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
864 ((eq key ?a)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
865 ;; Take all (marked), and push the symbol 'concat
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
866 (setq selected-entries
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
867 (cons 'concat
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
868 (if reftex-select-marked
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
869 (mapcar 'car (nreverse reftex-select-marked))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
870 found-list)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
871 (throw 'done t))
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
872 ((eq key ?e)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
873 ;; Take all (marked), and push the symbol 'concat
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
874 (reftex-extract-bib-file found-list reftex-select-marked)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
875 (setq selected-entries "BibTeX database file created")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
876 (throw 'done t))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
877 ((eq key ?E)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
878 ;; Take all (marked), and push the symbol 'concat
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
879 (reftex-extract-bib-file found-list reftex-select-marked
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
880 'complement)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
881 (setq selected-entries "BibTeX database file created")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
882 (throw 'done t))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
883 ((or (eq key ?\C-m)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
884 (eq key 'return))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
885 ;; Take selected
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
886 (setq selected-entries
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
887 (if reftex-select-marked
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
888 (cons 'concat
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
889 (mapcar 'car (nreverse reftex-select-marked)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
890 (if data (list data) nil)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
891 (throw 'done t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
892 ((stringp key)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
893 ;; Got this one with completion
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
894 (setq selected-entries key)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
895 (throw 'done t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
896 (t
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
897 (ding))))))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
898 selected-entries))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
899
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
900 (defun reftex-restrict-bib-matches (found-list)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
901 ;; Limit FOUND-LIST with more regular expressions
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
902 (let ((re-list (split-string (read-string
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
903 "RegExp [ && RegExp...]: "
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
904 nil 'reftex-cite-regexp-hist)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
905 "[ \t]*&&[ \t]*"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
906 (found-list-r found-list)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
907 re)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
908 (while (setq re (pop re-list))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
909 (setq found-list-r
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
910 (delq nil
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
911 (mapcar
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
912 (lambda (x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
913 (if (string-match
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
914 re (cdr (assoc "&entry" x)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
915 x
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
916 nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
917 found-list-r))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
918 (if found-list-r
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
919 found-list-r
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
920 (ding)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
921 found-list)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
922
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
923 (defun reftex-extract-bib-file (all &optional marked complement)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
924 ;; Limit FOUND-LIST with more regular expressions
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
925 (let ((file (read-file-name "File to create: ")))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
926 (find-file-other-window file)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
927 (if (> (buffer-size) 0)
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
928 (unless (yes-or-no-p
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
929 (format "Overwrite non-empty file %s? " file))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
930 (error "Abort")))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
931 (erase-buffer)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
932 (setq all (delq nil
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
933 (mapcar
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
934 (lambda (x)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
935 (if marked
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
936 (if (or (and (assoc x marked) (not complement))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
937 (and (not (assoc x marked)) complement))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
938 (cdr (assoc "&entry" x))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
939 nil)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
940 (cdr (assoc "&entry" x))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
941 all)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
942 (insert (mapconcat 'identity all "\n\n"))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
943 (save-buffer)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
944 (goto-char (point-min))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
945
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
946 (defun reftex-insert-bib-matches (list)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
947 ;; Insert the bib matches and number them correctly
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
948 (let ((mouse-face
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
949 (if (memq reftex-highlight-selection '(mouse both))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
950 reftex-mouse-selected-face
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
951 nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
952 tmp len)
85198
dae14770f516 Remove some trailing whitespace.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
953 (mapc
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
954 (lambda (x)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
955 (setq tmp (cdr (assoc "&formatted" x))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
956 len (length tmp))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
957 (put-text-property 0 len :data x tmp)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
958 (put-text-property 0 (1- len) 'mouse-face mouse-face tmp)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
959 (insert tmp))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
960 list))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
961 (run-hooks 'reftex-display-copied-context-hook))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
962
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
963 (defun reftex-format-names (namelist n)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
964 (let (last (len (length namelist)))
46612
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 46131
diff changeset
965 (if (= n 0) (setq n len))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
966 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
967 ((< len 1) "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
968 ((= 1 len) (car namelist))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
969 ((> len n) (concat (car namelist) (nth 2 reftex-cite-punctuation)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
970 (t
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
971 (setq n (min len n)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
972 last (nth (1- n) namelist))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
973 (setcdr (nthcdr (- n 2) namelist) nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
974 (concat
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
975 (mapconcat 'identity namelist (nth 0 reftex-cite-punctuation))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
976 (nth 1 reftex-cite-punctuation)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
977 last)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
978
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
979 (defun reftex-format-citation (entry format)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
980 ;; Format a citation from the info in the BibTeX ENTRY
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
981
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
982 (unless (stringp format) (setq format "\\cite{%l}"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
983
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
984 (if (and reftex-comment-citations
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
985 (string-match "%l" reftex-cite-comment-format))
60918
58a53f588384 * textmodes/refbib.el, textmodes/refer.el, textmodes/reftex-cite.el,
Werner LEMBERG <wl@gnu.org>
parents: 60056
diff changeset
986 (error "reftex-cite-comment-format contains invalid %%l"))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
987
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
988 (while (string-match
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
989 "\\(\\`\\|[^%]\\)\\(\\(%\\([0-9]*\\)\\([a-zA-Z]\\)\\)[.,;: ]*\\)"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
990 format)
62402
a7e02ef1e3d6 Replace `string-to-int' by `string-to-number'.
Juanma Barranquero <lekktu@gmail.com>
parents: 60918
diff changeset
991 (let ((n (string-to-number (match-string 4 format)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
992 (l (string-to-char (match-string 5 format)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
993 rpl b e)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
994 (save-match-data
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
995 (setq rpl
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
996 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
997 ((= l ?l) (concat
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
998 (reftex-get-bib-field "&key" entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
999 (if reftex-comment-citations
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1000 reftex-cite-comment-format
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1001 "")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1002 ((= l ?a) (reftex-format-names
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1003 (reftex-get-bib-names "author" entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1004 (or n 2)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1005 ((= l ?A) (car (reftex-get-bib-names "author" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1006 ((= l ?b) (reftex-get-bib-field "booktitle" entry "in: %s"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1007 ((= l ?B) (reftex-abbreviate-title
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1008 (reftex-get-bib-field "booktitle" entry "in: %s")))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1009 ((= l ?c) (reftex-get-bib-field "chapter" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1010 ((= l ?d) (reftex-get-bib-field "edition" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1011 ((= l ?e) (reftex-format-names
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1012 (reftex-get-bib-names "editor" entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1013 (or n 2)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1014 ((= l ?E) (car (reftex-get-bib-names "editor" entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1015 ((= l ?h) (reftex-get-bib-field "howpublished" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1016 ((= l ?i) (reftex-get-bib-field "institution" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1017 ((= l ?j) (reftex-get-bib-field "journal" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1018 ((= l ?k) (reftex-get-bib-field "key" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1019 ((= l ?m) (reftex-get-bib-field "month" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1020 ((= l ?n) (reftex-get-bib-field "number" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1021 ((= l ?o) (reftex-get-bib-field "organization" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1022 ((= l ?p) (reftex-get-bib-field "pages" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1023 ((= l ?P) (car (split-string
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1024 (reftex-get-bib-field "pages" entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1025 "[- .]+")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1026 ((= l ?s) (reftex-get-bib-field "school" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1027 ((= l ?u) (reftex-get-bib-field "publisher" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1028 ((= l ?r) (reftex-get-bib-field "address" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1029 ((= l ?t) (reftex-get-bib-field "title" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1030 ((= l ?T) (reftex-abbreviate-title
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1031 (reftex-get-bib-field "title" entry)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1032 ((= l ?v) (reftex-get-bib-field "volume" entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1033 ((= l ?y) (reftex-get-bib-field "year" entry)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1034
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1035 (if (string= rpl "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1036 (setq b (match-beginning 2) e (match-end 2))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1037 (setq b (match-beginning 3) e (match-end 3)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1038 (setq format (concat (substring format 0 b) rpl (substring format e)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1039 (while (string-match "%%" format)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1040 (setq format (replace-match "%" t t format)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1041 (while (string-match "[ ,.;:]*%<" format)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1042 (setq format (replace-match "" t t format)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1043 format)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1044
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1045 (defun reftex-make-cite-echo-string (entry docstruct-symbol)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1046 ;; Format a bibtex entry for the echo area and cache the result.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1047 (let* ((key (reftex-get-bib-field "&key" entry))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1048 (string
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1049 (let* ((reftex-cite-punctuation '(" " " & " " etal.")))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1050 (reftex-format-citation entry reftex-cite-view-format)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1051 (cache (assq 'bibview-cache (symbol-value docstruct-symbol)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1052 (cache-entry (assoc key (cdr cache))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1053 (unless cache
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1054 ;; This docstruct has no cache - make one.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1055 (set docstruct-symbol (cons (cons 'bibview-cache nil)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1056 (symbol-value docstruct-symbol))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1057 (when reftex-cache-cite-echo
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1058 (setq key (copy-sequence key))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1059 (set-text-properties 0 (length key) nil key)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1060 (set-text-properties 0 (length string) nil string)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1061 (if cache-entry
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1062 (unless (string= (cdr cache-entry) string)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1063 (setcdr cache-entry string)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1064 (put reftex-docstruct-symbol 'modified t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1065 (push (cons key string) (cdr cache))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1066 (put reftex-docstruct-symbol 'modified t)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1067 string))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1068
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1069 (defun reftex-bibtex-selection-callback (data ignore no-revisit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1070 ;; Callback function to be called from the BibTeX selection, in
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1071 ;; order to display context. This function is relatively slow and not
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1072 ;; recommended for follow mode. It works OK for individual lookups.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1073 (let ((win (selected-window))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1074 (key (reftex-get-bib-field "&key" data))
46973
11e08f9901ea Update to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
1075 bibfile-list item bibtype)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1076
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1077 (catch 'exit
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104768
diff changeset
1078 (with-current-buffer reftex-call-back-to-this-buffer
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1079 (setq bibtype (reftex-bib-or-thebib))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1080 (cond
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1081 ((eq bibtype 'bib)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1082 ; ((assq 'bib (symbol-value reftex-docstruct-symbol))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1083 (setq bibfile-list (reftex-get-bibfile-list)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1084 ((eq bibtype 'thebib)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1085 ; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1086 (setq bibfile-list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1087 (reftex-uniquify
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1088 (mapcar 'cdr
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1089 (reftex-all-assq
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1090 'thebib (symbol-value reftex-docstruct-symbol))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1091 item t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1092 (reftex-default-bibliography
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1093 (setq bibfile-list (reftex-default-bibliography)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1094 (t (ding) (throw 'exit nil))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1095
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1096 (when no-revisit
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1097 (setq bibfile-list (reftex-visited-files bibfile-list)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1098
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1099 (condition-case nil
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1100 (reftex-pop-to-bibtex-entry
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1101 key bibfile-list (not reftex-keep-temporary-buffers) t item)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50976
diff changeset
1102 (error (ding))))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1103
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1104 (select-window win)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1105
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1106 ;;; Global BibTeX file
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1107 (defun reftex-all-used-citation-keys ()
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1108 (reftex-access-scan-info)
65548
253cad16882d Little fixes to remove compiler warnings
Carsten Dominik <dominik@science.uva.nl>
parents: 64751
diff changeset
1109 (let ((files (reftex-all-document-files)) file keys kk k)
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104768
diff changeset
1110 (save-current-buffer
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1111 (while (setq file (pop files))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1112 (set-buffer (reftex-get-file-buffer-force file 'mark))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1113 (save-excursion
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1114 (save-restriction
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1115 (widen)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1116 (goto-char (point-min))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1117 (while (re-search-forward "^[^%\n\r]*\\\\\\(bibentry\\|[a-zA-Z]*cite[a-zA-Z]*\\)\\(\\[[^\\]]*\\]\\)?{\\([^}]+\\)}" nil t)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1118 (setq kk (match-string-no-properties 3))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1119 (while (string-match "%.*\n?" kk)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1120 (setq kk (replace-match "" t t kk)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1121 (setq kk (split-string kk "[, \t\r\n]+"))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1122 (while (setq k (pop kk))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1123 (or (member k keys)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1124 (setq keys (cons k keys)))))))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1125 (reftex-kill-temporary-buffers)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1126 keys))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1127
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1128 (defun reftex-create-bibtex-file (bibfile)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1129 "Create a new BibTeX database file with all entries referenced in document.
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1130 The command prompts for a filename and writes the collected entries to
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1131 that file. Only entries referenced in the current document with
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1132 any \\cite-like macros are used.
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1133 The sequence in the new file is the same as it was in the old database."
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1134 (interactive "FNew BibTeX file: ")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1135 (let ((keys (reftex-all-used-citation-keys))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1136 (files (reftex-get-bibfile-list))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1137 file key entries beg end entry)
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104768
diff changeset
1138 (save-current-buffer
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1139 (while (setq file (pop files))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1140 (set-buffer (reftex-get-file-buffer-force file 'mark))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1141 (reftex-with-special-syntax-for-bib
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1142 (save-excursion
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1143 (save-restriction
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1144 (widen)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1145 (goto-char (point-min))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1146 (while (re-search-forward
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1147 "^[ \t]*@[a-zA-Z]+[ \t]*{\\([^ \t\r\n]+\\),"
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1148 nil t)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1149 (setq key (match-string 1)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1150 beg (match-beginning 0)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1151 end (progn
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1152 (goto-char (match-beginning 1))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1153 (condition-case nil
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1154 (up-list 1)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1155 (error (goto-char (match-end 0))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1156 (point)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1157 (when (member key keys)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1158 (setq entry (buffer-substring beg end)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1159 entries (cons entry entries)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1160 keys (delete key keys)))))))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1161 (find-file-other-window bibfile)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1162 (if (> (buffer-size) 0)
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
1163 (unless (yes-or-no-p
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1164 (format "Overwrite non-empty file %s? " bibfile))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1165 (error "Abort")))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1166 (erase-buffer)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1167 (insert (mapconcat 'identity (reverse entries) "\n\n"))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1168 (goto-char (point-min))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1169 (save-buffer)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1170 (message "%d entries extracted and copied to new database"
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1171 (length entries))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1172
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 59373
diff changeset
1173
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
1174 ;; arch-tag: d53d0a5a-ab32-4b52-a846-2a7c3527cd89
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1175 ;;; reftex-cite.el ends here