Mercurial > emacs
comparison lisp/textmodes/reftex.el @ 65548:253cad16882d
Little fixes to remove compiler warnings
reftex-index.el (reftex-query-index-phrase): More efficient use
of markers.
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Fri, 16 Sep 2005 10:01:33 +0000 |
parents | 65e4d574d77c |
children | e274642bf5d5 fa0da9b57058 |
comparison
equal
deleted
inserted
replaced
65547:da6fcded2062 | 65548:253cad16882d |
---|---|
1 ;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX | 1 ;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX |
2 | 2 ;; Copyright (c) 1997, 1998, 1999, 2000, 2003, 2004, 2005 |
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2002, 2003, 2004, | 3 ;; Free Software Foundation, Inc. |
4 ;; 2005 Free Software Foundation, Inc. | |
5 | 4 |
6 ;; Author: Carsten Dominik <dominik@science.uva.nl> | 5 ;; Author: Carsten Dominik <dominik@science.uva.nl> |
7 ;; Version: 4.28 | 6 ;; Version: VERSIONTAG |
8 ;; Keywords: tex | 7 ;; Keywords: tex |
9 | 8 |
10 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
11 | 10 |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 ;; GNU General Public License for more details. | 19 ;; GNU General Public License for more details. |
21 | 20 |
22 ;; You should have received a copy of the GNU General Public License | 21 ;; You should have received a copy of the GNU General Public License |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
25 ;; Boston, MA 02110-1301, USA. | 24 ;; Boston, MA 02111-1307, USA. |
26 | 25 |
27 ;;--------------------------------------------------------------------------- | 26 ;;--------------------------------------------------------------------------- |
28 ;; | 27 ;; |
29 ;;; Commentary: | 28 ;;; Commentary: |
30 ;; | 29 ;; |
31 ;; RefTeX is a minor mode with distinct support for \ref, \label, \cite, | 30 ;; RefTeX is a minor mode with distinct support for \ref, \label, \cite, |
32 ;; and \index commands in (multi-file) LaTeX documents. | 31 ;; and \index commands in (multi-file) LaTeX documents. |
33 ;; - A table of contents provides easy access to any part of a document. | 32 ;; - A table of contents provides easy access to any part of a document. |
34 ;; - Labels are created semi-automatically. | 33 ;; - Labels are created semi-automatically. |
35 ;; - Definition context of labels is provided when creating a reference. | 34 ;; - Definition context of labels is provided when creating a reference. |
70 ;; | 69 ;; |
71 ;;--------------------------------------------------------------------------- | 70 ;;--------------------------------------------------------------------------- |
72 ;; | 71 ;; |
73 ;; Introduction | 72 ;; Introduction |
74 ;; ************ | 73 ;; ************ |
75 ;; | 74 ;; |
76 ;; RefTeX is a specialized package for support of labels, references, | 75 ;; RefTeX is a specialized package for support of labels, references, |
77 ;; citations, and the index in LaTeX. RefTeX wraps itself round 4 LaTeX | 76 ;; citations, and the index in LaTeX. RefTeX wraps itself round 4 LaTeX |
78 ;; macros: `\label', `\ref', `\cite', and `\index'. Using these macros | 77 ;; macros: `\label', `\ref', `\cite', and `\index'. Using these macros |
79 ;; usually requires looking up different parts of the document and | 78 ;; usually requires looking up different parts of the document and |
80 ;; searching through BibTeX database files. RefTeX automates these | 79 ;; searching through BibTeX database files. RefTeX automates these |
81 ;; time-consuming tasks almost entirely. It also provides functions to | 80 ;; time-consuming tasks almost entirely. It also provides functions to |
82 ;; display the structure of a document and to move around in this | 81 ;; display the structure of a document and to move around in this |
83 ;; structure quickly. | 82 ;; structure quickly. |
84 ;; | 83 ;; |
85 ;; *Note Imprint::, for information about who to contact for help, bug | 84 ;; *Note Imprint::, for information about who to contact for help, bug |
86 ;; reports or suggestions. | 85 ;; reports or suggestions. |
87 ;; | 86 ;; |
88 ;; Environment | 87 ;; Environment |
89 ;; =========== | 88 ;; =========== |
90 ;; | 89 ;; |
91 ;; RefTeX needs to access all files which are part of a multifile | 90 ;; RefTeX needs to access all files which are part of a multifile |
92 ;; document, and the BibTeX database files requested by the | 91 ;; document, and the BibTeX database files requested by the |
93 ;; `\bibliography' command. To find these files, RefTeX will require a | 92 ;; `\bibliography' command. To find these files, RefTeX will require a |
94 ;; search path, i.e. a list of directories to check. Normally this list | 93 ;; search path, i.e. a list of directories to check. Normally this list |
95 ;; is stored in the environment variables `TEXINPUTS' and `BIBINPUTS' | 94 ;; is stored in the environment variables `TEXINPUTS' and `BIBINPUTS' |
96 ;; which are also used by RefTeX. However, on some systems these | 95 ;; which are also used by RefTeX. However, on some systems these |
97 ;; variables do not contain the full search path. If RefTeX does not work | 96 ;; variables do not contain the full search path. If RefTeX does not work |
98 ;; for you because it cannot find some files, read *Note Finding Files::. | 97 ;; for you because it cannot find some files, read *Note Finding Files::. |
99 ;; | 98 ;; |
100 ;; Entering RefTeX Mode | 99 ;; Entering RefTeX Mode |
101 ;; ==================== | 100 ;; ==================== |
102 ;; | 101 ;; |
103 ;; To turn RefTeX Mode on and off in a particular buffer, use `M-x | 102 ;; To turn RefTeX Mode on and off in a particular buffer, use `M-x |
104 ;; reftex-mode'. To turn on RefTeX Mode for all LaTeX files, add the | 103 ;; reftex-mode'. To turn on RefTeX Mode for all LaTeX files, add the |
105 ;; following lines to your `.emacs' file: | 104 ;; following lines to your `.emacs' file: |
106 ;; | 105 ;; |
107 ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode | 106 ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode |
108 ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode | 107 ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode |
109 ;; | 108 ;; |
110 ;; RefTeX in a Nutshell | 109 ;; RefTeX in a Nutshell |
111 ;; ==================== | 110 ;; ==================== |
112 ;; | 111 ;; |
113 ;; 1. Table of Contents | 112 ;; 1. Table of Contents |
114 ;; Typing `C-c =' (`reftex-toc') will show a table of contents of the | 113 ;; Typing `C-c =' (`reftex-toc') will show a table of contents of the |
115 ;; document. This buffer can display sections, labels and index | 114 ;; document. This buffer can display sections, labels and index |
116 ;; entries defined in the document. From the buffer, you can jump | 115 ;; entries defined in the document. From the buffer, you can jump |
117 ;; quickly to every part of your document. Press `?' to get help. | 116 ;; quickly to every part of your document. Press `?' to get help. |
118 ;; | 117 ;; |
119 ;; 2. Labels and References | 118 ;; 2. Labels and References |
120 ;; RefTeX helps to create unique labels and to find the correct key | 119 ;; RefTeX helps to create unique labels and to find the correct key |
121 ;; for references quickly. It distinguishes labels for different | 120 ;; for references quickly. It distinguishes labels for different |
122 ;; environments, knows about all standard environments (and many | 121 ;; environments, knows about all standard environments (and many |
123 ;; others), and can be configured to recognize any additional labeled | 122 ;; others), and can be configured to recognize any additional labeled |
124 ;; environments you have defined yourself (variable | 123 ;; environments you have defined yourself (variable |
125 ;; `reftex-label-alist'). | 124 ;; `reftex-label-alist'). |
126 ;; | 125 ;; |
127 ;; * Creating Labels | 126 ;; * Creating Labels |
128 ;; Type `C-c (' (`reftex-label') to insert a label at point. | 127 ;; Type `C-c (' (`reftex-label') to insert a label at point. |
129 ;; RefTeX will either | 128 ;; RefTeX will either |
130 ;; - derive a label from context (default for section labels) | 129 ;; - derive a label from context (default for section labels) |
131 ;; - prompt for a label string (default for figures and | 130 ;; - prompt for a label string (default for figures and |
132 ;; tables) or | 131 ;; tables) or |
133 ;; - insert a simple label made of a prefix and a number (all | 132 ;; - insert a simple label made of a prefix and a number (all |
134 ;; other environments) | 133 ;; other environments) |
135 ;; | 134 ;; |
136 ;; Which labels are created how is configurable with the variable | 135 ;; Which labels are created how is configurable with the variable |
137 ;; `reftex-insert-label-flags'. | 136 ;; `reftex-insert-label-flags'. |
138 ;; | 137 ;; |
139 ;; * Referencing Labels | 138 ;; * Referencing Labels |
140 ;; To make a reference, type `C-c )' (`reftex-reference'). This | 139 ;; To make a reference, type `C-c )' (`reftex-reference'). This |
141 ;; shows an outline of the document with all labels of a certain | 140 ;; shows an outline of the document with all labels of a certain |
142 ;; type (figure, equation,...) and some label context. | 141 ;; type (figure, equation,...) and some label context. |
143 ;; Selecting a label inserts a `\ref{LABEL}' macro into the | 142 ;; Selecting a label inserts a `\ref{LABEL}' macro into the |
144 ;; original buffer. | 143 ;; original buffer. |
145 ;; | 144 ;; |
146 ;; 3. Citations | 145 ;; 3. Citations |
147 ;; Typing `C-c [' (`reftex-citation') will let you specify a regular | 146 ;; Typing `C-c [' (`reftex-citation') will let you specify a regular |
148 ;; expression to search in current BibTeX database files (as | 147 ;; expression to search in current BibTeX database files (as |
149 ;; specified in the `\bibliography' command) and pull out a list of | 148 ;; specified in the `\bibliography' command) and pull out a list of |
150 ;; matches for you to choose from. The list is _formatted_ and | 149 ;; matches for you to choose from. The list is _formatted_ and |
151 ;; sorted. The selected article is referenced as `\cite{KEY}' (see | 150 ;; sorted. The selected article is referenced as `\cite{KEY}' (see |
152 ;; the variable `reftex-cite-format' if you want to insert different | 151 ;; the variable `reftex-cite-format' if you want to insert different |
153 ;; macros). | 152 ;; macros). |
154 ;; | 153 ;; |
155 ;; 4. Index Support | 154 ;; 4. Index Support |
156 ;; RefTeX helps to enter index entries. It also compiles all entries | 155 ;; RefTeX helps to enter index entries. It also compiles all entries |
157 ;; into an alphabetically sorted `*Index*' buffer which you can use | 156 ;; into an alphabetically sorted `*Index*' buffer which you can use |
158 ;; to check and edit the entries. RefTeX knows about the standard | 157 ;; to check and edit the entries. RefTeX knows about the standard |
159 ;; index macros and can be configured to recognize any additional | 158 ;; index macros and can be configured to recognize any additional |
160 ;; macros you have defined (`reftex-index-macros'). Multiple indices | 159 ;; macros you have defined (`reftex-index-macros'). Multiple indices |
161 ;; are supported. | 160 ;; are supported. |
162 ;; | 161 ;; |
163 ;; * Creating Index Entries | 162 ;; * Creating Index Entries |
164 ;; To index the current selection or the word at point, type | 163 ;; To index the current selection or the word at point, type |
165 ;; `C-c /' (`reftex-index-selection-or-word'). The default macro | 164 ;; `C-c /' (`reftex-index-selection-or-word'). The default macro |
166 ;; `reftex-index-default-macro' will be used. For a more | 165 ;; `reftex-index-default-macro' will be used. For a more |
167 ;; complex entry type `C-c <' (`reftex-index'), select any of | 166 ;; complex entry type `C-c <' (`reftex-index'), select any of |
168 ;; the index macros and enter the arguments with completion. | 167 ;; the index macros and enter the arguments with completion. |
169 ;; | 168 ;; |
170 ;; * The Index Phrases File (Delayed Indexing) | 169 ;; * The Index Phrases File (Delayed Indexing) |
171 ;; Type `C-c \' (`reftex-index-phrase-selection-or-word') to add | 170 ;; Type `C-c \' (`reftex-index-phrase-selection-or-word') to add |
172 ;; the current word or selection to a special _index phrase | 171 ;; the current word or selection to a special _index phrase |
173 ;; file_. RefTeX can later search the document for occurrences | 172 ;; file_. RefTeX can later search the document for occurrences |
174 ;; of these phrases and let you interactively index the matches. | 173 ;; of these phrases and let you interactively index the matches. |
175 ;; | 174 ;; |
176 ;; * Displaying and Editing the Index | 175 ;; * Displaying and Editing the Index |
177 ;; To display the compiled index in a special buffer, type `C-c | 176 ;; To display the compiled index in a special buffer, type `C-c |
178 ;; >' (`reftex-display-index'). From that buffer you can check | 177 ;; >' (`reftex-display-index'). From that buffer you can check |
179 ;; and edit all entries. | 178 ;; and edit all entries. |
180 ;; | 179 ;; |
181 ;; 5. Viewing Cross-References | 180 ;; 5. Viewing Cross-References |
182 ;; When point is on the KEY argument of a cross-referencing macro | 181 ;; When point is on the KEY argument of a cross-referencing macro |
183 ;; (`\label', `\ref', `\cite', `\bibitem', `\index', and variations) | 182 ;; (`\label', `\ref', `\cite', `\bibitem', `\index', and variations) |
184 ;; or inside a BibTeX database entry, you can press `C-c &' | 183 ;; or inside a BibTeX database entry, you can press `C-c &' |
185 ;; (`reftex-view-crossref') to display corresponding locations in the | 184 ;; (`reftex-view-crossref') to display corresponding locations in the |
186 ;; document and associated BibTeX database files. | 185 ;; document and associated BibTeX database files. |
187 ;; When the enclosing macro is `\cite' or `\ref' and no other message | 186 ;; When the enclosing macro is `\cite' or `\ref' and no other message |
188 ;; occupies the echo area, information about the citation or label | 187 ;; occupies the echo area, information about the citation or label |
189 ;; will automatically be displayed in the echo area. | 188 ;; will automatically be displayed in the echo area. |
190 ;; | 189 ;; |
191 ;; 6. Multifile Documents | 190 ;; 6. Multifile Documents |
192 ;; Multifile Documents are fully supported. The included files must | 191 ;; Multifile Documents are fully supported. The included files must |
193 ;; have a file variable `TeX-master' or `tex-main-file' pointing to | 192 ;; have a file variable `TeX-master' or `tex-main-file' pointing to |
194 ;; the master file. RefTeX provides cross-referencing information | 193 ;; the master file. RefTeX provides cross-referencing information |
195 ;; from all parts of the document, and across document borders | 194 ;; from all parts of the document, and across document borders |
196 ;; (`xr.sty'). | 195 ;; (`xr.sty'). |
197 ;; | 196 ;; |
198 ;; 7. Document Parsing | 197 ;; 7. Document Parsing |
199 ;; RefTeX needs to parse the document in order to find labels and | 198 ;; RefTeX needs to parse the document in order to find labels and |
200 ;; other information. It does it automatically once and updates its | 199 ;; other information. It does it automatically once and updates its |
201 ;; list internally when `reftex-label' and `reftex-index' are used. | 200 ;; list internally when `reftex-label' and `reftex-index' are used. |
202 ;; To enforce reparsing, call any of the commands described above | 201 ;; To enforce reparsing, call any of the commands described above |
203 ;; with a raw `C-u' prefix, or press the `r' key in the label | 202 ;; with a raw `C-u' prefix, or press the `r' key in the label |
204 ;; selection buffer, the table of contents buffer, or the index | 203 ;; selection buffer, the table of contents buffer, or the index |
205 ;; buffer. | 204 ;; buffer. |
206 ;; | 205 ;; |
207 ;; 8. AUCTeX | 206 ;; 8. AUCTeX |
208 ;; If your major LaTeX mode is AUCTeX, RefTeX can cooperate with it | 207 ;; If your major LaTeX mode is AUCTeX, RefTeX can cooperate with it |
209 ;; (see variable `reftex-plug-into-AUCTeX'). AUCTeX contains style | 208 ;; (see variable `reftex-plug-into-AUCTeX'). AUCTeX contains style |
210 ;; files which trigger appropriate settings in RefTeX, so that for | 209 ;; files which trigger appropriate settings in RefTeX, so that for |
211 ;; many of the popular LaTeX packages no additional customizations | 210 ;; many of the popular LaTeX packages no additional customizations |
212 ;; will be necessary. | 211 ;; will be necessary. |
213 ;; | 212 ;; |
214 ;; 9. Useful Settings | 213 ;; 9. Useful Settings |
215 ;; To make RefTeX faster for large documents, try these: | 214 ;; To make RefTeX faster for large documents, try these: |
216 ;; (setq reftex-enable-partial-scans t) | 215 ;; (setq reftex-enable-partial-scans t) |
217 ;; (setq reftex-save-parse-info t) | 216 ;; (setq reftex-save-parse-info t) |
218 ;; (setq reftex-use-multiple-selection-buffers t) | 217 ;; (setq reftex-use-multiple-selection-buffers t) |
219 ;; | 218 ;; |
220 ;; To integrate with AUCTeX, use | 219 ;; To integrate with AUCTeX, use |
221 ;; (setq reftex-plug-into-AUCTeX t) | 220 ;; (setq reftex-plug-into-AUCTeX t) |
222 ;; | 221 ;; |
223 ;; To make your own LaTeX macro definitions known to RefTeX, | 222 ;; To make your own LaTeX macro definitions known to RefTeX, |
224 ;; customize the variables | 223 ;; customize the variables |
225 ;; `reftex-label-alist' (for label macros/environments) | 224 ;; `reftex-label-alist' (for label macros/environments) |
226 ;; `reftex-section-levels' (for sectioning commands) | 225 ;; `reftex-section-levels' (for sectioning commands) |
227 ;; `reftex-cite-format' (for `\cite'-like macros) | 226 ;; `reftex-cite-format' (for `\cite'-like macros) |
228 ;; `reftex-index-macros' (for `\index'-like macros) | 227 ;; `reftex-index-macros' (for `\index'-like macros) |
229 ;; `reftex-index-default-macro' (to set the default macro) | 228 ;; `reftex-index-default-macro' (to set the default macro) |
230 ;; If you have a large number of macros defined, you may want to write | 229 ;; If you have a large number of macros defined, you may want to write |
231 ;; an AUCTeX style file to support them with both AUCTeX and RefTeX. | 230 ;; an AUCTeX style file to support them with both AUCTeX and RefTeX. |
232 ;; | 231 ;; |
233 ;; 10. Where Next? | 232 ;; 10. Where Next? |
234 ;; Go ahead and use RefTeX. Use its menus until you have picked up | 233 ;; Go ahead and use RefTeX. Use its menus until you have picked up |
235 ;; the key bindings. For an overview of what you can do in each of | 234 ;; the key bindings. For an overview of what you can do in each of |
236 ;; the different special buffers, press `?'. Read the manual if you | 235 ;; the different special buffers, press `?'. Read the manual if you |
237 ;; get stuck, of if you are curious what else might be available. | 236 ;; get stuck, of if you are curious what else might be available. |
238 ;; The first part of the manual explains in a tutorial way how to use | 237 ;; The first part of the manual explains in a tutorial way how to use |
239 ;; and customize RefTeX. The second part is a command and variable | 238 ;; and customize RefTeX. The second part is a command and variable |
240 ;; reference. | 239 ;; reference. |
241 ;; | 240 ;; |
242 ;;--------------------------------------------------------------------------- | 241 ;;--------------------------------------------------------------------------- |
243 ;; | 242 ;; |
244 ;; AUTHOR | 243 ;; AUTHOR |
245 ;; ====== | 244 ;; ====== |
246 ;; | 245 ;; |
287 (eval-and-compile | 286 (eval-and-compile |
288 (defun reftex-set-dirty (symbol value) | 287 (defun reftex-set-dirty (symbol value) |
289 (setq reftex-tables-dirty t) | 288 (setq reftex-tables-dirty t) |
290 (set symbol value))) | 289 (set symbol value))) |
291 | 290 |
292 (defvar font-lock-keywords) | |
293 | |
294 | 291 |
295 ;;; ========================================================================= | 292 ;;; ========================================================================= |
296 ;;; | 293 ;;; |
297 ;;; Configuration variables | 294 ;;; Configuration variables |
298 | 295 |
302 ;;; ========================================================================= | 299 ;;; ========================================================================= |
303 ;;; | 300 ;;; |
304 ;;; Define the formal stuff for a minor mode named RefTeX. | 301 ;;; Define the formal stuff for a minor mode named RefTeX. |
305 ;;; | 302 ;;; |
306 | 303 |
307 (defconst reftex-version "RefTeX version 4.28" | 304 (defconst reftex-version "RefTeX version VERSIONTAG" |
308 "Version string for RefTeX.") | 305 "Version string for RefTeX.") |
309 | 306 |
310 (defvar reftex-mode nil | 307 (defvar reftex-mode nil |
311 "Determines if RefTeX mode is active.") | 308 "Determines if RefTeX mode is active.") |
312 (make-variable-buffer-local 'reftex-mode) | 309 (make-variable-buffer-local 'reftex-mode) |
320 | 317 |
321 (unless reftex-syntax-table | 318 (unless reftex-syntax-table |
322 (setq reftex-syntax-table (copy-syntax-table)) | 319 (setq reftex-syntax-table (copy-syntax-table)) |
323 (modify-syntax-entry ?\( "." reftex-syntax-table) | 320 (modify-syntax-entry ?\( "." reftex-syntax-table) |
324 (modify-syntax-entry ?\) "." reftex-syntax-table)) | 321 (modify-syntax-entry ?\) "." reftex-syntax-table)) |
325 | 322 |
326 (unless reftex-syntax-table-for-bib | 323 (unless reftex-syntax-table-for-bib |
327 (setq reftex-syntax-table-for-bib | 324 (setq reftex-syntax-table-for-bib |
328 (copy-syntax-table reftex-syntax-table)) | 325 (copy-syntax-table reftex-syntax-table)) |
329 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) | 326 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) |
330 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib) | 327 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib) |
396 | 393 |
397 ;; Prepare the special syntax tables. | 394 ;; Prepare the special syntax tables. |
398 (setq reftex-syntax-table (copy-syntax-table (syntax-table))) | 395 (setq reftex-syntax-table (copy-syntax-table (syntax-table))) |
399 (modify-syntax-entry ?\( "." reftex-syntax-table) | 396 (modify-syntax-entry ?\( "." reftex-syntax-table) |
400 (modify-syntax-entry ?\) "." reftex-syntax-table) | 397 (modify-syntax-entry ?\) "." reftex-syntax-table) |
401 | 398 |
402 (setq reftex-syntax-table-for-bib | 399 (setq reftex-syntax-table-for-bib |
403 (copy-syntax-table reftex-syntax-table)) | 400 (copy-syntax-table reftex-syntax-table)) |
404 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) | 401 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) |
405 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib) | 402 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib) |
406 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib) | 403 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib) |
455 (defvar LaTeX-section-hook) | 452 (defvar LaTeX-section-hook) |
456 (defvar LaTeX-label-function) | 453 (defvar LaTeX-label-function) |
457 (defvar tex-main-file) | 454 (defvar tex-main-file) |
458 (defvar outline-minor-mode) | 455 (defvar outline-minor-mode) |
459 (defvar font-lock-mode) | 456 (defvar font-lock-mode) |
457 (defvar font-lock-keywords) | |
460 (defvar font-lock-fontify-region-function) | 458 (defvar font-lock-fontify-region-function) |
461 (defvar font-lock-syntactic-keywords)) | 459 (defvar font-lock-syntactic-keywords)) |
462 | 460 |
463 ;;; ========================================================================= | 461 ;;; ========================================================================= |
464 ;;; | 462 ;;; |
537 ;; variable tex-main-file. | 535 ;; variable tex-main-file. |
538 (let | 536 (let |
539 ((master | 537 ((master |
540 (cond | 538 (cond |
541 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism. | 539 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism. |
542 (condition-case nil | 540 (condition-case nil |
543 (TeX-master-file t) | 541 (TeX-master-file t) |
544 (error (buffer-file-name)))) | 542 (error (buffer-file-name)))) |
545 ((fboundp 'tex-main-file) (tex-main-file)) ; Emacs LaTeX mode | 543 ((fboundp 'tex-main-file) (tex-main-file)) ; Emacs LaTeX mode |
546 ((boundp 'TeX-master) ; The variable is defined - lets use it. | 544 ((boundp 'TeX-master) ; The variable is defined - lets use it. |
547 (cond | 545 (cond |
577 (reftex-get-buffer-visiting master)) | 575 (reftex-get-buffer-visiting master)) |
578 ;; We either see the file, or have a buffer on it. OK. | 576 ;; We either see the file, or have a buffer on it. OK. |
579 ) | 577 ) |
580 (t | 578 (t |
581 ;; Use buffer file name. | 579 ;; Use buffer file name. |
582 (buffer-file-name))) | 580 (setq master (buffer-file-name)))) |
583 (expand-file-name master))) | 581 (expand-file-name master))) |
584 | 582 |
585 (defun reftex-is-multi () | 583 (defun reftex-is-multi () |
586 ;; Tell if this is a multifile document. When not sure, say yes. | 584 ;; Tell if this is a multifile document. When not sure, say yes. |
587 (let ((entry (assq 'is-multi (symbol-value reftex-docstruct-symbol)))) | 585 (let ((entry (assq 'is-multi (symbol-value reftex-docstruct-symbol)))) |
738 (defvar reftex-memory nil | 736 (defvar reftex-memory nil |
739 "Memorizes old variable values to indicate changes in these variables.") | 737 "Memorizes old variable values to indicate changes in these variables.") |
740 | 738 |
741 ;; A list of all variables in the cache. | 739 ;; A list of all variables in the cache. |
742 ;; The cache is used to save the compiled versions of some variables. | 740 ;; The cache is used to save the compiled versions of some variables. |
743 (defconst reftex-cache-variables | 741 (defconst reftex-cache-variables |
744 '(reftex-memory ;; This MUST ALWAYS be the first! | 742 '(reftex-memory ;; This MUST ALWAYS be the first! |
745 | 743 |
746 ;; Outline | 744 ;; Outline |
747 reftex-section-levels-all | 745 reftex-section-levels-all |
748 | 746 |
749 ;; Labels | 747 ;; Labels |
750 reftex-env-or-mac-alist | 748 reftex-env-or-mac-alist |
751 reftex-special-env-parsers | 749 reftex-special-env-parsers |
752 reftex-macros-with-labels | 750 reftex-macros-with-labels |
753 reftex-label-mac-list | 751 reftex-label-mac-list |
754 reftex-label-env-list | 752 reftex-label-env-list |
755 reftex-typekey-list | 753 reftex-typekey-list |
762 | 760 |
763 ;; Index | 761 ;; Index |
764 reftex-index-macro-alist | 762 reftex-index-macro-alist |
765 reftex-macros-with-index | 763 reftex-macros-with-index |
766 reftex-query-index-macro-prompt | 764 reftex-query-index-macro-prompt |
767 reftex-query-index-macro-help | 765 reftex-query-index-macro-help |
768 reftex-key-to-index-macro-alist | 766 reftex-key-to-index-macro-alist |
769 | 767 |
770 ;; Regular expressions | 768 ;; Regular expressions |
771 reftex-section-regexp | 769 reftex-section-regexp |
772 reftex-section-or-include-regexp | 770 reftex-section-or-include-regexp |
807 (message "Restoring cache") | 805 (message "Restoring cache") |
808 (mapcar (lambda (sym) (set sym (pop cache))) reftex-cache-variables)) | 806 (mapcar (lambda (sym) (set sym (pop cache))) reftex-cache-variables)) |
809 (t (reftex-compile-variables))))) | 807 (t (reftex-compile-variables))))) |
810 | 808 |
811 (defun reftex-reset-mode () | 809 (defun reftex-reset-mode () |
812 "Reset RefTeX Mode. | 810 "Reset RefTeX Mode. |
813 This will re-compile the configuration information and remove all | 811 This will re-compile the configuration information and remove all |
814 current scanning information and the parse file to enforce a rescan | 812 current scanning information and the parse file to enforce a rescan |
815 on next use." | 813 on next use." |
816 (interactive) | 814 (interactive) |
817 | 815 |
858 (not (null (symbol-value symbol)))) | 856 (not (null (symbol-value symbol)))) |
859 (set (symbol-value symbol) nil))))) | 857 (set (symbol-value symbol) nil))))) |
860 | 858 |
861 (defun reftex-erase-all-selection-and-index-buffers () | 859 (defun reftex-erase-all-selection-and-index-buffers () |
862 ;; Remove all selection buffers associated with current document. | 860 ;; Remove all selection buffers associated with current document. |
863 (mapcar | 861 (mapcar |
864 (lambda (type) | 862 (lambda (type) |
865 (reftex-erase-buffer (reftex-make-selection-buffer-name type))) | 863 (reftex-erase-buffer (reftex-make-selection-buffer-name type))) |
866 reftex-typekey-list) | 864 reftex-typekey-list) |
867 ;; Kill all index buffers | 865 ;; Kill all index buffers |
868 (mapcar | 866 (mapcar |
869 (lambda (tag) | 867 (lambda (tag) |
870 (reftex-kill-buffer (reftex-make-index-buffer-name tag))) | 868 (reftex-kill-buffer (reftex-make-index-buffer-name tag))) |
871 (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))) | 869 (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))) |
872 | 870 |
873 (defun reftex-compile-variables () | 871 (defun reftex-compile-variables () |
879 (when (and (featurep 'tex-site) (fboundp 'TeX-update-style)) | 877 (when (and (featurep 'tex-site) (fboundp 'TeX-update-style)) |
880 (condition-case nil (TeX-update-style) (error nil))) | 878 (condition-case nil (TeX-update-style) (error nil))) |
881 | 879 |
882 ;; Record that we have done this, and what we have used. | 880 ;; Record that we have done this, and what we have used. |
883 (setq reftex-tables-dirty nil) | 881 (setq reftex-tables-dirty nil) |
884 (setq reftex-memory | 882 (setq reftex-memory |
885 (list reftex-label-alist | 883 (list reftex-label-alist |
886 (get reftex-docstruct-symbol 'reftex-section-levels) | 884 (get reftex-docstruct-symbol 'reftex-section-levels) |
887 (get reftex-docstruct-symbol 'reftex-label-alist-style) | 885 (get reftex-docstruct-symbol 'reftex-label-alist-style) |
888 reftex-default-label-alist-entries | 886 reftex-default-label-alist-entries |
889 reftex-index-macros | 887 reftex-index-macros |
898 reftex-default-label-alist-entries) | 896 reftex-default-label-alist-entries) |
899 reftex-label-alist-builtin) | 897 reftex-label-alist-builtin) |
900 '(nil))) | 898 '(nil))) |
901 (all-index (reftex-uniquify-by-car | 899 (all-index (reftex-uniquify-by-car |
902 (reftex-splice-symbols-into-list | 900 (reftex-splice-symbols-into-list |
903 (append reftex-index-macros | 901 (append reftex-index-macros |
904 (get reftex-docstruct-symbol | 902 (get reftex-docstruct-symbol |
905 'reftex-index-macros-style) | 903 'reftex-index-macros-style) |
906 '(default)) | 904 '(default)) |
907 reftex-index-macros-builtin))) | 905 reftex-index-macros-builtin))) |
908 entry env-or-mac typekeychar typekey prefix context word | 906 entry env-or-mac typekeychar typekey prefix context word |
909 fmt reffmt labelfmt wordlist qh-list macros-with-labels | 907 fmt reffmt labelfmt wordlist qh-list macros-with-labels |
910 nargs nlabel opt-args cell sum i | 908 nargs nlabel opt-args cell sum i |
911 macro verify repeat nindex tag key toc-level toc-levels) | 909 macro verify repeat nindex tag key toc-level toc-levels) |
912 | 910 |
913 (setq reftex-words-to-typekey-alist nil | 911 (setq reftex-words-to-typekey-alist nil |
914 reftex-prefix-to-typekey-alist | 912 reftex-prefix-to-typekey-alist |
915 '(("sec:" . "s") ("cha:" . "s") ("chap:" . "s")) | 913 '(("sec:" . "s") ("cha:" . "s") ("chap:" . "s")) |
916 reftex-typekey-list nil | 914 reftex-typekey-list nil |
917 reftex-typekey-to-format-alist nil | 915 reftex-typekey-to-format-alist nil |
918 reftex-typekey-to-prefix-alist nil | 916 reftex-typekey-to-prefix-alist nil |
919 reftex-env-or-mac-alist nil | 917 reftex-env-or-mac-alist nil |
965 ;; Check if this is a macro or environment | 963 ;; Check if this is a macro or environment |
966 (cond | 964 (cond |
967 ((symbolp env-or-mac) | 965 ((symbolp env-or-mac) |
968 ;; A special parser function | 966 ;; A special parser function |
969 (unless (fboundp env-or-mac) | 967 (unless (fboundp env-or-mac) |
970 (message "Warning: %s does not seem to be a valid function" | 968 (message "Warning: %s does not seem to be a valid function" |
971 env-or-mac)) | 969 env-or-mac)) |
972 (setq nargs nil nlabel nil opt-args nil) | 970 (setq nargs nil nlabel nil opt-args nil) |
973 (add-to-list 'reftex-special-env-parsers env-or-mac) | 971 (add-to-list 'reftex-special-env-parsers env-or-mac) |
974 (setq env-or-mac (symbol-name env-or-mac))) | 972 (setq env-or-mac (symbol-name env-or-mac))) |
975 ((string-match "\\`\\\\" env-or-mac) | 973 ((string-match "\\`\\\\" env-or-mac) |
993 (let ((string (format "begin{%s}" env-or-mac))) | 991 (let ((string (format "begin{%s}" env-or-mac))) |
994 (or (assoc string toc-levels) | 992 (or (assoc string toc-levels) |
995 (push (cons string toc-level) toc-levels)))))))) | 993 (push (cons string toc-level) toc-levels)))))))) |
996 ;; Translate some special context cases | 994 ;; Translate some special context cases |
997 (when (assq context reftex-default-context-regexps) | 995 (when (assq context reftex-default-context-regexps) |
998 (setq context | 996 (setq context |
999 (format | 997 (format |
1000 (cdr (assq context reftex-default-context-regexps)) | 998 (cdr (assq context reftex-default-context-regexps)) |
1001 (regexp-quote env-or-mac)))) | 999 (regexp-quote env-or-mac)))) |
1002 ;; See if this is the first format for this typekey | 1000 ;; See if this is the first format for this typekey |
1003 (and reffmt | 1001 (and reffmt |
1004 (not (assoc typekey reftex-typekey-to-format-alist)) | 1002 (not (assoc typekey reftex-typekey-to-format-alist)) |
1027 | 1025 |
1028 (setq reftex-typekey-to-prefix-alist | 1026 (setq reftex-typekey-to-prefix-alist |
1029 (nreverse reftex-typekey-to-prefix-alist)) | 1027 (nreverse reftex-typekey-to-prefix-alist)) |
1030 | 1028 |
1031 ;; Prepare the typekey query prompt and help string. | 1029 ;; Prepare the typekey query prompt and help string. |
1032 (setq qh-list | 1030 (setq qh-list |
1033 (sort qh-list | 1031 (sort qh-list |
1034 (lambda (x1 x2) | 1032 (lambda (x1 x2) |
1035 (string< (downcase (car x1)) (downcase (car x2)))))) | 1033 (string< (downcase (car x1)) (downcase (car x2)))))) |
1036 (setq reftex-type-query-prompt | 1034 (setq reftex-type-query-prompt |
1037 (concat "Label type: [" | 1035 (concat "Label type: [" |
1038 (mapconcat (lambda(x) (format "%s" (car x))) | 1036 (mapconcat (lambda(x) (format "%s" (car x))) |
1039 qh-list "") | 1037 qh-list "") |
1040 "]")) | 1038 "]")) |
1041 ;; In the help string, we need to wrap lines... | 1039 ;; In the help string, we need to wrap lines... |
1042 (setq reftex-type-query-help | 1040 (setq reftex-type-query-help |
1043 (concat | 1041 (concat |
1044 "SELECT A LABEL TYPE:\n--------------------\n" | 1042 "SELECT A LABEL TYPE:\n--------------------\n" |
1045 (mapconcat | 1043 (mapconcat |
1046 (lambda(x) | 1044 (lambda(x) |
1047 (setq sum 0) | 1045 (setq sum 0) |
1048 (format " [%s] %s" | 1046 (format " [%s] %s" |
1058 | 1056 |
1059 ;; Convert magic words to regular expressions. We make regular expressions | 1057 ;; Convert magic words to regular expressions. We make regular expressions |
1060 ;; which allow for some chars from the ref format to be in the buffer. | 1058 ;; which allow for some chars from the ref format to be in the buffer. |
1061 ;; These characters will be seen and removed. | 1059 ;; These characters will be seen and removed. |
1062 (setq reftex-words-to-typekey-alist | 1060 (setq reftex-words-to-typekey-alist |
1063 (mapcar | 1061 (mapcar |
1064 (lambda (x) | 1062 (lambda (x) |
1065 (setq word (car x) | 1063 (setq word (car x) |
1066 typekey (cdr x) | 1064 typekey (cdr x) |
1067 fmt (cdr (assoc typekey reftex-typekey-to-format-alist))) | 1065 fmt (cdr (assoc typekey reftex-typekey-to-format-alist))) |
1068 (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\(")) | 1066 (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\(")) |
1111 (push macro reftex-macros-with-index)))) | 1109 (push macro reftex-macros-with-index)))) |
1112 ;; Make the prompt and help string for index macros query | 1110 ;; Make the prompt and help string for index macros query |
1113 (setq reftex-key-to-index-macro-alist | 1111 (setq reftex-key-to-index-macro-alist |
1114 (sort reftex-key-to-index-macro-alist | 1112 (sort reftex-key-to-index-macro-alist |
1115 (lambda (a b) (< (downcase (car a)) (downcase (car b)))))) | 1113 (lambda (a b) (< (downcase (car a)) (downcase (car b)))))) |
1116 (setq reftex-query-index-macro-prompt | 1114 (setq reftex-query-index-macro-prompt |
1117 (concat "Index macro: [" | 1115 (concat "Index macro: [" |
1118 (mapconcat (lambda (x) (char-to-string (car x))) | 1116 (mapconcat (lambda (x) (char-to-string (car x))) |
1119 reftex-key-to-index-macro-alist "") | 1117 reftex-key-to-index-macro-alist "") |
1120 "]")) | 1118 "]")) |
1121 (setq i 0 | 1119 (setq i 0 |
1122 reftex-query-index-macro-help | 1120 reftex-query-index-macro-help |
1123 (concat | 1121 (concat |
1124 "SELECT A MACRO:\n---------------\n" | 1122 "SELECT A MACRO:\n---------------\n" |
1125 (mapconcat | 1123 (mapconcat |
1126 (lambda(x) | 1124 (lambda(x) |
1127 (format "[%c] %-20.20s%s" (car x) (nth 1 x) | 1125 (format "[%c] %-20.20s%s" (car x) (nth 1 x) |
1128 (if (= 0 (mod (incf i) 3)) "\n" ""))) | 1126 (if (= 0 (mod (incf i) 3)) "\n" ""))) |
1129 reftex-key-to-index-macro-alist ""))) | 1127 reftex-key-to-index-macro-alist ""))) |
1130 | 1128 |
1131 ;; Make the full list of section levels | 1129 ;; Make the full list of section levels |
1132 (setq reftex-section-levels-all | 1130 (setq reftex-section-levels-all |
1136 | 1134 |
1137 ;; Calculate the regular expressions | 1135 ;; Calculate the regular expressions |
1138 (let* ( | 1136 (let* ( |
1139 ; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*") | 1137 ; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*") |
1140 (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because | 1138 (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because |
1141 ;;; because match number are hard coded | 1139 ;;; because match number are hard coded |
1142 (label-re "\\\\label{\\([^}]*\\)}") | 1140 (label-re "\\\\label{\\([^}]*\\)}") |
1143 (include-re (concat wbol | 1141 (include-re (concat wbol |
1144 "\\\\\\(" | 1142 "\\\\\\(" |
1145 (mapconcat 'identity | 1143 (mapconcat 'identity |
1146 reftex-include-file-commands "\\|") | 1144 reftex-include-file-commands "\\|") |
1147 "\\)[{ \t]+\\([^} \t\n\r]+\\)")) | 1145 "\\)[{ \t]+\\([^} \t\n\r]+\\)")) |
1148 (section-re | 1146 (section-re |
1149 (concat wbol "\\\\\\(" | 1147 (concat wbol "\\\\\\(" |
1150 (mapconcat (lambda (x) (regexp-quote (car x))) | 1148 (mapconcat (lambda (x) (regexp-quote (car x))) |
1194 reftex-index-level-re index-level-re | 1192 reftex-index-level-re index-level-re |
1195 reftex-index-key-end-re index-key-end-re | 1193 reftex-index-key-end-re index-key-end-re |
1196 reftex-macros-with-labels macros-with-labels | 1194 reftex-macros-with-labels macros-with-labels |
1197 reftex-find-index-entry-regexp-format find-index-re-format | 1195 reftex-find-index-entry-regexp-format find-index-re-format |
1198 reftex-find-label-regexp-format find-label-re-format | 1196 reftex-find-label-regexp-format find-label-re-format |
1199 reftex-find-label-regexp-format2 | 1197 reftex-find-label-regexp-format2 |
1200 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]") | 1198 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]") |
1201 (message "Compiling label environment definitions...done"))) | 1199 (message "Compiling label environment definitions...done"))) |
1202 (put reftex-docstruct-symbol 'reftex-cache | 1200 (put reftex-docstruct-symbol 'reftex-cache |
1203 (mapcar 'symbol-value reftex-cache-variables))) | 1201 (mapcar 'symbol-value reftex-cache-variables))) |
1204 | 1202 |
1271 (unless reftex-docstruct-symbol | 1269 (unless reftex-docstruct-symbol |
1272 (reftex-tie-multifile-symbols)) | 1270 (reftex-tie-multifile-symbols)) |
1273 (and (symbolp reftex-docstruct-symbol) | 1271 (and (symbolp reftex-docstruct-symbol) |
1274 (symbol-value reftex-docstruct-symbol) | 1272 (symbol-value reftex-docstruct-symbol) |
1275 t)) | 1273 t)) |
1276 | 1274 |
1277 (defun reftex-silence-toc-markers (list n) | 1275 (defun reftex-silence-toc-markers (list n) |
1278 ;; Set all toc markers in the first N entries in list to nil | 1276 ;; Set all toc markers in the first N entries in list to nil |
1279 (while (and list (> (decf n) -1)) | 1277 (while (and list (> (decf n) -1)) |
1280 (and (eq (car (car list)) 'toc) | 1278 (and (eq (car (car list)) 'toc) |
1281 (markerp (nth 4 (car list))) | 1279 (markerp (nth 4 (car list))) |
1288 (let* ((list (symbol-value reftex-docstruct-symbol)) | 1286 (let* ((list (symbol-value reftex-docstruct-symbol)) |
1289 (docstruct-symbol reftex-docstruct-symbol) | 1287 (docstruct-symbol reftex-docstruct-symbol) |
1290 (master (reftex-TeX-master-file)) | 1288 (master (reftex-TeX-master-file)) |
1291 (enable-local-variables nil) | 1289 (enable-local-variables nil) |
1292 (file (if (string-match "\\.[a-zA-Z]+\\'" master) | 1290 (file (if (string-match "\\.[a-zA-Z]+\\'" master) |
1293 (concat (substring master 0 (match-beginning 0)) | 1291 (concat (substring master 0 (match-beginning 0)) |
1294 reftex-parse-file-extension) | 1292 reftex-parse-file-extension) |
1295 (concat master reftex-parse-file-extension)))) | 1293 (concat master reftex-parse-file-extension)))) |
1296 (cond | 1294 (cond |
1297 ((eq action 'readable) | 1295 ((eq action 'readable) |
1298 (file-readable-p file)) | 1296 (file-readable-p file)) |
1367 (defun reftex-check-parse-consistency () | 1365 (defun reftex-check-parse-consistency () |
1368 ;; Check if parse file is consistent, throw an error if not. | 1366 ;; Check if parse file is consistent, throw an error if not. |
1369 | 1367 |
1370 ;; Check if the master is the same: when moving a document, this will see it. | 1368 ;; Check if the master is the same: when moving a document, this will see it. |
1371 (let* ((real-master (reftex-TeX-master-file)) | 1369 (let* ((real-master (reftex-TeX-master-file)) |
1372 (parsed-master | 1370 (parsed-master |
1373 (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol))))) | 1371 (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol))))) |
1374 (unless (string= (file-truename real-master) (file-truename parsed-master)) | 1372 (unless (string= (file-truename real-master) (file-truename parsed-master)) |
1375 (message "Master file name in load file is different: %s versus %s" | 1373 (message "Master file name in load file is different: %s versus %s" |
1376 parsed-master real-master) | 1374 parsed-master real-master) |
1377 (error "Master file name error"))) | 1375 (error "Master file name error"))) |
1387 ) | 1385 ) |
1388 | 1386 |
1389 (defun reftex-select-external-document (xr-alist xr-index) | 1387 (defun reftex-select-external-document (xr-alist xr-index) |
1390 ;; Return index of an external document. | 1388 ;; Return index of an external document. |
1391 (let* ((len (length xr-alist)) (highest (1- (+ ?0 len))) | 1389 (let* ((len (length xr-alist)) (highest (1- (+ ?0 len))) |
1392 (prompt (format "[%c-%c] Select TAB: Read prefix with completion" | 1390 (prompt (format "[%c-%c] Select TAB: Read prefix with completion" |
1393 ?0 highest)) | 1391 ?0 highest)) |
1394 key prefix) | 1392 key prefix) |
1395 (cond | 1393 (cond |
1396 ((= len 1) | 1394 ((= len 1) |
1397 (message "No external documents available") | 1395 (message "No external documents available") |
1398 (ding) (sit-for 1) 0) | 1396 (ding) (sit-for 1) 0) |
1399 ((= len 2) | 1397 ((= len 2) |
1400 (- 1 xr-index)) | 1398 (- 1 xr-index)) |
1401 (t | 1399 (t |
1402 (save-excursion | 1400 (save-excursion |
1403 (let* ((length (apply 'max (mapcar | 1401 (let* ((length (apply 'max (mapcar |
1404 (lambda(x) (length (car x))) xr-alist))) | 1402 (lambda(x) (length (car x))) xr-alist))) |
1405 (fmt (format " [%%c] %%-%ds %%s\n" length)) | 1403 (fmt (format " [%%c] %%-%ds %%s\n" length)) |
1406 (n (1- ?0))) | 1404 (n (1- ?0))) |
1407 (setq key | 1405 (setq key |
1408 (reftex-select-with-char | 1406 (reftex-select-with-char |
1409 prompt | 1407 prompt |
1410 (concat | 1408 (concat |
1411 "SELECT EXTERNAL DOCUMENT\n------------------------\n" | 1409 "SELECT EXTERNAL DOCUMENT\n------------------------\n" |
1412 (mapconcat | 1410 (mapconcat |
1413 (lambda (x) | 1411 (lambda (x) |
1414 (format fmt (incf n) (or (car x) "") | 1412 (format fmt (incf n) (or (car x) "") |
1415 (abbreviate-file-name (cdr x)))) | 1413 (abbreviate-file-name (cdr x)))) |
1416 xr-alist "")) | 1414 xr-alist "")) |
1417 nil t)) | 1415 nil t)) |
1418 (cond | 1416 (cond |
1432 try first the default extension and only then the naked file name. | 1430 try first the default extension and only then the naked file name. |
1433 When DIE is non-nil, throw an error if file not found." | 1431 When DIE is non-nil, throw an error if file not found." |
1434 (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t))) | 1432 (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t))) |
1435 (extensions (cdr (assoc type reftex-file-extensions))) | 1433 (extensions (cdr (assoc type reftex-file-extensions))) |
1436 (def-ext (car extensions)) | 1434 (def-ext (car extensions)) |
1437 (ext-re (concat "\\(" | 1435 (ext-re (concat "\\(" |
1438 (mapconcat 'regexp-quote extensions "\\|") | 1436 (mapconcat 'regexp-quote extensions "\\|") |
1439 "\\)\\'")) | 1437 "\\)\\'")) |
1440 (files (if (string-match ext-re file) | 1438 (files (if (string-match ext-re file) |
1441 (cons file nil) | 1439 (cons file nil) |
1442 (cons (concat file def-ext) file))) | 1440 (cons (concat file def-ext) file))) |
1443 path old-path file1) | 1441 path old-path file1) |
1444 (cond | 1442 (cond |
1445 ((file-name-absolute-p file) | 1443 ((file-name-absolute-p file) |
1446 (setq file1 | 1444 (setq file1 |
1447 (or | 1445 (or |
1448 (and (car files) (file-regular-p (car files)) (car files)) | 1446 (and (car files) (file-regular-p (car files)) (car files)) |
1449 (and (cdr files) (file-regular-p (cdr files)) (cdr files))))) | 1447 (and (cdr files) (file-regular-p (cdr files)) (cdr files))))) |
1450 ((and reftex-use-external-file-finders | 1448 ((and reftex-use-external-file-finders |
1451 (assoc type reftex-external-file-finders)) | 1449 (assoc type reftex-external-file-finders)) |
1452 (setq file1 (reftex-find-file-externally file type master-dir))) | 1450 (setq file1 (reftex-find-file-externally file type master-dir))) |
1457 (if (or (null old-path) | 1455 (if (or (null old-path) |
1458 (not (eq old-path path))) | 1456 (not (eq old-path path))) |
1459 (setq old-path path | 1457 (setq old-path path |
1460 path (cons master-dir path) | 1458 path (cons master-dir path) |
1461 file1 (or (and (car files) | 1459 file1 (or (and (car files) |
1462 (reftex-find-file-on-path | 1460 (reftex-find-file-on-path |
1463 (car files) path master-dir)) | 1461 (car files) path master-dir)) |
1464 (and (cdr files) | 1462 (and (cdr files) |
1465 (reftex-find-file-on-path | 1463 (reftex-find-file-on-path |
1466 (cdr files) path master-dir)))))))) | 1464 (cdr files) path master-dir)))))))) |
1467 (cond (file1 file1) | 1465 (cond (file1 file1) |
1468 (die (error "No such file: %s" file) nil) | 1466 (die (error "No such file: %s" file) nil) |
1469 (t (message "No such file: %s (ignored)" file) nil)))) | 1467 (t (message "No such file: %s (ignored)" file) nil)))) |
1470 | 1468 |
1505 ;; Get basic path | 1503 ;; Get basic path |
1506 (set pathvar | 1504 (set pathvar |
1507 (reftex-uniquify | 1505 (reftex-uniquify |
1508 (reftex-parse-colon-path | 1506 (reftex-parse-colon-path |
1509 (mapconcat | 1507 (mapconcat |
1510 (lambda(x) | 1508 (lambda(x) |
1511 (if (string-match "^!" x) | 1509 (if (string-match "^!" x) |
1512 (apply 'reftex-process-string | 1510 (apply 'reftex-process-string |
1513 (split-string (substring x 1))) | 1511 (split-string (substring x 1))) |
1514 (or (getenv x) x))) | 1512 (or (getenv x) x))) |
1515 ;; For consistency, the next line should look like this: | 1513 ;; For consistency, the next line should look like this: |
1516 ;; (cdr (assoc type reftex-path-environment)) | 1514 ;; (cdr (assoc type reftex-path-environment)) |
1517 ;; However, historically we have separate options for the | 1515 ;; However, historically we have separate options for the |
1518 ;; environment variables, so we have to do this: | 1516 ;; environment variables, so we have to do this: |
1519 (symbol-value (intern (concat "reftex-" type | 1517 (symbol-value (intern (concat "reftex-" type |
1520 "path-environment-variables"))) | 1518 "path-environment-variables"))) |
1521 path-separator)))) | 1519 path-separator)))) |
1522 (put pathvar 'status 'split) | 1520 (put pathvar 'status 'split) |
1523 ;; Check if we have recursive elements | 1521 ;; Check if we have recursive elements |
1524 (let ((path (symbol-value pathvar)) dir rec) | 1522 (let ((path (symbol-value pathvar)) dir rec) |
1540 (not (equal master-dir (get pathvar 'master-dir))))) | 1538 (not (equal master-dir (get pathvar 'master-dir))))) |
1541 ;; Either: We don't have a recursive expansion yet. | 1539 ;; Either: We don't have a recursive expansion yet. |
1542 ;; or: Relative recursive path elements need to be expanded | 1540 ;; or: Relative recursive path elements need to be expanded |
1543 ;; relative to new default directory | 1541 ;; relative to new default directory |
1544 (message "Expanding search path to find %s file: %s ..." type file) | 1542 (message "Expanding search path to find %s file: %s ..." type file) |
1545 (put pathvar 'recursive-path | 1543 (put pathvar 'recursive-path |
1546 (reftex-expand-path (symbol-value pathvar) master-dir)) | 1544 (reftex-expand-path (symbol-value pathvar) master-dir)) |
1547 (put pathvar 'master-dir master-dir) | 1545 (put pathvar 'master-dir master-dir) |
1548 (get pathvar 'recursive-path)) | 1546 (get pathvar 'recursive-path)) |
1549 (t | 1547 (t |
1550 ;; Recursive path computed earlier is still OK. | 1548 ;; Recursive path computed earlier is still OK. |
1551 (get pathvar 'recursive-path))) | 1549 (get pathvar 'recursive-path))) |
1552 ;; The simple path was requested | 1550 ;; The simple path was requested |
1553 (symbol-value pathvar)))) | 1551 (symbol-value pathvar)))) |
1554 | 1552 |
1573 (defun reftex-parse-colon-path (path) | 1571 (defun reftex-parse-colon-path (path) |
1574 ;; Like parse-colon-parse, but // or /~ are left alone. | 1572 ;; Like parse-colon-parse, but // or /~ are left alone. |
1575 ;; Trailing ! or !! will be converted into `//' (emTeX convention) | 1573 ;; Trailing ! or !! will be converted into `//' (emTeX convention) |
1576 (mapcar | 1574 (mapcar |
1577 (lambda (dir) | 1575 (lambda (dir) |
1578 (if (string-match "\\(//+\\|/*!+\\)\\'" dir) | 1576 (if (string-match "\\(//+\\|/*!+\\)\\'" dir) |
1579 (setq dir (replace-match "//" t t dir))) | 1577 (setq dir (replace-match "//" t t dir))) |
1580 (file-name-as-directory dir)) | 1578 (file-name-as-directory dir)) |
1581 (delete "" (split-string path (concat path-separator "+"))))) | 1579 (delete "" (split-string path (concat path-separator "+"))))) |
1582 | 1580 |
1583 (defun reftex-expand-path (path &optional default-dir) | 1581 (defun reftex-expand-path (path &optional default-dir) |
1602 (let ((path (list dir)) path1 file files) | 1600 (let ((path (list dir)) path1 file files) |
1603 (while (setq dir (pop path)) | 1601 (while (setq dir (pop path)) |
1604 (when (file-directory-p dir) | 1602 (when (file-directory-p dir) |
1605 (setq files (nreverse (directory-files dir t "[^.]"))) | 1603 (setq files (nreverse (directory-files dir t "[^.]"))) |
1606 (while (setq file (pop files)) | 1604 (while (setq file (pop files)) |
1607 (if (file-directory-p file) | 1605 (if (file-directory-p file) |
1608 (push (file-name-as-directory file) path))) | 1606 (push (file-name-as-directory file) path))) |
1609 (push dir path1))) | 1607 (push dir path1))) |
1610 path1)) | 1608 path1)) |
1611 | 1609 |
1612 ;;; ========================================================================= | 1610 ;;; ========================================================================= |
1665 | 1663 |
1666 (autoload 'reftex-toc "reftex-toc" | 1664 (autoload 'reftex-toc "reftex-toc" |
1667 "Show the table of contents for the current document." t) | 1665 "Show the table of contents for the current document." t) |
1668 (autoload 'reftex-toc-recenter "reftex-toc" | 1666 (autoload 'reftex-toc-recenter "reftex-toc" |
1669 "Display the TOC window and highlight line corresponding to current position." t) | 1667 "Display the TOC window and highlight line corresponding to current position." t) |
1670 (autoload 'reftex-toggle-auto-toc-recenter "reftex-toc" | 1668 (autoload 'reftex-toggle-auto-toc-recenter "reftex-toc" |
1671 "Toggle automatic recentering of TOC window." t) | 1669 "Toggle automatic recentering of TOC window." t) |
1672 | 1670 |
1673 ;;; ========================================================================= | 1671 ;;; ========================================================================= |
1674 ;;; | 1672 ;;; |
1675 ;;; BibTeX citations. | 1673 ;;; BibTeX citations. |
1884 ;; list also a list, so that the result can be used for completion. | 1882 ;; list also a list, so that the result can be used for completion. |
1885 (let (rtn) | 1883 (let (rtn) |
1886 (while list | 1884 (while list |
1887 (if (funcall predicate (car list)) | 1885 (if (funcall predicate (car list)) |
1888 (push (if completion | 1886 (push (if completion |
1889 (list (nth nth (car list))) | 1887 (list (nth nth (car list))) |
1890 (nth nth (car list))) | 1888 (nth nth (car list))) |
1891 rtn)) | 1889 rtn)) |
1892 (setq list (cdr list))) | 1890 (setq list (cdr list))) |
1893 (nreverse rtn))) | 1891 (nreverse rtn))) |
1894 | 1892 |
1920 (defun reftex-nearest-match (regexp &optional max-length) | 1918 (defun reftex-nearest-match (regexp &optional max-length) |
1921 ;; Find the nearest match of REGEXP. Set the match data. | 1919 ;; Find the nearest match of REGEXP. Set the match data. |
1922 ;; If POS is given, calculate distances relative to it. | 1920 ;; If POS is given, calculate distances relative to it. |
1923 ;; Return nil if there is no match. | 1921 ;; Return nil if there is no match. |
1924 (let ((pos (point)) | 1922 (let ((pos (point)) |
1925 (dist (or max-length (length regexp))) | 1923 (dist (or max-length (length regexp))) |
1926 match1 match2 match) | 1924 match1 match2 match) |
1927 (goto-char (min (+ pos dist) (point-max))) | 1925 (goto-char (min (+ pos dist) (point-max))) |
1928 (when (re-search-backward regexp nil t) | 1926 (when (re-search-backward regexp nil t) |
1929 (setq match1 (match-data))) | 1927 (setq match1 (match-data))) |
1930 (goto-char (max (- pos dist) (point-min))) | 1928 (goto-char (max (- pos dist) (point-min))) |
2006 (condition-case nil (scroll-up) (error nil)) | 2004 (condition-case nil (scroll-up) (error nil)) |
2007 (message prompt)) | 2005 (message prompt)) |
2008 ((and scroll (equal char ?\C-? )) | 2006 ((and scroll (equal char ?\C-? )) |
2009 (condition-case nil (scroll-down) (error nil)) | 2007 (condition-case nil (scroll-down) (error nil)) |
2010 (message prompt)) | 2008 (message prompt)) |
2011 (t (message "") | 2009 (t (message "") |
2012 (throw 'exit char))) | 2010 (throw 'exit char))) |
2013 (setq char (read-char-exclusive))))))) | 2011 (setq char (read-char-exclusive))))))) |
2014 | 2012 |
2015 | 2013 |
2016 (defun reftex-make-regexp-allow-for-ctrl-m (string) | 2014 (defun reftex-make-regexp-allow-for-ctrl-m (string) |
2017 ;; convert STRING into a regexp, allowing ^M for \n and vice versa | 2015 ;; convert STRING into a regexp, allowing ^M for \n and vice versa |
2018 (let ((start -2)) | 2016 (let ((start -2)) |
2019 (setq string (regexp-quote string)) | 2017 (setq string (regexp-quote string)) |
2207 (setq words (nreverse words)) | 2205 (setq words (nreverse words)) |
2208 | 2206 |
2209 ;; Restrict number of words | 2207 ;; Restrict number of words |
2210 (if (> (length words) nwords) | 2208 (if (> (length words) nwords) |
2211 (setcdr (nthcdr (1- nwords) words) nil)) | 2209 (setcdr (nthcdr (1- nwords) words) nil)) |
2212 | 2210 |
2213 ;; First, try to use all words | 2211 ;; First, try to use all words |
2214 (setq string (mapconcat 'identity words sep)) | 2212 (setq string (mapconcat 'identity words sep)) |
2215 | 2213 |
2216 ;; Abbreviate words if enforced by user settings or string length | 2214 ;; Abbreviate words if enforced by user settings or string length |
2217 (if (or (eq t abbrev) | 2215 (if (or (eq t abbrev) |
2218 (and abbrev | 2216 (and abbrev |
2219 (> (length string) maxchar))) | 2217 (> (length string) maxchar))) |
2220 (setq words | 2218 (setq words |
2302 (let ((major-mode 'latex-mode) | 2300 (let ((major-mode 'latex-mode) |
2303 (font-lock-defaults-computed nil)) | 2301 (font-lock-defaults-computed nil)) |
2304 (font-lock-set-defaults-1) | 2302 (font-lock-set-defaults-1) |
2305 (reftex-select-font-lock-fontify-region (point-min) (point-max)))) | 2303 (reftex-select-font-lock-fontify-region (point-min) (point-max)))) |
2306 (t | 2304 (t |
2307 ;; Oops? | 2305 ;; Oops? |
2308 (message "Sorry: cannot refontify RefTeX Select buffer.")))) | 2306 (message "Sorry: cannot refontify RefTeX Select buffer.")))) |
2309 (rename-buffer oldname)))) | 2307 (rename-buffer oldname)))) |
2310 | 2308 |
2311 (defun reftex-select-font-lock-fontify-region (beg end &optional loudly) | 2309 (defun reftex-select-font-lock-fontify-region (beg end &optional loudly) |
2312 ;; Fontify a region, but only lines starting with a dot. | 2310 ;; Fontify a region, but only lines starting with a dot. |
2351 ;; We keep a vector with several different overlays to do our highlighting. | 2349 ;; We keep a vector with several different overlays to do our highlighting. |
2352 (defvar reftex-highlight-overlays [nil nil nil]) | 2350 (defvar reftex-highlight-overlays [nil nil nil]) |
2353 | 2351 |
2354 ;; Initialize the overlays | 2352 ;; Initialize the overlays |
2355 (aset reftex-highlight-overlays 0 (reftex-make-overlay 1 1)) | 2353 (aset reftex-highlight-overlays 0 (reftex-make-overlay 1 1)) |
2356 (reftex-overlay-put (aref reftex-highlight-overlays 0) | 2354 (reftex-overlay-put (aref reftex-highlight-overlays 0) |
2357 'face 'highlight) | 2355 'face 'highlight) |
2358 (aset reftex-highlight-overlays 1 (reftex-make-overlay 1 1)) | 2356 (aset reftex-highlight-overlays 1 (reftex-make-overlay 1 1)) |
2359 (reftex-overlay-put (aref reftex-highlight-overlays 1) | 2357 (reftex-overlay-put (aref reftex-highlight-overlays 1) |
2360 'face reftex-cursor-selected-face) | 2358 'face reftex-cursor-selected-face) |
2361 (aset reftex-highlight-overlays 2 (reftex-make-overlay 1 1)) | 2359 (aset reftex-highlight-overlays 2 (reftex-make-overlay 1 1)) |
2376 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die) | 2374 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die) |
2377 (reftex-unhighlight 0)) | 2375 (reftex-unhighlight 0)) |
2378 | 2376 |
2379 ;;; ========================================================================= | 2377 ;;; ========================================================================= |
2380 ;;; | 2378 ;;; |
2381 ;;; Keybindings | 2379 ;;; Keybindings |
2382 | 2380 |
2383 ;; The default bindings in the mode map. | 2381 ;; The default bindings in the mode map. |
2384 (loop for x in | 2382 (loop for x in |
2385 '(("\C-c=" . reftex-toc) | 2383 '(("\C-c=" . reftex-toc) |
2386 ("\C-c-" . reftex-toc-recenter) | 2384 ("\C-c-" . reftex-toc-recenter) |
2396 do (define-key reftex-mode-map (car x) (cdr x))) | 2394 do (define-key reftex-mode-map (car x) (cdr x))) |
2397 | 2395 |
2398 ;; Bind `reftex-mouse-view-crossref' only when the key is still free | 2396 ;; Bind `reftex-mouse-view-crossref' only when the key is still free |
2399 (if (featurep 'xemacs) | 2397 (if (featurep 'xemacs) |
2400 (unless (key-binding [(shift button2)]) | 2398 (unless (key-binding [(shift button2)]) |
2401 (define-key reftex-mode-map [(shift button2)] | 2399 (define-key reftex-mode-map [(shift button2)] |
2402 'reftex-mouse-view-crossref)) | 2400 'reftex-mouse-view-crossref)) |
2403 (unless (key-binding [(shift mouse-2)]) | 2401 (unless (key-binding [(shift mouse-2)]) |
2404 (define-key reftex-mode-map [(shift mouse-2)] | 2402 (define-key reftex-mode-map [(shift mouse-2)] |
2405 'reftex-mouse-view-crossref))) | 2403 'reftex-mouse-view-crossref))) |
2406 | 2404 |
2407 ;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map | 2405 ;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map |
2408 (eval-after-load | 2406 (eval-after-load |
2409 "bibtex" | 2407 "bibtex" |
2503 ["isearch whole document" reftex-isearch-minor-mode | 2501 ["isearch whole document" reftex-isearch-minor-mode |
2504 :style toggle :selected reftex-isearch-minor-mode]) | 2502 :style toggle :selected reftex-isearch-minor-mode]) |
2505 ("Reference Style" | 2503 ("Reference Style" |
2506 ["Default" (setq reftex-vref-is-default nil | 2504 ["Default" (setq reftex-vref-is-default nil |
2507 reftex-fref-is-default nil) | 2505 reftex-fref-is-default nil) |
2508 :style radio :selected (not (or reftex-vref-is-default | 2506 :style radio :selected (not (or reftex-vref-is-default |
2509 reftex-fref-is-default))] | 2507 reftex-fref-is-default))] |
2510 ["Varioref" (setq reftex-vref-is-default t | 2508 ["Varioref" (setq reftex-vref-is-default t |
2511 reftex-fref-is-default nil) | 2509 reftex-fref-is-default nil) |
2512 :style radio :selected reftex-vref-is-default] | 2510 :style radio :selected reftex-vref-is-default] |
2513 ["Fancyref" (setq reftex-fref-is-default t | 2511 ["Fancyref" (setq reftex-fref-is-default t |
2538 (vector | 2536 (vector |
2539 (capitalize (symbol-name (car x))) | 2537 (capitalize (symbol-name (car x))) |
2540 (list 'reftex-add-index-macros (list 'list (list 'quote (car x)))) | 2538 (list 'reftex-add-index-macros (list 'list (list 'quote (car x)))) |
2541 :style 'radio :selected | 2539 :style 'radio :selected |
2542 (list 'memq (list 'quote (car x)) | 2540 (list 'memq (list 'quote (car x)) |
2543 (list 'get 'reftex-docstruct-symbol | 2541 (list 'get 'reftex-docstruct-symbol |
2544 (list 'quote 'reftex-index-macros-style))))) | 2542 (list 'quote 'reftex-index-macros-style))))) |
2545 reftex-index-macros-builtin)) | 2543 reftex-index-macros-builtin)) |
2546 "--" | 2544 "--" |
2547 ["Reset RefTeX Mode" reftex-reset-mode t] | 2545 ["Reset RefTeX Mode" reftex-reset-mode t] |
2548 "--" | 2546 "--" |
2549 ("Customize" | 2547 ("Customize" |
2550 ["Browse RefTeX Group" reftex-customize t] | 2548 ["Browse RefTeX Group" reftex-customize t] |
2551 "--" | 2549 "--" |
2552 ["Build Full Customize Menu" reftex-create-customize-menu | 2550 ["Build Full Customize Menu" reftex-create-customize-menu |
2553 (fboundp 'customize-menu-create)]) | 2551 (fboundp 'customize-menu-create)]) |
2554 ("Documentation" | 2552 ("Documentation" |
2555 ["Info" reftex-info t] | 2553 ["Info" reftex-info t] |
2556 ["Commentary" reftex-show-commentary t]))) | 2554 ["Commentary" reftex-show-commentary t]))) |
2557 | 2555 |
2563 (defun reftex-create-customize-menu () | 2561 (defun reftex-create-customize-menu () |
2564 "Create a full customization menu for RefTeX, insert it into the menu." | 2562 "Create a full customization menu for RefTeX, insert it into the menu." |
2565 (interactive) | 2563 (interactive) |
2566 (if (fboundp 'customize-menu-create) | 2564 (if (fboundp 'customize-menu-create) |
2567 (progn | 2565 (progn |
2568 (easy-menu-change | 2566 (easy-menu-change |
2569 '("Ref") "Customize" | 2567 '("Ref") "Customize" |
2570 `(["Browse RefTeX group" reftex-customize t] | 2568 `(["Browse RefTeX group" reftex-customize t] |
2571 "--" | 2569 "--" |
2572 ,(customize-menu-create 'reftex) | 2570 ,(customize-menu-create 'reftex) |
2573 ["Set" Custom-set t] | 2571 ["Set" Custom-set t] |
2601 (run-hooks 'reftex-load-hook) | 2599 (run-hooks 'reftex-load-hook) |
2602 | 2600 |
2603 ;;; That's it! ---------------------------------------------------------------- | 2601 ;;; That's it! ---------------------------------------------------------------- |
2604 | 2602 |
2605 (setq reftex-tables-dirty t) ; in case this file is evaluated by hand | 2603 (setq reftex-tables-dirty t) ; in case this file is evaluated by hand |
2606 (provide 'reftex) | 2604 (provide 'reftex) |
2607 | 2605 |
2608 ;;;============================================================================ | 2606 ;;;============================================================================ |
2609 | 2607 |
2610 ;;; arch-tag: 49e0da4e-bd5e-4cfc-a717-fb444fccb9e6 | 2608 ;;; arch-tag: 49e0da4e-bd5e-4cfc-a717-fb444fccb9e6 |
2611 ;;; reftex.el ends here | 2609 ;;; reftex.el ends here |