155
|
1 ;; reftex.el --- Minor mode for doing \label, \ref and \cite in LaTeX
|
|
2 ;; Copyright (c) 1997 Free Software Foundation, Inc.
|
|
3
|
207
|
4 ;; Version: 3.7
|
155
|
5 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
|
|
6 ;; Keywords: tex
|
|
7
|
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
23 ;; Boston, MA 02111-1307, USA.
|
|
24
|
|
25 ;;---------------------------------------------------------------------------
|
|
26 ;;
|
|
27 ;;; Commentary:
|
|
28 ;;
|
|
29 ;; RefTeX is a minor mode with distinct support for \ref, \label and
|
|
30 ;; \cite commands in (multi-file) LaTeX documents.
|
|
31 ;; Labels are created semi-automatically. Definition context of labels is
|
|
32 ;; provided when creating a reference. Citations are simplified with
|
207
|
33 ;; efficient database lookup. A table of contents buffer provides easy
|
|
34 ;; access to any part of a document.
|
155
|
35 ;;
|
|
36 ;; To turn RefTeX Minor Mode on and off in a particular buffer, use
|
|
37 ;; `M-x reftex-mode'.
|
|
38 ;;
|
|
39 ;; To turn on RefTeX Minor Mode for all LaTeX files, add one of the
|
|
40 ;; following lines to your .emacs file:
|
|
41 ;;
|
|
42 ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
|
|
43 ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
|
|
44 ;;
|
207
|
45 ;; For default key bindings, see further down in this documentation.
|
|
46 ;;
|
|
47 ;;---------------------------------------------------------------------------
|
|
48 ;;
|
|
49 ;; CONTENTS
|
|
50 ;; --------
|
|
51 ;;
|
|
52 ;; Overview............................ All you need to know to get started.
|
155
|
53 ;;
|
207
|
54 ;; Configuration....................... How to configure RefTeX.
|
|
55 ;; Configuration Examples........... Tutorial examples.
|
|
56 ;; Hooks............................ Available hooks.
|
|
57 ;; Configuration Variables.......... Complete listing.
|
|
58 ;; Key Bindings........................ A list of default bindings.
|
|
59 ;; Multifile Documents................. Documents spread over many files.
|
|
60 ;; References to Other Documents....... RefTeX and the LaTeX package `xr'.
|
|
61 ;; Optimizations for Large Documents... How to improve speed and memory use.
|
|
62 ;; Related Packages.................... Other Emacs packages.
|
|
63 ;; Known Bugs and Work-Arounds......... First aid.
|
|
64 ;; Author.............................. Who wrote RefTeX and who helped.
|
|
65 ;; History............................. What was new in which version.
|
155
|
66 ;;---------------------------------------------------------------------------
|
|
67 ;;
|
|
68 ;; OVERVIEW
|
207
|
69 ;; ========
|
|
70 ;;
|
|
71 ;; 1. USING \label AND \ref. Labels and references are one of the strong
|
|
72 ;; points of LaTeX. But, in documents with hundreds of equations,
|
|
73 ;; figures, tables etc. it becomes quickly impossible to find good label
|
|
74 ;; names and to actually remember them. Then, also completion of labels
|
|
75 ;; is not enough. One actually needs to see the context of the label
|
|
76 ;; definition to find the right one.
|
|
77 ;;
|
|
78 ;; - RefTeX distinguishes labels for different environments. It always
|
|
79 ;; knows if a certain label references a figure, table etc.. You can
|
|
80 ;; configure RefTeX to recognize any additional labeled environments
|
|
81 ;; you have defined yourself.
|
155
|
82 ;;
|
|
83 ;; - RefTeX defines automatically unique labels. Type `C-c ('
|
207
|
84 ;; (`reftex-label') to insert a label at point. RefTeX will either
|
155
|
85 ;; - derive a label from context (default for section labels)
|
|
86 ;; - insert a simple label consisting of a prefix and a number
|
207
|
87 ;; (default for equations,enumerate items, and footnotes) or
|
165
|
88 ;; - prompt for a label string (figures and tables).
|
155
|
89 ;; Which labels are created how can be controlled with the variable
|
165
|
90 ;; `reftex-insert-label-flags'.
|
155
|
91 ;;
|
207
|
92 ;; - Referencing labels is a snap and I promise you'll love it. In
|
|
93 ;; order to make a reference, type `C-c )' (`reftex-reference'). This
|
|
94 ;; shows an outline of the document with all labels of a certain type
|
|
95 ;; (figure, equation,...) and context of the label definition.
|
|
96 ;; Selecting one of the labels inserts a \ref macro into the original
|
|
97 ;; buffer. Online help during the selection is available with `?'.
|
|
98 ;;
|
|
99 ;; 2. CITATIONS. After typing `C-c [' (`reftex-citation'), RefTeX will let
|
|
100 ;; you specify a regexp to search in current BibTeX database files (as
|
|
101 ;; specified in the \bibliography command) and pull out a formatted list
|
|
102 ;; of matches for you to choose from. The list is *formatted* and
|
|
103 ;; sorted, thus much easier to read than the raw database entries. The
|
|
104 ;; text inserted into the buffer is by default just `\cite{KEY}', but
|
|
105 ;; can also contain author names and the year in a configurable way.
|
|
106 ;; See documentation of the variable `reftex-cite-format'.
|
155
|
107 ;;
|
207
|
108 ;; 3. TABLE OF CONTENTS. Typing `C-c =' (`reftex-toc') will show a table
|
|
109 ;; of contents of the document. From that buffer, you can jump quickly
|
|
110 ;; to every part of your document. This is similar to imenu, only it
|
|
111 ;; works for entire multifile documents and uses the keyboard rather
|
|
112 ;; than the mouse. The initial version of this function was contributed
|
|
113 ;; by Stephen Eglen.
|
155
|
114 ;;
|
207
|
115 ;; 4. MULTIFILE DOCUMENTS are fully supported by RefTeX. Such documents
|
|
116 ;; consist of a master file and many other files being included via
|
|
117 ;; \input or \include. RefTeX will provide cross referencing
|
|
118 ;; information from all files which are part of the document. See
|
|
119 ;; `RefTeX and Multifile Documents' further down in the documentation
|
|
120 ;; for more information on this topic.
|
155
|
121 ;;
|
207
|
122 ;; 5. DOCUMENT PARSING. RefTeX needs to parse the document in order to
|
|
123 ;; find labels and other information. It will do it automatically once,
|
|
124 ;; when you start working with a document. Re-parsing should not be
|
|
125 ;; necessary too often since RefTeX updates its lists internally when
|
|
126 ;; you make a new label with `reftex-label'. To enforce reparsing,
|
|
127 ;; call any of the functions `reftex-citation', `reftex-label',
|
|
128 ;; `reftex-reference', `reftex-toc' with a raw C-u prefix, or press the
|
|
129 ;; `r' key in the label menu and table of contents buffer.
|
|
130 ;;---------------------------------------------------------------------------
|
155
|
131 ;;
|
207
|
132 ;; CONFIGURATION
|
|
133 ;; =============
|
155
|
134 ;;
|
207
|
135 ;; RefTeX needs to be configured if you use labels to mark environments
|
|
136 ;; defined by yourself (e.g. with `\newenvironment') or in packages not
|
|
137 ;; included in the standard LaTeX distribution. RefTeX's default settings
|
|
138 ;; make it recognize practically all labeled environments and macros
|
|
139 ;; discussed in `The LaTeX Companion' by Goossens, Mittelbach & Samarin,
|
|
140 ;; Addison-Wesley 1994. These are:
|
155
|
141 ;;
|
207
|
142 ;; - figure, figure*, table, table*, equation, eqnarray, enumerate,
|
|
143 ;; the \footnote macro (this is the LaTeX core stuff)
|
|
144 ;; - align, gather, multline, flalign, alignat, xalignat, xxalignat,
|
|
145 ;; subequations (from AMS-LaTeX's amsmath.sty package)
|
|
146 ;; - the \endnote macro (from endnotes.sty)
|
|
147 ;; - Beqnarray (fancybox.sty)
|
|
148 ;; - floatingfig (floatfig.sty)
|
|
149 ;; - longtable (longtable.sty)
|
|
150 ;; - figwindow, tabwindow (picinpar.sty)
|
|
151 ;; - sidewaysfigure, sidewaystable (rotating.sty)
|
|
152 ;; - subfigure, subfigure*, the \subfigure macro (subfigure.sty)
|
|
153 ;; - supertabular (supertab.sty)
|
|
154 ;; - wrapfigure (wrapfig.sty)
|
155
|
155 ;;
|
207
|
156 ;; If you want to use any other labeled environments or macros, you need
|
|
157 ;; to configure RefTeX.
|
155
|
158 ;;
|
207
|
159 ;; Per Abrahamsens custom.el package provides a simple way to do
|
|
160 ;; configuration. To try it out, use `M-x reftex-customize'.
|
155
|
161 ;;
|
207
|
162 ;; CONFIGURATION EXAMPLES
|
|
163 ;; ----------------------
|
155
|
164 ;;
|
207
|
165 ;; Suppose you are working with AMS-LaTeX amsmath package (with its math
|
|
166 ;; environments like `align', `multline' etc.). RefTeX is preconfigured to
|
|
167 ;; recognize these - so there is nothing you have to do.
|
155
|
168 ;;
|
207
|
169 ;; Suppose you are also using `\newtheorem' in LaTeX in order to define two
|
|
170 ;; new environments `theorem' and `axiom'
|
155
|
171 ;;
|
|
172 ;; \newtheorem{axiom}{Axiom}
|
|
173 ;; \newtheorem{theorem}{Theorem}
|
|
174 ;;
|
207
|
175 ;; to be used like this:
|
155
|
176 ;;
|
207
|
177 ;; \begin{axiom}
|
|
178 ;; \label{ax:first}
|
|
179 ;; ....
|
|
180 ;; \end{axiom}
|
155
|
181 ;;
|
207
|
182 ;; So we need to tell RefTeX that `theorem' and `axiom' are new labeled
|
|
183 ;; environments which define their own label categories. Here is how:
|
155
|
184 ;;
|
207
|
185 ;; (setq reftex-label-alist
|
|
186 ;; '(("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax."))
|
|
187 ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th."))))
|
155
|
188 ;;
|
207
|
189 ;; The type indicator characters ?a and ?h are used for prompts when RefTeX
|
|
190 ;; queries for a label type. Note that `h' was chosen for `theorem' since
|
|
191 ;; `t' is already taken by `table'. Note that also `s', `f', `e', `i', `n'
|
|
192 ;; are already used for standard environments.
|
155
|
193 ;; The automatic labels for Axioms and Theorems will look like "ax:23" or
|
|
194 ;; "thr:24".
|
|
195 ;; The "\ref{%s}" is a format string indicating how to insert references to
|
207
|
196 ;; these labels.
|
|
197 ;; The next item indicates how to grab context of the label definition.
|
|
198 ;; - t means to get it from a default location (from the beginning of a
|
|
199 ;; \macro or after the \begin statement). t is *not* a good choice for
|
|
200 ;; eqnarray and similar environments.
|
155
|
201 ;; - nil means to use the text right after the label definition.
|
|
202 ;; - For more complex ways of getting context, see the docstring of
|
165
|
203 ;; `reftex-label-alist'.
|
155
|
204 ;; The strings at the end of each entry are used to guess the correct label
|
|
205 ;; type from the word before point when creating a reference. E.g. if you
|
207
|
206 ;; write: "As we have shown in Theorem" and then press `C-c )', RefTeX will
|
|
207 ;; know that you are looking for a theorem label and restrict the menu to
|
|
208 ;; only these labels without even asking.
|
|
209 ;;
|
|
210 ;; Depending on how you would like the label insertion and selection for
|
|
211 ;; the new environments to work, you might want to add the letters "a" and
|
|
212 ;; "h" to some of the flags in the following variables:
|
|
213 ;;
|
|
214 ;; reftex-insert-label-flags reftex-label-menu-flags
|
|
215 ;;
|
|
216 ;; Suppose you want to make figures not directly with the figure
|
|
217 ;; environment, but with a macro like
|
|
218 ;;
|
|
219 ;; \newcommand{\myfig}[5][tbp]{%
|
|
220 ;; \begin{figure}[#1]
|
|
221 ;; \epsimp[#5]{#2}
|
|
222 ;; \caption{#3}
|
|
223 ;; \label{#4}
|
|
224 ;; \end{figure}}
|
155
|
225 ;;
|
207
|
226 ;; which would be called like
|
|
227 ;;
|
|
228 ;; \myfig[htp]{filename}{caption text}{label}{1}
|
|
229 ;;
|
|
230 ;; Now we also need to tell RefTeX that the 4th argument of the \myfig
|
|
231 ;; macro is a figure label, and where to find the context.
|
155
|
232 ;;
|
207
|
233 ;; (setq reftex-label-alist
|
|
234 ;; '(("axiom" ?a "ax:" "~\\ref{%s}" nil ("Axiom" "Ax."))
|
|
235 ;; ("theorem" ?h "thr:" "~\\ref{%s}" t ("Theorem" "Theor." "Th."))
|
|
236 ;; ("\\myfig[]{}{}{*}{}" ?f nil nil 3)))
|
155
|
237 ;;
|
207
|
238 ;; The empty pairs of brackets indicate the different arguments of the
|
|
239 ;; \myfig macro. The `*' marks the label argument. `?f' indicates that
|
|
240 ;; this is a figure label which will be listed together with labels from
|
|
241 ;; normal figure environments. The nil entries for prefix and reference
|
|
242 ;; format mean to use the defaults for figure labels. The `3' for the
|
|
243 ;; context method means to grab the 3rd macro argument - the caption.
|
|
244 ;;
|
|
245 ;; As a side effect of this configuration, `reftex-label' will now insert
|
|
246 ;; the required naked label (without the \label macro) when point is
|
|
247 ;; directly after the opening parenthesis of a \myfig macro argument.
|
155
|
248 ;;
|
|
249 ;; -----
|
|
250 ;;
|
207
|
251 ;; If you are writing in a language different from English you might want
|
|
252 ;; to add magic words for that language. Here is a German example:
|
|
253 ;;
|
|
254 ;; (setq reftex-label-alist
|
155
|
255 ;; '((nil ?s nil nil nil ("Kapitel" "Kap." "Abschnitt" "Teil"))
|
|
256 ;; (nil ?e nil nil nil ("Gleichung" "Gl."))
|
|
257 ;; (nil ?t nil nil nil ("Tabelle"))
|
|
258 ;; (nil ?f nil nil nil ("Figur" "Abbildung" "Abb."))
|
207
|
259 ;; (nil ?n nil nil nil ("Anmerkung" "Anm."))
|
|
260 ;; (nil ?i nil nil nil ("Punkt"))))
|
155
|
261 ;;
|
165
|
262 ;; Using nil as first item in each entry makes sure that this entry does
|
207
|
263 ;; not replace the original entry for that label type, but just adds magic
|
|
264 ;; words.
|
|
265 ;;
|
|
266 ;; -----
|
|
267 ;;
|
|
268 ;; Normally, RefTeX inserts equation references with parenthesis like
|
|
269 ;; "~(\ref{KEY})". If you want to change this to square brackets, use
|
|
270 ;;
|
|
271 ;; (setq reftex-label-alist '((nil ?e nil "~[\\ref{%s}]" nil nil)))
|
|
272 ;;
|
|
273 ;; In order to use the AMS-LaTeX \eqref macro instead, either of the
|
|
274 ;; following lines does the job.
|
|
275 ;;
|
|
276 ;; (setq reftex-label-alist '((nil ?e nil "~\\eqref{%s}" nil nil)))
|
|
277 ;; (setq reftex-label-alist '(AMSTeX))
|
|
278 ;;
|
|
279 ;; ----
|
|
280 ;;
|
|
281 ;; By default, citations are inserted simply as \cite{KEY}. You can have
|
|
282 ;; more complex citation commands with many available packages, most
|
|
283 ;; notably the harvard and natbib packages. RefTeX can be configured to
|
|
284 ;; support these and other styles by setting the variable
|
|
285 ;; `reftex-cite-format'. E.g., for the natbib package you would use
|
|
286 ;;
|
|
287 ;; (setq reftex-cite-format 'natbib)
|
|
288 ;;
|
|
289 ;; This can also be done as a file variable. For the full list of builtin
|
|
290 ;; options, try `M-x customize-variable RET reftex-cite-format RET'.
|
155
|
291 ;;
|
|
292 ;; HOOKS
|
|
293 ;; -----
|
207
|
294 ;; - Loading reftex.el runs the hook `reftex-load-hook'.
|
|
295 ;; - Turning on reftex-mode runs `reftex-mode-hook'.
|
|
296 ;; - Files visited literally are processed with
|
|
297 ;; `reftex-initialize-temporary-buffers' if that is a list of functions.
|
|
298 ;;
|
|
299 ;; CONFIGURATION VARIABLES
|
|
300 ;; -----------------------
|
|
301 ;;
|
|
302 ;; The best way to learn about all configuration variables is via the
|
|
303 ;; browser interface of the custom library. For reference, I am giving
|
|
304 ;; here a complete list.
|
155
|
305 ;;
|
207
|
306 ;; ;; Defining label environments
|
|
307 ;; reftex-default-label-alist-entries
|
|
308 ;; reftex-label-alist
|
|
309 ;; reftex-section-levels
|
|
310 ;; reftex-default-context-regexps
|
|
311 ;; reftex-use-text-after-label-as-context
|
|
312 ;; ;; Label insertion
|
|
313 ;; reftex-insert-label-flags
|
|
314 ;; reftex-derive-label-parameters
|
|
315 ;; reftex-label-illegal-re
|
|
316 ;; reftex-abbrev-parameters
|
|
317 ;; ;; Label referencing
|
|
318 ;; reftex-label-menu-flags
|
|
319 ;; reftex-level-indent
|
|
320 ;; reftex-refontify-context
|
|
321 ;; reftex-guess-label-type
|
|
322 ;; ;; BibteX citation configuration
|
|
323 ;; reftex-bibpath-environment-variables
|
|
324 ;; reftex-bibfile-ignore-list
|
|
325 ;; reftex-sort-bibtex-matches
|
|
326 ;; reftex-cite-format
|
|
327 ;; reftex-comment-citations
|
|
328 ;; reftex-cite-comment-format
|
|
329 ;; reftex-cite-punctuation
|
|
330 ;; ;; Table of contents configuration
|
|
331 ;; reftex-toc-follow-mode
|
|
332 ;; ;; Fine-tuning the parser
|
|
333 ;; reftex-keep-temporary-buffers
|
|
334 ;; reftex-initialize-temporary-buffers
|
|
335 ;; reftex-enable-partial-scans
|
|
336 ;; reftex-save-parse-info
|
|
337 ;; ;; Miscellaneous configurations
|
|
338 ;; reftex-extra-bindings
|
|
339 ;; reftex-plug-into-AUCTeX
|
|
340 ;; reftex-use-fonts
|
|
341 ;; reftex-auto-show-entry
|
|
342 ;; reftex-load-hook
|
|
343 ;; reftex-mode-hook
|
155
|
344 ;;-------------------------------------------------------------------------
|
|
345 ;;
|
|
346 ;; KEY BINDINGS
|
207
|
347 ;; ============
|
155
|
348 ;;
|
207
|
349 ;; All RefTeX commands can be reached from its menu, the `Ref' menu on the
|
|
350 ;; menu bar. More frequently used commands have key bindings:
|
155
|
351 ;;
|
|
352 ;; C-c = reftex-toc
|
|
353 ;; C-c ( reftex-label
|
|
354 ;; C-c ) reftex-reference
|
|
355 ;; C-c [ reftex-citation
|
|
356 ;; C-c & reftex-view-crossref
|
|
357 ;;
|
207
|
358 ;; These keys are chosen to avoid interfering with AUCTeX's settings.
|
|
359 ;; Personally, I also bind some functions in the C-c LETTER map for
|
|
360 ;; easier access:
|
155
|
361 ;;
|
|
362 ;; C-c t reftex-toc
|
|
363 ;; C-c l reftex-label
|
|
364 ;; C-c r reftex-reference
|
|
365 ;; C-c c reftex-citation
|
|
366 ;; C-c v reftex-view-crossref
|
|
367 ;; C-c s reftex-search-document
|
|
368 ;; C-c g reftex-grep-document
|
|
369 ;;
|
|
370 ;; If you want to copy those as well, set in your .emacs file:
|
207
|
371 ;;
|
155
|
372 ;; (setq reftex-extra-bindings t)
|
|
373 ;;
|
|
374 ;; It is possible to bind the function for viewing cross references to a
|
207
|
375 ;; mouse event. Something like the following will do the trick:
|
155
|
376 ;;
|
207
|
377 ;; (add-hook 'reftex-load-hook
|
155
|
378 ;; '(lambda ()
|
207
|
379 ;; (define-key reftex-mode-map [(shift mouse-2)]
|
155
|
380 ;; 'reftex-mouse-view-crossref)))
|
207
|
381 ;;-------------------------------------------------------------------------
|
|
382 ;;
|
|
383 ;; REFTEX AND MULTIFILE DOCUMENTS
|
|
384 ;; ==============================
|
|
385 ;;
|
|
386 ;; The following is relevant when using RefTeX for multi-file documents:
|
|
387 ;;
|
|
388 ;; o RefTeX has full support for multifile documents. You can edit parts
|
|
389 ;; of several (multifile) documents at the same time without conflicts.
|
|
390 ;; RefTeX provides functions to run `grep', `search' and `query-replace'
|
|
391 ;; on all files which are part of a multifile document.
|
|
392 ;;
|
|
393 ;; o All files belonging to a multifile document should have a File
|
|
394 ;; Variable (`TeX-master' for AUCTeX or `tex-main-file' for the standard
|
|
395 ;; Emacs LaTeX mode) set to the name of the master file. See the
|
|
396 ;; documentation of your (La)TeX mode and the Emacs documentation on
|
|
397 ;; file variables: [Emacs/Customization/Variables/File Variables].
|
|
398 ;;
|
|
399 ;; o The context of a label definition must be found in the same file as
|
|
400 ;; the label itself in order to be processed correctly by RefTeX. The
|
|
401 ;; only exception is that section labels referring to a section statement
|
|
402 ;; outside the current file can still use that section title as context.
|
155
|
403 ;;-------------------------------------------------------------------------
|
|
404 ;;
|
207
|
405 ;; REFERENCES TO OTHER DOCUMENTS
|
|
406 ;; =============================
|
|
407 ;;
|
|
408 ;; RefTeX supports the LaTeX package `xr', which makes it possible to
|
|
409 ;; reference labels defined in another document. See the documentation on
|
|
410 ;; `xr' for details.
|
|
411 ;; When the document is set up to work with `xr', you can use the `x' key
|
|
412 ;; in the reference label menu to switch to the label menu of an external
|
|
413 ;; document and select any labels from there. In the *toc* buffer, the
|
|
414 ;; `x' key can be used to switch to the table of contents of an external
|
|
415 ;; document.
|
|
416 ;;
|
|
417 ;; For this kind of inter-document cross references, saving of parsing
|
|
418 ;; information can mean a large speed-up.
|
|
419 ;;
|
|
420 ;; (setq reftex-save-parse-info t)
|
|
421 ;;
|
|
422 ;;-------------------------------------------------------------------------
|
|
423 ;;
|
|
424 ;; OPTIMIZATIONS FOR LARGE DOCUMENTS
|
|
425 ;; =================================
|
|
426 ;;
|
|
427 ;; The default settings of RefTeX ensure a safe ride for beginners and
|
|
428 ;; casual users. However, when using RefTeX for a large project and/or on
|
|
429 ;; a small computer, there are ways to improve speed or memory usage.
|
|
430 ;;
|
|
431 ;; o RefTeX will load other parts of a multifile document as well as BibTeX
|
|
432 ;; database files for lookup purposes. These buffers are kept, so that
|
|
433 ;; subsequent use of the same files is fast. If you can't afford keeping
|
|
434 ;; these buffers around, and if you can live with a speed penalty, try
|
|
435 ;;
|
|
436 ;; (setq reftex-keep-temporary-buffers nil)
|
|
437 ;;
|
|
438 ;; o The `C-u' prefix on the major RefTeX commands `reftex-label',
|
|
439 ;; `reftex-reference', `reftex-citation' and `reftex-toc' initiates
|
|
440 ;; re-parsing of the entire document in order to update the parsing
|
|
441 ;; information. For a large document this can be unnecessary, in
|
|
442 ;; particular if only one file has changed. RefTeX can be configured to
|
|
443 ;; do partial scans instead of full ones. `C-u' re-parsing then does
|
|
444 ;; apply only to the current buffer and files included from it.
|
|
445 ;; Likewise, the `r' key in both the label menu and the table-of-contents
|
|
446 ;; buffer will only prompt scanning of the file in which the label or
|
|
447 ;; section macro near the cursor was defined. Re-parsing of the entire
|
|
448 ;; document is still available by using `C-u C-u' as a prefix, or the
|
|
449 ;; capital `R' key in the menus. To use this feature, try
|
|
450 ;;
|
|
451 ;; (setq reftex-enable-partial-scans t)
|
|
452 ;;
|
|
453 ;; o Even with partial scans enabled, RefTeX still has to make one full
|
|
454 ;; scan, when you start working with a document. To avoid this, parsing
|
|
455 ;; information can stored in a file. The file `MASTER.rel' is used for
|
|
456 ;; storing information about a document with master file `MASTER.tex'.
|
|
457 ;; It is written each time RefTeX parses (part of) the document, and
|
|
458 ;; restored when you begin working with a document in a new editing
|
|
459 ;; session. To use this feature, put into .emacs:
|
|
460 ;;
|
|
461 ;; (setq reftex-save-parse-info t)
|
|
462 ;;----------------------------------------------------------------------------
|
|
463 ;;
|
155
|
464 ;; RELATED PACKAGES
|
207
|
465 ;; ================
|
155
|
466 ;;
|
|
467 ;; AUCTeX
|
|
468 ;; ------
|
207
|
469 ;; If you are writing TeX or LaTeX documents with Emacs, you should have
|
|
470 ;; a look at AUCTeX, the definitive package to work with TeX and LaTeX.
|
155
|
471 ;; Information on AUCTeX can be found here:
|
|
472 ;;
|
|
473 ;; http://www.sunsite.auc.dk/auctex/
|
|
474 ;;
|
207
|
475 ;; Instead of using the RefTeX functions described above directly, you can
|
|
476 ;; also use them indirectly, through AUCTeX (version 9.8a or later).
|
|
477 ;; RefTeX provides several interface functions which can be used as
|
|
478 ;; replacement for corresponding AUCTeX functions dealing with labels and
|
|
479 ;; citations. In this way you can work normally with AUCTeX and use RefTeX
|
165
|
480 ;; internals to create and complete labels and citation keys.
|
155
|
481 ;;
|
165
|
482 ;; `reftex-label' can be used as the `LaTeX-label-function' which does
|
207
|
483 ;; label insertion when new environments are created with `C-c C-e'.
|
155
|
484 ;;
|
165
|
485 ;; `reftex-arg-label', `reftex-arg-ref' and `reftex-arg-cite' can replace
|
207
|
486 ;; the corresponding `TeX-arg-...' functions. E.g. when you insert a label
|
|
487 ;; macro with `C-c RET label RET', RefTeX will be transparently used to
|
|
488 ;; create the label.
|
165
|
489 ;;
|
207
|
490 ;; In order to plug all 4 functions into AUCTeX, use:
|
165
|
491 ;;
|
|
492 ;; (setq reftex-plug-into-AUCTeX t)
|
|
493 ;;
|
207
|
494 ;; You may also choose to plug in only some of these functions. See the
|
|
495 ;; docstring of `reftex-plug-into-AUCTeX'.
|
165
|
496 ;;
|
|
497 ;; AUCTeX can support RefTeX via style files. A style file may contain
|
|
498 ;; calls to `reftex-add-to-label-alist' which defines additions to
|
207
|
499 ;; `reftex-label-alist'. The argument taken by this function must have the
|
|
500 ;; same format as `reftex-label-alist'. The `amsmath.el' style file of
|
|
501 ;; AUCTeX (>9.7p) for example contains the following:
|
155
|
502 ;;
|
165
|
503 ;; (TeX-add-style-hook "amsmath"
|
|
504 ;; (function
|
|
505 ;; (lambda ()
|
|
506 ;; (if (featurep 'reftex)
|
|
507 ;; (reftex-add-to-label-alist '(AMSTeX))))))
|
155
|
508 ;;
|
165
|
509 ;; while a package `myprop' defining a proposition environment with
|
|
510 ;; \newtheorem might use
|
155
|
511 ;;
|
165
|
512 ;; (TeX-add-style-hook "myprop"
|
|
513 ;; (function
|
|
514 ;; (lambda ()
|
|
515 ;; (if (featurep 'reftex)
|
|
516 ;; (reftex-add-to-label-alist
|
207
|
517 ;; '(("proposition" ?p "prop:" "~\\ref{%s}" t
|
165
|
518 ;; ("Proposition" "Prop."))))))))
|
155
|
519 ;;
|
|
520 ;; Bib-cite.el
|
|
521 ;; -----------
|
207
|
522 ;; Once you have written a document with labels, refs and citations, it can
|
|
523 ;; be nice to read such a file like a hypertext document. RefTeX has some
|
|
524 ;; support for that (`reftex-view-crossref', `reftex-search-document'). A
|
|
525 ;; more elegant interface with mouse support and links into Hyperbole is
|
|
526 ;; provided (among other things) by Peter S. Galbraith's `bib-cite.el'.
|
|
527 ;; There is some overlap in the functionalities of Bib-cite and RefTeX.
|
|
528 ;; Bib-cite.el comes bundled with AUCTeX. You can also get the latest
|
|
529 ;; version from
|
155
|
530 ;;
|
|
531 ;; ftp://ftp.phys.ocean.dal.ca/users/rhogee/elisp/bib-cite.el
|
207
|
532 ;;---------------------------------------------------------------------------
|
155
|
533 ;;
|
207
|
534 ;; KNOWN BUGS AND WORK-AROUNDS
|
|
535 ;; ===========================
|
155
|
536 ;;
|
207
|
537 ;; o \input, \include, \bibliography and \section (etc.) statements have
|
|
538 ;; to be first on a line (except for white space).
|
155
|
539 ;;
|
207
|
540 ;; o RefTeX sees also labels in regions commented out and will refuse to
|
|
541 ;; make duplicates of such a label. This is considered to be a feature.
|
155
|
542 ;;
|
207
|
543 ;; o When using partial scans (`reftex-enable-partial-scans'), the section
|
|
544 ;; numbers in the table of contents may eventually become wrong. A full
|
|
545 ;; scan will fix this.
|
|
546 ;;
|
|
547 ;; o RefTeX keeps only a global copy of the configuration variables.
|
|
548 ;; Also, any additions from style files go into a global variable.
|
155
|
549 ;; Practically, this should not be a problem. Theoretically, it could
|
|
550 ;; give conflicts if two documents used environments with identical
|
|
551 ;; names, but different associated label types.
|
207
|
552 ;;
|
|
553 ;; o When using packages which make the buffer representation of a file
|
|
554 ;; different from its disk representation (e.g. x-symbol, isotex,
|
|
555 ;; iso-cvt) you may find that RefTeX's parsing information sometimes
|
|
556 ;; reflects the disk state of a file. This happens only in *unvisited*
|
|
557 ;; parts of a multifile document, because RefTeX visits these files
|
|
558 ;; literally for speed reasons. Then both short context and section
|
|
559 ;; headings may look different from what you usually see on your screen.
|
|
560 ;; In rare cases `reftex-toc' may have problems to jump to an affected
|
|
561 ;; section heading. There are three possible ways to deal with this:
|
|
562 ;;
|
|
563 ;; - (setq reftex-keep-temporary-buffers t)
|
|
564 ;; This implies that RefTeX will load all parts of a multifile
|
|
565 ;; document into Emacs (i.e. there will be no temporary buffers).
|
|
566 ;; - (setq reftex-initialize-temporary-buffers t)
|
|
567 ;; This means full initialization of temporary buffers. It involves
|
|
568 ;; a penalty when the same file is used for lookup often.
|
|
569 ;; - Set `reftex-initialize-temporary-buffers' to a list of hook
|
|
570 ;; functions doing a minimal initialization.
|
|
571 ;;
|
|
572 ;; You might also want to check the variable `reftex-refontify-context'.
|
155
|
573 ;;
|
207
|
574 ;; o Some nasty :-# packages use an additional argument to a \begin macro
|
|
575 ;; to specify a label. E.g. Lamport's "pf.sty" uses both
|
|
576 ;;
|
|
577 ;; \step{LABEL}{CLAIM} and \begin{step+}{LABEL}
|
|
578 ;; CLAIM
|
|
579 ;; \end{step+}
|
|
580 ;;
|
|
581 ;; We need to trick RefTeX into swallowing this:
|
155
|
582 ;;
|
207
|
583 ;; ;; Configuration for Lamport's pf.sty
|
|
584 ;; (setq reftex-label-alist
|
|
585 ;; '(("\\step{*}{}" ?p "st:" "~\\stepref{%s}" 2 ("Step" "St."))
|
|
586 ;; ("\\begin{step+}{*}" ?p "st:" "~\\stepref{%s}" 1000)))
|
155
|
587 ;;
|
207
|
588 ;; The first line is just a normal configuration for a macro. For the
|
|
589 ;; `step+' environment we actually tell RefTeX to look for the *macro*
|
|
590 ;; "\begin{step+}" and interprete the *first* argument (which in reality
|
|
591 ;; is a second argument to the macro \begin) as a label of type ?p.
|
|
592 ;; Argument count for this macro starts only after the {step+}, also
|
|
593 ;; when specifying how to get context.
|
155
|
594 ;;
|
207
|
595 ;; o In XEmacs 19.15, the overlay library has a bug. RefTeX does not
|
|
596 ;; suffer from it, but since it loads the library, other packages like
|
|
597 ;; GNUS will switch from extents to overlays and hit the bug. Upgrade
|
|
598 ;; to XEmacs 20, or fix the overlay library (in line 180 of overlay.el,
|
|
599 ;; change `(list before after)' to `(cons before after)').
|
155
|
600 ;;---------------------------------------------------------------------------
|
|
601 ;;
|
|
602 ;; AUTHOR
|
207
|
603 ;; ======
|
155
|
604 ;;
|
|
605 ;; Carsten Dominik <dominik@strw.LeidenUniv.nl>
|
|
606 ;;
|
|
607 ;; with contributions from Stephen Eglen
|
|
608 ;;
|
|
609 ;; The newest version of RefTeX can be found at
|
|
610 ;;
|
|
611 ;; http://www.strw.leidenuniv.nl/~dominik/Tools/
|
|
612 ;; ftp://strw.leidenuniv.nl/pub/dominik/
|
|
613 ;;
|
|
614 ;; THANKS TO:
|
|
615 ;; ---------
|
|
616 ;; At least the following people have invested time to test and bug-fix
|
207
|
617 ;; reftex.el. Some have send patches for fixes or new features, or came
|
|
618 ;; up with useful ideas.
|
155
|
619 ;;
|
|
620 ;; Stephen Eglen <stephene@cogs.susx.ac.uk>
|
207
|
621 ;; F.E. Burstall <F.E.Burstall@maths.bath.ac.uk>
|
155
|
622 ;; Karl Eichwalder <ke@ke.Central.DE>
|
|
623 ;; Laurent Mugnier <mugnier@onera.fr>
|
|
624 ;; Rory Molinari <molinari@yunt.math.lsa.umich.edu>
|
|
625 ;; Soren Dayton <csdayton@cs.uchicago.edu>
|
|
626 ;; Daniel Polani <polani@Informatik.Uni-Mainz.DE>
|
|
627 ;; Allan Strand <astrand@trillium.NMSU.Edu>
|
207
|
628 ;; Adrian Lanz <lanz@waho.ethz.ch>
|
|
629 ;; Jan Vroonhof <vroonhof@math.ethz.ch>
|
|
630 ;; Alastair Burt <alastair.burt@dfki.de>
|
|
631 ;; Dieter Kraft <dkraft@acm.org>
|
|
632 ;; Robin S. Socha <r.socha@franck.pc.uni-koeln.de>
|
155
|
633 ;;
|
207
|
634 ;; The view crossref feature was inspired by the similar function in
|
155
|
635 ;; Peter S. Galbraith's bib-cite.el.
|
207
|
636 ;;
|
155
|
637 ;; Finally thanks to Uwe Bolick <bolick@physik.tu-berlin.de> who first
|
|
638 ;; got me (some years ago) into supporting LaTeX labels and references
|
|
639 ;; with an Editor (which was MicroEmacs at the time).
|
|
640 ;;
|
|
641 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
642 ;;
|
207
|
643 ;; HISTORY
|
|
644 ;; =======
|
|
645 ;;
|
|
646 ;; Here are the more important changes made to RefTeX since initial release.
|
|
647 ;; Minor bug fixes are not mentioned.
|
|
648 ;;
|
|
649 ;; Version 1.00
|
|
650 ;; - released on 7 Jan 1997.
|
|
651 ;; Version 1.04
|
|
652 ;; - Macros as wrappers, AMSTeX support, delayed context parsing for
|
|
653 ;; new labels.
|
|
654 ;; Version 1.05
|
|
655 ;; - XEmacs port.
|
|
656 ;; Version 1.07
|
|
657 ;; - RefTeX gets its own menu.
|
|
658 ;; Version 1.09
|
|
659 ;; - Support for tex-main-file, an analogue for TeX-master.
|
|
660 ;; - MS-DOS support.
|
|
661 ;; Version 2.00
|
|
662 ;; - Labels can be derived from context (default for sections).
|
|
663 ;; - Configuration of label insertion and label referencing revised.
|
|
664 ;; - Crossref fields in BibTeX database entries.
|
|
665 ;; - `reftex-toc' introduced (thanks to Stephen Eglen).
|
|
666 ;; Version 2.03
|
|
667 ;; - Figure*, table*, Sidewaysfigure/table added to default environments.
|
|
668 ;; - `reftex-bibfile-ignore-list' introduced (thanks to Rory Molinari).
|
|
669 ;; - New functions `reftex-arg-label', `reftex-arg-ref', `reftex-arg-cite'.
|
|
670 ;; - Emacs/XEmacs compatibility reworked. XEmacs 19.15 now is required.
|
|
671 ;; - `reftex-add-to-label-alist' (to be called from AUCTeX style files).
|
|
672 ;; - Finding context with a hook function.
|
|
673 ;; - Sorting BibTeX entries (new variable: `reftex-sort-bibtex-matches').
|
|
674 ;; Version 2.05
|
|
675 ;; - Support for `custom.el'.
|
|
676 ;; - New function `reftex-grep-document' (thanks to Stephen Eglen).
|
|
677 ;; Version 2.07
|
|
678 ;; - New functions `reftex-search-document', `reftex-query-replace-document'
|
|
679 ;; Version 2.11
|
|
680 ;; - Submitted for inclusion to Emacs and XEmacs.
|
|
681 ;; Version 2.14
|
|
682 ;; - Variable `reftex-plug-into-AUCTeX' simplifies cooperation with AUCTeX.
|
|
683 ;; Version 2.17
|
|
684 ;; - Label prefix expands % escapes with current file name and other stuff.
|
|
685 ;; - Citation format now with % escapes. This is not backward compatible!
|
|
686 ;; - TEXINPUTS variable recognized when looking for input files.
|
|
687 ;; - Context can be the nth argument of a macro.
|
|
688 ;; - Searching in the select buffer is now possible (C-s and C-r).
|
|
689 ;; - Display and derive-label can use two different context methods.
|
|
690 ;; - AMSmath xalignat and xxalignat added.
|
|
691 ;; - THIS IS THE VERSION DISTRIBUTED WITH EMACS 20.1 and 20.2
|
|
692 ;; Version 3.00
|
|
693 ;; - RefTeX should work better for very large projects:
|
|
694 ;; - The new parser works without creating a master buffer.
|
|
695 ;; - Rescanning can be limited to a part of a multifile document.
|
|
696 ;; - Information from the parser can be stored in a file.
|
|
697 ;; - RefTeX can deal with macros having a naked label as an argument.
|
|
698 ;; - Macros may have white space and newlines between arguments.
|
|
699 ;; - Multiple identical section headings no longer confuse `reftex-toc'.
|
|
700 ;; - RefTeX should work correctly in combination with buffer-altering
|
|
701 ;; packages like outline, folding, x-symbol, iso-cvt, isotex, etc.
|
|
702 ;; - All labeled environments discussed in `The LaTeX Companion' by
|
|
703 ;; Goossens, Mittelbach & Samarin, Addison-Wesley 1994) are part of
|
|
704 ;; RefTeX's defaults.
|
|
705 ;; Version 3.03
|
|
706 ;; - Support for the LaTeX package `xr', for inter-document references.
|
|
707 ;; - A few (minor) Mule-related changes.
|
|
708 ;; - Fixed bug which could cause HUGE .rel files.
|
|
709 ;; - Search for input and .bib files with recursive path definitions.
|
|
710 ;; Version 3.04
|
|
711 ;; - Fixed BUG in the `xr' support.
|
|
712 ;; Version 3.05
|
|
713 ;; - Compatibility code now first checks for XEmacs feature.
|
|
714 ;; Version 3.07
|
|
715 ;; - `Ref' menu improved.
|
|
716 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
717 ;;
|
|
718 ;;;;;;
|
155
|
719
|
|
720 ;;; Code:
|
|
721
|
207
|
722 (eval-when-compile (require 'cl))
|
|
723
|
155
|
724 ;; Stuff that needs to be there when we use defcustom
|
|
725 ;; --------------------------------------------------
|
|
726
|
|
727 (require 'custom)
|
|
728
|
|
729 (defvar reftex-tables-dirty t
|
|
730 "Flag showing if tables need to be re-computed.")
|
|
731
|
|
732 (eval-and-compile
|
|
733 (defun reftex-set-dirty (symbol value)
|
|
734 (setq reftex-tables-dirty t)
|
|
735 (set symbol value)))
|
|
736
|
207
|
737 (eval-and-compile
|
|
738 (defmacro reftex-fp (n)
|
|
739 (if (fboundp 'forward-point)
|
|
740 (list 'forward-point n)
|
|
741 (list '+ '(point) n))))
|
|
742
|
155
|
743 ;;; Begin of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
744
|
207
|
745 ;; Define the two constants which are needed during compilation
|
|
746
|
|
747 (eval-and-compile
|
|
748 (defconst reftex-label-alist-builtin
|
|
749 '(
|
|
750 ;; Some aliases, mostly for backward compatibility
|
|
751 (Sideways "Alias for -->rotating" (rotating))
|
|
752 (AMSTeX "amsmath with eqref macro"
|
|
753 ((nil ?e nil "~\\eqref{%s}")
|
|
754 amsmath))
|
|
755
|
|
756 ;; Individual package defaults
|
|
757 (amsmath "AMS-LaTeX math environments"
|
|
758 (("align" ?e nil nil eqnarray-like)
|
|
759 ("gather" ?e nil nil eqnarray-like)
|
|
760 ("multline" ?e nil nil t)
|
|
761 ("flalign" ?e nil nil eqnarray-like)
|
|
762 ("alignat" ?e nil nil alignat-like)
|
|
763 ("xalignat" ?e nil nil alignat-like)
|
|
764 ("xxalignat" ?e nil nil alignat-like)
|
|
765 ("subequations" ?e nil nil t)))
|
|
766
|
|
767 (endnotes "The \\endnote macro"
|
|
768 (("\\endnote[]{}" ?n nil nil 2 ("Endnote"))))
|
|
769
|
|
770 (fancybox "The Beqnarray environment"
|
|
771 (("Beqnarray" ?e nil nil eqnarray-like)))
|
|
772
|
|
773 (floatfig "The floatingfigure environment"
|
|
774 (("floatingfigure" ?f nil nil caption)))
|
|
775
|
|
776 (longtable "The longtable environment"
|
|
777 (("longtable" ?t nil nil caption)))
|
|
778
|
|
779 (picinpar "The figwindow and tabwindow environments"
|
|
780 (("figwindow" ?f nil nil 1)
|
|
781 ("tabwindow" ?f nil nil 1)))
|
|
782
|
|
783 (rotating "Sidewaysfigure and table"
|
|
784 (("sidewaysfigure" ?f nil nil caption)
|
|
785 ("sidewaystable" ?t nil nil caption)))
|
|
786
|
|
787 (subfigure "Subfigure environments/macro"
|
|
788 (("subfigure" ?f nil nil caption)
|
|
789 ("subfigure*" ?f nil nil caption)
|
|
790 ("\\subfigure[]{}" ?f nil nil 1)))
|
|
791
|
|
792 (supertab "Supertabular environment"
|
|
793 (("supertabular" ?t nil nil "\\tablecaption{")))
|
|
794
|
|
795 (wrapfig "The wrapfigure environment"
|
|
796 (("wrapfigure" ?f nil nil caption)))
|
|
797
|
|
798 ;; The LaTeX core stuff
|
|
799 (LaTeX "LaTeX default environments"
|
|
800 (("section" ?s "sec:" "~\\ref{%s}" (nil . t)
|
|
801 ("Part" "Chapter" "Chap." "Section" "Sec." "Sect." "Paragraph" "Par."
|
|
802 "\\S" "Teil" "Kapitel" "Kap." "Abschnitt" ))
|
|
803
|
|
804 ("enumerate" ?i "item:" "~\\ref{%s}" item
|
|
805 ("Item" "Punkt"))
|
|
806
|
|
807 ("equation" ?e "eq:" "~(\\ref{%s})" t
|
|
808 ("Equation" "Eq." "Eqn." "Gleichung" "Gl."))
|
|
809 ("eqnarray" ?e "eq:" nil eqnarray-like)
|
|
810
|
|
811 ("figure" ?f "fig:" "~\\ref{%s}" caption
|
|
812 ("Figure" "Fig." "Abbildung" "Abb."))
|
|
813 ("figure*" ?f nil nil caption)
|
|
814
|
|
815 ("table" ?t "tab:" "~\\ref{%s}" caption
|
|
816 ("Table" "Tab." "Tabelle"))
|
|
817 ("table*" ?t nil nil caption)
|
|
818
|
|
819 ("\\footnote[]{}" ?n "note:" "~\\ref{%s}" 2
|
|
820 ("Footnote" "Note"))
|
|
821
|
|
822 ("any" ?\ " " "\\ref{%s}" nil)))
|
|
823
|
|
824 )
|
|
825 "The default label environment descriptions.
|
|
826 Lower-case symbols correspond to a style file of the same name in the LaTeX
|
|
827 distribution. Mixed-case symbols are convenience aliases.")
|
|
828
|
|
829 (defconst reftex-cite-format-builtin
|
|
830 '(
|
|
831 (default "Default macro \\cite{%l}"
|
|
832 "\\cite{%l}")
|
|
833 (natbib "The Natbib package"
|
|
834 ((?\C-m . "\\cite{%l}")
|
|
835 (?t . "\\citet{%l}")
|
|
836 (?T . "\\citet*{%l}")
|
|
837 (?p . "\\citep{%l}")
|
|
838 (?P . "\\citep*{%l}")
|
|
839 (?e . "\\citep[e.g.][]{%l}")
|
|
840 (?a . "\\citeauthor{%l}")
|
|
841 (?y . "\\citeyear{%l}")))
|
|
842 (harvard "The Harvard package"
|
|
843 ((?\C-m . "\\cite{%l}")
|
|
844 (?p . "\\cite{%l}")
|
|
845 (?t . "\\citeasnoun{%l}")
|
|
846 (?n . "\\citeasnoun{%l}")
|
|
847 (?s . "\\possessivecite{%l}")
|
|
848 (?e . "\\citeaffixed{%l}{?}")
|
|
849 (?y . "\\citeyear{%l}")
|
|
850 (?a . "\\citename{%l}")))
|
|
851 (chicago "The Chicago package"
|
|
852 ((?\C-m . "\\cite{%l}")
|
|
853 (?t . "\\citeN{%l}")
|
|
854 (?T . "\\shortciteN{%l}")
|
|
855 (?p . "\\cite{%l}")
|
|
856 (?P . "\\shortcite{%l}")
|
|
857 (?a . "\\citeA{%l}")
|
|
858 (?A . "\\shortciteA{%l}")
|
|
859 (?y . "\\citeyear{key}")))
|
|
860 (astron "The Astron package"
|
|
861 ((?\C-m . "\\cite{%l}")
|
|
862 (?p . "\\cite{%l}" )
|
|
863 (?t . "%2a (\\cite{%l})")))
|
|
864 (author-year "Do-it-yourself Author-year"
|
|
865 ((?\C-m . "\\cite{%l}")
|
|
866 (?t . "%2a (%y)\\nocite{%l}")
|
|
867 (?p . "(%2a %y\\nocite{%l})")))
|
|
868 (locally "Full info in parenthesis"
|
|
869 "(%2a %y, %j %v, %P, %e: %b, %u, %s %<)")
|
|
870 ;; undocumented feature: `%<' kills white space and punctuation locally.
|
|
871 )
|
|
872 "Builtin versions of for the citation format.
|
|
873 The following conventions are valid for all alist entries:
|
|
874 `?\C-m' should always point to a straight \\cite{%l} macro.
|
|
875 `?t' should point to a textual citation (citation as a noun).
|
|
876 `?p' should point to a parenthetical citation.")
|
|
877 )
|
|
878
|
155
|
879 ;; Configuration Variables and User Options for RefTeX ------------------
|
|
880
|
|
881 (defgroup reftex nil
|
|
882 "LaTeX label and citation support."
|
|
883 :tag "RefTeX"
|
207
|
884 :link '(url-link :tag "Home Page"
|
|
885 "http://strw.leidenuniv.nl/~dominik/Tools/")
|
|
886 :link '(emacs-commentary-link :tag "Commentary in reftex.el" "reftex.el")
|
155
|
887 :prefix "reftex-"
|
|
888 :group 'tex)
|
|
889
|
|
890 (defun reftex-customize ()
|
|
891 "Call the customize function with reftex as argument."
|
|
892 (interactive)
|
207
|
893 ;; Depending on the customize version we can call different functions.
|
|
894 (cond
|
|
895 ((fboundp 'customize-browse)
|
|
896 (customize-browse 'reftex))
|
|
897 ((fboundp 'customize-group)
|
|
898 (customize-group 'reftex))
|
|
899 ((fboundp 'customize)
|
|
900 (customize 'reftex))
|
|
901 (t (error "Custom.el not available"))))
|
|
902
|
|
903 (defun reftex-show-commentary ()
|
|
904 "Use the finder to view the file documentation from `reftex.el'."
|
|
905 (interactive)
|
|
906 (require 'finder)
|
|
907 (finder-commentary "reftex.el"))
|
155
|
908
|
|
909 ;; Support for \label and \ref --------------------------------------
|
|
910
|
|
911 (defgroup reftex-label-support nil
|
165
|
912 "Support for creation, insertion and referencing of labels in LaTeX."
|
155
|
913 :group 'reftex)
|
|
914
|
|
915 (defgroup reftex-defining-label-environments nil
|
165
|
916 "Definition of environments and macros to do with label."
|
155
|
917 :group 'reftex-label-support)
|
|
918
|
207
|
919 ;; Make a constant for the customization stuff
|
|
920 (eval-and-compile
|
|
921 (defconst reftex-tmp
|
|
922 '((const :tag "Default position" t)
|
|
923 (const :tag "After label" nil)
|
|
924 (number :tag "Macro arg nr" 1)
|
|
925 (regexp :tag "Regexp" "")
|
|
926 (const :tag "Caption in float" caption)
|
|
927 (const :tag "Item in list" item)
|
|
928 (const :tag "Eqnarray-like" eqnarray-like)
|
|
929 (const :tag "Alignat-like" alignat-like)
|
|
930 (symbol :tag "Function" my-func))))
|
|
931
|
|
932 (defcustom reftex-default-label-alist-entries
|
|
933 '(amsmath endnotes fancybox floatfig longtable picinpar
|
|
934 rotating subfigure supertab wrapfig LaTeX)
|
|
935 "Default label alist specifications. LaTeX should be the last entry.
|
|
936 This list describes the default label environments RefTeX should always use.
|
|
937 It is probably a mistake to remove the LaTeX symbol from this list.
|
|
938
|
|
939 The options include:
|
|
940 LaTeX The standard LaTeX environments.
|
|
941 Sideways The sidewaysfigure and sidewaystable environments.
|
|
942 AMSTeX The math environments in the AMS-LaTeX amsmath package.
|
|
943
|
|
944 For the full list of options, try
|
|
945
|
|
946 M-x customize-variable RET reftex-default-label-alist-entries RET."
|
|
947 :group 'reftex-defining-label-environments
|
|
948 :set 'reftex-set-dirty
|
|
949 :type `(set
|
|
950 :indent 4
|
|
951 :inline t
|
|
952 :greedy t
|
|
953 ,@(mapcar
|
|
954 (function
|
|
955 (lambda (x)
|
|
956 (list 'const ':tag (concat (symbol-name (nth 0 x))
|
|
957 ": " (nth 1 x))
|
|
958 (nth 0 x))))
|
|
959 reftex-label-alist-builtin)))
|
155
|
960
|
|
961 (defcustom reftex-label-alist nil
|
|
962 "Alist with information on environments for \\label-\\ref use.
|
207
|
963
|
|
964 This docstring is easier to understand after reading the configuration
|
|
965 examples in `reftex.el'. Looking at the builtin defaults in the constant
|
|
966 `reftex-label-alist-builtin' may also be instructive.
|
|
967
|
|
968 Set this variable to define additions and changes to the default. The only
|
|
969 things you MUST NOT change is that `?s' is the type indicator for section
|
|
970 labels, and SPC for the `any' label type. These are hard-coded at other
|
|
971 places in the code.
|
|
972
|
|
973 Each list entry describes either an environment carrying a counter for use
|
|
974 with \\label and \\ref, or a LaTeX macro defining a label as (or inside)
|
|
975 one of its arguments. The elements of each list entry are:
|
155
|
976
|
|
977 0. Name of the environment (like \"table\") or macro (like \"\\\\myfig\").
|
207
|
978 For macros, indicate the macro arguments for best results, as in
|
|
979 \"\\\\myfig[]{}{}{*}{}\". Use square brackets for optional arguments,
|
|
980 a star to mark the label argument, if any. The macro does not have to
|
|
981 have a label argument - you could also use \\label{..} inside one of
|
|
982 its arguments.
|
155
|
983 Special names: `section' for section labels, `any' to define a group
|
|
984 which contains all labels.
|
207
|
985 This may also be nil if the entry is only meant to change some settings
|
155
|
986 associated with the type indicator character (see below).
|
|
987
|
207
|
988 1. Type indicator character, like `?t', must be a printable ASCII character.
|
|
989 The type indicator is a single character which defines a label type.
|
|
990 Any label inside the environment or macro is assumed to belong to this
|
|
991 type. The same character may occur several times in this list, to cover
|
|
992 cases in which different environments carry the same label type (like
|
|
993 `equation' and `eqnarray').
|
155
|
994
|
|
995 2. Label prefix string, like \"tab:\".
|
165
|
996 The prefix is a short string used as the start of a label. It may be the
|
207
|
997 empty string. The prefix may contain the following `%' escapes:
|
|
998 %f Current file name with directory and extension stripped.
|
|
999 %F Current file name relative to directory of master file.
|
|
1000 %u User login name, on systems which support this.
|
|
1001
|
|
1002 Example: In a file `intro.tex', \"eq:%f:\" will become \"eq:intro:\").
|
|
1003
|
|
1004 3. Format string for reference insert in buffer. `%s' will be replaced by
|
|
1005 the label.
|
165
|
1006 When the format starts with `~', whitespace before point will be removed
|
|
1007 so that the reference cannot be separated from the word before it.
|
155
|
1008
|
|
1009 4. Indication on how to find the short context.
|
165
|
1010 - If nil, use the text following the \\label{...} macro.
|
|
1011 - If t, use
|
155
|
1012 - the section heading for section labels.
|
207
|
1013 - text following the \\begin{...} statement of environments.
|
|
1014 (not a good choice for environments like eqnarray or enumerate,
|
|
1015 where one has several labels in a single environment).
|
|
1016 - text after the macro name (stearting with the first arg) for macros.
|
|
1017 - If an integer, use the nth argument of the macro. As a special case,
|
|
1018 1000 means to get text after the last macro argument.
|
165
|
1019 - If a string, use as regexp to search *backward* from the label. Context
|
|
1020 is then the text following the end of the match. E.g. putting this to
|
207
|
1021 \"\\\\\\\\caption[[{]\" will use the caption in a figure or table
|
|
1022 environment.
|
165
|
1023 \"\\\\\\\\begin{eqnarray}\\\\|\\\\\\\\\\\\\\\\\" works for eqnarrays.
|
207
|
1024 - If any of `caption', `item', `eqnarray-like', `alignat-like', this
|
|
1025 symbol will internally be translated into an appropriate regexp
|
|
1026 (see also the variable `reftex-default-context-regexps').
|
155
|
1027 - If a function, call this function with the name of the environment/macro
|
165
|
1028 as argument. On call, point will be just after the \\label macro. The
|
|
1029 function is expected to return a suitable context string. It should
|
155
|
1030 throw an exception (error) when failing to find context.
|
207
|
1031 As an example, here is a function returning the 10 chars following
|
|
1032 the label macro as context:
|
155
|
1033
|
|
1034 (defun my-context-function (env-or-mac)
|
|
1035 (if (> (point-max) (+ 10 (point)))
|
|
1036 (buffer-substring (point) (+ 10 (point)))
|
|
1037 (error \"Buffer too small\")))
|
|
1038
|
207
|
1039 Label context is used in two ways by RefTeX: For display in the label
|
|
1040 menu, and to derive a label string. If you want to use a different
|
|
1041 method for each of these, specify them as a dotted pair.
|
|
1042 E.g. `(nil . t)' uses the text after the label (nil) for display, and
|
|
1043 text from the default position (t) to derive a label string. This is
|
|
1044 actually used for section labels.
|
|
1045
|
165
|
1046 Setting the variable `reftex-use-text-after-label-as-context' to t
|
|
1047 overrides the setting here.
|
|
1048
|
|
1049 5. List of magic words which identify a reference to be of this type.
|
|
1050 If the word before point is equal to one of these words when calling
|
207
|
1051 `reftex-reference', the label list offered will be automatically
|
|
1052 restricted to labels of the correct type.
|
155
|
1053
|
|
1054 If the type indicator characters of two or more entries are the same, RefTeX
|
|
1055 will use
|
|
1056 - the first non-nil format and prefix
|
|
1057 - the magic words of all involved entries.
|
|
1058
|
165
|
1059 Any list entry may also be a symbol. If that has an association in
|
|
1060 `reftex-label-alist-builtin', the cdr of that association is spliced into the
|
207
|
1061 list. However, builtin defaults should normally be set here but with the
|
|
1062 variable `reftex-default-label-alist-entries."
|
155
|
1063 :group 'reftex-defining-label-environments
|
|
1064 :set 'reftex-set-dirty
|
207
|
1065 :type
|
|
1066 `(repeat
|
|
1067 (choice
|
|
1068 :value ("" ?a nil nil nil nil)
|
|
1069 (list :tag "Detailed label alist entry"
|
|
1070 :value ("" ?a nil nil nil nil)
|
|
1071 (choice :tag "Environment or \\macro "
|
|
1072 (const :tag "Ignore, just use typekey" nil)
|
|
1073 (string ""))
|
|
1074 (character :tag "Typekey character " ?a)
|
|
1075 (choice :tag "Label prefix string "
|
|
1076 (const :tag "Default" nil)
|
|
1077 (string :tag "String" "lab:"))
|
|
1078 (choice :tag "Label reference format"
|
|
1079 (const :tag "Default" nil)
|
|
1080 (string :tag "String" "~\\ref{%s}"))
|
|
1081 (choice :tag "Context"
|
|
1082 (choice
|
|
1083 :tag "1 method"
|
|
1084 ,@reftex-tmp)
|
|
1085 (cons :tag "Split methods"
|
|
1086 (choice
|
|
1087 :tag " Display context "
|
|
1088 ,@reftex-tmp)
|
|
1089 (choice
|
|
1090 :tag " Derive label context"
|
|
1091 ,@reftex-tmp)))
|
|
1092 (repeat :tag "List of Magic Words" (string)))
|
|
1093 (choice
|
|
1094 :tag "Package"
|
|
1095 :value AMSTeX
|
|
1096 ,@(mapcar
|
|
1097 (function
|
|
1098 (lambda (x)
|
|
1099 (list 'const ':tag (concat (symbol-name (nth 0 x))); ": " (nth 1 x))
|
|
1100 (nth 0 x))))
|
|
1101 reftex-label-alist-builtin)))))
|
|
1102
|
|
1103 ;; LaTeX section commands and level numbers
|
|
1104 (defcustom reftex-section-levels
|
|
1105 '(
|
|
1106 ("part" . 0)
|
|
1107 ("chapter" . 1)
|
|
1108 ("section" . 2)
|
|
1109 ("subsection" . 3)
|
|
1110 ("subsubsection" . 4)
|
|
1111 ("paragraph" . 5)
|
|
1112 ("subparagraph" . 6)
|
|
1113 ("subsubparagraph" . 7)
|
|
1114 )
|
|
1115 "Commands and levels used for defining sections in the document.
|
|
1116 The car of each cons cell is the name of the section macro. The cdr is a
|
|
1117 number indicating its level."
|
155
|
1118 :group 'reftex-defining-label-environments
|
207
|
1119 :set 'reftex-set-dirty
|
|
1120 :type '(repeat
|
|
1121 (cons (string :tag "sectioning macro" "")
|
|
1122 (number :tag "level " 0))))
|
|
1123
|
|
1124 (defcustom reftex-default-context-regexps
|
|
1125 '((caption . "\\\\\\(rot\\)?caption\\*?[[{]")
|
|
1126 (item . "\\\\item\\(\\[[^]]*\\]\\)?")
|
|
1127 (eqnarray-like . "\\\\begin{%s}\\|\\\\\\\\")
|
|
1128 (alignat-like . "\\\\begin{%s}{[0-9]*}\\|\\\\\\\\"))
|
|
1129 "Alist with default regular expressions for finding context.
|
|
1130 The form (format regexp (regexp-quote environment)) is used to calculate
|
|
1131 the final regular expression - so %s will be replaced with the environment
|
|
1132 or macro."
|
|
1133 :group 'reftex-defining-label-environments
|
|
1134 :type '(repeat (cons (symbol) (regexp))))
|
|
1135
|
155
|
1136 (defcustom reftex-use-text-after-label-as-context nil
|
|
1137 "*t means, grab context from directly after the \\label{..} macro.
|
|
1138 This is the fastest method for obtaining context of the label definition, but
|
165
|
1139 requires discipline when placing labels. Setting this variable to t takes
|
|
1140 precedence over the individual settings in `reftex-label-alist'.
|
155
|
1141 This variable may be set to t, nil, or a string of label type letters
|
|
1142 indicating the label types for which it should be true."
|
|
1143 :group 'reftex-defining-label-environments
|
|
1144 :set 'reftex-set-dirty
|
|
1145 :type '(choice
|
207
|
1146 (const :tag "on" t) (const :tag "off" nil)
|
|
1147 (string :tag "Selected label types")))
|
155
|
1148
|
|
1149 ;; Label insertion
|
|
1150
|
|
1151 (defgroup reftex-making-and-inserting-labels nil
|
165
|
1152 "Options on how to create new labels."
|
155
|
1153 :group 'reftex-label-support)
|
|
1154
|
|
1155 (defcustom reftex-insert-label-flags '("s" "sft")
|
165
|
1156 "Flags governing label insertion. First flag DERIVE, second flag PROMPT.
|
155
|
1157
|
|
1158 If DERIVE is t, RefTeX will try to derive a sensible label from context.
|
|
1159 A section label for example will be derived from the section heading.
|
|
1160 The conversion of the context to a legal label is governed by the
|
165
|
1161 specifications given in `reftex-derive-label-parameters'.
|
155
|
1162 If RefTeX fails to derive a label, it will prompt the user.
|
207
|
1163 If DERIVE is nil, the label generated will consist of the prefix and a
|
|
1164 unique number, like `eq:23'.
|
155
|
1165
|
165
|
1166 If PROMPT is t, the user will be prompted for a label string. The prompt will
|
155
|
1167 already contain the prefix, and (if DERIVE is t) a default label derived from
|
|
1168 context. When PROMPT is nil, the default label will be inserted without
|
|
1169 query.
|
|
1170
|
165
|
1171 So the combination of DERIVE and PROMPT controls label insertion. Here is a
|
155
|
1172 table describing all four possibilities:
|
|
1173
|
|
1174 DERIVE PROMPT ACTION
|
|
1175 -------------------------------------------------------------------------
|
165
|
1176 nil nil Insert simple label, like eq:22 or sec:13. No query.
|
|
1177 nil t Prompt for label.
|
|
1178 t nil Derive a label from context and insert without query.
|
|
1179 t t Derive a label from context and prompt for confirmation.
|
155
|
1180
|
|
1181 Each flag may be set to t, nil, or a string of label type letters
|
|
1182 indicating the label types for which it should be true.
|
165
|
1183 Thus, the combination may be set differently for each label type. The
|
155
|
1184 default settings \"s\" and \"sft\" mean: Derive section labels from headings
|
165
|
1185 (with confirmation). Prompt for figure and table labels. Use simple labels
|
155
|
1186 without confirmation for everything else."
|
|
1187 :group 'reftex-making-and-inserting-labels
|
|
1188 :type '(list (choice :tag "Derive label from context"
|
|
1189 (const :tag "always" t)
|
|
1190 (const :tag "never" nil)
|
207
|
1191 (string :tag "selected label types" ""))
|
155
|
1192 (choice :tag "Prompt for label string "
|
|
1193 :entry-format " %b %v"
|
|
1194 (const :tag "always" t)
|
|
1195 (const :tag "never" nil)
|
207
|
1196 (string :tag "selected label types" ""))))
|
|
1197
|
|
1198 (defcustom reftex-derive-label-parameters '(3 20 t 1 "-"
|
155
|
1199 ("the" "on" "in" "off" "a" "for" "by" "of" "and" "is"))
|
|
1200 "Parameters for converting a string into a label.
|
|
1201 NWORDS Number of words to use.
|
|
1202 MAXCHAR Maximum number of characters in a label string.
|
|
1203 ILLEGAL nil: Throw away any words containing characters illegal in labels.
|
|
1204 t: Throw away only the illegal characters, not the whole word.
|
|
1205 ABBREV nil: Never abbreviate words.
|
165
|
1206 t: Always abbreviate words (see `reftex-abbrev-parameters').
|
155
|
1207 not t and not nil: Abbreviate words if necessary to shorten
|
|
1208 label string below MAXCHAR.
|
165
|
1209 SEPARATOR String separating different words in the label.
|
|
1210 IGNOREWORDS List of words which should not be part of labels."
|
155
|
1211 :group 'reftex-making-and-inserting-labels
|
|
1212 :type '(list (integer :tag "Number of words " 3)
|
207
|
1213 (integer :tag "Maximum label length " 20)
|
|
1214 (choice :tag "Illegal characters in words"
|
|
1215 (const :tag "throw away entire word" nil)
|
|
1216 (const :tag "throw away single chars" t))
|
|
1217 (choice :tag "Abbreviate words "
|
|
1218 (const :tag "never" nil)
|
|
1219 (const :tag "always" t)
|
|
1220 (const :tag "when label is too long" 1))
|
|
1221 (string :tag "Separator between words " "-")
|
|
1222 (repeat :tag "Ignore words"
|
|
1223 :entry-format " %i %d %v"
|
|
1224 (string :tag ""))))
|
|
1225
|
155
|
1226 (defcustom reftex-label-illegal-re "[\000-\040\177-\377\\\\#$%&~^_{}]"
|
|
1227 "Regexp matching characters not legal in labels.
|
|
1228 For historic reasons, this character class comes *with* the [] brackets."
|
|
1229 :group 'reftex-making-and-inserting-labels
|
|
1230 :type '(regexp :tag "Character class"))
|
|
1231
|
|
1232 (defcustom reftex-abbrev-parameters '(4 2 "^saeiou" "aeiou")
|
|
1233 "Parameters for abbreviation of words.
|
165
|
1234 MIN-CHARS Minimum number of characters remaining after abbreviation.
|
|
1235 MIN-KILL Minimum number of characters to remove when abbreviating words.
|
|
1236 BEFORE Character class before abbrev point in word.
|
|
1237 AFTER Character class after abbrev point in word."
|
155
|
1238 :group 'reftex-making-and-inserting-labels
|
|
1239 :type '(list
|
207
|
1240 (integer :tag "Minimum chars per word" 4)
|
|
1241 (integer :tag "Shorten by at least " 2)
|
|
1242 (string :tag "cut before char class " "^saeiou")
|
|
1243 (string :tag "cut after char class " "aeiou")))
|
155
|
1244
|
|
1245 ;; Label referencing
|
|
1246
|
|
1247 (defgroup reftex-referencing-labels nil
|
165
|
1248 "Options on how to reference labels."
|
155
|
1249 :group 'reftex-label-support)
|
|
1250
|
207
|
1251 (eval-and-compile
|
|
1252 (defconst reftex-tmp
|
|
1253 '((const :tag "on" t)
|
|
1254 (const :tag "off" nil)
|
|
1255 (string :tag "Selected label types"))))
|
|
1256
|
|
1257 (defcustom reftex-label-menu-flags '(t t nil nil nil nil t nil)
|
|
1258 "List of flags governing the label menu makeup.
|
155
|
1259 The flags are:
|
|
1260
|
|
1261 TABLE-OF-CONTENTS Show the labels embedded in a table of context.
|
|
1262 SECTION-NUMBERS Include section numbers (like 4.1.3) in table of contents.
|
165
|
1263 COUNTERS Show counters. This just numbers the labels in the menu.
|
155
|
1264 NO-CONTEXT Non-nil means do NOT show the short context.
|
165
|
1265 FOLLOW Follow full context in other window.
|
207
|
1266 SHOW-COMMENTED Show labels from regions which are commented out.
|
|
1267 MATCH-IN-TOC Searches in label menu will also match in toc lines.
|
|
1268 SHOW FILES Show Begin and end of included files.
|
155
|
1269
|
|
1270 Each of these flags can be set to t or nil, or to a string of type letters
|
165
|
1271 indicating the label types for which it should be true. These strings work
|
|
1272 like character classes in regular expressions. Thus, setting one of the
|
155
|
1273 flags to \"sf\" makes the flag true for section and figure labels, nil
|
165
|
1274 for everything else. Setting it to \"^ft\" makes it the other way round.
|
155
|
1275
|
|
1276 Most options can also be switched from the label menu itself - so if you
|
|
1277 decide here to not have a table of contents in the label menu, you can still
|
|
1278 get one interactively during selection from the label menu."
|
|
1279 :group 'reftex-referencing-labels
|
207
|
1280 :type
|
|
1281 `(list
|
|
1282 (choice :tag "Embed in table of contents " ,@reftex-tmp)
|
|
1283 (choice :tag "Show section numbers " ,@reftex-tmp)
|
|
1284 (choice :tag "Show individual counters " ,@reftex-tmp)
|
|
1285 (choice :tag "Hide short context " ,@reftex-tmp)
|
|
1286 (choice :tag "Follow context in other window " ,@reftex-tmp)
|
|
1287 (choice :tag "Show commented labels " ,@reftex-tmp)
|
|
1288 (choice :tag "Searches match in toc lines " ,@reftex-tmp)
|
|
1289 (choice :tag "Show begin/end of included files" ,@reftex-tmp)))
|
|
1290
|
|
1291 (defcustom reftex-level-indent 2
|
|
1292 "*Number of spaces to be used for indentation per section level."
|
|
1293 :group 'reftex-referencing-labels
|
|
1294 :type '(integer))
|
|
1295
|
|
1296 (defcustom reftex-refontify-context 1
|
|
1297 "*Non-nil means, re-fontify the context in the label menu with font-lock.
|
|
1298 This slightly slows down the creation of the label menu. It is only necessay
|
|
1299 when you definitely want the context fontified.
|
|
1300
|
|
1301 This option may have 3 different values:
|
|
1302 nil Never refontify.
|
|
1303 t Always refontify.
|
|
1304 1 Refontify when absolutly necessary, e.g. when with the x-symbol package.
|
|
1305 The option is ignored when `reftex-use-fonts' is nil."
|
|
1306 :group 'reftex-referencing-labels
|
|
1307 :type '(choice
|
|
1308 (const :tag "Never" nil)
|
|
1309 (const :tag "Always" t)
|
|
1310 (const :tag "When necessary" 1)))
|
155
|
1311
|
|
1312 (defcustom reftex-guess-label-type t
|
165
|
1313 "*Non-nil means, `reftex-reference' will try to guess the label type.
|
155
|
1314 To do that, RefTeX will look at the word before the cursor and compare it with
|
165
|
1315 the words given in `reftex-label-alist'. When it finds a match, RefTeX will
|
155
|
1316 immediately offer the correct label menu - otherwise it will prompt you for
|
165
|
1317 a label type. If you set this variable to nil, RefTeX will always prompt."
|
155
|
1318 :group 'reftex-referencing-labels
|
|
1319 :type '(boolean))
|
|
1320
|
|
1321 ;; BibteX citation configuration ----------------------------------------
|
|
1322
|
|
1323 (defgroup reftex-citation-support nil
|
165
|
1324 "Support for referencing bibliographic data with BibTeX."
|
155
|
1325 :group 'reftex)
|
|
1326
|
|
1327 (defcustom reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB")
|
|
1328 "*List of env vars which might contain the path to BibTeX database files."
|
|
1329 :group 'reftex-citation-support
|
|
1330 :set 'reftex-set-dirty
|
|
1331 :type '(repeat (string :tag "Environment variable")))
|
|
1332
|
|
1333 (defcustom reftex-bibfile-ignore-list nil
|
207
|
1334 "*List of files in \\bibliography{..} RefTeX should *not* parse.
|
155
|
1335 The file names have to be in the exact same form as in the bibliography
|
165
|
1336 macro - i.e. without the `.bib' extension.
|
155
|
1337 Intended for files which contain only `@string' macro definitions and the
|
|
1338 like, which are ignored by RefTeX anyway."
|
|
1339 :group 'reftex-citation-support
|
|
1340 :set 'reftex-set-dirty
|
|
1341 :type '(repeat (string :tag "File name")))
|
|
1342
|
|
1343 (defcustom reftex-sort-bibtex-matches 'reverse-year
|
|
1344 "*Sorting of the entries found in BibTeX databases by reftex-citation.
|
|
1345 Possible values:
|
|
1346 nil Do not sort entries.
|
|
1347 'author Sort entries by author name.
|
|
1348 'year Sort entries by increasing year.
|
|
1349 'reverse-year Sort entries by decreasing year."
|
|
1350 :group 'reftex-citation-support
|
|
1351 :type '(choice (const :tag "not" nil)
|
207
|
1352 (const :tag "by author" author)
|
|
1353 (const :tag "by year" year)
|
|
1354 (const :tag "by year, reversed" reverse-year)))
|
|
1355
|
|
1356 (defcustom reftex-cite-format 'default
|
|
1357 "*The format of citations to be inserted into the buffer.
|
|
1358 It can be a string or an alist. In the simplest case this is just
|
|
1359 the string \"\\cite{%l}\", which is also the default. See the
|
|
1360 definition of `reftex-cite-format-builtin' for more complex examples.
|
|
1361
|
|
1362 If `reftex-cite-format' is a string, it will be used as the format.
|
|
1363 In the format, the following percent escapes will be expanded.
|
|
1364
|
|
1365 %l The BibTeX label of the citation.
|
|
1366 %a List of author names, see also `reftex-cite-punctuation.
|
|
1367 %2a Like %a, but abbreviate more than 2 authors like Jones et al.
|
|
1368 %A First author name only.
|
|
1369 %e Works like %a, but on list of editor names. (%2e and %E work a well)
|
|
1370
|
|
1371 It is also possible to access all other BibTeX database fields:
|
|
1372 %b booktitle %c chapter %d edition %h howpublished
|
|
1373 %i institution %j journal %k key %m month
|
|
1374 %n number %o organization %p pages %P first page
|
|
1375 %r address %s school %u publisher %t title
|
|
1376 %v volume %y year
|
|
1377
|
|
1378 Usually, only %l is needed. Try, however, (setq reftex-comment-citations t).
|
|
1379
|
|
1380 If `reftex-cite-format' is an alist of characters and strings, the user
|
|
1381 will be prompted for a character to select one of the possible format
|
|
1382 strings.
|
155
|
1383 In order to configure this variable, you can either set
|
165
|
1384 `reftex-cite-format' directly yourself or set it to the SYMBOL of one of
|
207
|
1385 the predefined styles (see `reftex-cite-format-builtin'). E.g.:
|
|
1386 (setq reftex-cite-format 'harvard)"
|
|
1387 :group 'reftex-citation-support
|
|
1388 :type
|
|
1389 `(choice
|
|
1390 :format "%{%t%}: \n%[Value Menu%] %v"
|
|
1391 (radio :tag "Symbolic Builtins"
|
|
1392 :indent 4
|
|
1393 :value default
|
|
1394 ,@(mapcar
|
|
1395 (function
|
|
1396 (lambda (x)
|
|
1397 (list 'const ':tag (concat (symbol-name (nth 0 x))
|
|
1398 ": " (nth 1 x))
|
|
1399 (nth 0 x))))
|
|
1400 reftex-cite-format-builtin))
|
|
1401 (string :tag "format string" "\\cite{%l}")
|
|
1402 (repeat :tag "key-ed format strings"
|
|
1403 :value ((?\r . "\\cite{%l}")
|
|
1404 (?t . "\\cite{%l}") (?p . "\\cite{%l}"))
|
|
1405 (cons (character :tag "Key character" ?\r)
|
|
1406 (string :tag "Format string" "")))))
|
|
1407
|
|
1408 (defcustom reftex-comment-citations nil
|
|
1409 "*Non-nil means add a comment for each citation describing the full entry.
|
|
1410 The comment is formatted according to `reftex-cite-comment-format'."
|
|
1411 :group 'reftex-citation-support
|
|
1412 :type '(boolean))
|
|
1413
|
|
1414 (defcustom reftex-cite-comment-format
|
|
1415 "%% %2a %y, %j %v, %P, %e: %b, %u, %s %<\n"
|
|
1416 "Citation format used for commented citations. Must NOT contain %l."
|
|
1417 :group 'reftex-citation-support
|
|
1418 :type '(string))
|
|
1419
|
|
1420 (defcustom reftex-cite-punctuation '(", " " \\& " " {\\it et al.}")
|
|
1421 "Punctuation for formatting of name lists in citations.
|
|
1422 This is a list of 3 strings.
|
|
1423 1. normal names separator, like \", \" in Jones, Brown and Miller
|
|
1424 2. final names separator, like \" and \" in Jones, Brown and Miller
|
|
1425 3. The \"et al\" string, like \" {...}\" in Jones {\\it et al.}"
|
|
1426 :group 'reftex-citation-support
|
|
1427 :type '(list
|
|
1428 (string :tag "Separator for names ")
|
|
1429 (string :tag "Separator for last name in list")
|
|
1430 (string :tag "string used as et al. ")))
|
155
|
1431
|
|
1432 ;; Table of contents configuration --------------------------------------
|
|
1433
|
|
1434 (defgroup reftex-table-of-contents-browser nil
|
|
1435 "A multifile table of contents browser."
|
|
1436 :group 'reftex)
|
|
1437
|
|
1438 (defcustom reftex-toc-follow-mode nil
|
207
|
1439 "*Non-nil means, point in *toc* buffer will cause other window to follow.
|
155
|
1440 The other window will show the corresponding part of the document.
|
|
1441 This flag can be toggled from within the *toc* buffer with the `f' key."
|
|
1442 :group 'reftex-table-of-contents-browser
|
|
1443 :type '(boolean))
|
|
1444
|
207
|
1445 ;; Tuning the parser ----------------------------------------------------
|
|
1446
|
|
1447 (defgroup reftex-optimizations-for-large-documents nil
|
|
1448 "Configuration of parser speed and memory usage."
|
|
1449 :group 'reftex)
|
|
1450
|
|
1451 (defcustom reftex-keep-temporary-buffers 1
|
|
1452 "*Non-nil means, keep buffers created for parsing and lookup.
|
|
1453 RefTeX sometimes needs to visit files related to the current document.
|
|
1454 We distinguish files visited for
|
|
1455 PARSING: Parts of a multifile document loaded when (re)-parsing the document.
|
|
1456 LOOKUP: BibTeX database files and TeX files loaded to find a reference,
|
|
1457 to display label context, etc.
|
|
1458 The created buffers can be kept for later use, or be thrown away immediately
|
|
1459 after use, depending on the value of this variable:
|
|
1460
|
|
1461 nil Throw away as much as possible.
|
|
1462 t Keep everything.
|
|
1463 1 Throw away buffers created for parsing, but keep the ones created
|
|
1464 for lookup.
|
|
1465
|
|
1466 If a buffer is to be kept, the file is visited normally (which is potentially
|
|
1467 slow but will happen only once).
|
|
1468 If a buffer is to be thrown away, the initialization of the buffer depends
|
|
1469 upon the variable `reftex-initialize-temporary-buffers'."
|
|
1470 :group 'reftex-miscellaneous-configurations
|
|
1471 :type '(choice
|
|
1472 (const :tag "Throw away everything" nil)
|
|
1473 (const :tag "Keep everything" t)
|
|
1474 (const :tag "Keep lookup buffers only" 1)))
|
|
1475
|
|
1476 (defcustom reftex-initialize-temporary-buffers nil
|
|
1477 "*Non-nil means do initializations even when visiting file temporarily.
|
|
1478 When nil, RefTeX may turn off find-file hooks and other stuff to briefly
|
|
1479 visit a file.
|
|
1480 When t, the full default initializations are done (find-file-hook etc.).
|
|
1481 Instead of t or nil, this variable may also be a list of hook functions to
|
|
1482 do a minimal initialization."
|
|
1483 :group 'reftex-miscellaneous-configurations
|
|
1484 :type '(choice
|
|
1485 (const :tag "Read files literally" nil)
|
|
1486 (const :tag "Fully initialize buffers" t)
|
|
1487 (repeat :tag "Hook functions" :value (nil)
|
|
1488 (function-item))))
|
|
1489
|
|
1490 (defcustom reftex-enable-partial-scans nil
|
|
1491 "*Non-nil means, re-parse only 1 file when asked to re-parse.
|
|
1492 Re-parsing is normally requested with a `C-u' prefix to many RefTeX commands,
|
|
1493 or with the `r' key in menus. When this option is t in a multifile document,
|
|
1494 we will only parse the current buffer, or the file associated with the label
|
|
1495 or section heading near point in a menu. Requesting re-parsing of an entire
|
|
1496 multifile document then requires a `C-u C-u' prefix or the capital `R' key
|
|
1497 in menus."
|
|
1498 :group 'reftex-optimizations-for-large-documents
|
|
1499 :type 'boolean)
|
|
1500
|
|
1501 (defcustom reftex-save-parse-info nil
|
|
1502 "*Non-nil means, save information gathered with parsing in a file.
|
|
1503 The file MASTER.rel in the same directory as MASTER.tex is used to save the
|
|
1504 information. When this variable is t,
|
|
1505 - accessing the parsing information for the first time in an editing session
|
|
1506 will read that file (if available) instead of parsing the document.
|
|
1507 - each time (part of) the document is rescanned, a new version of the file
|
|
1508 is written."
|
|
1509 :group 'reftex-optimizations-for-large-documents
|
|
1510 :type 'boolean)
|
|
1511
|
155
|
1512 ;; Miscellaneous configurations -----------------------------------------
|
|
1513
|
|
1514 (defgroup reftex-miscellaneous-configurations nil
|
165
|
1515 "Collection of further configurations."
|
155
|
1516 :group 'reftex)
|
|
1517
|
|
1518 (defcustom reftex-extra-bindings nil
|
|
1519 "Non-nil means, make additional key bindings on startup.
|
165
|
1520 These extra bindings are located in the users `C-c letter' map."
|
155
|
1521 :group 'reftex-miscellaneous-configurations
|
207
|
1522 :type '(boolean))
|
155
|
1523
|
165
|
1524 (defcustom reftex-plug-into-AUCTeX nil
|
207
|
1525 "*Plug-in flags for AUCTeX interface.
|
165
|
1526 This variable is a list of 4 boolean flags. When a flag is non-nil, it
|
|
1527 means:
|
|
1528
|
|
1529 Flag 1: use `reftex-label' as `LaTeX-label-function'.
|
|
1530 Flag 2: use `reftex-arg-label' as `TeX-arg-label'
|
|
1531 Flag 3: use `reftex-arg-ref' as `TeX-arg-ref'
|
|
1532 Flag 4: use `reftex-arg-cite' as `TeX-arg-cite'
|
|
1533
|
|
1534 You may also set the variable itself to t or nil in order to turn all
|
|
1535 plug-ins on or off, respectively.
|
|
1536 \\<LaTeX-mode-map>`LaTeX-label-function' is the function used for label insertion when you
|
|
1537 enter a new environment in AUCTeX with \\[LaTeX-environment].
|
|
1538 The `TeX-arg-label' etc. functions are for entering macro arguments during
|
|
1539 macro insertion with \\[TeX-insert-macro].
|
|
1540 See the AUCTeX documentation for more information.
|
|
1541 RefTeX uses `fset' to take over the function calls. Changing the variable
|
|
1542 may require a restart of Emacs in order to become effective."
|
|
1543 :group 'reftex-miscellaneous-configurations
|
|
1544 :type '(choice (const :tag "No plug-ins" nil)
|
207
|
1545 (const :tag "All possible plug-ins" t)
|
|
1546 (list
|
|
1547 :tag "Individual choice"
|
|
1548 :value (nil nil nil nil)
|
|
1549 (boolean :tag "Use reftex-label as LaTeX-label-function")
|
|
1550 (boolean :tag "Use reftex-arg-label as TeX-arg-label ")
|
|
1551 (boolean :tag "Use reftex-arg-ref as TeX-arg-ref ")
|
|
1552 (boolean :tag "Use reftex-arg-cite as TeX-arg-cite ")
|
|
1553 )))
|
165
|
1554
|
155
|
1555 (defcustom reftex-use-fonts t
|
|
1556 "*Non-nil means, use fonts in label menu and on-the-fly help.
|
|
1557 Font-lock must be loaded as well to actually get fontified display."
|
|
1558 :group 'reftex-miscellaneous-configurations
|
|
1559 :type '(boolean))
|
|
1560
|
207
|
1561 (defcustom reftex-auto-show-entry 'copy
|
|
1562 "*Non-nil means, do something when context in other window is hidden.
|
|
1563 Some modes like `outline-mode' or `folding-mode' hide parts of buffers.
|
|
1564 When RefTeX is asked to show context for a label definition, and the context
|
|
1565 is invisible, it can unhide that section permanently (value t), or copy the
|
|
1566 context to a temporary buffer (value 'copy)."
|
155
|
1567 :group 'reftex-miscellaneous-configurations
|
207
|
1568 :type '(radio :value copy
|
|
1569 :indent 4
|
|
1570 (const :tag "Do nothing" nil)
|
|
1571 (const :tag "Unhide section permanently" t)
|
|
1572 (const :tag "Copy context to show" copy)))
|
|
1573
|
|
1574 (defcustom reftex-load-hook nil
|
|
1575 "Hook which is being run when loading reftex.el."
|
155
|
1576 :group 'reftex-miscellaneous-configurations
|
207
|
1577 :type 'hook)
|
|
1578
|
|
1579 (defcustom reftex-mode-hook nil
|
|
1580 "Hook which is being run when turning on RefTeX mode."
|
|
1581 :group 'reftex-miscellaneous-configurations
|
|
1582 :type 'hook)
|
155
|
1583
|
|
1584 ;;; End of Configuration Section ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1585
|
|
1586 ;;;===========================================================================
|
|
1587 ;;;
|
|
1588 ;;; Define the formal stuff for a minor mode named RefTeX.
|
|
1589 ;;;
|
|
1590
|
207
|
1591 (defconst reftex-version "RefTeX version 3.7"
|
165
|
1592 "Version string for RefTeX.")
|
|
1593
|
155
|
1594 (defvar reftex-mode nil
|
|
1595 "Determines if RefTeX minor mode is active.")
|
|
1596 (make-variable-buffer-local 'reftex-mode)
|
|
1597
|
|
1598 (defvar reftex-mode-map (make-sparse-keymap)
|
|
1599 "Keymap for RefTeX minor mode.")
|
|
1600
|
|
1601 (defvar reftex-mode-menu nil)
|
|
1602
|
|
1603 ;;;###autoload
|
|
1604 (defun turn-on-reftex ()
|
|
1605 "Turn on RefTeX minor mode."
|
|
1606 (reftex-mode t))
|
|
1607
|
|
1608 ;;;###autoload
|
|
1609 (defun reftex-mode (&optional arg)
|
|
1610 "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX.
|
|
1611
|
|
1612 Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'.
|
|
1613 When referencing, you get a menu with all labels of a given type and
|
165
|
1614 context of the label definition. The selected label is inserted as a
|
155
|
1615 \\ref macro.
|
|
1616
|
207
|
1617 Citations can be made with `\\[reftex-citation]' which will use a regular expression
|
155
|
1618 to pull out a *formatted* list of articles from your BibTeX
|
165
|
1619 database. The selected citation is inserted as a \\cite macro.
|
155
|
1620
|
|
1621 A Table of Contents of the entire (multifile) document with browsing
|
|
1622 capabilities is available with `\\[reftex-toc]'.
|
|
1623
|
165
|
1624 Most command have help available on the fly. This help is accessed by
|
155
|
1625 pressing `?' to any prompt mentioning this feature.
|
|
1626
|
207
|
1627 Extensive documentation about RefTeX is in the file header of `reftex.el'.
|
|
1628 You can view this information with `\\[reftex-show-commentary]'.
|
165
|
1629
|
155
|
1630 \\{reftex-mode-map}
|
207
|
1631 Under X, these and other functions will also be available as `Ref' menu
|
|
1632 on the menu bar.
|
155
|
1633
|
|
1634 ------------------------------------------------------------------------------"
|
|
1635
|
|
1636 (interactive "P")
|
|
1637 (setq reftex-mode (not (or (and (null arg) reftex-mode)
|
|
1638 (<= (prefix-numeric-value arg) 0))))
|
|
1639
|
|
1640 ; Add or remove the menu, and run the hook
|
|
1641 (if reftex-mode
|
|
1642 (progn
|
207
|
1643 (easy-menu-add reftex-mode-menu)
|
|
1644 (reftex-plug-into-AUCTeX)
|
|
1645 (run-hooks 'reftex-mode-hook))
|
155
|
1646 (easy-menu-remove reftex-mode-menu)))
|
207
|
1647
|
155
|
1648 (or (assoc 'reftex-mode minor-mode-alist)
|
207
|
1649 (push '(reftex-mode " Ref") minor-mode-alist))
|
155
|
1650
|
|
1651 (or (assoc 'reftex-mode minor-mode-map-alist)
|
207
|
1652 (push (cons 'reftex-mode reftex-mode-map) minor-mode-map-alist))
|
165
|
1653
|
|
1654 ;;; ===========================================================================
|
|
1655 ;;;
|
|
1656 ;;; Silence warnings about variables in other packages.
|
|
1657 (defvar TeX-master)
|
|
1658 (defvar LaTeX-label-function)
|
|
1659 (defvar tex-main-file)
|
|
1660 (defvar outline-minor-mode)
|
|
1661
|
155
|
1662 ;;; ===========================================================================
|
|
1663 ;;;
|
|
1664 ;;; Interfaces for other packages
|
|
1665 ;;; -----------------------------
|
|
1666 ;;;
|
|
1667 ;;; AUCTeX
|
|
1668 ;;; ------
|
|
1669
|
207
|
1670 (defun reftex-arg-label (optional &optional prompt definition)
|
165
|
1671 "Use `reftex-label' to create label. Insert it with `TeX-argument-insert'.
|
155
|
1672 This function is intended for AUCTeX macro support."
|
|
1673 (let ((label (reftex-label nil t)))
|
207
|
1674 (if (and definition (not (string-equal "" label)))
|
|
1675 (LaTeX-add-labels label))
|
155
|
1676 (TeX-argument-insert label optional optional)))
|
|
1677
|
207
|
1678 (defun reftex-arg-ref (optional &optional prompt definition)
|
165
|
1679 "Use `reftex-reference' to select label. Insert with `TeX-argument-insert'.
|
155
|
1680 This function is intended for AUCTeX macro support."
|
|
1681 (let ((label (reftex-reference nil t)))
|
207
|
1682 (if (and definition (not (string-equal "" label)))
|
|
1683 (LaTeX-add-labels label))
|
155
|
1684 (TeX-argument-insert label optional optional)))
|
|
1685
|
207
|
1686 (defun reftex-arg-cite (optional &optional prompt definition)
|
165
|
1687 "Use reftex-citation to select a key. Insert with `TeX-argument-insert'.
|
155
|
1688 This function is intended for AUCTeX macro support."
|
207
|
1689 (let ((key (reftex-citation t)))
|
155
|
1690 (TeX-argument-insert (or key "") optional optional)))
|
|
1691
|
165
|
1692 (defun reftex-plug-into-AUCTeX ()
|
|
1693 ;; Replace AucTeX functions with RefTeX functions.
|
|
1694 ;; Which functions are replaced is controlled by the variable
|
|
1695 ;; `reftex-plug-into-AUCTeX'.
|
207
|
1696 (let ((flags
|
|
1697 (cond ((eq reftex-plug-into-AUCTeX t) '(t t t t))
|
|
1698 ((eq reftex-plug-into-AUCTeX nil) '(nil nil nil nil))
|
|
1699 (t reftex-plug-into-AUCTeX))))
|
165
|
1700
|
|
1701 (and (nth 0 flags)
|
207
|
1702 (boundp 'LaTeX-label-function)
|
|
1703 (setq LaTeX-label-function 'reftex-label))
|
165
|
1704
|
|
1705 (and (nth 1 flags)
|
207
|
1706 (fboundp 'TeX-arg-label)
|
|
1707 (fset 'TeX-arg-label 'reftex-arg-label))
|
165
|
1708
|
|
1709 (and (nth 2 flags)
|
207
|
1710 (fboundp 'TeX-arg-ref)
|
|
1711 (fset 'TeX-arg-ref 'reftex-arg-ref))
|
165
|
1712
|
|
1713 (and (nth 3 flags)
|
207
|
1714 (fboundp 'TeX-arg-cite)
|
|
1715 (fset 'TeX-arg-cite 'reftex-arg-cite))))
|
|
1716
|
165
|
1717
|
155
|
1718 (defvar reftex-label-alist-external-add-ons nil
|
|
1719 "List of label alist entries added with reftex-add-to-label-alist.")
|
|
1720
|
|
1721 (defun reftex-add-to-label-alist (entry-list)
|
165
|
1722 "Add label environment descriptions to `reftex-label-alist-external-add-ons'.
|
207
|
1723 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there
|
155
|
1724 for details.
|
|
1725 This function makes it possible to support RefTeX from AUCTeX style files.
|
|
1726 The entries in ENTRY-LIST will be processed after the user settings in
|
165
|
1727 `reftex-label-alist', and before the defaults (specified in
|
|
1728 `reftex-default-label-alist-entries'). Any changes made to
|
|
1729 `reftex-label-alist-external-add-ons' will raise a flag to the effect that a
|
155
|
1730 mode reset is done on the next occasion."
|
|
1731 (let (entry)
|
|
1732 (while entry-list
|
|
1733 (setq entry (car entry-list)
|
|
1734 entry-list (cdr entry-list))
|
207
|
1735 (unless (member entry reftex-label-alist-external-add-ons)
|
|
1736 (setq reftex-tables-dirty t)
|
|
1737 (push entry reftex-label-alist-external-add-ons)))))
|
155
|
1738
|
|
1739 ;;; ===========================================================================
|
|
1740 ;;;
|
|
1741 ;;; Multifile support
|
|
1742 ;;;
|
|
1743 ;;; Technical notes: Multifile works as follows: We keep just one list
|
|
1744 ;;; of labels for each master file - this can save a lot of memory.
|
165
|
1745 ;;; `reftex-master-index-list' is an alist which connects the true file name
|
155
|
1746 ;;; of each master file with the symbols holding the information on that
|
165
|
1747 ;;; document. Each buffer has local variables which point to these symbols.
|
155
|
1748
|
|
1749 ;; List of variables which handle the multifile stuff.
|
|
1750 ;; This list is used to tie, untie, and reset these symbols.
|
|
1751 (defconst reftex-multifile-symbols
|
207
|
1752 '(reftex-docstruct-symbol))
|
155
|
1753
|
165
|
1754 ;; Alist connecting master file names with the corresponding lisp symbols.
|
155
|
1755 (defvar reftex-master-index-list nil)
|
|
1756
|
165
|
1757 ;; Last index used for a master file.
|
155
|
1758 (defvar reftex-multifile-index 0)
|
|
1759
|
|
1760 ;; Variable holding the symbol with the label list of the document.
|
207
|
1761 (defvar reftex-docstruct-symbol nil)
|
|
1762 (make-variable-buffer-local 'reftex-docstruct-symbol)
|
155
|
1763
|
|
1764 (defun reftex-next-multifile-index ()
|
|
1765 ;; Return the next free index for multifile symbols.
|
207
|
1766 (incf reftex-multifile-index))
|
155
|
1767
|
|
1768 (defun reftex-tie-multifile-symbols ()
|
|
1769 ;; Tie the buffer-local symbols to globals connected with the master file.
|
|
1770 ;; If the symbols for the current master file do not exist, they are created.
|
|
1771
|
|
1772 (let* ((master (file-truename (reftex-TeX-master-file)))
|
|
1773 (index (assoc master reftex-master-index-list))
|
|
1774 (symlist reftex-multifile-symbols)
|
|
1775 (symbol nil)
|
|
1776 (symname nil)
|
|
1777 (newflag nil))
|
165
|
1778 ;; Find the correct index.
|
155
|
1779 (if index
|
|
1780 ;; symbols do exist
|
|
1781 (setq index (cdr index))
|
165
|
1782 ;; Get a new index and add info to the alist.
|
155
|
1783 (setq index (reftex-next-multifile-index)
|
207
|
1784 newflag t)
|
|
1785 (push (cons master index) reftex-master-index-list))
|
155
|
1786
|
165
|
1787 ;; Get/create symbols and tie them.
|
155
|
1788 (while symlist
|
|
1789 (setq symbol (car symlist)
|
|
1790 symlist (cdr symlist)
|
|
1791 symname (symbol-name symbol))
|
|
1792 (set symbol (intern (concat symname "-" (int-to-string index))))
|
165
|
1793 ;; Initialize if new symbols.
|
155
|
1794 (if newflag (set (symbol-value symbol) nil)))
|
|
1795
|
165
|
1796 ;; Return t if the symbols did already exist, nil when we've made them.
|
155
|
1797 (not newflag)))
|
|
1798
|
|
1799 (defun reftex-untie-multifile-symbols ()
|
|
1800 ;; Remove ties from multifile symbols, so that next use makes new ones.
|
|
1801 (let ((symlist reftex-multifile-symbols)
|
|
1802 (symbol nil))
|
|
1803 (while symlist
|
|
1804 (setq symbol (car symlist)
|
|
1805 symlist (cdr symlist))
|
|
1806 (set symbol nil))))
|
|
1807
|
|
1808 (defun reftex-TeX-master-file ()
|
|
1809 ;; Return the name of the master file associated with the current buffer.
|
|
1810 ;; When AUCTeX is loaded, we will use it's more sophisticated method.
|
|
1811 ;; We also support the default TeX and LaTeX modes by checking for a
|
|
1812 ;; variable tex-main-file.
|
|
1813
|
|
1814 (let
|
|
1815 ((master
|
|
1816 (cond
|
165
|
1817 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism.
|
155
|
1818 (TeX-master-file t))
|
|
1819 ((boundp 'TeX-master) ; The variable is defined - lets use it.
|
|
1820 (cond
|
|
1821 ((eq TeX-master t)
|
|
1822 (buffer-file-name))
|
|
1823 ((eq TeX-master 'shared)
|
|
1824 (setq TeX-master (read-file-name "Master file: "
|
|
1825 nil nil t nil)))
|
|
1826 (TeX-master)
|
|
1827 (t
|
|
1828 (setq TeX-master (read-file-name "Master file: "
|
|
1829 nil nil t nil)))))
|
|
1830 ((boundp 'tex-main-file)
|
165
|
1831 ;; This is the variable from the default TeX modes.
|
155
|
1832 (cond
|
|
1833 ((stringp tex-main-file)
|
|
1834 ;; ok, this must be it
|
|
1835 tex-main-file)
|
|
1836 (t
|
165
|
1837 ;; In this case, the buffer is its own master.
|
155
|
1838 (buffer-file-name))))
|
|
1839 (t
|
165
|
1840 ;; Know nothing about master file. Assume this is a master file.
|
155
|
1841 (buffer-file-name)))))
|
|
1842 (cond
|
|
1843 ((null master)
|
165
|
1844 (error "Need a filename for this buffer. Please save it first."))
|
155
|
1845 ((or (file-exists-p master)
|
|
1846 (reftex-get-buffer-visiting master))
|
165
|
1847 ;; We either see the file, or have a buffer on it. OK.
|
155
|
1848 )
|
|
1849 ((or (file-exists-p (concat master ".tex"))
|
|
1850 (reftex-get-buffer-visiting (concat master ".tex")))
|
|
1851 ;; Ahh, an extra .tex was missing...
|
|
1852 (setq master (concat master ".tex")))
|
|
1853 (t
|
165
|
1854 ;; Something is wrong here. Throw an exception.
|
155
|
1855 (error "No such master file %s" master)))
|
|
1856 (expand-file-name master)))
|
|
1857
|
207
|
1858 (defun reftex-parse-one ()
|
|
1859 "Re-parse this file."
|
|
1860 (interactive)
|
|
1861 (let ((reftex-enable-partial-scans t))
|
|
1862 (reftex-access-scan-info '(4))))
|
|
1863
|
|
1864 (defun reftex-parse-all ()
|
|
1865 "Re-parse entire document."
|
155
|
1866 (interactive)
|
207
|
1867 (reftex-access-scan-info '(16)))
|
|
1868
|
|
1869 (defun reftex-all-document-files (&optional relative)
|
|
1870 ;; Return a list of all files belonging to the current document.
|
|
1871 ;; When RELATIVE is non-nil, give file names relative to directory
|
|
1872 ;; of master file.
|
|
1873 (let* ((all (symbol-value reftex-docstruct-symbol))
|
|
1874 (master-dir (file-name-directory (reftex-TeX-master-file)))
|
|
1875 (re (concat "\\`" (regexp-quote master-dir)))
|
|
1876 file-list tmp file)
|
|
1877 (while (setq tmp (assoc 'bof all))
|
|
1878 (setq file (nth 1 tmp)
|
|
1879 all (cdr (memq tmp all)))
|
|
1880 (and relative
|
|
1881 (string-match re file)
|
|
1882 (setq file (substring file (match-end 0))))
|
|
1883 (push file file-list))
|
|
1884 (nreverse file-list)))
|
155
|
1885
|
|
1886 (defun reftex-create-tags-file ()
|
|
1887 "Create TAGS file by running `etags' on the current document.
|
165
|
1888 The TAGS file is also immediately visited with `visit-tags-table'."
|
155
|
1889 (interactive)
|
|
1890 (reftex-access-scan-info current-prefix-arg)
|
|
1891 (let* ((master (reftex-TeX-master-file))
|
207
|
1892 (files (reftex-all-document-files))
|
|
1893 (cmd (format "etags %s" (mapconcat 'identity files " "))))
|
155
|
1894 (save-excursion
|
|
1895 (set-buffer (reftex-get-buffer-visiting master))
|
|
1896 (message "Running etags to create TAGS file...")
|
|
1897 (shell-command cmd)
|
|
1898 (visit-tags-table "TAGS"))))
|
|
1899
|
|
1900 ;; History of grep commands.
|
|
1901 (defvar reftex-grep-history nil)
|
|
1902 (defvar reftex-grep-command "grep -n "
|
|
1903 "Last grep command used in \\[reftex-grep-document]; default for next grep.")
|
|
1904
|
|
1905 (defun reftex-grep-document (grep-cmd)
|
165
|
1906 "Run grep query through all files related to this document.
|
155
|
1907 With prefix arg, force to rescan document.
|
|
1908 This works also without an active TAGS table."
|
|
1909
|
|
1910 (interactive
|
|
1911 (list (read-from-minibuffer "Run grep on document (like this): "
|
207
|
1912 reftex-grep-command nil nil
|
155
|
1913 'reftex-grep-history)))
|
|
1914 (reftex-access-scan-info current-prefix-arg)
|
207
|
1915 (let* ((files (reftex-all-document-files t))
|
|
1916 (cmd (format
|
|
1917 "%s %s" grep-cmd
|
|
1918 (mapconcat 'identity files " "))))
|
155
|
1919 (grep cmd)))
|
|
1920
|
|
1921 (defun reftex-search-document (&optional regexp)
|
|
1922 "Regexp search through all files of the current TeX document.
|
165
|
1923 Starts always in the master file. Stops when a match is found.
|
155
|
1924 To continue searching for next match, use command \\[tags-loop-continue].
|
|
1925 This works also without an active TAGS table."
|
|
1926 (interactive)
|
|
1927 (let ((default (reftex-this-word)))
|
207
|
1928 (unless regexp
|
|
1929 (setq regexp (read-string (format "Search regexp in document [%s]: "
|
|
1930 default))))
|
155
|
1931 (if (string= regexp "") (setq regexp (regexp-quote default)))
|
|
1932
|
|
1933 (reftex-access-scan-info current-prefix-arg)
|
207
|
1934 (tags-search regexp (list 'reftex-all-document-files))))
|
155
|
1935
|
|
1936 (defun reftex-query-replace-document (&optional from to delimited)
|
|
1937 "Run a query-replace-regexp of FROM with TO over the entire TeX document.
|
|
1938 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
|
|
1939 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
|
|
1940 with the command \\[tags-loop-continue].
|
|
1941 This works also without an active TAGS table."
|
|
1942 (interactive)
|
|
1943 (let ((default (reftex-this-word)))
|
207
|
1944 (unless from
|
|
1945 (setq from (read-string (format "Replace regexp in document [%s]: "
|
|
1946 default)))
|
|
1947 (if (string= from "") (setq from (regexp-quote default))))
|
|
1948 (unless to
|
|
1949 (setq to (read-string (format "Replace regexp %s with: " from))))
|
155
|
1950 (reftex-access-scan-info current-prefix-arg)
|
|
1951 (tags-query-replace from to (or delimited current-prefix-arg)
|
207
|
1952 (list 'reftex-all-document-files))))
|
155
|
1953
|
|
1954 (defun reftex-change-label (&optional from to)
|
|
1955 "Query replace FROM with TO in all \\label and \\ref commands.
|
|
1956 Works on the entire multifile document.
|
|
1957 If you exit (\\[keyboard-quit] or ESC), you can resume the query replace
|
|
1958 with the command \\[tags-loop-continue].
|
|
1959 This works also without an active TAGS table."
|
|
1960 (interactive)
|
|
1961 (let ((default (reftex-this-word "-a-zA-Z0-9_*.:")))
|
207
|
1962 (unless from
|
|
1963 (setq from (read-string (format "Replace label globally [%s]: "
|
|
1964 default))))
|
155
|
1965 (if (string= from "") (setq from default))
|
207
|
1966 (unless to
|
|
1967 (setq to (read-string (format "Replace label %s with: "
|
|
1968 from))))
|
155
|
1969 (reftex-query-replace-document
|
|
1970 (concat "\\\\\\(label\\|[a-z]*ref\\){" (regexp-quote from) "}")
|
|
1971 (format "\\\\\\1{%s}" to))))
|
|
1972
|
|
1973 ;;; ===========================================================================
|
|
1974 ;;;
|
165
|
1975 ;;; Functions to create and reference automatic labels.
|
|
1976
|
|
1977 ;; The following constants are derived from `reftex-label-alist'.
|
|
1978
|
|
1979 ;; Prompt used for label type querys directed to the user.
|
155
|
1980 (defconst reftex-type-query-prompt nil)
|
|
1981
|
165
|
1982 ;; Help string for label type querys.
|
155
|
1983 (defconst reftex-type-query-help nil)
|
|
1984
|
165
|
1985 ;; Alist relating label type to reference format.
|
155
|
1986 (defconst reftex-typekey-to-format-alist nil)
|
|
1987
|
165
|
1988 ;; Alist relating label type to label affix.
|
155
|
1989 (defconst reftex-typekey-to-prefix-alist nil)
|
|
1990
|
165
|
1991 ;; Alist relating environments or macros to label type and context regexp.
|
155
|
1992 (defconst reftex-env-or-mac-alist nil)
|
|
1993
|
165
|
1994 ;; List of macros carrying a label.
|
155
|
1995 (defconst reftex-label-mac-list nil)
|
|
1996
|
165
|
1997 ;; List of environments carrying a label.
|
155
|
1998 (defconst reftex-label-env-list nil)
|
|
1999
|
165
|
2000 ;; List of all typekey letters in use.
|
155
|
2001 (defconst reftex-typekey-list nil)
|
|
2002
|
165
|
2003 ;; Alist relating magic words to a label type.
|
155
|
2004 (defconst reftex-words-to-typekey-alist nil)
|
|
2005
|
165
|
2006 ;; The last list-of-labels entry used in a reference.
|
155
|
2007 (defvar reftex-last-used-reference (list nil nil nil nil))
|
|
2008
|
165
|
2009 ;; The regular expression used to abbreviate words.
|
155
|
2010 (defconst reftex-abbrev-regexp
|
|
2011 (concat
|
207
|
2012 "\\`\\("
|
155
|
2013 (make-string (nth 0 reftex-abbrev-parameters) ?.)
|
|
2014 "[" (nth 2 reftex-abbrev-parameters) "]*"
|
|
2015 "\\)"
|
|
2016 "[" (nth 3 reftex-abbrev-parameters) "]"
|
|
2017 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
|
|
2018
|
165
|
2019 ;; Global variables used for communication between functions.
|
155
|
2020 (defvar reftex-default-context-position nil)
|
|
2021 (defvar reftex-location-start nil)
|
|
2022 (defvar reftex-call-back-to-this-buffer nil)
|
207
|
2023 (defvar reftex-active-toc nil)
|
|
2024 (defvar reftex-tex-path nil)
|
|
2025 (defvar reftex-bib-path nil)
|
|
2026
|
|
2027 ;; Internal list with index numbers of labels in the selection menu
|
|
2028 (defvar reftex-label-index-list)
|
155
|
2029
|
165
|
2030 ;; List of buffers created temporarily for lookup, which should be killed.
|
155
|
2031 (defvar reftex-buffers-to-kill nil)
|
|
2032
|
207
|
2033 ;; Regexp to find section statements. Computed from reftex-section-levels.
|
|
2034 (defvar reftex-section-regexp nil)
|
|
2035 (defvar reftex-section-or-include-regexp nil)
|
|
2036 (defvar reftex-everything-regexp nil)
|
|
2037 (defvar reftex-find-label-regexp-format nil)
|
|
2038 (defvar reftex-find-label-regexp-format2 nil)
|
|
2039
|
|
2040 ;; The parser functions ----------------------------------
|
|
2041
|
|
2042 (defvar reftex-memory nil
|
|
2043 "Memorizes old variable values to indicate changes in these variables.")
|
|
2044
|
|
2045 (defun reftex-access-scan-info (&optional rescan file)
|
|
2046 ;; Access the scanning info. When the multifile symbols are not yet tied,
|
|
2047 ;; tie them. When they are empty or RESCAN is non-nil, scan the document.
|
|
2048
|
|
2049 ;; Reset the mode if we had changes to important variables.
|
|
2050 (when (or reftex-tables-dirty
|
|
2051 (not (eq reftex-label-alist (nth 0 reftex-memory)))
|
|
2052 (not (eq reftex-label-alist-external-add-ons
|
|
2053 (nth 1 reftex-memory)))
|
|
2054 (not (eq reftex-default-label-alist-entries
|
|
2055 (nth 2 reftex-memory))))
|
|
2056 (reftex-reset-mode))
|
|
2057
|
|
2058 (if (eq reftex-docstruct-symbol nil)
|
|
2059 ;; Symbols are not yet tied: Tie them.
|
|
2060 (reftex-tie-multifile-symbols))
|
|
2061
|
|
2062 (if (and (null (symbol-value reftex-docstruct-symbol))
|
|
2063 reftex-save-parse-info)
|
|
2064 ;; Try to read the stuff from a file
|
|
2065 (reftex-access-parse-file 'read))
|
|
2066
|
|
2067 (cond
|
|
2068 ((not (symbol-value reftex-docstruct-symbol))
|
|
2069 (reftex-do-parse 1 file))
|
|
2070 ((member rescan '(t 1 (4) (16)))
|
|
2071 (reftex-do-parse rescan file))))
|
|
2072
|
|
2073 (defun reftex-do-parse (rescan &optional file)
|
|
2074 ;; Access the scanning info. When the multifile symbols are not yet tied,
|
|
2075 ;; tie them. When they are have to be created, do a buffer scan to
|
|
2076 ;; fill them.
|
|
2077
|
|
2078 ;; If RESCAN is non-nil, enforce document scanning
|
|
2079
|
|
2080 ;; Normalize the rescan argument
|
|
2081 (setq rescan (cond ((eq rescan t) t)
|
|
2082 ((eq rescan 1) 1)
|
|
2083 ((equal rescan '(4)) t)
|
|
2084 ((equal rescan '(16)) 1)
|
|
2085 (t 1)))
|
|
2086
|
|
2087 ;; Partial scans only when allowed
|
|
2088 (unless reftex-enable-partial-scans
|
|
2089 (setq rescan 1))
|
|
2090
|
|
2091 ;; Do the scanning.
|
|
2092
|
|
2093 (let* ((old-list (symbol-value reftex-docstruct-symbol))
|
|
2094 (master (reftex-TeX-master-file))
|
|
2095 (master-dir (file-name-as-directory (file-name-directory master)))
|
|
2096 (file (or file (buffer-file-name)))
|
|
2097 from-file
|
|
2098 docstruct tmp)
|
|
2099
|
|
2100 ;; Make sure replacement is really an option here
|
|
2101 (when (and (eq rescan t)
|
|
2102 (not (and (member (list 'bof file) old-list)
|
|
2103 (member (list 'eof file) old-list))))
|
|
2104 (message "Scanning whole document (no file section %s)" file)
|
|
2105 (setq rescan 1))
|
|
2106 (when (string= file master)
|
|
2107 (message "Scanning whole document (%s is master)" file)
|
|
2108 (setq rescan 1))
|
|
2109
|
|
2110 ;; From which file do we start?
|
|
2111 (setq from-file
|
|
2112 (cond ((eq rescan t) (or file master))
|
|
2113 ((eq rescan 1) master)
|
|
2114 (t (error "horrible!!"))))
|
|
2115
|
|
2116 ;; Find active toc entry and initialize section-numbers
|
|
2117 (setq reftex-active-toc
|
|
2118 (reftex-last-assoc-before-elt
|
|
2119 'toc (list 'bof from-file) old-list))
|
|
2120 (reftex-init-section-numbers reftex-active-toc)
|
|
2121
|
|
2122 (if (eq rescan 1)
|
|
2123 (message "Scanning entire document...")
|
|
2124 (message "Scanning document from %s..." from-file))
|
|
2125
|
|
2126 (save-window-excursion
|
|
2127 (save-excursion
|
|
2128 (unwind-protect
|
|
2129 (setq docstruct
|
|
2130 (reftex-parse-from-file
|
|
2131 from-file docstruct master-dir))
|
|
2132 (reftex-kill-temporary-buffers))))
|
|
2133
|
|
2134 (message "Scanning document... done")
|
|
2135
|
|
2136 ;; Turn the list around.
|
|
2137 (setq docstruct (nreverse docstruct))
|
|
2138
|
|
2139 ;; Set or insert
|
|
2140 (setq docstruct (reftex-replace-label-list-segment
|
|
2141 old-list docstruct (eq rescan 1)))
|
|
2142
|
|
2143 ;; Add all missing information
|
|
2144 (unless (assq 'label-numbers docstruct)
|
|
2145 (push (cons 'label-numbers nil) docstruct))
|
|
2146 (unless (assq 'master-dir docstruct)
|
|
2147 (push (cons 'master-dir master-dir) docstruct))
|
|
2148 (let* ((bof1 (memq (assq 'bof docstruct) docstruct))
|
|
2149 (bof2 (assq 'bof (cdr bof1)))
|
|
2150 (is-multi (not (not (and bof1 bof2))))
|
|
2151 (entry (or (assq 'is-multi docstruct)
|
|
2152 (car (push (list 'is-multi is-multi) docstruct)))))
|
|
2153 (setcdr entry (cons is-multi nil)))
|
|
2154 (unless (assq 'xr docstruct)
|
|
2155 (let* ((allxr (reftex-all-assq 'xr-doc docstruct))
|
|
2156 (alist (mapcar
|
|
2157 '(lambda (x)
|
|
2158 (if (setq tmp (reftex-find-tex-file (nth 2 x)
|
|
2159 master-dir))
|
|
2160 (cons (nth 1 x) tmp)
|
|
2161 (message "Can't find external document %s"
|
|
2162 (nth 2 x))
|
|
2163 nil))
|
|
2164 allxr))
|
|
2165 (alist (delete nil alist))
|
|
2166 (allprefix (delete nil (mapcar 'car alist)))
|
|
2167 (regexp (concat "\\`\\(" (mapconcat 'identity allprefix "\\|")
|
|
2168 "\\)")))
|
|
2169 (push (list 'xr alist regexp) docstruct)))
|
|
2170
|
|
2171 (set reftex-docstruct-symbol docstruct)
|
|
2172
|
|
2173 ;; Save the parsing informtion into a file?
|
|
2174 (if reftex-save-parse-info
|
|
2175 (reftex-access-parse-file 'write))))
|
|
2176
|
|
2177 (defun reftex-is-multi ()
|
|
2178 ;; Tell if this is a multifile document. When not sure, say yes.
|
|
2179 (let ((entry (assq 'is-multi (symbol-value reftex-docstruct-symbol))))
|
|
2180 (if entry
|
|
2181 (nth 1 entry)
|
|
2182 t)))
|
|
2183
|
|
2184 (defun reftex-parse-from-file (file docstruct master-dir)
|
|
2185 ;; Scan the buffer for labels and save them in a list.
|
|
2186 (let ((regexp reftex-everything-regexp)
|
|
2187 (bound 0)
|
|
2188 file-found tmp
|
|
2189 (level 1)
|
|
2190 (highest-level 100)
|
|
2191 toc-entry next-buf)
|
|
2192
|
|
2193 (catch 'exit
|
|
2194 (setq file-found (reftex-find-tex-file file master-dir))
|
|
2195 (unless file-found
|
|
2196 (push (list 'file-error file) docstruct)
|
|
2197 (throw 'exit nil))
|
|
2198
|
|
2199 (save-excursion
|
|
2200
|
|
2201 (message "Scanning file %s" file)
|
|
2202 (set-buffer
|
|
2203 (setq next-buf
|
|
2204 (reftex-get-file-buffer-force
|
|
2205 file-found
|
|
2206 (not (eq t reftex-keep-temporary-buffers)))))
|
|
2207
|
|
2208 ;; Begin of file mark
|
|
2209 (setq file (buffer-file-name))
|
|
2210 (push (list 'bof file) docstruct)
|
|
2211
|
|
2212 (save-excursion
|
|
2213 (save-restriction
|
|
2214 (widen)
|
|
2215 (goto-char 1)
|
|
2216
|
|
2217 (while (re-search-forward regexp nil t)
|
|
2218
|
|
2219 (cond
|
|
2220
|
|
2221 ((match-end 1)
|
|
2222 ;; It is a label
|
|
2223 (push (reftex-label-info (reftex-match-string 1) file bound)
|
|
2224 docstruct))
|
|
2225
|
|
2226 ((match-end 3)
|
|
2227 ;; It is a section
|
|
2228 (setq bound (point))
|
|
2229
|
|
2230 ;; Insert in List
|
|
2231 (setq toc-entry (reftex-section-info file))
|
|
2232 (setq level (nth 5 toc-entry))
|
|
2233 (setq highest-level (min highest-level level))
|
|
2234 (if (= level highest-level)
|
|
2235 (message
|
|
2236 "Scanning %s %s ..."
|
|
2237 (car (nth level reftex-section-levels))
|
|
2238 (nth 6 toc-entry)))
|
|
2239
|
|
2240 (push toc-entry docstruct)
|
|
2241 (setq reftex-active-toc toc-entry))
|
|
2242
|
|
2243 ((match-end 7)
|
|
2244 ;; It's an include or input
|
|
2245 (setq docstruct
|
|
2246 (reftex-parse-from-file
|
|
2247 (reftex-match-string 7)
|
|
2248 docstruct master-dir)))
|
|
2249
|
|
2250 ((match-end 8)
|
|
2251 ;; A macro with label
|
|
2252 (save-excursion
|
|
2253 (let* ((mac (reftex-match-string 8))
|
|
2254 (label (progn (goto-char (match-end 8))
|
|
2255 (save-match-data
|
|
2256 (reftex-no-props
|
|
2257 (reftex-nth-arg-wrapper
|
|
2258 mac)))))
|
|
2259 (entry (progn (goto-char (match-end 0))
|
|
2260 (reftex-label-info
|
|
2261 label file bound mac))))
|
|
2262 (push entry docstruct))))
|
|
2263 (t (error "This should not happen (reftex-parse-from-file)")))
|
|
2264 )
|
|
2265
|
|
2266
|
|
2267 ;; Find bibliography statement
|
|
2268 (when (setq tmp (reftex-locate-bibliography-files master-dir))
|
|
2269 (push (cons 'bib tmp) docstruct))
|
|
2270
|
|
2271 ;; Find external document specifications
|
|
2272 (goto-char 1)
|
|
2273 (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t)
|
|
2274 (push (list 'xr-doc (reftex-match-string 2)
|
|
2275 (reftex-match-string 3))
|
|
2276 docstruct))
|
|
2277
|
|
2278 ;; End of file mark
|
|
2279 (push (list 'eof file) docstruct))))
|
|
2280
|
|
2281 ;; Kill the scanned buffer
|
|
2282 (reftex-kill-temporary-buffers next-buf))
|
|
2283
|
|
2284 ;; Return the list
|
|
2285 docstruct))
|
|
2286
|
|
2287 (defun reftex-locate-bibliography-files (master-dir)
|
|
2288 ;; Scan buffer for bibliography macro and return file list.
|
|
2289 (let (file-list)
|
|
2290 (save-excursion
|
|
2291 (goto-char (point-min))
|
|
2292 (if (re-search-forward
|
|
2293 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\bibliography{[ \t]*\\([^}]+\\)" nil t)
|
|
2294 (setq file-list
|
|
2295 (mapcar '(lambda (x) (concat x ".bib"))
|
|
2296 (reftex-delete-list
|
|
2297 reftex-bibfile-ignore-list
|
|
2298 (split-string
|
|
2299 (reftex-match-string 2)
|
|
2300 "[ \t\n\r]*,[ \t\n\r]*")))))
|
|
2301 (delete nil
|
|
2302 (mapcar
|
|
2303 (function
|
|
2304 (lambda (file) (reftex-find-bib-file file master-dir)))
|
|
2305 file-list)))))
|
|
2306
|
|
2307 (defun reftex-last-assoc-before-elt (key elt list)
|
|
2308 ;; Find the last association of KEY in LIST before or at ELT
|
|
2309 ;; ELT is found in LIST with equal, not eq.
|
|
2310 ;; Returns nil when either KEY or elt are not found in LIST.
|
|
2311 ;; On success, returns the association.
|
|
2312 (let* ((elt (car (member elt list))) ass last-ass)
|
|
2313
|
|
2314 (while (and (setq ass (assoc key list))
|
|
2315 (setq list (memq ass list))
|
|
2316 (memq elt list))
|
|
2317 (setq last-ass ass
|
|
2318 list (cdr list)))
|
|
2319 last-ass))
|
|
2320
|
|
2321 (defun reftex-replace-label-list-segment (old insert &optional entirely)
|
|
2322 ;; Replace the segment in OLD which corresponds to INSERT.
|
|
2323 ;; Works with side effects, directly changes old.
|
|
2324 ;; If entirely is t, just return INSERT.
|
|
2325 ;; This function also makes sure the old toc markers do not point anywhere.
|
|
2326
|
|
2327 (cond
|
|
2328 (entirely
|
|
2329 (reftex-silence-toc-markers old (length old))
|
|
2330 insert)
|
|
2331 (t (let* ((new old)
|
|
2332 (file (nth 1 (car insert)))
|
|
2333 (eof-list (member (list 'eof file) old))
|
|
2334 (bof-list (member (list 'bof file) old))
|
|
2335 n)
|
|
2336 (if (not (and bof-list eof-list))
|
|
2337 (error "Cannot splice")
|
|
2338 ;; Splice
|
|
2339 (reftex-silence-toc-markers bof-list (- (length bof-list)
|
|
2340 (length eof-list)))
|
|
2341 (setq n (- (length old) (length bof-list)))
|
|
2342 (setcdr (nthcdr n new) (cdr insert))
|
|
2343 (setcdr (nthcdr (1- (length new)) new) (cdr eof-list)))
|
|
2344 new))))
|
|
2345
|
|
2346 (defun reftex-silence-toc-markers (list n)
|
|
2347 ;; Set all markers in list to nil
|
|
2348 (while (and list (> (decf n) -1))
|
|
2349 (and (eq (car (car list)) 'toc)
|
|
2350 (markerp (nth 4 (car list)))
|
|
2351 (set-marker (nth 4 (car list)) nil))
|
|
2352 (pop list)))
|
|
2353
|
|
2354 (defun reftex-access-parse-file (action)
|
|
2355 (let* ((list (symbol-value reftex-docstruct-symbol))
|
|
2356 (master (reftex-TeX-master-file))
|
|
2357 (enable-local-variables nil)
|
|
2358 (file (if (string-match "\\.[a-zA-Z]+\\'" master)
|
|
2359 (concat (substring master 0 (match-beginning 0)) ".rel")
|
|
2360 (concat master ".rel"))))
|
|
2361 (cond
|
|
2362 ((eq action 'readable)
|
|
2363 (file-readable-p file))
|
|
2364 ((eq action 'restore)
|
|
2365 (if (eq reftex-docstruct-symbol nil)
|
|
2366 ;; Symbols are not yet tied: Tie them.
|
|
2367 (reftex-tie-multifile-symbols))
|
|
2368 (if (file-exists-p file)
|
|
2369 ;; load the file and return t for success
|
|
2370 (progn (load-file file) t)
|
|
2371 ;; return nil for failure
|
|
2372 nil))
|
|
2373 ((eq action 'read)
|
|
2374 (if (file-exists-p file)
|
|
2375 ;; load the file and return t for success
|
|
2376 (progn (load-file file) t)
|
|
2377 ;; return nil for failure
|
|
2378 nil))
|
|
2379 (t
|
|
2380 (save-excursion
|
|
2381 (if (file-writable-p file)
|
|
2382 (progn
|
|
2383 (message "Writing parse file %s" (abbreviate-file-name file))
|
|
2384 (find-file file)
|
|
2385 (erase-buffer)
|
|
2386 (insert (format ";; RefTeX parse info file\n"))
|
|
2387 (insert (format ";; File: %s\n" master))
|
|
2388 (insert (format ";; Date: %s\n"
|
|
2389 (format-time-string "%D %T"
|
|
2390 (current-time))))
|
|
2391 (insert (format ";; User: %s (%s)\n\n"
|
|
2392 (user-login-name) (user-full-name)))
|
|
2393 (insert "(set reftex-docstruct-symbol '(\n\n")
|
|
2394 (let ((standard-output (current-buffer)))
|
|
2395 (mapcar
|
|
2396 (function
|
|
2397 (lambda (x)
|
|
2398 (cond ((eq (car x) 'toc)
|
|
2399 ;; A toc entry. Do not save the marker.
|
|
2400 ;; Save the markers position at position 8
|
|
2401 (print (list 'toc "toc" (nth 2 x) (nth 3 x)
|
|
2402 nil (nth 5 x) (nth 6 x) (nth 7 x)
|
|
2403 (or (and (markerp (nth 4 x))
|
|
2404 (marker-position (nth 4 x)))
|
|
2405 (nth 8 x)))))
|
|
2406 (t (print x)))))
|
|
2407 list))
|
|
2408 (insert "))")
|
|
2409 (save-buffer 0)
|
|
2410 (kill-buffer (current-buffer)))
|
|
2411 (error "Cannot write to file %s" file)))
|
|
2412 t))))
|
|
2413
|
|
2414 ;; Creating labels --------------
|
155
|
2415
|
|
2416 (defun reftex-label (&optional environment no-insert)
|
165
|
2417 "Insert a unique label. Return the label.
|
155
|
2418 If ENVIRONMENT is given, don't bother to find out yourself.
|
|
2419 If NO-INSERT is non-nil, do not insert label into buffer.
|
|
2420 With prefix arg, force to rescan document first.
|
|
2421 The label is also inserted into the label list.
|
|
2422 This function is controlled by the settings of reftex-insert-label-flags."
|
|
2423
|
|
2424 (interactive)
|
|
2425
|
165
|
2426 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4).
|
155
|
2427 (reftex-access-scan-info current-prefix-arg)
|
|
2428
|
165
|
2429 ;; Find out what kind of environment this is and abort if necessary.
|
155
|
2430 (if (or (not environment)
|
|
2431 (not (assoc environment reftex-env-or-mac-alist)))
|
|
2432 (setq environment (reftex-label-location)))
|
207
|
2433 (unless environment
|
|
2434 (error "Can't figure out what kind of label should be inserted"))
|
155
|
2435
|
165
|
2436 ;; Ok, go ahead.
|
207
|
2437 (let* ((entry (assoc environment reftex-env-or-mac-alist))
|
|
2438 (typekey (nth 1 entry))
|
|
2439 (format (nth 3 entry))
|
|
2440 label prefix valid default force-prompt)
|
|
2441 (when (and (eq (string-to-char environment) ?\\)
|
|
2442 (nth 4 entry)
|
|
2443 (memq (preceding-char) '(?\[ ?\{)))
|
|
2444 (setq format "%s"))
|
|
2445
|
155
|
2446 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
|
|
2447 (concat typekey "-")))
|
207
|
2448 ;; Replace any escapes in the prefix
|
|
2449 (setq prefix (reftex-replace-prefix-escapes prefix))
|
155
|
2450
|
165
|
2451 ;; Make a default label.
|
155
|
2452 (cond
|
|
2453
|
|
2454 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
|
165
|
2455 ;; Derive a label from context.
|
207
|
2456 (setq reftex-active-toc (reftex-last-assoc-before-elt
|
|
2457 'toc (car (reftex-where-am-I))
|
|
2458 (symbol-value reftex-docstruct-symbol)))
|
|
2459 (setq default (reftex-no-props
|
|
2460 (nth 2 (reftex-label-info " " nil nil t))))
|
165
|
2461 ;; Catch the cases where the is actually no context available.
|
155
|
2462 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
|
|
2463 (string-match "ILLEGAL VALUE OF PARSE" default)
|
|
2464 (string-match "SECTION HEADING NOT FOUND" default)
|
|
2465 (string-match "HOOK ERROR" default)
|
|
2466 (string-match "^[ \t]*$" default))
|
|
2467 (setq default prefix
|
|
2468 force-prompt t) ; need to prompt
|
|
2469 (setq default (concat prefix (reftex-string-to-label default)))
|
|
2470
|
165
|
2471 ;; Make it unique.
|
207
|
2472 (setq default (reftex-uniquify-label default nil "-"))))
|
155
|
2473
|
|
2474 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) ; prompt
|
165
|
2475 ;; Minimal default: the user will be prompted.
|
155
|
2476 (setq default prefix))
|
|
2477
|
|
2478 (t
|
165
|
2479 ;; Make an automatic label.
|
207
|
2480 (setq default (reftex-uniquify-label prefix t))))
|
155
|
2481
|
|
2482 ;; Should we ask the user?
|
|
2483 (if (or (reftex-typekey-check typekey
|
|
2484 (nth 1 reftex-insert-label-flags)) ; prompt
|
|
2485 force-prompt)
|
|
2486
|
|
2487 (while (not valid)
|
|
2488 ;; iterate until we get a legal label
|
|
2489
|
207
|
2490 (setq label (read-string
|
|
2491 (if (string= format "%s") "Naked Label: " "Label: ")
|
|
2492 default))
|
155
|
2493
|
|
2494 ;; Lets make sure that this is a legal label
|
|
2495 (cond
|
|
2496
|
|
2497 ;; Test if label contains strange characters
|
|
2498 ((string-match reftex-label-illegal-re label)
|
|
2499 (message "Label \"%s\" contains illegal characters" label)
|
|
2500 (ding)
|
|
2501 (sit-for 2))
|
|
2502
|
|
2503 ;; Look it up in the label list
|
|
2504 ((setq entry (assoc label
|
207
|
2505 (symbol-value reftex-docstruct-symbol)))
|
155
|
2506 (message "Label \"%s\" exists in file %s" label (nth 3 entry))
|
|
2507 (ding)
|
|
2508 (sit-for 2))
|
|
2509
|
|
2510 ;; Label is ok
|
|
2511 (t
|
|
2512 (setq valid t))))
|
|
2513 (setq label default))
|
|
2514
|
|
2515 ;; Insert the label into the label list
|
207
|
2516 (let* ((here-I-am-info (reftex-where-am-I))
|
|
2517 (here-I-am (car here-I-am-info))
|
|
2518 (note (if (cdr here-I-am-info)
|
|
2519 ""
|
|
2520 "POSITION UNCERTAIN. RESCAN TO FIX."))
|
|
2521 (file (buffer-file-name))
|
|
2522 (text nil)
|
|
2523 (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
|
|
2524
|
|
2525 (if tail
|
|
2526 (setcdr tail (cons (list label typekey text file note)
|
|
2527 (cdr tail)))))
|
|
2528
|
|
2529 ;; Insert the label into the buffer
|
|
2530 (unless no-insert
|
|
2531 (insert (format format label)))
|
|
2532
|
155
|
2533 ;; return value of the function is the label
|
|
2534 label))
|
|
2535
|
|
2536 (defun reftex-string-to-label (string)
|
|
2537 ;; Convert a string (a sentence) to a label.
|
|
2538 ;;
|
|
2539 ;; Uses reftex-derive-label-parameters and reftex-abbrev-parameters
|
|
2540 ;;
|
|
2541
|
207
|
2542 (let* ((words0 (split-string string "[- \t\n\r]+"))
|
155
|
2543 (ignore-words (nth 5 reftex-derive-label-parameters))
|
|
2544 words word)
|
|
2545
|
|
2546 ;; remove words from the ignore list or with funny characters
|
207
|
2547 (while (setq word (pop words0))
|
155
|
2548 (cond
|
|
2549 ((member (downcase word) ignore-words))
|
|
2550 ((string-match reftex-label-illegal-re word)
|
207
|
2551 (when (nth 2 reftex-derive-label-parameters)
|
|
2552 (while (string-match reftex-label-illegal-re word)
|
|
2553 (setq word (replace-match "" nil nil word)))
|
|
2554 (push word words)))
|
155
|
2555 (t
|
207
|
2556 (push word words))))
|
155
|
2557 (setq words (nreverse words))
|
|
2558
|
|
2559 ;; restrict number of words
|
|
2560 (if (> (length words) (nth 0 reftex-derive-label-parameters))
|
|
2561 (setcdr (nthcdr (1- (nth 0 reftex-derive-label-parameters)) words) nil))
|
|
2562
|
|
2563 ;; First, try to use all words
|
|
2564 (setq string (mapconcat '(lambda(w) w) words
|
|
2565 (nth 4 reftex-derive-label-parameters)))
|
|
2566
|
|
2567 ;; Abbreviate words if enforced by user settings or string length
|
|
2568 (if (or (eq t (nth 3 reftex-derive-label-parameters))
|
|
2569 (and (nth 3 reftex-derive-label-parameters)
|
|
2570 (> (length string) (nth 1 reftex-derive-label-parameters))))
|
|
2571 (setq words
|
|
2572 (mapcar
|
|
2573 '(lambda (w) (if (string-match reftex-abbrev-regexp w)
|
|
2574 (match-string 1 w)
|
|
2575 w))
|
|
2576 words)
|
|
2577 string (mapconcat '(lambda(w) w) words
|
|
2578 (nth 4 reftex-derive-label-parameters))))
|
|
2579
|
|
2580 ;; Shorten if still to long
|
|
2581 (setq string
|
|
2582 (if (> (length string) (nth 1 reftex-derive-label-parameters))
|
|
2583 (substring string 0 (nth 1 reftex-derive-label-parameters))
|
|
2584 string))
|
|
2585
|
|
2586 ;; Delete the final punctuation, if any
|
207
|
2587 (if (string-match "[^a-zA-Z0-9]+\\'" string)
|
155
|
2588 (setq string (replace-match "" nil nil string)))
|
|
2589 string))
|
|
2590
|
207
|
2591 (defun reftex-replace-prefix-escapes (prefix)
|
|
2592 ;; Replace %escapes in a label prefix
|
|
2593 (save-match-data
|
|
2594 (let (letter (num 0) replace)
|
|
2595 (while (string-match "\\%\\([a-zA-Z]\\)" prefix num)
|
|
2596 (setq letter (match-string 1 prefix))
|
|
2597 (setq replace
|
|
2598 (cond
|
|
2599 ((equal letter "f")
|
|
2600 (file-name-sans-extension
|
|
2601 (file-name-nondirectory (buffer-file-name))))
|
|
2602 ((equal letter "F")
|
|
2603 (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
|
|
2604 (file (file-name-sans-extension (buffer-file-name))))
|
|
2605 (if (string-match (concat "\\`" (regexp-quote masterdir))
|
|
2606 file)
|
|
2607 (substring file (length masterdir))
|
|
2608 file)))
|
|
2609 ((equal letter "u")
|
|
2610 (or (user-login-name) ""))
|
|
2611 (t "")))
|
|
2612 (setq num (1- (+ (match-beginning 1) (length replace)))
|
|
2613 prefix (replace-match replace nil nil prefix)))
|
|
2614 prefix)))
|
|
2615
|
155
|
2616 (defun reftex-label-location (&optional bound)
|
|
2617 ;; Return the environment or macro which determines the label type at point.
|
|
2618 ;; If optional BOUND is an integer, limit backward searches to that point.
|
|
2619
|
|
2620 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
|
|
2621 (loc2 (reftex-what-environment reftex-label-env-list bound))
|
|
2622 (p1 (or (cdr loc1) 0))
|
|
2623 (p2 (or (cdr loc2) 0)))
|
|
2624
|
|
2625 (setq reftex-location-start (max p1 p2))
|
207
|
2626 (if (>= p1 p2)
|
155
|
2627 (progn
|
207
|
2628 (setq reftex-default-context-position (+ p1 (length (car loc1))))
|
|
2629 (or (car loc1) "section"))
|
|
2630 (setq reftex-default-context-position (+ p2 8 (length (car loc2))))
|
155
|
2631 (or (car loc2) "section"))))
|
|
2632
|
207
|
2633 (defun reftex-uniquify-label (label &optional force separator)
|
|
2634 ;; Make label unique by appending a number.
|
|
2635 ;; Optional FORCE means, force appending a number, even if label is unique.
|
|
2636 ;; Optional SEPARATOR is a string to stick between label and number.
|
155
|
2637
|
|
2638 ;; Ensure access to scanning info
|
|
2639 (reftex-access-scan-info)
|
|
2640
|
207
|
2641 (cond
|
|
2642 ((and (not force)
|
|
2643 (not (assoc label (symbol-value reftex-docstruct-symbol))))
|
|
2644 label)
|
|
2645 (t
|
|
2646 (let* ((label-numbers (assq 'label-numbers
|
|
2647 (symbol-value reftex-docstruct-symbol)))
|
|
2648 (label-numbers-alist (cdr label-numbers))
|
|
2649 (cell (or (assoc label label-numbers-alist)
|
|
2650 (car (setcdr label-numbers
|
|
2651 (cons (cons label 0)
|
|
2652 label-numbers-alist)))))
|
|
2653 (num (1+ (cdr cell)))
|
|
2654 (sep (or separator "")))
|
|
2655 (while (assoc (concat label sep (int-to-string num))
|
|
2656 (symbol-value reftex-docstruct-symbol))
|
|
2657 (incf num))
|
|
2658 (setcdr cell num)
|
|
2659 (concat label sep (int-to-string num))))))
|
155
|
2660
|
|
2661 ;; Help string for the reference label menu
|
207
|
2662 (defconst reftex-select-label-prompt
|
|
2663 "Select: [n]ext [p]revious [r]escan [ ]context e[x]tern [q]uit RET [?]HELP+more")
|
|
2664
|
|
2665 (defconst reftex-select-label-help
|
155
|
2666 " AVAILABLE KEYS IN REFERENCE LABEL MENU
|
207
|
2667 --------------------------------------
|
|
2668 n / p Go to next/previous label (Cursor motion works as well)
|
|
2669 C-s / C-r Search forward/backward. Use repeated C-s/C-r as in isearch.
|
|
2670 r / s Reparse document / Switch label type
|
|
2671 x Switch to label menu of external document (with LaTeX package `xr')
|
|
2672 t i c # % Toggle: [i]ncl. file borders, [t]able of contents, [c]ontext
|
|
2673 [#] label counters, [%] labels in comments
|
|
2674 SPC Show full context for current label in other window
|
|
2675 f Toggle follow mode: other window will follow context
|
|
2676 l / q Reuse last referenced label / Quit without accepting label
|
|
2677 e Recursive Edit into other window
|
|
2678 RET Accept current label")
|
155
|
2679
|
|
2680 (defun reftex-reference (&optional type no-insert)
|
165
|
2681 "Make a LaTeX reference. Look only for labels of a certain TYPE.
|
|
2682 With prefix arg, force to rescan buffer for labels. This should only be
|
155
|
2683 necessary if you have recently entered labels yourself without using
|
165
|
2684 reftex-label. Rescanning of the buffer can also be requested from the
|
155
|
2685 label selection menu.
|
|
2686 The function returns the selected label or nil.
|
|
2687 If NO-INSERT is non-nil, do not insert \\ref command, just return label.
|
|
2688 When called with 2 C-u prefix args, disable magic word recognition."
|
|
2689
|
|
2690 (interactive)
|
|
2691
|
|
2692 ;; check for active recursive edits
|
|
2693 (reftex-check-recursive-edit)
|
|
2694
|
|
2695 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
|
|
2696 (reftex-access-scan-info current-prefix-arg)
|
|
2697
|
207
|
2698 (unless type
|
|
2699 ;; guess type from context
|
|
2700 (if (and reftex-guess-label-type
|
|
2701 (setq type (assoc (downcase (reftex-word-before-point))
|
|
2702 reftex-words-to-typekey-alist)))
|
|
2703 (setq type (cdr type))
|
|
2704 (setq type (reftex-query-label-type))))
|
155
|
2705
|
|
2706 (let (label pair
|
|
2707 (form (or (cdr (assoc type reftex-typekey-to-format-alist))
|
|
2708 "\\ref{%s}")))
|
|
2709
|
|
2710 ;; Have the user select a label
|
|
2711 (setq pair (reftex-offer-label-menu type))
|
|
2712 (setq label (car pair))
|
|
2713
|
|
2714 (if (and label
|
|
2715 (not no-insert))
|
|
2716 (progn
|
|
2717 ;; do we need to remove spaces?
|
|
2718 (if (string= "~" (substring form 0 1))
|
|
2719 (while (or (= (preceding-char) ?\ )
|
|
2720 (= (preceding-char) ?\C-i))
|
|
2721 (backward-delete-char 1)))
|
|
2722 ;; ok, insert the reference
|
|
2723 (insert (format form label label))
|
|
2724 (message ""))
|
|
2725 (message "Quit"))
|
|
2726 ;; return the label
|
|
2727 label))
|
|
2728
|
|
2729 (defun reftex-offer-label-menu (typekey)
|
165
|
2730 ;; Offer a menu with the appropriate labels. Return (label . file).
|
155
|
2731 (let* ((buf (current-buffer))
|
207
|
2732 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
|
|
2733 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
|
|
2734 (xr-index 0)
|
|
2735 (here-I-am (car (reftex-where-am-I)))
|
155
|
2736 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
|
207
|
2737 (files (reftex-typekey-check typekey reftex-label-menu-flags 7))
|
155
|
2738 (context (not (reftex-typekey-check
|
|
2739 typekey reftex-label-menu-flags 3)))
|
|
2740 (counter (reftex-typekey-check
|
|
2741 typekey reftex-label-menu-flags 2))
|
|
2742 (follow (reftex-typekey-check
|
|
2743 typekey reftex-label-menu-flags 4))
|
207
|
2744 (commented (nth 5 reftex-label-menu-flags))
|
|
2745 (match-everywhere (reftex-typekey-check
|
|
2746 typekey reftex-label-menu-flags 6))
|
|
2747 (prefix "")
|
|
2748 offset rtn key cnt last-cnt entry)
|
|
2749
|
155
|
2750 (setq entry (cons nil nil))
|
|
2751
|
207
|
2752 ;; The following unwind-protect kills temporary buffers after use
|
155
|
2753 (unwind-protect
|
|
2754 (catch 'exit
|
|
2755 (while t
|
|
2756 (save-window-excursion
|
207
|
2757 (setq reftex-call-back-to-this-buffer buf)
|
155
|
2758 (switch-to-buffer-other-window "*RefTeX Select*")
|
|
2759 (erase-buffer)
|
|
2760 (setq truncate-lines t)
|
207
|
2761 (setq mode-line-format
|
|
2762 (list "---- " 'mode-line-buffer-identification
|
|
2763 " " (abbreviate-file-name
|
|
2764 (buffer-file-name buf))
|
|
2765 " -%-"))
|
|
2766
|
|
2767 (setq reftex-label-index-list
|
|
2768 (reftex-make-and-insert-label-list
|
|
2769 typekey buf toc files context counter commented
|
|
2770 here-I-am prefix))
|
|
2771 (setq here-I-am nil) ; turn off determination of offset
|
|
2772 ;; use only when searched
|
155
|
2773 (setq offset (or (car reftex-label-index-list) offset))
|
|
2774 ;; only this is the true list
|
207
|
2775 (pop reftex-label-index-list)
|
155
|
2776 (setq rtn
|
|
2777 (reftex-select-item
|
207
|
2778 reftex-select-label-prompt
|
155
|
2779 "^>"
|
|
2780 2
|
207
|
2781 reftex-select-label-help
|
|
2782 '(?r ?R ?g ?c ?t ?s ?# ?i ?l ?% ?x)
|
155
|
2783 offset
|
207
|
2784 'reftex-select-label-callback follow
|
|
2785 match-everywhere))
|
|
2786 (setq key (car rtn)
|
|
2787 cnt (nth 1 rtn)
|
|
2788 last-cnt (nth 2 rtn)
|
|
2789 offset (1+ (or cnt last-cnt 0)))
|
|
2790 (unless key (throw 'exit nil))
|
155
|
2791 (cond
|
207
|
2792 ((or (eq key ?r)
|
|
2793 (eq key ?R)
|
|
2794 (eq key ?g))
|
155
|
2795 ;; rescan buffer
|
207
|
2796 (reftex-parse-document buf (or cnt last-cnt) key))
|
|
2797 ((eq key ?c)
|
155
|
2798 ;; toggle context mode
|
|
2799 (setq context (not context)))
|
207
|
2800 ((eq key ?s)
|
155
|
2801 ;; switch type
|
|
2802 (setq typekey (reftex-query-label-type)))
|
207
|
2803 ((eq key ?t)
|
155
|
2804 ;; toggle tabel of contents display
|
|
2805 (setq toc (not toc)))
|
207
|
2806 ((eq key ?i)
|
|
2807 ;; toggle display of included file borders
|
|
2808 (setq files (not files)))
|
|
2809 ((eq key ?#)
|
155
|
2810 ;; toggle counter display
|
|
2811 (setq counter (not counter)))
|
207
|
2812 ((eq key ?%)
|
|
2813 ;; toggle display of commented labels
|
|
2814 (setq commented (not commented)))
|
|
2815 ((eq key ?l)
|
155
|
2816 ;; reuse the last referenced label again
|
|
2817 (setq entry reftex-last-used-reference)
|
|
2818 (throw 'exit t))
|
207
|
2819 ((eq key ?x)
|
|
2820 ;; select an external document
|
|
2821 (setq xr-index (reftex-select-external-document
|
|
2822 xr-alist xr-index))
|
|
2823 (setq buf (or (reftex-get-file-buffer-force
|
|
2824 (cdr (nth xr-index xr-alist)))
|
|
2825 (error "Cannot switch document"))
|
|
2826 prefix (or (car (nth xr-index xr-alist)) "")
|
|
2827 offset nil))
|
155
|
2828 (t
|
|
2829 (set-buffer buf)
|
207
|
2830 (if cnt
|
|
2831 (progn
|
|
2832 (setq entry (nth (nth cnt reftex-label-index-list)
|
|
2833 (symbol-value reftex-docstruct-symbol)))
|
|
2834 (setq reftex-last-used-reference entry))
|
|
2835 (setq entry nil))
|
155
|
2836 (throw 'exit t))))))
|
|
2837 (kill-buffer "*RefTeX Select*")
|
207
|
2838 (and (get-buffer "*RefTeX Context Copy*")
|
|
2839 (kill-buffer "*RefTeX Context Copy*"))
|
155
|
2840 (reftex-kill-temporary-buffers))
|
207
|
2841 (cons (if (nth 0 entry) (concat prefix (nth 0 entry)) nil)
|
|
2842 (nth 3 entry))))
|
|
2843
|
|
2844 (defun reftex-select-external-document (xr-alist xr-index)
|
|
2845 ;; Return index of an external document.
|
|
2846 (cond
|
|
2847 ((= (length xr-alist) 1)
|
|
2848 (message "No external douments available")
|
|
2849 (ding) 0)
|
|
2850 ((= (length xr-alist) 2)
|
|
2851 (- 1 xr-index))
|
|
2852 (t
|
|
2853 (save-window-excursion
|
|
2854 (let* ((fmt " [%c] %-5s %s\n") (n (1- ?0)) key)
|
|
2855 (with-output-to-temp-buffer "*RefTeX Select*"
|
|
2856 (princ
|
|
2857 (concat "Select a document by pressing a number key:\n KEY PREFIX DOCUMENT\n----------------------\n"
|
|
2858 (mapconcat '(lambda (x)
|
|
2859 (format fmt (incf n) (or (car x) "")
|
|
2860 (abbreviate-file-name (cdr x))))
|
|
2861 xr-alist ""))))
|
|
2862 (setq key (read-char))
|
|
2863 (if (< (- key ?1) (length xr-alist))
|
|
2864 (- key ?0)
|
|
2865 (error "Illegal document selection [%c]" key)))))))
|
|
2866
|
|
2867 (defun reftex-make-and-insert-label-list
|
|
2868 (typekey0 buf toc files context counter show-commented here-I-am xr-prefix)
|
155
|
2869 ;; Insert a menu of all labels in buffer BUF into current buffer.
|
207
|
2870 ;; Return the list of labels, with the index of HERE-I-AM as extra car.
|
|
2871 (let* ((font (reftex-use-fonts))
|
|
2872 (refont (reftex-refontify))
|
|
2873 (cnt 0)
|
|
2874 (index -1)
|
|
2875 (toc-indent " ")
|
|
2876 (label-indent
|
|
2877 (concat "> "
|
|
2878 (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
|
|
2879 (context-indent
|
|
2880 (concat ". "
|
|
2881 (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
|
|
2882 all cell text label typekey note comment master-dir-re
|
|
2883 index-list offset docstruct-symbol from from1 to)
|
|
2884
|
|
2885 ;; Pop to buffer buf to get the correct buffer-local variables
|
155
|
2886 (save-excursion
|
|
2887 (set-buffer buf)
|
207
|
2888
|
|
2889 ;; Ensure access to scanning info
|
|
2890 (reftex-access-scan-info)
|
|
2891
|
|
2892 (setq docstruct-symbol reftex-docstruct-symbol
|
|
2893 all (symbol-value reftex-docstruct-symbol)
|
|
2894 reftex-active-toc nil
|
|
2895 master-dir-re
|
|
2896 (concat "\\`" (regexp-quote
|
|
2897 (file-name-directory (reftex-TeX-master-file))))))
|
|
2898
|
|
2899 (when refont
|
|
2900 ;; Calculate font-lock-defaults as in LaTeX mode.
|
|
2901 (make-local-variable 'font-lock-defaults)
|
|
2902 (setq font-lock-defaults nil)
|
|
2903 (let ((major-mode 'latex-mode))
|
|
2904 (font-lock-set-defaults))
|
|
2905 ;; The following is only needed for XEmacs, but does not hurt Emacs.
|
|
2906 (setq font-lock-mode nil))
|
|
2907
|
|
2908 ;; Walk the docstruct and insert the appropriate stuff
|
|
2909
|
|
2910 (while (setq cell (pop all))
|
|
2911
|
|
2912 (incf index)
|
|
2913 (setq from (point))
|
|
2914
|
|
2915 (if (eq cell here-I-am) (setq offset (1+ cnt)))
|
|
2916
|
|
2917 (cond
|
|
2918
|
|
2919 ((memq (car cell) '(bib label-numbers master-dir is-multi
|
|
2920 xr xr-doc)))
|
|
2921 ;; These are currently ignored
|
|
2922
|
|
2923 ((memq (car cell) '(bof eof file-error))
|
|
2924 ;; Beginning or end of a file
|
|
2925 (when files
|
|
2926 (insert
|
|
2927 " " (if (string-match master-dir-re (nth 1 cell))
|
|
2928 (substring (nth 1 cell) (match-end 0))
|
|
2929 (nth 1 cell))
|
|
2930 (cond ((eq (car cell) 'bof) " starts here\n")
|
|
2931 ((eq (car cell) 'eof) " ends here\n")
|
|
2932 ((eq (car cell) 'file-error) " was not found\n")))
|
|
2933 (when font
|
|
2934 (put-text-property from (point)
|
|
2935 'face 'font-lock-function-name-face))))
|
|
2936
|
|
2937 ((eq (car cell) 'toc)
|
|
2938 ;; a table of contents entry
|
|
2939 (when toc
|
|
2940 (setq reftex-active-toc cell)
|
|
2941 (insert (concat toc-indent (nth 2 cell) "\n"))))
|
|
2942
|
|
2943 ((stringp (car cell))
|
|
2944 ;; a label
|
|
2945 (when (null (nth 2 cell))
|
|
2946 ;; No context yet. Quick update.
|
|
2947 (setq cell (reftex-label-info-update cell))
|
|
2948 (setcar (nthcdr index (symbol-value docstruct-symbol))
|
|
2949 cell))
|
|
2950
|
|
2951 (setq label (car cell)
|
|
2952 typekey (nth 1 cell)
|
|
2953 text (nth 2 cell)
|
|
2954 note (nth 4 cell)
|
|
2955 comment (get-text-property 0 'in-comment text))
|
|
2956
|
|
2957 (when (and (or (string= typekey typekey0) (string= typekey0 " "))
|
|
2958 (or show-commented (null comment)))
|
|
2959
|
|
2960 ;; Yes we want this one
|
|
2961 (incf cnt)
|
|
2962 (push index index-list)
|
|
2963
|
|
2964 (setq label (concat xr-prefix label))
|
|
2965 (when comment (setq label (concat "% " label)))
|
|
2966 (insert label-indent label)
|
|
2967 (when font
|
|
2968 (put-text-property
|
|
2969 (- (point) (length label)) (point)
|
|
2970 'face (if comment
|
|
2971 'font-lock-comment-face
|
|
2972 'font-lock-reference-face)))
|
|
2973
|
|
2974 (insert (if counter (format " (%d) " cnt) "")
|
|
2975 (if comment " LABEL IS COMMENTED OUT " "")
|
|
2976 (if note (concat " " note) "")
|
|
2977 "\n")
|
|
2978 (setq to (point))
|
|
2979
|
|
2980 (when context
|
|
2981 (setq from1 to)
|
|
2982 (insert context-indent text "\n")
|
|
2983 (setq to (point))
|
|
2984 (when refont
|
|
2985 (font-lock-fontify-region from1 to)
|
|
2986 (goto-char to)))
|
|
2987 (put-text-property from to 'cnt (1- cnt))
|
|
2988 (goto-char to)))))
|
|
2989
|
|
2990 ;; Return the index list
|
155
|
2991 (cons offset (nreverse index-list))))
|
|
2992
|
207
|
2993 (defun reftex-parse-document (&optional buffer cnt key)
|
|
2994 "Rescan the document."
|
|
2995 (interactive)
|
|
2996 (save-window-excursion
|
|
2997 (save-excursion
|
|
2998 (if buffer
|
|
2999 (if (not (bufferp buffer))
|
|
3000 (error "No such buffer %s" (buffer-name buffer))
|
|
3001 (set-buffer buffer)))
|
|
3002 (let ((arg (if (eq key ?R) '(16) '(4)))
|
|
3003 (file (if cnt
|
|
3004 (nth 3
|
|
3005 (nth (nth cnt reftex-label-index-list)
|
|
3006 (symbol-value reftex-docstruct-symbol))))))
|
|
3007 (reftex-access-scan-info arg file)))))
|
|
3008
|
155
|
3009 (defun reftex-query-label-type ()
|
|
3010 ;; Ask for label type
|
|
3011 (message reftex-type-query-prompt)
|
|
3012 (let ((key (read-char)))
|
207
|
3013 (when (eq key ?\?)
|
|
3014 (save-window-excursion
|
|
3015 (with-output-to-temp-buffer "*RefTeX Help*"
|
|
3016 (princ reftex-type-query-help))
|
|
3017 (setq key (read-char))
|
|
3018 (kill-buffer "*RefTeX Help*")))
|
|
3019 (unless (member (char-to-string key) reftex-typekey-list)
|
|
3020 (error "No such label type: %s" (char-to-string key)))
|
155
|
3021 (char-to-string key)))
|
|
3022
|
|
3023 ;; Variable holding the vector with section numbers
|
|
3024 (defvar reftex-section-numbers [0 0 0 0 0 0 0 0])
|
|
3025
|
207
|
3026 (defun reftex-section-info (file)
|
|
3027 ;; Return a section entry for the current match.
|
|
3028 ;; Carefull: This function expects the match-data to be still in place!
|
|
3029 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3))))
|
|
3030 (macro (reftex-match-string 3))
|
|
3031 (star (= ?* (char-after (match-end 3))))
|
|
3032 (level (cdr (assoc macro reftex-section-levels)))
|
|
3033 (section-number (reftex-section-number
|
|
3034 reftex-section-numbers level star))
|
|
3035 (text1 (save-match-data (save-excursion (reftex-context-substring))))
|
|
3036 (literal (buffer-substring-no-properties
|
|
3037 (1- (match-beginning 3))
|
|
3038 (min (point-max) (+ (match-end 0) (length text1) 1))))
|
|
3039 ;; Literal can be too short since text1 too short. No big problem.
|
|
3040 (text (reftex-nicify-text text1)))
|
|
3041
|
|
3042 ;; Add section number and indentation
|
|
3043 (setq text
|
|
3044 (concat
|
|
3045 (make-string (* reftex-level-indent level) ?\ )
|
|
3046 (if (nth 1 reftex-label-menu-flags) ; section number flag
|
|
3047 (concat section-number " "))
|
|
3048 text))
|
|
3049 ;; Fontify
|
|
3050 (if (reftex-use-fonts)
|
|
3051 (put-text-property 0 (length text)
|
|
3052 'face 'font-lock-comment-face text))
|
|
3053 (list 'toc "toc" text file marker level section-number
|
|
3054 literal (marker-position marker))))
|
155
|
3055
|
|
3056 (defun reftex-label-info-update (cell)
|
|
3057 ;; Update information about just one label in a different file.
|
|
3058 ;; CELL contains the old info list
|
|
3059 (let* ((label (nth 0 cell))
|
|
3060 (typekey (nth 1 cell))
|
207
|
3061 ;; (text (nth 2 cell))
|
155
|
3062 (file (nth 3 cell))
|
|
3063 (note (nth 4 cell))
|
|
3064 (buf (reftex-get-file-buffer-force
|
207
|
3065 file (not (eq t reftex-keep-temporary-buffers)))))
|
155
|
3066 (if (not buf)
|
165
|
3067 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")
|
155
|
3068 (save-excursion
|
|
3069 (set-buffer buf)
|
|
3070 (save-restriction
|
|
3071 (widen)
|
|
3072 (goto-char 1)
|
|
3073
|
207
|
3074 (if (or (re-search-forward
|
|
3075 (format reftex-find-label-regexp-format
|
|
3076 (regexp-quote label)) nil t)
|
|
3077 (re-search-forward
|
|
3078 (format reftex-find-label-regexp-format2
|
|
3079 (regexp-quote label)) nil t))
|
|
3080
|
|
3081 (progn
|
|
3082 (backward-char 1)
|
|
3083 (append (reftex-label-info label file) (list note)))
|
165
|
3084 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")))))))
|
155
|
3085
|
207
|
3086 (defun reftex-label-info (label &optional file bound derive env-or-mac)
|
155
|
3087 ;; Return info list on LABEL at point.
|
207
|
3088 (let* ((env-or-mac (or env-or-mac (reftex-label-location bound)))
|
155
|
3089 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist)))
|
|
3090 (file (or file (buffer-file-name)))
|
|
3091 (parse (if (reftex-typekey-check
|
|
3092 typekey reftex-use-text-after-label-as-context)
|
|
3093 nil
|
|
3094 (nth 2 (assoc env-or-mac reftex-env-or-mac-alist))))
|
207
|
3095 (text (reftex-short-context env-or-mac parse reftex-location-start
|
|
3096 derive)))
|
155
|
3097 (if (reftex-in-comment)
|
|
3098 (put-text-property 0 1 'in-comment t text))
|
|
3099 (list label typekey text file)))
|
|
3100
|
|
3101 (defun reftex-in-comment ()
|
|
3102 (save-excursion
|
|
3103 (skip-chars-backward "^%\n\r")
|
207
|
3104 (eq (preceding-char) ?%)))
|
|
3105
|
|
3106 (defun reftex-short-context (env parse &optional bound derive)
|
155
|
3107 ;; Get about one line of useful context for the label definition at point.
|
|
3108
|
207
|
3109 (if (consp parse)
|
|
3110 (setq parse (if derive (cdr parse) (car parse))))
|
|
3111
|
155
|
3112 (reftex-nicify-text
|
|
3113
|
|
3114 (cond
|
|
3115
|
|
3116 ((null parse)
|
|
3117 (save-excursion
|
|
3118 (reftex-context-substring)))
|
|
3119
|
|
3120 ((eq parse t)
|
|
3121 (if (string= env "section")
|
|
3122 ;; special treatment for section labels
|
|
3123 (save-excursion
|
207
|
3124 (if (and (re-search-backward reftex-section-or-include-regexp
|
|
3125 (point-min) t)
|
|
3126 (match-end 2))
|
155
|
3127 (progn
|
|
3128 (goto-char (match-end 0))
|
|
3129 (reftex-context-substring))
|
207
|
3130 (if reftex-active-toc
|
|
3131 (progn
|
|
3132 (string-match "{\\([^}]*\\)" (nth 7 reftex-active-toc))
|
|
3133 (match-string 1 (nth 7 reftex-active-toc)))
|
|
3134 "SECTION HEADING NOT FOUND")))
|
155
|
3135 (save-excursion
|
207
|
3136 (goto-char reftex-default-context-position)
|
|
3137 (unless (eq (string-to-char env) ?\\)
|
|
3138 (reftex-move-over-touching-args))
|
155
|
3139 (reftex-context-substring))))
|
|
3140
|
|
3141 ((stringp parse)
|
|
3142 (save-excursion
|
|
3143 (if (re-search-backward parse bound t)
|
|
3144 (progn
|
|
3145 (goto-char (match-end 0))
|
|
3146 (reftex-context-substring))
|
|
3147 "NO MATCH FOR CONTEXT REGEXP")))
|
207
|
3148
|
|
3149 ((integerp parse)
|
|
3150 (or (save-excursion
|
|
3151 (goto-char reftex-default-context-position)
|
|
3152 (reftex-nth-arg
|
|
3153 parse
|
|
3154 (nth 6 (assoc env reftex-env-or-mac-alist))))
|
|
3155 ""))
|
|
3156
|
155
|
3157 ((fboundp parse)
|
165
|
3158 ;; A hook function. Call it.
|
155
|
3159 (save-excursion
|
|
3160 (condition-case error-var
|
|
3161 (funcall parse env)
|
207
|
3162 (error (format "HOOK ERROR: %s" (cdr error-var))))))
|
155
|
3163 (t
|
|
3164 "ILLEGAL VALUE OF PARSE"))))
|
|
3165
|
207
|
3166 (defun reftex-where-am-I ()
|
|
3167 ;; Return the docstruct entry above point. Actually returns a cons
|
|
3168 ;; cell in which the cdr is a flag indicating if the information is
|
|
3169 ;; exact (t) or approximate (nil).
|
|
3170 (interactive)
|
|
3171
|
|
3172 (let ((docstruct (symbol-value reftex-docstruct-symbol))
|
|
3173 (cnt 0) rtn
|
|
3174 found)
|
|
3175 (save-excursion
|
|
3176 (while (not rtn)
|
|
3177 (incf cnt)
|
|
3178 (setq found (re-search-backward reftex-everything-regexp nil t))
|
|
3179 (setq rtn
|
|
3180 (cond
|
|
3181 ((not found)
|
|
3182 ;; no match
|
|
3183 (or
|
|
3184 (car (member (list 'bof (buffer-file-name)) docstruct))
|
|
3185 (not (setq cnt 2))
|
|
3186 (assq 'bof docstruct) ;; for safety reasons
|
|
3187 'corrupted))
|
|
3188 ((match-end 1)
|
|
3189 ;; Label
|
|
3190 (assoc (reftex-match-string 1)
|
|
3191 (symbol-value reftex-docstruct-symbol)))
|
|
3192 ((match-end 3)
|
|
3193 ;; Section
|
|
3194 (goto-char (1- (match-beginning 3)))
|
|
3195 (let* ((list (member (list 'bof (buffer-file-name))
|
|
3196 docstruct))
|
|
3197 (endelt (car (member (list 'eof (buffer-file-name))
|
|
3198 list)))
|
|
3199 rtn1)
|
|
3200 (while (and list (not (eq endelt (car list))))
|
|
3201 (if (and (eq (car (car list)) 'toc)
|
|
3202 (string= (buffer-file-name)
|
|
3203 (nth 3 (car list))))
|
|
3204 (cond
|
|
3205 ((equal (point)
|
|
3206 (or (and (markerp (nth 4 (car list)))
|
|
3207 (marker-position (nth 4 (car list))))
|
|
3208 (nth 8 (car list))))
|
|
3209 ;; Fits with marker position or recorded position
|
|
3210 (setq rtn1 (car list) list nil))
|
|
3211 ((looking-at (reftex-make-regexp-allow-for-ctrl-m
|
|
3212 (nth 7 (car list))))
|
|
3213 ;; Same title
|
|
3214 (setq rtn1 (car list) list nil cnt 2))))
|
|
3215 (pop list))
|
|
3216 rtn1))
|
|
3217 ((match-end 7)
|
|
3218 ;; Input or include...
|
|
3219 (car
|
|
3220 (member (list 'eof (reftex-find-tex-file
|
|
3221 (reftex-match-string 7)
|
|
3222 (cons
|
|
3223 (cdr (assq 'master-dir docstruct))
|
|
3224 reftex-tex-path)))
|
|
3225 docstruct)))
|
|
3226 ((match-end 8)
|
|
3227 (save-excursion
|
|
3228 (goto-char (match-end 8))
|
|
3229 (assoc (reftex-no-props
|
|
3230 (reftex-nth-arg-wrapper
|
|
3231 (reftex-match-string 8)))
|
|
3232 (symbol-value reftex-docstruct-symbol))))
|
|
3233 (t
|
|
3234 (error "This should not happen (reftex-where-am-I)"))))))
|
|
3235 (cons rtn (eq cnt 1))))
|
|
3236
|
|
3237 (defun reftex-parse-args (macro)
|
|
3238 ;; Return a list of macro name, nargs, arg-nr which is label and a list of
|
|
3239 ;; optional argument indices.
|
|
3240 (if (string-match "[[{]\\*?[]}]" macro)
|
|
3241 (progn
|
|
3242 (let ((must-match (substring macro 0 (match-beginning 0)))
|
|
3243 (args (substring macro (match-beginning 0)))
|
|
3244 opt-list nlabel (cnt 0))
|
|
3245 (while (string-match "\\`[[{]\\(\\*\\)?[]}]" args)
|
|
3246 (incf cnt)
|
|
3247 (when (eq ?\[ (string-to-char args))
|
|
3248 (push cnt opt-list))
|
|
3249 (when (and (match-end 1)
|
|
3250 (not nlabel))
|
|
3251 (setq nlabel cnt))
|
|
3252 (setq args (substring args (match-end 0))))
|
|
3253 (list must-match cnt nlabel opt-list)))
|
|
3254 nil))
|
|
3255
|
|
3256 (defsubst reftex-move-to-next-arg (&optional ignore)
|
|
3257 ;; Assuming that we are at the end of a macro name or a macro argument,
|
|
3258 ;; move forward to the opening parenthesis of the next argument.
|
|
3259 ;; This function understands the splitting of macros over several lines
|
|
3260 ;; in TeX.
|
|
3261 (cond
|
|
3262 ;; Just to be quick:
|
|
3263 ((memq (following-char) '(?\[ ?\{)))
|
|
3264 ;; Do a search
|
|
3265 ((looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]")
|
|
3266 (goto-char (1- (match-end 0)))
|
|
3267 t)
|
|
3268 (t nil)))
|
|
3269
|
|
3270 (defsubst reftex-move-to-previous-arg (&optional bound)
|
|
3271 ;; Assuming that we are in front of a macro argument,
|
|
3272 ;; move backward to the closing parenthesis of the previous argument.
|
|
3273 ;; This function understands the splitting of macros over several lines
|
|
3274 ;; in TeX.
|
|
3275 (cond
|
|
3276 ;; Just to be quick:
|
|
3277 ((memq (preceding-char) '(?\] ?\})))
|
|
3278 ;; Do a search
|
|
3279 ((re-search-backward
|
|
3280 "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t)
|
|
3281 (goto-char (1+ (match-beginning 0)))
|
|
3282 t)
|
|
3283 (t nil)))
|
|
3284
|
|
3285 (defun reftex-nth-arg-wrapper (key)
|
|
3286 (let ((entry (assoc key reftex-env-or-mac-alist)))
|
|
3287 (reftex-nth-arg (nth 5 entry) (nth 6 entry))))
|
|
3288
|
|
3289 (defun reftex-nth-arg (n &optional opt-args)
|
|
3290 ;; Return the nth following {} or [] parentheses content.
|
|
3291 ;; OPT-ARGS is a list of argument numbers which are optional.
|
|
3292
|
|
3293 ;; If we are sitting at a macro start, skip to end of macro name.
|
|
3294 (and (eq (following-char) ?\\) (skip-chars-forward "a-zA-Z*\\\\"))
|
|
3295
|
|
3296 (if (= n 1000)
|
|
3297 ;; Special case: Skip all touching arguments
|
|
3298 (progn
|
|
3299 (reftex-move-over-touching-args)
|
|
3300 (reftex-context-substring))
|
|
3301
|
|
3302 ;; Do the real thing.
|
|
3303 (let ((cnt 1))
|
|
3304
|
|
3305 (when (reftex-move-to-next-arg)
|
|
3306
|
|
3307 (while (< cnt n)
|
|
3308 (while (and (member cnt opt-args)
|
|
3309 (eq (following-char) ?\{))
|
|
3310 (incf cnt))
|
|
3311 (when (< cnt n)
|
|
3312 (unless (and (condition-case nil
|
|
3313 (or (forward-list 1) t)
|
|
3314 (error nil))
|
|
3315 (reftex-move-to-next-arg)
|
|
3316 (incf cnt))
|
|
3317 (setq cnt 1000))))
|
|
3318
|
|
3319 (while (and (memq cnt opt-args)
|
|
3320 (eq (following-char) ?\{))
|
|
3321 (incf cnt)))
|
|
3322 (if (and (= n cnt)
|
|
3323 (> (skip-chars-forward "{\\[") 0))
|
|
3324 (reftex-context-substring)
|
|
3325 nil))))
|
|
3326
|
|
3327 (defun reftex-move-over-touching-args ()
|
|
3328 (condition-case nil
|
|
3329 (while (memq (following-char) '(?\[ ?\{))
|
|
3330 (forward-list 1))
|
|
3331 (error nil)))
|
|
3332
|
155
|
3333 (defun reftex-context-substring ()
|
|
3334 ;; Return up to 100 chars from point
|
|
3335 ;; When point is just after a { or [, limit string to matching parenthesis
|
|
3336 (cond
|
|
3337 ((or (= (preceding-char) ?\{)
|
|
3338 (= (preceding-char) ?\[))
|
207
|
3339 ;; Inside a list - get only the list.
|
|
3340 (buffer-substring-no-properties
|
155
|
3341 (point)
|
207
|
3342 (min (reftex-fp 150)
|
|
3343 (point-max)
|
|
3344 (condition-case nil
|
|
3345 (progn
|
|
3346 (up-list 1)
|
|
3347 (1- (point)))
|
|
3348 (error (point-max))))))
|
155
|
3349 (t
|
|
3350 ;; no list - just grab 100 characters
|
207
|
3351 (buffer-substring-no-properties (point) (min (reftex-fp 150) (point-max))))))
|
|
3352
|
|
3353 (defun reftex-init-section-numbers (&optional toc-entry)
|
|
3354 ;; Initialize the section numbers with zeros or with what is found
|
|
3355 ;; in the toc entry.
|
|
3356 (let* ((level (or (nth 5 toc-entry) -1))
|
|
3357 (numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\.")))
|
|
3358 (depth (1- (length reftex-section-numbers)))
|
|
3359 (i depth))
|
|
3360 (while (>= i 0)
|
|
3361 (if (> i level)
|
|
3362 (aset reftex-section-numbers i 0)
|
|
3363 (aset reftex-section-numbers i (string-to-int (or (car numbers) "0")))
|
|
3364 (pop numbers))
|
|
3365 (decf i))))
|
155
|
3366
|
|
3367 (defun reftex-section-number (section-numbers &optional level star)
|
|
3368 ;; Return a string with the current section number.
|
|
3369 ;; When LEVEL is non-nil, increase section numbers on that level.
|
207
|
3370 (let* ((depth (1- (length section-numbers))) idx n (string ""))
|
|
3371 (when level
|
|
3372 (when (and (> level -1) (not star))
|
|
3373 (aset section-numbers level (1+ (aref section-numbers level))))
|
|
3374 (setq idx (1+ level))
|
|
3375 (while (<= idx depth)
|
|
3376 (aset section-numbers idx 0)
|
|
3377 (incf idx)))
|
155
|
3378 (setq idx 0)
|
|
3379 (while (<= idx depth)
|
|
3380 (setq n (aref section-numbers idx))
|
|
3381 (setq string (concat string (if (not (string= string "")) "." "")
|
|
3382 (int-to-string n)))
|
207
|
3383 (incf idx))
|
155
|
3384 (save-match-data
|
|
3385 (if (string-match "\\`\\(0\\.\\)+" string)
|
|
3386 (setq string (replace-match "" nil nil string)))
|
|
3387 (if (string-match "\\(\\.0\\)+\\'" string)
|
|
3388 (setq string (replace-match "" nil nil string))))
|
207
|
3389 (if star
|
|
3390 (concat (make-string (1- (length string)) ?\ ) "*")
|
155
|
3391 string)))
|
|
3392
|
|
3393 ;; A variable to remember the index of the last label context shown
|
|
3394 (defvar reftex-last-cnt 0)
|
|
3395
|
|
3396 (defun reftex-select-label-callback (cnt)
|
|
3397 ;; Callback function called from the label selection in order to
|
|
3398 ;; show context in another window
|
|
3399 (let* ((this-window (selected-window))
|
207
|
3400 index entry label file buffer re)
|
155
|
3401 ;; pop to original buffer in order to get correct variables
|
|
3402 (catch 'exit
|
|
3403 (save-excursion
|
|
3404 (set-buffer reftex-call-back-to-this-buffer)
|
|
3405 (setq index (nth (or cnt 1) reftex-label-index-list)
|
207
|
3406 entry (nth index (symbol-value reftex-docstruct-symbol))
|
155
|
3407 label (nth 0 entry)
|
|
3408 file (nth 3 entry)))
|
|
3409
|
|
3410 ;; goto the file in another window
|
|
3411 (setq buffer (reftex-get-file-buffer-force
|
|
3412 file (not reftex-keep-temporary-buffers)))
|
|
3413 (if buffer
|
|
3414 ;; good - the file is available
|
|
3415 (switch-to-buffer-other-window buffer)
|
165
|
3416 ;; we have got a problem here. The file does not exist.
|
155
|
3417 ;; Let' get out of here..
|
|
3418 (ding)
|
|
3419 (throw 'exit nil))
|
|
3420
|
|
3421
|
|
3422 ;; search for that label
|
207
|
3423 (setq re (format reftex-find-label-regexp-format (regexp-quote label)))
|
|
3424 (unless (and (integerp cnt)
|
|
3425 (integerp reftex-last-cnt)
|
|
3426 (if (> cnt reftex-last-cnt)
|
|
3427 (re-search-forward re nil t)
|
|
3428 (re-search-backward re nil t)))
|
|
3429 (goto-char (point-min))
|
|
3430 (unless (re-search-forward re nil t)
|
|
3431 ;; Ooops. Must be in a macro with distributed args.
|
|
3432 (re-search-forward (format reftex-find-label-regexp-format2
|
|
3433 (regexp-quote label)) nil t)))
|
|
3434 (when (match-end 3)
|
|
3435 (reftex-highlight 0 (match-beginning 3) (match-end 3))
|
|
3436 (reftex-show-entry (- (point) (match-beginning 3))
|
|
3437 (- (point) (match-end 3)))
|
|
3438 (recenter (/ (window-height) 2)))
|
155
|
3439 (select-window this-window))))
|
|
3440
|
|
3441 (defun reftex-pop-to-label (label file-list &optional mark-to-kill highlight)
|
|
3442 ;; Find LABEL in any file in FILE-LIST in another window.
|
|
3443 ;; If mark-to-kill is non-nil, mark new buffer for killing.
|
|
3444 ;; If HIGHLIGHT is non-nil, highlight the label definition.
|
207
|
3445 (let* ((re1 (format reftex-find-label-regexp-format (regexp-quote label)))
|
|
3446 (re2 (format reftex-find-label-regexp-format2 (regexp-quote label)))
|
|
3447 (re-list (list re1 re2)) re
|
|
3448 (file-list-1 file-list)
|
155
|
3449 file buf)
|
|
3450 (catch 'exit
|
207
|
3451 (while (setq re (pop re-list))
|
|
3452 (setq file-list file-list-1)
|
|
3453 (while (setq file (pop file-list))
|
|
3454 (unless (setq buf (reftex-get-file-buffer-force file mark-to-kill))
|
|
3455 (error "No such file %s" file))
|
|
3456 (set-buffer buf)
|
|
3457 (widen)
|
|
3458 (goto-char (point-min))
|
|
3459 (when (re-search-forward re nil t)
|
|
3460 (switch-to-buffer-other-window buf)
|
|
3461 (goto-char (match-beginning 0))
|
|
3462 (recenter (/ (window-height) 2))
|
|
3463 (if highlight
|
|
3464 (reftex-highlight 0 (match-beginning 3) (match-end 3)))
|
|
3465 (throw 'exit (selected-window)))))
|
155
|
3466 (error "Label %s not found" label))))
|
|
3467
|
|
3468 (defun reftex-find-duplicate-labels ()
|
|
3469 "Produce a list of all duplicate labels in the document."
|
|
3470
|
|
3471 (interactive)
|
|
3472
|
|
3473 ;; Rescan the document to make sure
|
|
3474 (reftex-access-scan-info t)
|
|
3475
|
|
3476 (let ((master (reftex-TeX-master-file))
|
207
|
3477 (cnt 0)
|
|
3478 (dlist
|
155
|
3479 (mapcar
|
|
3480 '(lambda(x)
|
|
3481 (let (x1)
|
|
3482 (cond
|
207
|
3483 ((memq (car x)
|
|
3484 '(toc bof eof bib label-numbers xr xr-doc
|
|
3485 master-dir file-error is-multi))
|
|
3486 nil)
|
|
3487 (t
|
155
|
3488 (setq x1 (reftex-all-assoc-string
|
207
|
3489 (car x) (symbol-value reftex-docstruct-symbol)))
|
155
|
3490 (if (< 1 (length x1))
|
207
|
3491 (append (list (car x))
|
155
|
3492 (mapcar '(lambda(x)
|
|
3493 (abbreviate-file-name (nth 3 x))) x1))
|
207
|
3494 (list nil))))))
|
|
3495 (reftex-uniquify (symbol-value reftex-docstruct-symbol)))))
|
|
3496
|
155
|
3497 (setq dlist (reftex-uniquify dlist))
|
|
3498 (if (null dlist) (error "No duplicate labels in document"))
|
165
|
3499 (switch-to-buffer-other-window "*Duplicate Labels*")
|
155
|
3500 (make-local-variable 'TeX-master)
|
|
3501 (setq TeX-master master)
|
|
3502 (erase-buffer)
|
|
3503 (insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n")
|
207
|
3504 (insert
|
|
3505 " Move point to label and type `r' to run a query-replace on the label\n"
|
|
3506 " and its references. Type `q' to exit this buffer.\n\n")
|
155
|
3507 (insert " LABEL FILE\n")
|
|
3508 (insert " -------------------------------------------------------------\n")
|
207
|
3509 (use-local-map (make-sparse-keymap))
|
|
3510 (local-set-key [?q] '(lambda () (interactive)
|
|
3511 (kill-buffer (current-buffer)) (delete-window)))
|
|
3512 (local-set-key [?r] 'reftex-change-label)
|
155
|
3513 (while dlist
|
207
|
3514 (when (and (car (car dlist))
|
|
3515 (cdr (car dlist)))
|
|
3516 (incf cnt)
|
|
3517 (insert (mapconcat '(lambda(x) x) (car dlist) "\n ") "\n"))
|
|
3518 (pop dlist))
|
|
3519 (goto-char (point-min))
|
|
3520 (when (= cnt 0)
|
|
3521 (kill-buffer (current-buffer))
|
|
3522 (delete-window)
|
|
3523 (message "Document does not contain duplicate labels."))))
|
|
3524
|
|
3525 (defun reftex-all-assq (key list)
|
|
3526 ;; Return a list of all associations of KEY in LIST. Comparison with string=
|
|
3527 (let (rtn)
|
|
3528 (while (setq list (memq (assq key list) list))
|
|
3529 (push (car list) rtn)
|
|
3530 (pop list))
|
|
3531 (nreverse rtn)))
|
155
|
3532
|
|
3533 (defun reftex-all-assoc-string (key list)
|
165
|
3534 ;; Return a list of all associations of KEY in LIST. Comparison with string=
|
155
|
3535 (let (rtn)
|
|
3536 (while list
|
|
3537 (if (string= (car (car list)) key)
|
207
|
3538 (push (car list) rtn))
|
|
3539 (pop list))
|
155
|
3540 (nreverse rtn)))
|
|
3541
|
207
|
3542 (defun reftex-kill-temporary-buffers (&optional buffer)
|
155
|
3543 ;; Kill all buffers in the list reftex-kill-temporary-buffers.
|
207
|
3544 (cond
|
|
3545 (buffer
|
|
3546 (when (member buffer reftex-buffers-to-kill)
|
|
3547 (kill-buffer buffer)
|
|
3548 (setq reftex-buffers-to-kill
|
|
3549 (delete buffer reftex-buffers-to-kill))))
|
|
3550 (t
|
|
3551 (while (setq buffer (pop reftex-buffers-to-kill))
|
|
3552 (when (bufferp buffer)
|
|
3553 (and (buffer-modified-p buffer)
|
|
3554 (y-or-n-p (format "Save file %s? "
|
|
3555 (buffer-file-name buffer)))
|
|
3556 (save-excursion
|
|
3557 (set-buffer buffer)
|
|
3558 (save-buffer)))
|
|
3559 (kill-buffer buffer))
|
|
3560 (pop reftex-buffers-to-kill)))))
|
|
3561
|
|
3562 (defun reftex-show-entry (beg-hlt end-hlt)
|
155
|
3563 ;; Show entry if point is hidden by outline mode
|
207
|
3564 (let* ((pos (point))
|
|
3565 (n (/ (window-height) 2))
|
|
3566 (beg (save-excursion
|
|
3567 (re-search-backward "[\n\r]" nil 1 n) (point)))
|
|
3568 (end (save-excursion
|
|
3569 (re-search-forward "[\n\r]" nil 1 n) (point))))
|
155
|
3570 (if (and reftex-auto-show-entry
|
207
|
3571 (string-match
|
|
3572 "\r" (buffer-substring beg end)))
|
|
3573 (cond
|
|
3574 ((eq t reftex-auto-show-entry)
|
|
3575 (subst-char-in-region
|
|
3576 (save-excursion (search-backward "\n" nil t) (point))
|
|
3577 (save-excursion (search-forward "\n" nil t) (point))
|
|
3578 ?\r ?\n t))
|
|
3579 ((eq reftex-auto-show-entry 'copy)
|
|
3580 (let ((string (buffer-substring beg end)))
|
|
3581 (switch-to-buffer "*RefTeX Context Copy*")
|
|
3582 (setq buffer-read-only nil)
|
|
3583 (erase-buffer)
|
|
3584 (insert string)
|
|
3585 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
|
|
3586 (goto-char (- pos beg))
|
|
3587 (reftex-highlight 0 (1+ (- (point) beg-hlt))
|
|
3588 (1+ (- (point) end-hlt)))
|
|
3589 (when (reftex-refontify)
|
|
3590 (make-local-variable 'font-lock-defaults)
|
|
3591 (setq font-lock-defaults nil)
|
|
3592 (let ((major-mode 'latex-mode))
|
|
3593 (font-lock-set-defaults)
|
|
3594 (font-lock-fontify-buffer)))
|
|
3595 (setq buffer-read-only t)))
|
|
3596 ))))
|
155
|
3597
|
|
3598 (defun reftex-nicify-text (text)
|
207
|
3599 ;; Make TEXT nice for inclusion as context into label menu
|
155
|
3600 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) ; remove extra whitespace
|
|
3601 (setq text (replace-match " " nil t text)))
|
|
3602 (if (string-match "\\\\end{.*" text) ; nothing beyond \end{
|
|
3603 (setq text (replace-match "" nil t text)))
|
|
3604 (if (string-match "\\\\label{[^}]*}" text) ; kill the label
|
|
3605 (setq text (replace-match "" nil t text)))
|
207
|
3606 (if (string-match "\\`[ }]+" text) ; leading whitespace, `}'
|
155
|
3607 (setq text (replace-match "" nil t text)))
|
|
3608 (cond
|
207
|
3609 ((> (length text) 100) (substring text 0 100))
|
|
3610 ((= (length text) 0) " ")
|
|
3611 (t text)))
|
155
|
3612
|
|
3613 (defun reftex-typekey-check (typekey conf-variable &optional n)
|
|
3614 ;; Check if CONF-VARIABLE is true or contains TYPEKEY
|
|
3615 (and n (setq conf-variable (nth n conf-variable)))
|
207
|
3616 (or (eq conf-variable t)
|
155
|
3617 (and (stringp conf-variable)
|
|
3618 (string-match (concat "[" conf-variable "]") typekey))))
|
|
3619
|
|
3620 ;;; ===========================================================================
|
|
3621 ;;;
|
207
|
3622 ;;; Table of contents
|
155
|
3623
|
|
3624 ;; We keep at most one *toc* buffer - it is easy to make them
|
|
3625
|
|
3626 (defvar reftex-last-toc-master nil
|
|
3627 "Stores the name of the tex file that `reftex-toc' was last run on.")
|
|
3628
|
|
3629 (defvar reftex-last-toc-file nil
|
165
|
3630 "Stores the file name from which `reftex-toc' was called. For redo command.")
|
155
|
3631
|
207
|
3632 (defvar reftex-last-window-height nil)
|
|
3633
|
155
|
3634 (defvar reftex-toc-return-marker (make-marker)
|
|
3635 "Marker which makes it possible to return from toc to old position.")
|
|
3636
|
207
|
3637 (defconst reftex-toc-help
|
|
3638 " AVAILABLE KEYS IN TOC BUFFER
|
|
3639 ============================
|
|
3640 SPC Show the corresponding section of the LaTeX document.
|
|
3641 TAB Goto the section.
|
|
3642 RET Goto the section and hide the *toc* buffer (also on mouse-2).
|
|
3643 q / Q Hide/Kill *toc* buffer, return to position of last reftex-toc command.
|
|
3644 f Toggle follow mode on and off.
|
|
3645 r / g Reparse the LaTeX document.
|
|
3646 x Switch to TOC of external document (with LaTeX package `xr').")
|
|
3647
|
155
|
3648 (defun reftex-toc ()
|
|
3649 "Show the table of contents for the current document.
|
|
3650 When called with a raw C-u prefix, rescan the document first."
|
|
3651
|
|
3652 (interactive)
|
|
3653
|
207
|
3654 (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
|
|
3655 current-prefix-arg)
|
|
3656 (reftex-empty-toc-buffer))
|
155
|
3657
|
|
3658 (setq reftex-last-toc-file (buffer-file-name))
|
|
3659 (setq reftex-last-toc-master (reftex-TeX-master-file))
|
|
3660
|
|
3661 (set-marker reftex-toc-return-marker (point))
|
|
3662
|
207
|
3663 ;; If follow mode is active, arrange to delay it one command
|
155
|
3664 (if reftex-toc-follow-mode
|
|
3665 (setq reftex-toc-follow-mode 1))
|
|
3666
|
|
3667 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
|
|
3668 (reftex-access-scan-info current-prefix-arg)
|
|
3669
|
207
|
3670 (let* ((all (symbol-value reftex-docstruct-symbol))
|
|
3671 (xr-data (assq 'xr all))
|
|
3672 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
|
155
|
3673 (where (reftex-nearest-section))
|
207
|
3674 toc1 cell startpos)
|
|
3675
|
|
3676 (if (get-buffer-window "*toc*")
|
|
3677 (select-window (get-buffer-window "*toc*"))
|
|
3678 (setq reftex-last-window-height (window-height)) ; remember
|
|
3679 (split-window-vertically)
|
|
3680 (switch-to-buffer (get-buffer-create "*toc*")))
|
155
|
3681
|
|
3682 (cond
|
|
3683 ;; buffer is empty - fill it with the table of contents
|
|
3684 ((= (buffer-size) 0)
|
|
3685
|
207
|
3686 (local-set-key "?" 'reftex-toc-show-help)
|
|
3687 (local-set-key " " 'reftex-toc-view-line)
|
|
3688 (local-set-key "\C-m" 'reftex-toc-goto-line-and-hide)
|
|
3689 (local-set-key "\C-i" 'reftex-toc-goto-line)
|
|
3690 (local-set-key "r" 'reftex-toc-redo)
|
|
3691 (local-set-key "R" 'reftex-toc-Redo)
|
|
3692 (local-set-key "g" 'revert-buffer)
|
|
3693 (local-set-key "q" 'reftex-toc-quit)
|
|
3694 (local-set-key "Q" 'reftex-toc-quit-and-kill)
|
|
3695 (local-set-key "f" 'reftex-toc-toggle-follow)
|
|
3696 (local-set-key "x" 'reftex-toc-external)
|
|
3697 (local-set-key [(mouse-2)] 'reftex-toc-mouse-goto-line-and-hide); Emacs
|
|
3698 (local-set-key [(button2)] 'reftex-toc-mouse-goto-line-and-hide); XEmacs
|
165
|
3699 (make-local-variable 'revert-buffer-function)
|
|
3700 (setq revert-buffer-function 'reftex-toc-redo)
|
155
|
3701 (setq truncate-lines t)
|
|
3702 (make-local-hook 'post-command-hook)
|
|
3703 (make-local-hook 'pre-command-hook)
|
|
3704 (setq post-command-hook '(reftex-toc-post-command-hook))
|
|
3705 (setq pre-command-hook '(reftex-toc-pre-command-hook))
|
|
3706
|
|
3707 (insert (format
|
|
3708 "TABLE-OF-CONTENTS on %s
|
207
|
3709 SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [f]ollow-mode e[x]tern [?]Help
|
155
|
3710 -------------------------------------------------------------------------------
|
|
3711 " (abbreviate-file-name reftex-last-toc-master)))
|
|
3712 (setq startpos (point))
|
|
3713
|
|
3714 (if (reftex-use-fonts)
|
|
3715 (put-text-property 1 (point) 'face 'font-lock-keyword-face))
|
|
3716 (put-text-property 1 (point) 'intangible t)
|
207
|
3717 (put-text-property 1 2 'xr-alist xr-alist)
|
155
|
3718
|
|
3719 (while all
|
|
3720 (setq cell (car all)
|
|
3721 all (cdr all))
|
207
|
3722 (when (eq (car cell) 'toc)
|
|
3723 (setq toc1 (concat (nth 2 cell) "\n"))
|
|
3724 (put-text-property 0 (length toc1) 'toc cell toc1)
|
|
3725 (insert toc1)))
|
155
|
3726
|
|
3727 (backward-delete-char 1)
|
|
3728
|
|
3729 (setq buffer-read-only t))
|
|
3730 (t
|
|
3731 (goto-line 3)
|
|
3732 (beginning-of-line)
|
|
3733 (setq startpos (point))))
|
|
3734
|
|
3735 ;; Find the correct section
|
|
3736 (goto-char (point-max))
|
|
3737 (beginning-of-line)
|
|
3738 (while (and (> (point) startpos)
|
207
|
3739 (not (eq (get-text-property (point) 'toc) where)))
|
155
|
3740 (beginning-of-line 0))))
|
|
3741
|
|
3742 (defun reftex-nearest-section ()
|
|
3743 ;; Return (file . find) of nearest section command
|
207
|
3744 (let* ((here-I-am (car (reftex-where-am-I))))
|
|
3745 (reftex-last-assoc-before-elt
|
|
3746 'toc here-I-am (symbol-value reftex-docstruct-symbol))))
|
155
|
3747
|
|
3748 (defun reftex-toc-pre-command-hook ()
|
|
3749 ;; used as pre command hook in *toc* buffer
|
|
3750 (reftex-unhighlight 0)
|
|
3751 (reftex-unhighlight 1))
|
|
3752
|
|
3753 (defun reftex-toc-post-command-hook ()
|
|
3754 ;; used in the post-command-hook for the *toc* buffer
|
|
3755 (and (> (point) 1)
|
|
3756 (save-excursion
|
207
|
3757 (reftex-highlight 1
|
|
3758 (progn (beginning-of-line) (point))
|
|
3759 (progn (end-of-line) (point)))))
|
155
|
3760 (cond
|
|
3761 ((integerp reftex-toc-follow-mode)
|
|
3762 ;; remove delayed action
|
|
3763 (setq reftex-toc-follow-mode t))
|
|
3764 (reftex-toc-follow-mode
|
|
3765 ;; show context in other window
|
|
3766 (condition-case nil
|
|
3767 (reftex-toc-visit-line)
|
207
|
3768 (error (ding) t)))))
|
|
3769
|
|
3770 (defun reftex-empty-toc-buffer ()
|
|
3771 (if (get-buffer "*toc*")
|
|
3772 (save-excursion
|
|
3773 (set-buffer "*toc*")
|
|
3774 (setq buffer-read-only nil)
|
|
3775 (erase-buffer))))
|
|
3776
|
|
3777 (defun reftex-re-enlarge ()
|
|
3778 (enlarge-window
|
|
3779 (max 0 (- (or reftex-last-window-height (window-height))
|
|
3780 (window-height)))))
|
|
3781
|
|
3782 (defun reftex-toc-show-help ()
|
|
3783 (interactive)
|
|
3784 (with-output-to-temp-buffer "*RefTeX Help*"
|
|
3785 (princ reftex-toc-help))
|
|
3786 ;; If follow mode is active, arrange to delay it one command
|
|
3787 (if reftex-toc-follow-mode
|
|
3788 (setq reftex-toc-follow-mode 1)))
|
155
|
3789
|
|
3790 (defun reftex-toc-toggle-follow ()
|
|
3791 "Toggle toc-follow mode.
|
165
|
3792 (It is not really a mode, just a flag)."
|
155
|
3793 (interactive)
|
|
3794 (setq reftex-toc-follow-mode (not reftex-toc-follow-mode)))
|
|
3795 (defun reftex-toc-view-line ()
|
|
3796 "View document location in other window."
|
|
3797 (interactive)
|
|
3798 (reftex-toc-visit-line))
|
|
3799 (defun reftex-toc-goto-line-and-hide ()
|
165
|
3800 "Go to document location in other window. Hide the *toc* window."
|
155
|
3801 (interactive)
|
|
3802 (reftex-toc-visit-line 'hide))
|
207
|
3803 (defun reftex-toc-goto-line ()
|
|
3804 "Go to document location in other window. Hide the *toc* window."
|
|
3805 (interactive)
|
|
3806 (reftex-toc-visit-line t))
|
|
3807 (defun reftex-toc-mouse-goto-line-and-hide (ev)
|
|
3808 "Go to document location in other window. Hide the *toc* window."
|
|
3809 (interactive "e")
|
|
3810 (mouse-set-point ev)
|
|
3811 (reftex-toc-visit-line 'hide))
|
155
|
3812 (defun reftex-toc-quit ()
|
|
3813 "Hide the *toc* window and do not move point."
|
|
3814 (interactive)
|
207
|
3815 (or (one-window-p) (delete-window))
|
155
|
3816 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
|
207
|
3817 (reftex-re-enlarge)
|
|
3818 (goto-char (or (marker-position reftex-toc-return-marker) (point))))
|
155
|
3819 (defun reftex-toc-quit-and-kill ()
|
|
3820 "Kill the *toc* buffer."
|
|
3821 (interactive)
|
|
3822 (kill-buffer "*toc*")
|
207
|
3823 (or (one-window-p) (delete-window))
|
155
|
3824 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
|
207
|
3825 (reftex-re-enlarge)
|
155
|
3826 (goto-char (marker-position reftex-toc-return-marker)))
|
165
|
3827 (defun reftex-toc-redo (&rest ignore)
|
207
|
3828 "Regenerate the *toc* buffer by reparsing file of last reftex-toc command."
|
|
3829 (interactive)
|
|
3830 (if reftex-enable-partial-scans
|
|
3831 (let ((file (nth 3 (get-text-property (point) 'toc))))
|
|
3832 (if (not file)
|
|
3833 (error "Don't know which file to rescan. Try `R'.")
|
|
3834 (switch-to-buffer-other-window
|
|
3835 (reftex-get-file-buffer-force file))
|
|
3836 (setq current-prefix-arg '(4))
|
|
3837 (reftex-toc)))
|
|
3838 (reftex-toc-Redo))
|
|
3839 (reftex-kill-temporary-buffers))
|
|
3840 (defun reftex-toc-Redo (&rest ignore)
|
|
3841 "Regenerate the *toc* buffer by reparsing the entire document."
|
155
|
3842 (interactive)
|
207
|
3843 (switch-to-buffer-other-window
|
|
3844 (reftex-get-file-buffer-force reftex-last-toc-file))
|
|
3845 (setq current-prefix-arg '(16))
|
155
|
3846 (reftex-toc))
|
207
|
3847 (defun reftex-toc-external (&rest ignore)
|
|
3848 "Switch to table of contents of an external document."
|
|
3849 (interactive)
|
|
3850 (let* ((xr-alist (get-text-property 1 'xr-alist))
|
|
3851 (xr-index (reftex-select-external-document
|
|
3852 xr-alist 0)))
|
|
3853 (switch-to-buffer-other-window (or (reftex-get-file-buffer-force
|
|
3854 (cdr (nth xr-index xr-alist)))
|
|
3855 (error "Cannot switch document")))
|
|
3856 (reftex-toc)))
|
155
|
3857
|
|
3858 (defun reftex-toc-visit-line (&optional final)
|
|
3859 ;; Visit the tex file corresponding to the toc entry on the current line.
|
|
3860 ;; If FINAL is t, stay there
|
|
3861 ;; If FINAL is 'hide, hide the *toc* window.
|
207
|
3862 ;; Otherwise, move cursor back into *toc* window.
|
|
3863 ;; This function is pretty clever about finding back a section heading,
|
|
3864 ;; even if the buffer is not live, or things like outline, x-symbol etc.
|
|
3865 ;; have been active.
|
|
3866
|
|
3867 (let* ((toc (get-text-property (point) 'toc))
|
|
3868 (file (nth 3 toc))
|
|
3869 (marker (nth 4 toc))
|
|
3870 (level (nth 5 toc))
|
|
3871 (literal (nth 7 toc))
|
|
3872 (emergency-point (nth 8 toc))
|
|
3873 (toc-window (selected-window))
|
|
3874 show-window show-buffer match)
|
|
3875
|
|
3876 (unless toc (error "Don't know which toc line to visit"))
|
|
3877
|
|
3878 (setq match
|
|
3879 (cond
|
|
3880 ((and (markerp marker) (marker-buffer marker))
|
|
3881 ;; Buffer is still live and we have the marker. Should be easy.
|
|
3882 (switch-to-buffer-other-window (marker-buffer marker))
|
|
3883 (goto-char (marker-position marker))
|
|
3884 (or (looking-at (regexp-quote literal))
|
|
3885 (looking-at (reftex-make-regexp-allow-for-ctrl-m literal))
|
|
3886 (looking-at (reftex-make-desparate-section-regexp literal))
|
|
3887 (looking-at (concat "\\\\"
|
|
3888 (regexp-quote
|
|
3889 (car (rassq level reftex-section-levels)))
|
|
3890 "[[{]"))))
|
|
3891 (t
|
|
3892 ;; Marker is lost. Use the backup method.
|
|
3893 (switch-to-buffer-other-window
|
|
3894 (reftex-get-file-buffer-force file nil))
|
|
3895 (goto-char (or emergency-point (point-min)))
|
|
3896 (or (looking-at (regexp-quote literal))
|
|
3897 (let ((pos (point)))
|
|
3898 (re-search-backward "\\`\\|[\r\n][ \t]*[\r\n]" nil t)
|
|
3899 (or (reftex-nearest-match (regexp-quote literal) pos)
|
|
3900 (reftex-nearest-match
|
|
3901 (reftex-make-regexp-allow-for-ctrl-m literal) pos)
|
|
3902 (reftex-nearest-match
|
|
3903 (reftex-make-desparate-section-regexp literal) pos)))))
|
|
3904 ))
|
|
3905
|
|
3906 (setq show-window (selected-window)
|
|
3907 show-buffer (current-buffer))
|
|
3908
|
|
3909 (unless match
|
|
3910 (select-window toc-window)
|
|
3911 (error "Cannot find line"))
|
|
3912
|
|
3913 (goto-char (match-beginning 0))
|
155
|
3914 (recenter 1)
|
207
|
3915 (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer))
|
155
|
3916
|
|
3917 (select-window toc-window)
|
|
3918
|
|
3919 ;; use the `final' parameter to decide what to do next
|
|
3920 (cond
|
207
|
3921 ((eq final t)
|
155
|
3922 (reftex-unhighlight 0)
|
|
3923 (select-window show-window))
|
|
3924 ((eq final 'hide)
|
|
3925 (reftex-unhighlight 0)
|
207
|
3926 (or (one-window-p) (delete-window))
|
|
3927 (switch-to-buffer show-buffer)
|
|
3928 (reftex-re-enlarge))
|
155
|
3929 (t nil))))
|
|
3930
|
|
3931 ;;; ===========================================================================
|
|
3932 ;;;
|
|
3933 ;;; BibTeX citations.
|
|
3934
|
|
3935 ;; Variables and constants
|
|
3936
|
165
|
3937 ;; Define variable to silence compiler warnings
|
|
3938 (defvar reftex-found-list)
|
207
|
3939 (defvar reftex-cite-format-builtin)
|
155
|
3940
|
|
3941 ;; The history list of regular expressions used for citations
|
|
3942 (defvar reftex-cite-regexp-hist nil)
|
|
3943
|
207
|
3944 ;; Prompt and help string for citation selection
|
|
3945 (defconst reftex-citation-prompt
|
|
3946 "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more")
|
|
3947
|
155
|
3948 (defconst reftex-citation-help
|
|
3949 "AVAILABLE KEYS IN MAKE CITATION MENU
|
|
3950 ---------------------------------------
|
207
|
3951 n / p Go to next/previous entry (Cursor motion works as well).
|
|
3952 C-s / C-r Search forward/backward. Use repeated C-s/C-r as in isearch.
|
|
3953 g / r Start over with new regexp / Restrict with additional regexp.
|
|
3954 SPC Show full database entry in other window.
|
|
3955 f Toggle follow mode: Other window will follow with full db entry.
|
|
3956 q Quit without inserting \\cite macro into buffer.
|
|
3957 e Recursive edit into other window.
|
|
3958 RET / a Accept current entry / Accept all entries.")
|
155
|
3959
|
|
3960 ;; Find bibtex files
|
|
3961
|
|
3962 (defun reftex-get-bibfile-list ()
|
207
|
3963 ;; Return list of bibfiles for current document.
|
|
3964 ;; When using the chapterbib or bibunits package you should either
|
|
3965 ;; use the same database files everywhere, or separate parts using
|
|
3966 ;; different databases into different files (included into the mater file).
|
|
3967 ;; Then this function will return the applicable database files.
|
155
|
3968
|
|
3969 ;; Ensure access to scanning info
|
|
3970 (reftex-access-scan-info)
|
207
|
3971 (or
|
|
3972 ;; Try inside this file (and its includes)
|
|
3973 (cdr (reftex-last-assoc-before-elt
|
|
3974 'bib (list 'eof (buffer-file-name))
|
|
3975 (member (list 'bof (buffer-file-name))
|
|
3976 (symbol-value reftex-docstruct-symbol))))
|
|
3977 ;; Try after the beginning of this file
|
|
3978 (cdr (assq 'bib (member (list 'bof (buffer-file-name))
|
|
3979 (symbol-value reftex-docstruct-symbol))))
|
|
3980 ;; Anywhere in the entire document
|
|
3981 (cdr (assq 'bib (symbol-value reftex-docstruct-symbol)))
|
|
3982 (error "\\bibliography statment missing or .bib files not found.")))
|
|
3983
|
|
3984 (defun reftex-find-tex-file (file master-dir &optional die)
|
|
3985 ;; Find FILE in MASTER-DIR or on reftex-tex-path.
|
|
3986 ;; FILE may be given without the .tex extension.
|
|
3987 (reftex-access-search-path "tex")
|
|
3988 (let* ((path (cons master-dir reftex-tex-path))
|
|
3989 file1)
|
|
3990 (setq file1
|
|
3991 (or (reftex-find-file-on-path (concat file ".tex") path)
|
|
3992 (reftex-find-file-on-path file path)))
|
|
3993 (unless file1
|
|
3994 (reftex-access-search-path "tex" t file)
|
|
3995 (setq path (cons master-dir reftex-tex-path))
|
|
3996 (setq file1
|
|
3997 (or (reftex-find-file-on-path (concat file ".tex") path)
|
|
3998 (reftex-find-file-on-path file path))))
|
|
3999 (cond (file1 file1)
|
|
4000 (die (error "No such file: %s" file) nil)
|
|
4001 (t (message "No such file: %s (ignored)" file) nil))))
|
|
4002
|
|
4003 (defun reftex-find-bib-file (file master-dir &optional die)
|
|
4004 ;; Find FILE in MASTER-DIR or on reftex-bib-path
|
|
4005 (reftex-access-search-path "bib")
|
|
4006 (let ((file1 (reftex-find-file-on-path
|
|
4007 file (cons master-dir reftex-bib-path))))
|
|
4008 (unless file1
|
|
4009 (reftex-access-search-path "bib" t file)
|
|
4010 (setq file1 (reftex-find-file-on-path
|
|
4011 file (cons master-dir reftex-bib-path))))
|
|
4012 (cond (file1 file1)
|
|
4013 (die (error "No such file: %s" file) nil)
|
|
4014 (t (message "No such file: %s (ignored)" file) nil))))
|
155
|
4015
|
|
4016 ;; Find a certain reference in any of the BibTeX files.
|
|
4017
|
|
4018 (defun reftex-pop-to-bibtex-entry (key file-list
|
207
|
4019 &optional mark-to-kill highlight)
|
155
|
4020 ;; Find BibTeX KEY in any file in FILE-LIST in another window.
|
|
4021 ;; If mark-to-kill is non-nil, mark new buffer to kill."
|
|
4022
|
165
|
4023 (let* ((re (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) "[ \t\n\r,]"))
|
155
|
4024 (window-conf (current-window-configuration))
|
|
4025 file buf)
|
|
4026 (catch 'exit
|
|
4027 (switch-to-buffer-other-window (current-buffer))
|
|
4028 (while file-list
|
|
4029 (setq file (car file-list)
|
|
4030 file-list (cdr file-list))
|
207
|
4031 (unless (setq buf (reftex-get-file-buffer-force file mark-to-kill))
|
|
4032 (error "No such file %s" file))
|
155
|
4033 (switch-to-buffer buf)
|
|
4034 (widen)
|
207
|
4035 (goto-char (point-min))
|
|
4036 (when (re-search-forward re nil t)
|
|
4037 (goto-char (match-beginning 0))
|
|
4038 (recenter 0)
|
|
4039 (if highlight
|
|
4040 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
|
|
4041 (throw 'exit (selected-window))))
|
155
|
4042 (set-window-configuration window-conf)
|
|
4043 (beep)
|
|
4044 (message "No BibTeX entry with citation key %s" key))))
|
|
4045
|
|
4046 ;; Parse bibtex buffers
|
|
4047
|
|
4048 (defun reftex-extract-bib-entries (buffers &optional get-word)
|
|
4049 ;; Extract bib entries which match regexps from BUFFERS.
|
|
4050 ;; BUFFERS is a list of buffers or file names.
|
|
4051 ;; Return list with entries."
|
|
4052 (let* (re-list first-re rest-re
|
|
4053 (buffer-list (if (listp buffers) buffers (list buffers)))
|
|
4054 found-list entry buffer1 buffer alist
|
|
4055 key-point start-point end-point)
|
|
4056
|
207
|
4057 (setq re-list (split-string
|
|
4058 (read-string "RegExp [ && RegExp...]: "
|
|
4059 nil 'reftex-cite-regexp-hist)
|
|
4060 "[ \t]*&&[ \t]*"))
|
155
|
4061
|
|
4062 (setq first-re (car re-list) ; We'll use the first re to find things,
|
|
4063 rest-re (cdr re-list)) ; the other to narrow down.
|
|
4064 (if (string-match "\\`[ \t]*\\'" first-re)
|
|
4065 (error "Empty regular expression"))
|
|
4066
|
|
4067 (save-excursion
|
|
4068 (save-window-excursion
|
|
4069
|
207
|
4070 ;; Walk through all bibtex files
|
155
|
4071 (while buffer-list
|
|
4072 (setq buffer (car buffer-list)
|
|
4073 buffer-list (cdr buffer-list))
|
|
4074 (if (and (bufferp buffer)
|
|
4075 (buffer-live-p buffer))
|
|
4076 (setq buffer1 buffer)
|
|
4077 (setq buffer1 (reftex-get-file-buffer-force
|
|
4078 buffer (not reftex-keep-temporary-buffers))))
|
|
4079 (if (not buffer1)
|
|
4080 (error "Cannot find BibTeX file %s" buffer)
|
|
4081 (message "Scanning bibliography database %s" buffer1))
|
|
4082
|
|
4083 (set-buffer buffer1)
|
207
|
4084 (save-excursion
|
|
4085 (goto-char (point-min))
|
|
4086 (while (re-search-forward first-re nil t)
|
|
4087 (catch 'search-again
|
|
4088 (setq key-point (point))
|
|
4089 (unless (re-search-backward
|
|
4090 "\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t)
|
|
4091 (throw 'search-again nil))
|
|
4092 (setq start-point (point))
|
|
4093 (goto-char (match-end 0))
|
|
4094 (condition-case nil
|
|
4095 (up-list 1)
|
|
4096 (error (goto-char key-point)
|
|
4097 (throw 'search-again nil)))
|
|
4098 (setq end-point (point))
|
|
4099
|
|
4100 ;; Ignore @string, @comment and @c entries or things
|
|
4101 ;; outside entries
|
|
4102 (when (or (string= (downcase (match-string 2)) "string")
|
|
4103 (string= (downcase (match-string 2)) "comment")
|
|
4104 (string= (downcase (match-string 2)) "c")
|
|
4105 (< (point) key-point)) ; this means match not in {}
|
|
4106 (goto-char key-point)
|
|
4107 (throw 'search-again nil))
|
|
4108
|
|
4109 ;; Well, we have got a match
|
|
4110 (setq entry (concat
|
|
4111 (buffer-substring start-point (point)) "\n"))
|
|
4112
|
|
4113 ;; Check if other regexp match as well
|
|
4114 (setq re-list rest-re)
|
|
4115 (while re-list
|
|
4116 (unless (string-match (car re-list) entry)
|
|
4117 ;; nope - move on
|
|
4118 (throw 'search-again nil))
|
|
4119 (pop re-list))
|
|
4120
|
|
4121 (setq alist (reftex-parse-bibtex-entry
|
|
4122 nil start-point end-point))
|
|
4123 (push (cons "&entry" entry) alist)
|
|
4124
|
|
4125 ;; check for crossref entries
|
|
4126 (if (assoc "crossref" alist)
|
|
4127 (setq alist
|
|
4128 (append
|
|
4129 alist (reftex-get-crossref-alist alist))))
|
|
4130
|
|
4131 ;; format the entry
|
|
4132 (push (cons "&formatted" (reftex-format-bib-entry alist))
|
|
4133 alist)
|
|
4134
|
|
4135 ;; add it to the list
|
|
4136 (push alist found-list))))
|
155
|
4137 (reftex-kill-temporary-buffers))))
|
|
4138 (setq found-list (nreverse found-list))
|
207
|
4139
|
155
|
4140 ;; Sorting
|
207
|
4141 (cond
|
155
|
4142 ((eq 'author reftex-sort-bibtex-matches)
|
|
4143 (sort found-list 'reftex-bib-sort-author))
|
|
4144 ((eq 'year reftex-sort-bibtex-matches)
|
|
4145 (sort found-list 'reftex-bib-sort-year))
|
|
4146 ((eq 'reverse-year reftex-sort-bibtex-matches)
|
|
4147 (sort found-list 'reftex-bib-sort-year-reverse))
|
|
4148 (t found-list))))
|
|
4149
|
|
4150 (defun reftex-bib-sort-author (e1 e2)
|
207
|
4151 (let ((al1 (reftex-get-bib-names "author" e1))
|
|
4152 (al2 (reftex-get-bib-names "author" e2)))
|
155
|
4153 (while (and al1 al2 (string= (car al1) (car al2)))
|
207
|
4154 (pop al1)
|
|
4155 (pop al2))
|
155
|
4156 (if (and (stringp (car al1))
|
207
|
4157 (stringp (car al2)))
|
|
4158 (string< (car al1) (car al2))
|
155
|
4159 (not (stringp (car al1))))))
|
|
4160
|
|
4161 (defun reftex-bib-sort-year (e1 e2)
|
|
4162 (< (string-to-int (cdr (assoc "year" e1)))
|
|
4163 (string-to-int (cdr (assoc "year" e2)))))
|
|
4164
|
|
4165 (defun reftex-bib-sort-year-reverse (e1 e2)
|
|
4166 (> (string-to-int (or (cdr (assoc "year" e1)) "0"))
|
|
4167 (string-to-int (or (cdr (assoc "year" e2)) "0"))))
|
|
4168
|
|
4169 (defun reftex-get-crossref-alist (entry)
|
|
4170 ;; return the alist from a crossref entry
|
|
4171 (let ((crkey (cdr (assoc "crossref" entry)))
|
|
4172 start)
|
|
4173 (save-excursion
|
|
4174 (save-restriction
|
|
4175 (widen)
|
|
4176 (if (re-search-forward
|
207
|
4177 (concat "@\\w+[{(][ \t\n\r]*" (regexp-quote crkey)
|
|
4178 "[ \t\n\r]*,") nil t)
|
155
|
4179 (progn
|
|
4180 (setq start (match-beginning 0))
|
|
4181 (condition-case nil
|
|
4182 (up-list 1)
|
207
|
4183 (error nil))
|
155
|
4184 (reftex-parse-bibtex-entry nil start (point)))
|
|
4185 nil)))))
|
|
4186
|
|
4187 ;; Parse and format individual entries
|
|
4188
|
207
|
4189 (defun reftex-get-bib-names (field entry)
|
|
4190 ;; Return a list with the author or editor anmes in ENTRY
|
|
4191 (let ((names (reftex-get-bib-field field entry)))
|
|
4192 (if (equal "" names)
|
|
4193 (setq names (reftex-get-bib-field "editor" entry)))
|
|
4194 (while (string-match "\\band\\b[ \t]*" names)
|
|
4195 (setq names (replace-match "\n" nil t names)))
|
|
4196 (while (string-match "[\\.a-zA-Z\\-]+\\.[ \t]*\\|,.*\\|[{}]+" names)
|
|
4197 (setq names (replace-match "" nil t names)))
|
|
4198 (while (string-match "^[ \t]+\\|[ \t]+$" names)
|
|
4199 (setq names (replace-match "" nil t names)))
|
|
4200 (while (string-match "[ \t][ \t]+" names)
|
|
4201 (setq names (replace-match " " nil t names)))
|
|
4202 (split-string names "\n")))
|
155
|
4203
|
|
4204 (defun reftex-parse-bibtex-entry (entry &optional from to)
|
|
4205 (let (alist key start field)
|
|
4206 (save-excursion
|
|
4207 (save-restriction
|
|
4208 (if entry
|
|
4209 (progn
|
|
4210 (switch-to-buffer "*RefTeX-scratch*")
|
|
4211 (fundamental-mode)
|
|
4212 (erase-buffer)
|
|
4213 (insert entry))
|
|
4214 (widen)
|
|
4215 (narrow-to-region from to))
|
|
4216 (goto-char (point-min))
|
|
4217
|
207
|
4218 (if (re-search-forward
|
165
|
4219 "@\\(\\w+\\)[ \t\n\r]*[{(][ \t\n\r]*\\([^ \t\n\r,]+\\)" nil t)
|
155
|
4220 (setq alist
|
|
4221 (list
|
207
|
4222 (cons "&type" (downcase (reftex-match-string 1)))
|
|
4223 (cons "&key" (reftex-match-string 2)))))
|
155
|
4224 (while (re-search-forward "\\(\\w+\\)[ \t\n\r]*=[ \t\n\r]*" nil t)
|
207
|
4225 (setq key (downcase (reftex-match-string 1)))
|
155
|
4226 (cond
|
|
4227 ((= (following-char) ?{)
|
|
4228 (forward-char 1)
|
|
4229 (setq start (point))
|
|
4230 (condition-case nil
|
|
4231 (up-list 1)
|
207
|
4232 (error nil)))
|
155
|
4233 ((= (following-char) ?\")
|
|
4234 (forward-char 1)
|
|
4235 (setq start (point))
|
|
4236 (while (and (search-forward "\"" nil t)
|
|
4237 (= ?\\ (char-after (- (point) 2))))))
|
|
4238 (t
|
|
4239 (setq start (point))
|
|
4240 (re-search-forward "[ \t\n\r,}]" nil 1)))
|
|
4241 (setq field (buffer-substring-no-properties start (1- (point))))
|
|
4242 ;; remove extra whitesp
|
|
4243 (while (string-match "[\n\t\r]\\|[ \t][ \t]+" field)
|
|
4244 (setq field (replace-match " " nil t field)))
|
|
4245 ;; remove leading garbage
|
|
4246 (if (string-match "^[ \t{]+" field)
|
|
4247 (setq field (replace-match "" nil t field)))
|
|
4248 ;; remove trailing garbage
|
|
4249 (if (string-match "[ \t}]+$" field)
|
|
4250 (setq field (replace-match "" nil t field)))
|
207
|
4251 (push (cons key field) alist))))
|
|
4252 alist))
|
155
|
4253
|
|
4254 (defun reftex-get-bib-field (fieldname entry)
|
|
4255 ;; Extract the field FIELDNAME from an ENTRY
|
|
4256 (or (cdr (assoc fieldname entry))
|
|
4257 ""))
|
|
4258
|
|
4259 (defun reftex-format-bib-entry (entry)
|
|
4260 ;; Format a BibTeX ENTRY so that it is nice to look at
|
|
4261 (let*
|
207
|
4262 ((auth-list (reftex-get-bib-names "author" entry))
|
155
|
4263 (authors (mapconcat '(lambda (x) x) auth-list ", "))
|
|
4264 (year (reftex-get-bib-field "year" entry))
|
|
4265 (title (reftex-get-bib-field "title" entry))
|
|
4266 (type (reftex-get-bib-field "&type" entry))
|
|
4267 (key (reftex-get-bib-field "&key" entry))
|
|
4268 (extra
|
|
4269 (cond
|
|
4270 ((equal type "article")
|
|
4271 (concat (reftex-get-bib-field "journal" entry) " "
|
|
4272 (reftex-get-bib-field "volume" entry) ", "
|
|
4273 (reftex-get-bib-field "pages" entry)))
|
|
4274 ((equal type "book")
|
|
4275 (concat "book (" (reftex-get-bib-field "publisher" entry) ")"))
|
|
4276 ((equal type "phdthesis")
|
|
4277 (concat "PhD: " (reftex-get-bib-field "school" entry)))
|
|
4278 ((equal type "mastersthesis")
|
|
4279 (concat "Master: " (reftex-get-bib-field "school" entry)))
|
|
4280 ((equal type "inbook")
|
|
4281 (concat "Chap: " (reftex-get-bib-field "chapter" entry)
|
|
4282 ", pp. " (reftex-get-bib-field "pages" entry)))
|
|
4283 ((or (equal type "conference")
|
|
4284 (equal type "incollection")
|
|
4285 (equal type "inproceedings"))
|
|
4286 (concat "in: " (reftex-get-bib-field "booktitle" entry)))
|
|
4287 (t ""))))
|
207
|
4288 (setq authors (reftex-truncate authors 30 t t))
|
|
4289 (when (reftex-use-fonts)
|
|
4290 (put-text-property 0 (length authors) 'face 'font-lock-keyword-face
|
|
4291 authors)
|
|
4292 (put-text-property 0 (length title) 'face 'font-lock-comment-face
|
|
4293 title)
|
|
4294 (put-text-property 0 (length extra) 'face 'font-lock-reference-face
|
|
4295 extra))
|
|
4296 (concat key "\n " authors " " year " " extra "\n " title "\n\n")))
|
155
|
4297
|
|
4298 ;; Make a citation
|
|
4299
|
207
|
4300 (defun reftex-citation (&optional no-insert)
|
165
|
4301 "Make a citation using BibTeX database files.
|
155
|
4302 After asking for a Regular Expression, it scans the buffers with
|
|
4303 bibtex entries (taken from the \\bibliography command) and offers the
|
165
|
4304 matching entries for selection. The selected entry is formated according
|
|
4305 to `reftex-cite-format' and inserted into the buffer.
|
155
|
4306 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
|
165
|
4307 The regular expression uses an expanded syntax: && is interpreted as `and'.
|
|
4308 Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'.
|
155
|
4309 When this function is called with point inside the braces of a \\cite
|
165
|
4310 command, it will add another key, ignoring the value of `reftex-cite-format'.
|
155
|
4311 When called with a numeric prefix, that many citations will be made and all
|
|
4312 put into the same \\cite command.
|
|
4313 When called with just C-u as prefix, enforces rescan of buffer for
|
|
4314 bibliography statement (e.g. if it was changed)."
|
|
4315
|
207
|
4316 (interactive)
|
155
|
4317
|
|
4318 ;; check for recursive edit
|
|
4319 (reftex-check-recursive-edit)
|
|
4320
|
|
4321 ;; if there is just 1 C-u prefix arg, force to rescan buffer
|
207
|
4322 (reftex-access-scan-info current-prefix-arg)
|
|
4323
|
|
4324 ;; Call reftex-do-citation, but protected
|
|
4325 (unwind-protect
|
|
4326 (reftex-do-citation current-prefix-arg no-insert)
|
|
4327 (reftex-kill-temporary-buffers)))
|
|
4328
|
|
4329 (defun reftex-do-citation (&optional arg no-insert)
|
|
4330 ;; This really does the work of reftex-citation.
|
|
4331
|
|
4332 ;; Check if there is already a cite command at point and change cite format
|
155
|
4333 ;; in order to only add another reference in the same cite command.
|
207
|
4334 (let (key format (macro (car (car (reftex-what-macro t)))))
|
|
4335 (if (and (stringp macro)
|
|
4336 (string-match "\\`\\\\cite\\|cite\\'" macro))
|
155
|
4337 (progn
|
|
4338 (cond
|
|
4339 ((or (not arg)
|
|
4340 (not (listp arg)))
|
207
|
4341 (setq format
|
155
|
4342 (concat
|
|
4343 (if (not (or (= (preceding-char) ?{)
|
|
4344 (= (preceding-char) ?,)))
|
|
4345 ","
|
|
4346 "")
|
207
|
4347 "%l"
|
155
|
4348 (if (not (or (= (following-char) ?})
|
|
4349 (= (following-char) ?,)))
|
|
4350 ","
|
|
4351 ""))))
|
|
4352 (t
|
207
|
4353 (setq format "%l"))))
|
|
4354 ;; else: figure out the correct format
|
|
4355 (setq format
|
|
4356 (cond
|
|
4357 ((stringp reftex-cite-format) reftex-cite-format)
|
|
4358 ((and (symbolp reftex-cite-format)
|
|
4359 (assq reftex-cite-format reftex-cite-format-builtin))
|
|
4360 (nth 2 (assq reftex-cite-format reftex-cite-format-builtin)))
|
|
4361 (t reftex-cite-format)))
|
|
4362 (if (listp format)
|
|
4363 (save-window-excursion
|
|
4364 (with-output-to-temp-buffer "*RefTeX Select*"
|
|
4365 (princ "SELECT A CITATION FORMAT\n\n")
|
|
4366 (princ
|
|
4367 (mapconcat
|
|
4368 (function (lambda (x)
|
|
4369 (format "[%c] %s %s" (car x)
|
|
4370 (if (> (car x) 31) " " "")
|
|
4371 (cdr x))))
|
|
4372 format "\n")))
|
|
4373 (setq key (read-char))
|
|
4374 (if (assq key format)
|
|
4375 (setq format (cdr (assq key format)))
|
|
4376 (error "No citation format associated with key `%c'" key)))))
|
|
4377
|
|
4378 (let* (entry cnt rtn ins-string re-list re
|
|
4379 ;; scan bibtex files
|
|
4380 (reftex-found-list (reftex-extract-bib-entries
|
|
4381 (reftex-get-bibfile-list)))
|
|
4382 (found-list-r nil))
|
|
4383 (unless reftex-found-list
|
155
|
4384 (error "Sorry, no matches found"))
|
|
4385
|
207
|
4386 ;; remember where we came from
|
|
4387 (setq reftex-call-back-to-this-buffer (current-buffer))
|
|
4388
|
|
4389 ;; offer selection
|
|
4390 (save-window-excursion
|
|
4391 (switch-to-buffer-other-window "*RefTeX Select*")
|
|
4392 (erase-buffer)
|
|
4393 (reftex-insert-bib-matches reftex-found-list)
|
|
4394 (if (= 0 (buffer-size))
|
|
4395 (error "Sorry, no matches found"))
|
|
4396 (setq truncate-lines t)
|
|
4397 (goto-char 1)
|
|
4398 (if (catch 'exit
|
|
4399 (while t
|
|
4400 (setq rtn
|
|
4401 (reftex-select-item
|
|
4402 reftex-citation-prompt
|
|
4403 "^[^ \t\n\r]"
|
|
4404 4
|
|
4405 reftex-citation-help
|
|
4406 '(?r ?a ?g ?\C-m)
|
|
4407 nil
|
|
4408 'reftex-bibtex-selection-callback nil))
|
|
4409 (setq key (car rtn)
|
|
4410 cnt (nth 1 rtn))
|
|
4411 (unless key (throw 'exit nil))
|
|
4412 (cond
|
|
4413 ((eq key ?g)
|
|
4414 (setq reftex-found-list
|
|
4415 (save-excursion
|
|
4416 (set-buffer reftex-call-back-to-this-buffer)
|
|
4417 (reftex-extract-bib-entries
|
|
4418 (reftex-get-bibfile-list))))
|
|
4419 (erase-buffer)
|
|
4420 (reftex-insert-bib-matches reftex-found-list)
|
|
4421 (if (= 0 (buffer-size))
|
|
4422 (error "Sorry, no matches found"))
|
|
4423 (goto-char 1))
|
|
4424
|
|
4425 ((eq key ?r)
|
|
4426 ;; restrict with new regular expression
|
|
4427 (setq re-list
|
|
4428 (split-string (read-string
|
|
4429 "RegExp [ && RegExp...]: "
|
|
4430 nil 'reftex-cite-regexp-hist)
|
|
4431 "[ \t]*&&[ \t]*"))
|
|
4432 (while re-list
|
|
4433 (setq re (car re-list)
|
|
4434 re-list (cdr re-list))
|
|
4435 (setq found-list-r
|
|
4436 (delete ""
|
|
4437 (mapcar
|
|
4438 '(lambda (x)
|
|
4439 (if (string-match
|
|
4440 re (cdr (assoc "&entry" x)))
|
|
4441 x
|
|
4442 ""))
|
|
4443 reftex-found-list))))
|
|
4444 (if found-list-r
|
|
4445 (setq reftex-found-list found-list-r)
|
|
4446 (ding))
|
|
4447 (erase-buffer)
|
|
4448 (reftex-insert-bib-matches reftex-found-list)
|
|
4449 (goto-char 1))
|
|
4450 ((eq key ?a)
|
|
4451 (setq entry 'all)
|
|
4452 (throw 'exit t))
|
|
4453 ((or (eq key ?\C-m)
|
|
4454 (eq key 'return))
|
|
4455 (if cnt
|
|
4456 (setq entry (nth cnt reftex-found-list))
|
|
4457 (setq entry nil))
|
|
4458 (throw 'exit t))
|
|
4459 (t
|
|
4460 (ding)))))
|
|
4461 (progn
|
|
4462 ;; format the entry
|
|
4463 (if (eq entry 'all)
|
|
4464 (setq ins-string
|
|
4465 (mapconcat
|
|
4466 '(lambda (entry)
|
|
4467 (reftex-format-citation entry format))
|
|
4468 reftex-found-list "\n"))
|
|
4469 (setq ins-string (reftex-format-citation entry format))))
|
|
4470 (setq ins-string "")
|
|
4471 (message "Quit")))
|
|
4472 (kill-buffer "*RefTeX Select*")
|
|
4473
|
|
4474 (unless no-insert
|
|
4475 (insert ins-string)
|
|
4476 (when (string-match "\\?" ins-string)
|
|
4477 (search-backward "?")
|
|
4478 (delete-char 1)))
|
|
4479 (message "")
|
|
4480
|
|
4481 ;; Check if the prefix arg was numeric, and call recursively
|
|
4482 (when (and (integerp arg)
|
|
4483 (> arg 1)
|
|
4484 (re-search-backward
|
|
4485 "\\\\\\([a-zA-Z]*cite\\|cite[a-zA-Z]*\\)\\**\\(\\[[^]]*\\]\\)*{\\([^}]*\\)" nil t))
|
|
4486 (goto-char (match-end 0))
|
|
4487 (decf arg)
|
|
4488 (reftex-do-citation arg))
|
|
4489
|
|
4490 ;; Return the citation key
|
|
4491 (or (eq entry 'all)
|
|
4492 (reftex-get-bib-field "&key" entry)))))
|
|
4493
|
|
4494 (defun reftex-insert-bib-matches (list)
|
|
4495 ;; Insert the bib matches and number them correctly
|
|
4496 (let ((cnt -1) tmp)
|
|
4497 (mapcar '(lambda (x)
|
|
4498 (setq tmp (cdr (assoc "&formatted" x)))
|
|
4499 (incf cnt)
|
|
4500 (put-text-property 0 (length tmp) 'cnt cnt tmp)
|
|
4501 (insert tmp))
|
|
4502 list)))
|
|
4503
|
|
4504 (defun reftex-format-names (namelist n)
|
|
4505 (interactive)
|
|
4506 (let (last (len (length namelist)))
|
|
4507 (cond
|
|
4508 ((= 1 len) (car namelist))
|
|
4509 ((> len n) (concat (car namelist) (nth 2 reftex-cite-punctuation)))
|
|
4510 (t
|
|
4511 (setq n (min len n)
|
|
4512 last (nth (1- n) namelist))
|
|
4513 (setcdr (nthcdr (- n 2) namelist) nil)
|
|
4514 (concat
|
|
4515 (mapconcat 'identity namelist (nth 0 reftex-cite-punctuation))
|
|
4516 (nth 1 reftex-cite-punctuation)
|
|
4517 last)))))
|
|
4518
|
|
4519 (defun reftex-format-citation (entry format)
|
|
4520 ;; Format a citation from the info in the BibTeX ENTRY
|
|
4521
|
|
4522 (unless (stringp format) (setq format "\\cite{%l}"))
|
|
4523
|
|
4524 (if (and reftex-comment-citations
|
|
4525 (string-match "%l" reftex-cite-comment-format))
|
|
4526 (error "reftex-cite-comment-format contains illeagal %%l"))
|
|
4527
|
|
4528 (while (string-match
|
|
4529 "\\(\\`\\|[^%]\\)\\(\\(%\\([0-9]*\\)\\([a-zA-Z]\\)\\)[.,;: ]*\\)"
|
|
4530 format)
|
|
4531 (let ((n (string-to-int (match-string 4 format)))
|
|
4532 (l (string-to-char (match-string 5 format)))
|
|
4533 rpl b e)
|
|
4534 (save-match-data
|
|
4535 (setq rpl
|
155
|
4536 (cond
|
207
|
4537 ((= l ?l) (concat
|
|
4538 (reftex-get-bib-field "&key" entry)
|
|
4539 (if reftex-comment-citations
|
|
4540 reftex-cite-comment-format
|
|
4541 "")))
|
|
4542 ((= l ?a) (reftex-format-names
|
|
4543 (reftex-get-bib-names "author" entry)
|
|
4544 (or n 2)))
|
|
4545 ((= l ?A) (car (reftex-get-bib-names "author" entry)))
|
|
4546 ((= l ?b) (reftex-get-bib-field "booktitle" entry))
|
|
4547 ((= l ?c) (reftex-get-bib-field "chapter" entry))
|
|
4548 ((= l ?d) (reftex-get-bib-field "edition" entry))
|
|
4549 ((= l ?e) (reftex-format-names
|
|
4550 (reftex-get-bib-names "editor" entry)
|
|
4551 (or n 2)))
|
|
4552 ((= l ?E) (car (reftex-get-bib-names "editor" entry)))
|
|
4553 ((= l ?h) (reftex-get-bib-field "howpublished" entry))
|
|
4554 ((= l ?i) (reftex-get-bib-field "institution" entry))
|
|
4555 ((= l ?j) (reftex-get-bib-field "journal" entry))
|
|
4556 ((= l ?k) (reftex-get-bib-field "key" entry))
|
|
4557 ((= l ?m) (reftex-get-bib-field "month" entry))
|
|
4558 ((= l ?n) (reftex-get-bib-field "number" entry))
|
|
4559 ((= l ?o) (reftex-get-bib-field "organization" entry))
|
|
4560 ((= l ?p) (reftex-get-bib-field "pages" entry))
|
|
4561 ((= l ?P) (car (split-string
|
|
4562 (reftex-get-bib-field "pages" entry)
|
|
4563 "[- .]+")))
|
|
4564 ((= l ?s) (reftex-get-bib-field "school" entry))
|
|
4565 ((= l ?u) (reftex-get-bib-field "publisher" entry))
|
|
4566 ((= l ?r) (reftex-get-bib-field "address" entry))
|
|
4567 ((= l ?t) (reftex-get-bib-field "title" entry))
|
|
4568 ((= l ?v) (reftex-get-bib-field "volume" entry))
|
|
4569 ((= l ?y) (reftex-get-bib-field "year" entry)))))
|
|
4570
|
|
4571 (if (string= rpl "")
|
|
4572 (setq b (match-beginning 2) e (match-end 2))
|
|
4573 (setq b (match-beginning 3) e (match-end 3)))
|
|
4574 (setq format (concat (substring format 0 b) rpl (substring format e)))))
|
|
4575 (while (string-match "%%" format)
|
|
4576 (setq format (replace-match "%" t t format)))
|
|
4577 (while (string-match "[ ,.;:]*%<" format)
|
|
4578 (setq format (replace-match "" t t format)))
|
|
4579 format)
|
|
4580
|
|
4581 ;; This is slow and not recommended for follow mode
|
155
|
4582 (defun reftex-bibtex-selection-callback (cnt)
|
|
4583 ;; Callback function to be called from the BibTeX selection, in
|
165
|
4584 ;; order to display context. This function is relatively slow and not
|
155
|
4585 ;; recommended for follow mode, just for individual lookups.
|
|
4586 (let ((win (selected-window))
|
165
|
4587 (key (reftex-get-bib-field "&key" (nth cnt reftex-found-list)))
|
155
|
4588 (bibfile-list (save-excursion
|
|
4589 (set-buffer reftex-call-back-to-this-buffer)
|
|
4590 (reftex-get-bibfile-list))))
|
|
4591 (reftex-pop-to-bibtex-entry key bibfile-list
|
|
4592 (not reftex-keep-temporary-buffers) t)
|
|
4593 (select-window win)))
|
|
4594
|
|
4595 ;;; ===========================================================================
|
|
4596 ;;;
|
|
4597 ;;; Here is the routine used for selection
|
|
4598
|
|
4599 ;; Marker for return point from recursive edit
|
|
4600 (defvar reftex-recursive-edit-marker (make-marker))
|
|
4601
|
|
4602 (defun reftex-check-recursive-edit ()
|
165
|
4603 ;; Check if we are already in a recursive edit. Abort with helpful
|
155
|
4604 ;; message if so.
|
|
4605 (if (marker-position reftex-recursive-edit-marker)
|
|
4606 (error
|
|
4607 (substitute-command-keys
|
|
4608 "In unfinished recursive edit. Finish (\\[exit-recursive-edit]) or abort (\\[abort-recursive-edit])."))))
|
|
4609
|
207
|
4610 (defun reftex-select-item (prompt next-re size help-string
|
155
|
4611 event-list &optional offset
|
207
|
4612 call-back cb-flag match-everywhere)
|
|
4613 ;; Select an item. Show PROMPT to user, find next item with NEXT-RE
|
|
4614 ;; regular expression, return on any of the events listed in
|
|
4615 ;; EVENT-LIST. The function returns the event along with an integer
|
|
4616 ;; indicating which item was selected. When OFFSET is specified,
|
|
4617 ;; starts at that item in the list. When CALL-BACK is given, it is a
|
|
4618 ;; function which is called with the index of the element.
|
|
4619
|
|
4620 (let* (key key-sq b e ev cnt last-cnt cmd skip-callback
|
|
4621 (search-str "") tmp search-start matched forward mini-map last-key
|
|
4622 (offset1 (or offset 1)) win1 win2)
|
|
4623
|
|
4624 ;; Set up a minibuffer keymap for the search stuff
|
|
4625 (setq mini-map (copy-keymap minibuffer-local-map))
|
|
4626 (define-key mini-map "\C-s"
|
|
4627 '(lambda () (interactive) (setq forward t) (exit-minibuffer)))
|
|
4628 (define-key mini-map "\C-r"
|
|
4629 '(lambda () (interactive) (setq forward nil) (exit-minibuffer)))
|
|
4630 (define-key mini-map "\C-m" 'exit-minibuffer)
|
|
4631
|
155
|
4632 (setq ev
|
|
4633 (catch 'exit
|
|
4634 (save-window-excursion
|
|
4635 (setq truncate-lines t)
|
|
4636 (goto-char 1)
|
207
|
4637 (unless (re-search-forward next-re nil t offset1)
|
|
4638 ;; in case the offset is illegal
|
|
4639 (setq offset1 1)
|
|
4640 (re-search-forward next-re nil t offset1))
|
155
|
4641 (beginning-of-line 1)
|
|
4642 (while t
|
207
|
4643 (setq last-cnt (or cnt last-cnt))
|
|
4644 (setq cnt (get-text-property (point) 'cnt))
|
|
4645 (if (and cnt cb-flag call-back (not skip-callback))
|
155
|
4646 (funcall call-back cnt))
|
207
|
4647 (setq skip-callback nil)
|
|
4648 (if cnt
|
|
4649 (setq b (or (previous-single-property-change
|
|
4650 (1+ (point)) 'cnt)
|
|
4651 (point-min))
|
|
4652 e (or (next-single-property-change
|
|
4653 (point) 'cnt)
|
|
4654 (point-max)))
|
|
4655 (setq b (point) e (point)))
|
155
|
4656 (reftex-highlight 1 b e)
|
|
4657 (if (or (not (pos-visible-in-window-p b))
|
|
4658 (not (pos-visible-in-window-p e)))
|
|
4659 (recenter (/ (window-height) 2)))
|
|
4660 (setq key-sq (read-key-sequence prompt))
|
207
|
4661 (setq last-key key)
|
155
|
4662 (setq key (car
|
|
4663 (cond
|
207
|
4664 ((fboundp 'event-to-character) ; XEmacs
|
|
4665 (mapcar 'event-to-character key-sq))
|
155
|
4666 ((fboundp 'listify-key-sequence) ; Emacs
|
|
4667 (listify-key-sequence key-sq))
|
|
4668 (t (error "Please report this problem to dominik@strw.leidenuniv.nl")))))
|
|
4669
|
|
4670 (setq cmd (key-binding key-sq))
|
|
4671
|
207
|
4672 (reftex-unhighlight 2)
|
155
|
4673 (reftex-unhighlight 0)
|
|
4674
|
|
4675 (cond
|
|
4676
|
207
|
4677 ;; Single line motions
|
|
4678 ((or (eq key ?n)
|
|
4679 (eq key ?\C-i)
|
|
4680 (eq cmd 'next-line))
|
|
4681 (or (eobp) (forward-char 1))
|
|
4682 (re-search-forward next-re nil t 1)
|
155
|
4683 (beginning-of-line 1))
|
207
|
4684 ((or (eq key ?p)
|
|
4685 (eq cmd 'previous-line))
|
|
4686 (re-search-backward next-re nil t))
|
|
4687
|
|
4688 ;; Page motions
|
|
4689 ((eq cmd 'scroll-up)
|
155
|
4690 (while (and (pos-visible-in-window-p)
|
207
|
4691 (re-search-forward next-re nil t)))
|
155
|
4692 (beginning-of-line 1)
|
|
4693 (recenter 1))
|
207
|
4694 ((eq cmd 'scroll-down)
|
155
|
4695 (while (and (pos-visible-in-window-p)
|
207
|
4696 (re-search-backward next-re nil t)))
|
155
|
4697 (recenter (- (window-height) size 2)))
|
|
4698
|
207
|
4699 ;; Begin and end of buffer
|
|
4700 ((eq cmd 'beginning-of-buffer)
|
|
4701 (goto-char (point-min))
|
|
4702 (re-search-forward next-re nil t)
|
|
4703 (beginning-of-line 1))
|
|
4704 ((eq cmd 'end-of-buffer)
|
|
4705 (goto-char (point-max))
|
|
4706 (re-search-backward next-re nil t))
|
|
4707
|
|
4708 ;; Exit
|
|
4709 ((eq key ?q)
|
155
|
4710 (throw 'exit nil))
|
207
|
4711 ((eq key ?\C-g)
|
|
4712 (if (or (eq last-key ?\C-s) (eq last-key ?\C-r))
|
|
4713 (ding)
|
|
4714 (bury-buffer)
|
|
4715 (error "Abort")))
|
|
4716 ((or (eq key ?\C-m)
|
|
4717 (eq key 'return)
|
|
4718 (eq cmd 'newline))
|
155
|
4719 (throw 'exit 'return))
|
207
|
4720 ((memq key event-list)
|
|
4721 (throw 'exit key))
|
|
4722
|
|
4723 ;; Callback
|
|
4724 ((or (eq key ?C) ; backward compatibility
|
|
4725 (eq key ?f))
|
155
|
4726 (setq cb-flag (not cb-flag)))
|
207
|
4727 ((eq key ?\ )
|
|
4728 (if cnt (funcall call-back cnt) (ding)))
|
|
4729
|
|
4730 ;; Help
|
|
4731 ((eq key ?\?)
|
|
4732 (with-output-to-temp-buffer "*RefTeX Help*"
|
|
4733 (princ help-string))
|
|
4734 (setq win1 (selected-window)
|
|
4735 win2 (get-buffer-window "*RefTeX Help*" t))
|
|
4736 (select-window win2)
|
|
4737 (unless (and (pos-visible-in-window-p 1)
|
|
4738 (pos-visible-in-window-p (point-max)))
|
|
4739 (enlarge-window (1+ (- (count-lines 1 (point-max))
|
|
4740 (window-height)))))
|
|
4741 (select-window win1)
|
|
4742 (setq skip-callback t))
|
|
4743
|
|
4744 ;; Searching
|
|
4745 ((or (setq forward (eq key ?\C-s)) (eq key ?\C-r))
|
|
4746 (if (or (and (not (eq last-key ?\C-s))
|
|
4747 (not (eq last-key ?\C-r)))
|
|
4748 (string= search-str ""))
|
|
4749 (setq tmp ; get a new string
|
|
4750 (read-from-minibuffer
|
|
4751 (if (string= search-str "")
|
|
4752 "Search: "
|
|
4753 (format "Search [%s]:" search-str))
|
|
4754 nil mini-map)
|
|
4755 search-str (if (string= tmp "")
|
|
4756 search-str tmp)))
|
|
4757 (setq search-start (point))
|
|
4758 (and (not (string= search-str ""))
|
|
4759 (progn
|
|
4760 (while
|
|
4761 (and (setq matched
|
|
4762 (if forward
|
|
4763 (search-forward search-str nil 1)
|
|
4764 (search-backward search-str nil 1)))
|
|
4765 (or (>= (save-excursion
|
|
4766 (goto-char (match-beginning 0))
|
|
4767 (current-column))
|
|
4768 (window-width))
|
|
4769 (not (or (get-text-property (point) 'cnt)
|
|
4770 match-everywhere)))))
|
|
4771 (if matched
|
|
4772 (reftex-highlight 2 (match-beginning 0)
|
|
4773 (match-end 0))
|
|
4774 (ding)
|
|
4775 (goto-char search-start)))))
|
|
4776
|
|
4777 ;; Recursive edit
|
|
4778 ((eq key ?e)
|
155
|
4779 (set-marker reftex-recursive-edit-marker (point))
|
|
4780 (unwind-protect
|
|
4781 (progn
|
|
4782 (save-window-excursion
|
|
4783 (save-excursion
|
|
4784 (other-window 1)
|
|
4785 (message
|
|
4786 (substitute-command-keys
|
165
|
4787 "Recursive edit. Return to selection with \\[exit-recursive-edit]"))
|
155
|
4788 (recursive-edit)))
|
207
|
4789 (unless (equal (marker-buffer
|
|
4790 reftex-recursive-edit-marker)
|
|
4791 (current-buffer))
|
|
4792 (error "Cannot continue RefTeX from this buffer."))
|
155
|
4793 (goto-char reftex-recursive-edit-marker))
|
|
4794 (set-marker reftex-recursive-edit-marker nil)))
|
|
4795
|
|
4796 (t
|
|
4797 (ding)))))))
|
207
|
4798 (and (get-buffer "*RefTeX Help*") (kill-buffer "*RefTeX Help*"))
|
155
|
4799 (message "")
|
207
|
4800 (list ev cnt last-cnt)))
|
155
|
4801
|
|
4802 ;;; ===========================================================================
|
|
4803 ;;;
|
|
4804 ;;; View cross references
|
|
4805
|
|
4806 (defun reftex-view-crossref (&optional arg)
|
|
4807 "View cross reference of \\ref or \\cite macro at point.
|
|
4808 If the macro at point is a \\ref, show the corresponding label definition.
|
|
4809 If it is a \\cite, show the BibTeX database entry.
|
|
4810 If there is no such macro at point, search forward to find one.
|
|
4811 When you call this function several times in direct successtion, point will
|
|
4812 move to view subsequent cross references further down in the buffer.
|
207
|
4813 To cope with the plethora of variations in packages, this function
|
|
4814 assumes any macro either starting with ending in `ref' or `cite' to contain
|
|
4815 cross references.
|
155
|
4816 With argument, actually select the window showing the cross reference."
|
|
4817
|
|
4818 (interactive "P")
|
|
4819
|
|
4820 ;; See where we are.
|
207
|
4821 (let* ((re "\\\\\\([a-z]*\\(cite\\|ref\\)\\|\\(cite\\|ref\\)[a-z]*\\)\\**\\(\\[[^{}]*\\]\\)?{")
|
|
4822 (macro (car (car (reftex-what-macro t))))
|
|
4823 (this-word (reftex-this-word "*a-zA-Z\\\\"))
|
|
4824 (my-window (selected-window))
|
|
4825 pop-window cmd args point)
|
|
4826
|
|
4827 (if (and macro
|
|
4828 (string-match "\\`\\\\cite\\|\\`\\\\ref\\|cite\\'\\|ref\\'"
|
|
4829 macro))
|
|
4830 (and (setq macro (match-string 0 macro))
|
|
4831 (string-match "\\`\\\\" macro)
|
|
4832 (setq macro (substring macro 1)))
|
|
4833 (setq macro nil))
|
155
|
4834
|
|
4835 (if (and macro (eq last-command this-command))
|
207
|
4836 (if (string= macro "cite")
|
|
4837 (progn
|
|
4838 (skip-chars-forward "^},%")
|
|
4839 (while (and (eq (following-char) ?%)
|
|
4840 (or (beginning-of-line 2) t)
|
|
4841 (skip-chars-forward " \t\n\r")))
|
|
4842 (skip-chars-forward ",")
|
|
4843 (if (eq (following-char) ?})
|
|
4844 (setq macro nil)))
|
|
4845 (setq macro nil)))
|
|
4846
|
|
4847 (if (and (not macro)
|
|
4848 (or (not (string-match "\\`\\\\" this-word))
|
|
4849 (eq (following-char) ?\\)
|
|
4850 (search-backward "\\" nil t)
|
|
4851 t))
|
|
4852 (if (interactive-p)
|
|
4853 ;; Only move far if this function was called directly
|
|
4854 (and (re-search-forward re nil t)
|
|
4855 (setq macro (or (match-string 2) (match-string 3))))
|
|
4856 ;; The macro needs to be at point
|
|
4857 (and (looking-at re)
|
|
4858 (setq macro (or (match-string 2) (match-string 3)))
|
|
4859 (goto-char (match-end 0)))))
|
|
4860
|
|
4861
|
|
4862 (unless macro
|
|
4863 (error "No cross reference to display"))
|
155
|
4864
|
|
4865 ;; Ensure access to scanning info
|
|
4866 (reftex-access-scan-info)
|
|
4867
|
207
|
4868 (cond
|
155
|
4869 ((string= macro "cite")
|
|
4870 (setq cmd 'reftex-pop-to-bibtex-entry
|
207
|
4871 args (list
|
|
4872 (reftex-this-word "^{},%\n\r")
|
|
4873 (reftex-get-bibfile-list) nil t)))
|
155
|
4874 ((string= macro "ref")
|
207
|
4875 (let* ((label (reftex-this-word "^{}%\n\r"))
|
|
4876 (xr-data (assoc 'xr (symbol-value reftex-docstruct-symbol)))
|
|
4877 (xr-re (nth 2 xr-data))
|
|
4878 (entry (assoc label (symbol-value reftex-docstruct-symbol))))
|
|
4879 (if (and (not entry) (string-match xr-re label))
|
|
4880 ;; Label is defined in external document
|
|
4881 (save-excursion
|
|
4882 (save-match-data
|
|
4883 (set-buffer
|
|
4884 (or (reftex-get-file-buffer-force
|
|
4885 (cdr (assoc (match-string 1 label) (nth 1 xr-data))))
|
|
4886 (error "Problem with external label %s" label))))
|
|
4887 (setq label (substring label (match-end 1)))
|
|
4888 (reftex-access-scan-info)
|
|
4889 (setq entry
|
|
4890 (assoc label (symbol-value reftex-docstruct-symbol)))))
|
155
|
4891 (if entry
|
|
4892 (setq cmd 'reftex-pop-to-label
|
207
|
4893 args (list label (list (nth 3 entry)) nil t))
|
|
4894 (error "Label %s not known - reparse document might help" label))))
|
|
4895 (t (error "This should not happen (reftex-view-crossref)")))
|
155
|
4896 (setq point (point))
|
|
4897 (apply cmd args)
|
|
4898 (setq pop-window (selected-window))
|
|
4899 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)
|
|
4900 (select-window my-window)
|
|
4901 (goto-char point)
|
|
4902 (and arg (select-window pop-window))))
|
|
4903
|
|
4904 (defun reftex-mouse-view-crossref (ev)
|
|
4905 "View cross reference of \\ref or \\cite macro where you click.
|
|
4906 If the macro at point is a \\ref, show the corresponding label definition.
|
|
4907 If it is a \\cite, show the BibTeX database entry.
|
|
4908 If there is no such macro at point, search forward to find one.
|
|
4909 With argument, actually select the window showing the cross reference."
|
|
4910 (interactive "e")
|
|
4911 (mouse-set-point ev)
|
207
|
4912 (setq last-command 'self-insert-command) ;; make sure we do not move!
|
155
|
4913 (reftex-view-crossref current-prefix-arg))
|
|
4914
|
|
4915 ;;; ===========================================================================
|
|
4916 ;;;
|
|
4917 ;;; Functions that check out the surroundings
|
|
4918
|
|
4919 (defun reftex-what-macro (which &optional bound)
|
|
4920 ;; Find out if point is within the arguments of any TeX-macro.
|
165
|
4921 ;; The return value is either ("\\macro" . (point)) or a list of them.
|
155
|
4922
|
|
4923 ;; If WHICH is nil, immediately return nil.
|
|
4924 ;; If WHICH is t, return list of all macros enclosing point.
|
|
4925 ;; If WHICH is a list of macros, look only for those macros and return the
|
|
4926 ;; name of the first macro in this list found to enclose point.
|
|
4927 ;; If the optional BOUND is an integer, bound backwards directed
|
165
|
4928 ;; searches to this point. If it is nil, limit to nearest \section -
|
155
|
4929 ;; like statement.
|
|
4930
|
|
4931 ;; This function is pretty stable, but can be fooled if the text contains
|
165
|
4932 ;; things like \macro{aa}{bb} where \macro is defined to take only one
|
|
4933 ;; argument. As RefTeX cannot know this, the string "bb" would still be
|
|
4934 ;; considered an argument of macro \macro.
|
155
|
4935
|
|
4936 (catch 'exit
|
|
4937 (if (null which) (throw 'exit nil))
|
|
4938 (let ((bound (or bound (save-excursion (re-search-backward
|
|
4939 reftex-section-regexp nil 1)
|
|
4940 (point))))
|
207
|
4941 pos cmd-list cmd cnt cnt-opt entry)
|
155
|
4942 (save-restriction
|
|
4943 (save-excursion
|
|
4944 (narrow-to-region (max 1 bound) (point-max))
|
|
4945 ;; move back out of the current parenthesis
|
|
4946 (while (condition-case nil
|
|
4947 (progn (up-list -1) t)
|
|
4948 (error nil))
|
207
|
4949 (setq cnt 1 cnt-opt 0)
|
155
|
4950 ;; move back over any touching sexps
|
207
|
4951 (while (and (reftex-move-to-previous-arg bound)
|
|
4952 (condition-case nil
|
|
4953 (progn (backward-sexp) t)
|
|
4954 (error nil)))
|
|
4955 (if (eq (following-char) ?\[) (incf cnt-opt))
|
|
4956 (incf cnt))
|
155
|
4957 (setq pos (point))
|
207
|
4958 (when (and (or (= (following-char) ?\[)
|
|
4959 (= (following-char) ?\{))
|
|
4960 (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
|
|
4961 (setq cmd (reftex-match-string 0))
|
|
4962 (when (looking-at "\\\\begin{[^}]*}")
|
|
4963 (setq cmd (reftex-match-string 0)
|
|
4964 cnt (1- cnt)))
|
|
4965 ;; This does ignore optional arguments. Very hard to fix.
|
|
4966 (when (setq entry (assoc cmd reftex-env-or-mac-alist))
|
|
4967 (if (> cnt (or (nth 4 entry) 100))
|
|
4968 (setq cmd nil)))
|
|
4969 (cond
|
|
4970 ((null cmd))
|
|
4971 ((eq t which)
|
|
4972 (push (cons cmd (point)) cmd-list))
|
|
4973 ((member cmd which)
|
|
4974 (throw 'exit (cons cmd (point))))))
|
155
|
4975 (goto-char pos)))
|
|
4976 (nreverse cmd-list)))))
|
|
4977
|
|
4978 (defun reftex-what-environment (which &optional bound)
|
|
4979 ;; Find out if point is inside a LaTeX environment.
|
165
|
4980 ;; The return value is (e.g.) either ("equation" . (point)) or a list of
|
155
|
4981 ;; them.
|
|
4982
|
|
4983 ;; If WHICH is nil, immediately return nil.
|
|
4984 ;; If WHICH is t, return list of all environments enclosing point.
|
|
4985 ;; If WHICH is a list of environments, look only for those environments and
|
|
4986 ;; return the name of the first environment in this list found to enclose
|
|
4987 ;; point.
|
|
4988
|
|
4989 ;; If the optional BOUND is an integer, bound backwards directed searches to
|
165
|
4990 ;; this point. If it is nil, limit to nearest \section - like statement.
|
155
|
4991
|
|
4992 (catch 'exit
|
|
4993 (save-excursion
|
|
4994 (if (null which) (throw 'exit nil))
|
|
4995 (let ((bound (or bound (save-excursion (re-search-backward
|
|
4996 reftex-section-regexp nil 1)
|
|
4997 (point))))
|
|
4998 env-list end-list env)
|
|
4999 (while (re-search-backward "\\\\\\(begin\\|end\\){\\([^}]+\\)}"
|
|
5000 bound t)
|
|
5001 (setq env (buffer-substring-no-properties
|
|
5002 (match-beginning 2) (match-end 2)))
|
|
5003 (cond
|
|
5004 ((string= (match-string 1) "end")
|
|
5005 (add-to-list 'end-list env))
|
|
5006 ((member env end-list)
|
|
5007 (setq end-list (delete env end-list)))
|
|
5008 ((eq t which)
|
207
|
5009 (push (cons env (point)) env-list))
|
155
|
5010 ((member env which)
|
|
5011 (throw 'exit (cons env (point))))))
|
|
5012 (nreverse env-list)))))
|
|
5013
|
|
5014 (defun reftex-word-before-point ()
|
165
|
5015 ;; Return the word before point. Word means here:
|
155
|
5016 ;; Consists of [a-zA-Z0-9.:] and ends at point or whitespace.
|
|
5017 (let ((pos (point)))
|
|
5018 (save-excursion
|
|
5019 (re-search-backward "[^ \t\n\r]" (point-min) 1)
|
207
|
5020 (setq pos (min (1+ (point)) (point-max)))
|
155
|
5021 (if (re-search-backward "[^a-zA-Z0-9\\\.:]" (point-min) 1)
|
|
5022 (forward-char 1))
|
|
5023 (buffer-substring-no-properties (point) pos))))
|
|
5024
|
|
5025 ;; ============================================================================
|
|
5026 ;;
|
|
5027 ;; Some generally useful functions
|
|
5028
|
|
5029 (defun reftex-no-props (string)
|
|
5030 ;; Return STRING with all text properties removed
|
|
5031 (and (stringp string)
|
|
5032 (set-text-properties 0 (length string) nil string))
|
|
5033 string)
|
|
5034
|
207
|
5035 (defun reftex-match-string (n)
|
|
5036 ;; Match string without properties
|
|
5037 (when (match-beginning n)
|
|
5038 (buffer-substring-no-properties (match-beginning n) (match-end n))))
|
|
5039
|
|
5040 (defun reftex-this-word (&optional class)
|
|
5041 ;; Grab the word around point.
|
|
5042 (setq class (or class "-a-zA-Z0-9:_/.*;|"))
|
|
5043 (save-excursion
|
|
5044 (buffer-substring-no-properties
|
|
5045 (progn (skip-chars-backward class) (point))
|
|
5046 (progn (skip-chars-forward class) (point)))))
|
|
5047
|
|
5048 (defvar enable-multibyte-characters)
|
|
5049 (defun reftex-truncate (string ncols &optional ellipses padding)
|
|
5050 ;; Truncate a string to NCHAR characters.
|
|
5051 ;; Works fast with ASCII and correctly with Mule characters.
|
|
5052 ;; When ELLIPSES is non-nil, put three dots at the end of the string.
|
|
5053 (setq string
|
|
5054 (cond
|
|
5055 ((and (boundp 'enable-multibyte-characters)
|
|
5056 enable-multibyte-characters)
|
|
5057 (if (<= (string-width string) ncols)
|
|
5058 string
|
|
5059 (if ellipses
|
|
5060 (concat (truncate-string-to-width string (- ncols 3)) "...")
|
|
5061 (truncate-string-to-width string ncols))))
|
|
5062 (t
|
|
5063 (if (<= (length string) ncols)
|
|
5064 string
|
|
5065 (if ellipses
|
|
5066 (concat (substring string 0 (- ncols 3)) "...")
|
|
5067 (substring string 0 ncols))))))
|
|
5068 (if padding
|
|
5069 (format (format "%%-%ds" ncols) string)
|
|
5070 string))
|
|
5071
|
|
5072 (defun reftex-nearest-match (regexp &optional pos)
|
|
5073 ;; Find the nearest match of REGEXP. Set the match data.
|
|
5074 ;; If POS is given, calculate distances relative to it.
|
|
5075 ;; Return nil if there is no match.
|
|
5076 (let ((start (point)) (pos (or pos (point))) match1 match2 match)
|
|
5077 (goto-char start)
|
|
5078 (when (re-search-backward regexp nil t)
|
|
5079 (setq match1 (match-data)))
|
|
5080 (goto-char start)
|
|
5081 (when (re-search-forward regexp nil t)
|
|
5082 (setq match2 (match-data)))
|
|
5083 (goto-char start)
|
|
5084 (setq match
|
|
5085 (cond
|
|
5086 ((not match1) match2)
|
|
5087 ((not match2) match1)
|
|
5088 ((< (abs (- pos (car match1))) (abs (- pos (car match2)))) match1)
|
|
5089 (t match2)))
|
|
5090 (if match (progn (store-match-data match) t) nil)))
|
|
5091
|
|
5092 (defun reftex-auto-mode-alist ()
|
|
5093 ;; Return an `auto-mode-alist' with only the .gz (etc) thingies.
|
|
5094 ;; Stolen from gnus nnheader.
|
|
5095 (let ((alist auto-mode-alist)
|
|
5096 out)
|
|
5097 (while alist
|
|
5098 (when (listp (cdr (car alist)))
|
|
5099 (push (car alist) out))
|
|
5100 (pop alist))
|
|
5101 (nreverse out)))
|
|
5102
|
|
5103 (defun reftex-access-search-path (which &optional recurse file)
|
|
5104 ;; Access path from environment variables. WHICH is either "tex" or "bib".
|
|
5105 ;; When RECURSE is t, expand recursive paths, ending in double slash
|
|
5106 ;; FILE is just for the message.
|
|
5107 (let* ((pathvar (intern (concat "reftex-" which "-path")))
|
|
5108 (status (get pathvar 'status)))
|
|
5109 (cond
|
|
5110 ((eq status 'recursed))
|
|
5111 ((and status (null recurse)))
|
|
5112 ((null status)
|
|
5113 (let ((env-vars (if (equal which "tex") (list "TEXINPUTS")
|
|
5114 reftex-bibpath-environment-variables)))
|
|
5115 (set pathvar (reftex-parse-colon-path
|
|
5116 (mapconcat '(lambda(x) (or (getenv x) ""))
|
|
5117 env-vars path-separator))))
|
|
5118 (put pathvar 'status 'split))
|
|
5119 ((and (eq 'split status) recurse)
|
|
5120 (message "Expanding search path to find %s file: %s ..." which file)
|
|
5121 (set pathvar (reftex-expand-path (symbol-value pathvar)))
|
|
5122 (put pathvar 'status 'recursed)))))
|
|
5123
|
|
5124 (defun reftex-find-file-on-path (file path)
|
|
5125 ;; Find FILE along the directory list PATH.
|
|
5126 (catch 'exit
|
|
5127 (when (file-name-absolute-p file)
|
|
5128 (if (file-exists-p file)
|
|
5129 (throw 'exit file)
|
|
5130 (throw 'exit nil)))
|
|
5131 (let* ((thepath path) file1 dir
|
|
5132 (doubleslash (concat "/" "/")))
|
|
5133 (while (setq dir (pop thepath))
|
|
5134 (when (string= (substring dir -2) doubleslash)
|
|
5135 (setq dir (substring dir 0 -1)))
|
|
5136 (setq file1 (expand-file-name file dir))
|
|
5137 (if (file-exists-p file1)
|
|
5138 (throw 'exit file1)))
|
|
5139 ;; No such file
|
|
5140 nil)))
|
|
5141
|
|
5142 (defun reftex-parse-colon-path (path)
|
|
5143 ;; Like parse-colon-parse, but // or /~ have no effects.
|
|
5144 (mapcar 'file-name-as-directory
|
|
5145 (delete "" (split-string path (concat path-separator "+")))))
|
|
5146
|
|
5147 (defun reftex-expand-path (path)
|
|
5148 ;; Expand parts of path ending in a double slash
|
|
5149 (let (path1 dir dirs (doubleslash (concat "/" "/")))
|
|
5150 (while (setq dir (pop path))
|
|
5151 (if (string= (substring dir -2) doubleslash)
|
|
5152 (progn
|
|
5153 (setq dir (substring dir 0 -1))
|
|
5154 (setq dirs (reftex-recursive-directory-list dir))
|
|
5155 (setq path1 (append dirs path1)))
|
|
5156 (push dir path1)))
|
|
5157 (nreverse path1)))
|
|
5158
|
|
5159 (defun reftex-recursive-directory-list (dir)
|
|
5160 (let ((path (list dir)) dirs path1)
|
|
5161 (while (setq dir (pop path))
|
|
5162 (setq dirs
|
|
5163 (delete nil
|
|
5164 (mapcar (function
|
|
5165 (lambda (x)
|
|
5166 (if (and (file-directory-p x)
|
|
5167 (not (string-match "/\\.+\\'" x)))
|
|
5168 (file-name-as-directory x)
|
|
5169 nil)))
|
|
5170 (directory-files dir t))))
|
|
5171 (setq path (append dirs path))
|
|
5172 (push dir path1))
|
|
5173 path1))
|
|
5174
|
|
5175 (defun reftex-make-regexp-allow-for-ctrl-m (string)
|
|
5176 ;; convert STRING into a regexp, allowing ^M for \n and vice versa
|
155
|
5177 (let ((start -2))
|
|
5178 (setq string (regexp-quote string))
|
|
5179 (while (setq start (string-match "[\n\r]" string (+ 3 start)))
|
|
5180 (setq string (replace-match "[\n\r]" nil t string)))
|
|
5181 string))
|
|
5182
|
207
|
5183 (defun reftex-make-desparate-section-regexp (old)
|
|
5184 ;; Return a regexp which will still match a section statement even if
|
|
5185 ;; x-symbol or isotex or the like have been at work in the mean time.
|
|
5186 (let* ((n (1+ (string-match "[[{]" old)))
|
|
5187 (new (regexp-quote (substring old 0 (1+ (string-match "[[{]" old)))))
|
|
5188 (old (substring old n)))
|
|
5189 (while (string-match
|
|
5190 "\\([\r\n]\\)\\|\\(\\`\\|[ \t\n\r]\\)\\([a-zA-Z0-9]+\\)\\([ \t\n\r]\\|}\\'\\)"
|
|
5191 old)
|
|
5192 (if (match-beginning 1)
|
|
5193 (setq new (concat new "[^\n\r]*[\n\r]"))
|
|
5194 (setq new (concat new "[^\n\r]*" (match-string 3 old))))
|
|
5195 (setq old (substring old (match-end 0))))
|
|
5196 new))
|
|
5197
|
155
|
5198 (defun reftex-delete-list (elt-list list)
|
|
5199 ;; like delete, but with a list of things to delete
|
|
5200 ;; (original code from Rory Molinari)
|
|
5201 (while elt-list
|
|
5202 (setq list (delete (car elt-list) list)
|
|
5203 elt-list (cdr elt-list)))
|
|
5204 list)
|
|
5205
|
|
5206 (defun reftex-get-buffer-visiting (file)
|
|
5207 ;; return a buffer visiting FILE
|
|
5208 (cond
|
|
5209 ((boundp 'find-file-compare-truenames) ; XEmacs
|
|
5210 (let ((find-file-compare-truenames t))
|
|
5211 (get-file-buffer file)))
|
207
|
5212 ((fboundp 'find-buffer-visiting) ; Emacs
|
|
5213 (find-buffer-visiting file))
|
155
|
5214 (t (error "Please report this problem to dominik@strw.leidenuniv.nl"))))
|
|
5215
|
|
5216 (defun reftex-get-file-buffer-force (file &optional mark-to-kill)
|
165
|
5217 ;; Return a buffer visiting file. Make one, if necessary.
|
207
|
5218 ;; If neither such a buffer nor the file exist, return nil.
|
|
5219 ;; If MARK-TO-KILL is t and there is no live buffer, load the file with
|
|
5220 ;; initializations according to `reftex-initialize-temporary-buffers',
|
|
5221 ;; and mark the buffer to be killed after use.
|
155
|
5222
|
|
5223 (let ((buf (reftex-get-buffer-visiting file)))
|
207
|
5224
|
|
5225 (cond (buf
|
|
5226 ;; We have it already as a buffer - just return it
|
|
5227 buf)
|
|
5228
|
|
5229 ((file-readable-p file)
|
|
5230 ;; At least there is such a file and we can read it.
|
|
5231
|
|
5232 (if (or (not mark-to-kill)
|
|
5233 (eq t reftex-initialize-temporary-buffers))
|
|
5234
|
|
5235 ;; Visit the file with full magic
|
|
5236 (setq buf (find-file-noselect file))
|
|
5237
|
|
5238 ;; Else: Visit the file just briefly, without or
|
|
5239 ;; with limited Magic
|
|
5240
|
|
5241 ;; The magic goes away
|
|
5242 (let ((format-alist nil)
|
|
5243 (auto-mode-alist (reftex-auto-mode-alist))
|
|
5244 (default-major-mode 'fundamental-mode)
|
|
5245 (after-insert-file-functions nil))
|
|
5246 (setq buf (find-file-noselect file)))
|
|
5247
|
|
5248 ;; Is there a hook to run?
|
|
5249 (when (listp reftex-initialize-temporary-buffers)
|
|
5250 (save-excursion
|
|
5251 (set-buffer buf)
|
|
5252 (run-hooks 'reftex-initialize-temporary-buffers))))
|
|
5253
|
|
5254 ;; Lets see if we got a license to kill :-|
|
|
5255 (and mark-to-kill
|
|
5256 (add-to-list 'reftex-buffers-to-kill buf))
|
|
5257
|
|
5258 ;; Return the new buffer
|
|
5259 buf)
|
|
5260
|
|
5261 ;; If no such file exists, return nil
|
|
5262 (t nil))))
|
155
|
5263
|
|
5264 (defun reftex-splice-symbols-into-list (list alist)
|
|
5265 ;; Splice the association in ALIST of any symbols in LIST into the list.
|
|
5266 ;; Return new list.
|
|
5267 (let (rtn tmp)
|
|
5268 (while list
|
207
|
5269 (while (and (not (null (car list))) ;; keep list elements nil
|
|
5270 (symbolp (car list)))
|
155
|
5271 (setq tmp (car list))
|
|
5272 (cond
|
|
5273 ((assoc tmp alist)
|
207
|
5274 (setq list (append (nth 2 (assoc tmp alist)) (cdr list))))
|
155
|
5275 (t
|
|
5276 (error "Cannot treat symbol %s in reftex-label-alist"
|
|
5277 (symbol-name tmp)))))
|
207
|
5278 (push (pop list) rtn))
|
155
|
5279 (nreverse rtn)))
|
|
5280
|
|
5281 (defun reftex-uniquify (alist &optional keep-list)
|
165
|
5282 ;; Return a list of all elements in ALIST, but each car only once.
|
|
5283 ;; Elements of KEEP-LIST are not removed even if duplicate.
|
155
|
5284 (let (new elm)
|
|
5285 (while alist
|
207
|
5286 (setq elm (pop alist))
|
155
|
5287 (if (or (member (car elm) keep-list)
|
207
|
5288 (not (assoc (car elm) new)))
|
|
5289 (push elm new)))
|
|
5290 (nreverse new)))
|
155
|
5291
|
|
5292 (defun reftex-use-fonts ()
|
165
|
5293 ;; Return t if we can and want to use fonts.
|
155
|
5294 (and window-system
|
|
5295 reftex-use-fonts
|
207
|
5296 (featurep 'font-lock)))
|
|
5297
|
|
5298 (defun reftex-refontify ()
|
|
5299 ;; Return t if we need to refontify context
|
|
5300 (and (reftex-use-fonts)
|
|
5301 (or (eq t reftex-refontify-context)
|
|
5302 (and (eq 1 reftex-refontify-context)
|
|
5303 (or (featurep 'x-symbol))))))
|
155
|
5304
|
165
|
5305 ;; Highlighting uses overlays. If this is for XEmacs, we need to load
|
155
|
5306 ;; the overlay library, available in version 19.15
|
|
5307 (and (not (fboundp 'make-overlay))
|
|
5308 (condition-case nil
|
|
5309 (require 'overlay)
|
207
|
5310 (error
|
155
|
5311 (error "RefTeX needs overlay emulation (available in XEmacs 19.15)"))))
|
|
5312
|
|
5313 ;; We keep a vector with several different overlays to do our highlighting.
|
207
|
5314 (defvar reftex-highlight-overlays [nil nil nil])
|
155
|
5315
|
|
5316 ;; Initialize the overlays
|
|
5317 (aset reftex-highlight-overlays 0 (make-overlay 1 1))
|
|
5318 (overlay-put (aref reftex-highlight-overlays 0) 'face 'highlight)
|
|
5319 (aset reftex-highlight-overlays 1 (make-overlay 1 1))
|
|
5320 (overlay-put (aref reftex-highlight-overlays 1) 'face 'highlight)
|
207
|
5321 (aset reftex-highlight-overlays 2 (make-overlay 1 1))
|
|
5322 (overlay-put (aref reftex-highlight-overlays 2) 'face
|
|
5323 (if (string-match "XEmacs" emacs-version) 'zmacs-region 'region))
|
155
|
5324
|
|
5325 ;; Two functions for activating and deactivation highlight overlays
|
|
5326 (defun reftex-highlight (index begin end &optional buffer)
|
|
5327 "Highlight a region with overlay INDEX."
|
|
5328 (move-overlay (aref reftex-highlight-overlays index)
|
|
5329 begin end (or buffer (current-buffer))))
|
|
5330 (defun reftex-unhighlight (index)
|
|
5331 "Detatch overlay INDEX."
|
|
5332 (delete-overlay (aref reftex-highlight-overlays index)))
|
|
5333
|
|
5334 (defun reftex-highlight-shall-die ()
|
165
|
5335 ;; Function used in pre-command-hook to remove highlights.
|
155
|
5336 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die)
|
|
5337 (reftex-unhighlight 0))
|
|
5338
|
|
5339 ;;; ---------------------------------------------------------------------------
|
|
5340 ;;;
|
|
5341 ;;; Functions to compile the tables, reset the mode etc.
|
|
5342
|
|
5343 (defun reftex-reset-mode ()
|
165
|
5344 "Reset RefTeX Mode. Required to implement changes to some list variables.
|
|
5345 This function will compile the information in `reftex-label-alist' and similar
|
|
5346 variables. It is called when RefTeX is first used, and after changes to
|
207
|
5347 these variables."
|
155
|
5348 (interactive)
|
|
5349
|
165
|
5350 ;; Record that we have done this
|
155
|
5351 (setq reftex-tables-dirty nil)
|
207
|
5352 (setq reftex-memory
|
|
5353 (list reftex-label-alist reftex-label-alist-external-add-ons
|
|
5354 reftex-default-label-alist-entries))
|
|
5355
|
|
5356 ;; Reset the file search path variables
|
|
5357 (put 'reftex-tex-path 'status nil)
|
|
5358 (put 'reftex-bib-path 'status nil)
|
155
|
5359
|
165
|
5360 ;; Kill temporary buffers associated with RefTeX - just in case they
|
|
5361 ;; were not cleaned up properly
|
207
|
5362 (let ((buffer-list '("*RefTeX Master*" "*RefTeX Help*" "*RefTeX Select*"
|
|
5363 "*Duplicate Labels*" "*toc*" "*RefTeX-scratch*"))
|
|
5364 buf)
|
|
5365 (while (setq buf (pop buffer-list))
|
|
5366 (if (get-buffer buf)
|
|
5367 (kill-buffer buf))))
|
|
5368
|
|
5369 ;; Make sure the current document will be rescanned soon.
|
|
5370 (reftex-reset-scanning-information)
|
|
5371
|
|
5372 ;; Plug functions into AUCTeX if the user option says so.
|
165
|
5373 (reftex-plug-into-AUCTeX)
|
|
5374
|
155
|
5375 (message "updating internal tables...")
|
|
5376 (reftex-compute-ref-cite-tables)
|
207
|
5377 (message "updating internal tables... done"))
|
155
|
5378
|
|
5379 (defun reftex-reset-scanning-information ()
|
|
5380 "Reset the symbols containing information from buffer scanning.
|
|
5381 This enforces rescanning the buffer on next use."
|
207
|
5382 (if (string= reftex-last-toc-master (reftex-TeX-master-file))
|
|
5383 (reftex-empty-toc-buffer))
|
155
|
5384 (let ((symlist reftex-multifile-symbols)
|
|
5385 symbol)
|
|
5386 (while symlist
|
|
5387 (setq symbol (car symlist)
|
|
5388 symlist (cdr symlist))
|
|
5389 (if (and (symbolp (symbol-value symbol))
|
|
5390 (not (null (symbol-value symbol))))
|
|
5391 (set (symbol-value symbol) nil)))))
|
|
5392
|
|
5393 (defun reftex-compute-ref-cite-tables ()
|
|
5394 ;; Update ref and cite tables
|
|
5395
|
|
5396 (interactive)
|
|
5397
|
|
5398 ;; Compile information in reftex-label-alist
|
|
5399 (let ((tmp (reftex-uniquify (reftex-splice-symbols-into-list
|
207
|
5400 (append
|
|
5401 reftex-label-alist
|
|
5402 reftex-label-alist-external-add-ons
|
|
5403 reftex-default-label-alist-entries)
|
|
5404 reftex-label-alist-builtin)
|
|
5405 '(nil)))
|
|
5406 entry env-or-mac typekeychar typekey prefix context word
|
|
5407 fmt reffmt labelfmt wordlist qh-list macros-with-labels
|
|
5408 nargs nlabel opt-args cell sum)
|
155
|
5409
|
|
5410 (setq reftex-words-to-typekey-alist nil
|
|
5411 reftex-typekey-list nil
|
|
5412 reftex-typekey-to-format-alist nil
|
|
5413 reftex-typekey-to-prefix-alist nil
|
|
5414 reftex-env-or-mac-alist nil
|
|
5415 reftex-label-env-list nil
|
|
5416 reftex-label-mac-list nil)
|
|
5417 (while tmp
|
|
5418 (catch 'next-entry
|
207
|
5419 (setq entry (car tmp)
|
|
5420 env-or-mac (car entry)
|
|
5421 entry (cdr entry)
|
|
5422 tmp (cdr tmp))
|
|
5423 (if (null env-or-mac)
|
|
5424 (setq env-or-mac ""))
|
|
5425 (if (stringp (car entry))
|
|
5426 ;; This is before version 2.00 - convert entry to new format
|
|
5427 ;; This is just to keep old users happy
|
|
5428 (setq entry (cons (string-to-char (car entry))
|
|
5429 (cons (concat (car entry) ":")
|
|
5430 (cdr entry)))))
|
|
5431 (setq typekeychar (nth 0 entry)
|
|
5432 typekey (char-to-string typekeychar)
|
|
5433 prefix (nth 1 entry)
|
|
5434 fmt (nth 2 entry)
|
|
5435 context (nth 3 entry)
|
|
5436 wordlist (nth 4 entry))
|
|
5437 (if (stringp wordlist)
|
|
5438 ;; This is before version 2.04 - convert to new format
|
|
5439 (setq wordlist (nthcdr 4 entry)))
|
|
5440
|
|
5441 (if (and (stringp fmt)
|
|
5442 (string-match "@" fmt))
|
|
5443 ;; special syntax for specifying a label format
|
|
5444 (setq fmt (split-string fmt "@+"))
|
|
5445 (setq fmt (list "\\label{%s}" fmt)))
|
|
5446 (setq labelfmt (car fmt)
|
|
5447 reffmt (nth 1 fmt))
|
|
5448 (if typekey
|
|
5449 (add-to-list 'reftex-typekey-list typekey))
|
|
5450 (if (and typekey prefix
|
|
5451 (not (assoc typekey reftex-typekey-to-prefix-alist)))
|
|
5452 (add-to-list 'reftex-typekey-to-prefix-alist
|
|
5453 (cons typekey prefix)))
|
|
5454 (cond
|
|
5455 ((string-match "\\`\\\\" env-or-mac)
|
|
5456 ;; It's a macro
|
|
5457 (let ((result (reftex-parse-args env-or-mac)))
|
|
5458 (setq env-or-mac (or (first result) env-or-mac)
|
|
5459 nargs (second result)
|
|
5460 nlabel (third result)
|
|
5461 opt-args (fourth result))
|
|
5462 (if nlabel (add-to-list 'macros-with-labels env-or-mac)))
|
|
5463 (add-to-list 'reftex-label-mac-list env-or-mac))
|
|
5464 (t
|
|
5465 (setq nargs nil nlabel nil opt-args nil)
|
|
5466 (cond ((string= env-or-mac "any"))
|
|
5467 ((string= env-or-mac ""))
|
|
5468 ((string= env-or-mac "section"))
|
|
5469 (t
|
|
5470 (add-to-list 'reftex-label-env-list env-or-mac)
|
|
5471 ;; Translate some special context cases
|
|
5472 (when (assq context reftex-default-context-regexps)
|
|
5473 (setq context
|
|
5474 (format
|
|
5475 (cdr (assq context reftex-default-context-regexps))
|
|
5476 (regexp-quote env-or-mac))))))))
|
|
5477 (and reffmt
|
|
5478 (not (assoc typekey reftex-typekey-to-format-alist))
|
|
5479 (push (cons typekey reffmt) reftex-typekey-to-format-alist))
|
|
5480 (and (not (string= env-or-mac "any"))
|
|
5481 (not (string= env-or-mac ""))
|
|
5482 (not (assoc env-or-mac reftex-env-or-mac-alist))
|
|
5483 (push (list env-or-mac typekey context labelfmt
|
|
5484 nargs nlabel opt-args)
|
|
5485 reftex-env-or-mac-alist))
|
|
5486 (while (and (setq word (pop wordlist))
|
|
5487 (stringp word))
|
|
5488 (setq word (downcase word))
|
|
5489 (or (assoc word reftex-words-to-typekey-alist)
|
|
5490 (push (cons word typekey) reftex-words-to-typekey-alist)))
|
|
5491 (cond
|
|
5492 ((string= "" env-or-mac) nil)
|
|
5493 ((setq cell (assoc typekey qh-list))
|
|
5494 (push env-or-mac (cdr cell)))
|
|
5495 (t
|
|
5496 (push (list typekey env-or-mac) qh-list)))))
|
|
5497
|
|
5498 (setq qh-list (sort qh-list '(lambda (x1 x2) (string< (car x1) (car x2)))))
|
155
|
5499 (setq reftex-typekey-to-prefix-alist
|
|
5500 (nreverse reftex-typekey-to-prefix-alist))
|
|
5501 (setq reftex-type-query-prompt
|
|
5502 (concat "Label type: "
|
|
5503 (mapconcat '(lambda(x)
|
|
5504 (format "[%s]" (car x)))
|
|
5505 qh-list " ")
|
|
5506 " (?=Help)"))
|
|
5507 (setq reftex-type-query-help
|
|
5508 (concat "SELECT A LABEL TYPE:\n--------------------\n"
|
207
|
5509 (mapconcat
|
|
5510 '(lambda(x)
|
|
5511 (setq sum 0)
|
|
5512 (format " [%s] %s"
|
|
5513 (car x)
|
|
5514 (mapconcat
|
|
5515 '(lambda(x)
|
|
5516 (setq sum (+ sum (length x)))
|
|
5517 (if (< sum 60)
|
|
5518 x
|
|
5519 (setq sum 0)
|
|
5520 (concat "\n " x)))
|
|
5521 (cdr x) " ")))
|
|
5522 qh-list "\n")))
|
|
5523
|
|
5524 ;; Calculate the regular expressions
|
|
5525 (let ((label-re "\\\\label{\\([^}]*\\)}")
|
|
5526 (include-re "\\(\\`\\|[\n\r]\\)[ \t]*\\\\\\(include\\|input\\)[{ \t]+\\([^} \t\n\r]+\\)")
|
|
5527 (section-re
|
|
5528 (concat "\\(\\`\\|[\n\r]\\)[ \t]*\\\\\\("
|
|
5529 (mapconcat 'car reftex-section-levels "\\|")
|
|
5530 "\\)\\*?\\(\\[[^]]*\\]\\)?{"))
|
|
5531 (macro-re
|
|
5532 (if macros-with-labels
|
|
5533 (concat "\\("
|
|
5534 (mapconcat 'regexp-quote macros-with-labels "\\|")
|
|
5535 "\\)[[{]")
|
|
5536 ""))
|
|
5537 (find-label-re-format
|
|
5538 (concat "\\("
|
|
5539 (mapconcat 'regexp-quote (append '("\\label")
|
|
5540 macros-with-labels) "\\|")
|
|
5541 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]")))
|
|
5542 (setq reftex-section-regexp section-re
|
|
5543 reftex-section-or-include-regexp
|
|
5544 (concat section-re "\\|" include-re)
|
|
5545 reftex-everything-regexp
|
|
5546 (concat label-re "\\|" section-re "\\|" include-re
|
|
5547 (if macros-with-labels "\\|" "") macro-re)
|
|
5548 reftex-find-label-regexp-format find-label-re-format
|
|
5549 reftex-find-label-regexp-format2
|
|
5550 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]"))))
|
155
|
5551
|
|
5552 ;;; Keybindings --------------------------------------------------------------
|
|
5553
|
|
5554 (define-key reftex-mode-map "\C-c=" 'reftex-toc)
|
|
5555 (define-key reftex-mode-map "\C-c(" 'reftex-label)
|
|
5556 (define-key reftex-mode-map "\C-c)" 'reftex-reference)
|
|
5557 (define-key reftex-mode-map "\C-c[" 'reftex-citation)
|
|
5558 (define-key reftex-mode-map "\C-c&" 'reftex-view-crossref)
|
|
5559
|
|
5560 ;; If the user requests so, she can have a few more bindings:
|
|
5561 (cond
|
|
5562 (reftex-extra-bindings
|
|
5563 (define-key reftex-mode-map "\C-ct" 'reftex-toc)
|
|
5564 (define-key reftex-mode-map "\C-cl" 'reftex-label)
|
|
5565 (define-key reftex-mode-map "\C-cr" 'reftex-reference)
|
|
5566 (define-key reftex-mode-map "\C-cc" 'reftex-citation)
|
|
5567 (define-key reftex-mode-map "\C-cv" 'reftex-view-crossref)
|
|
5568 (define-key reftex-mode-map "\C-cg" 'reftex-grep-document)
|
|
5569 (define-key reftex-mode-map "\C-cs" 'reftex-search-document)))
|
|
5570
|
|
5571 ;;; Menus --------------------------------------------------------------------
|
|
5572
|
|
5573 ;; Define a menu for the menu bar if Emacs is running under X
|
|
5574
|
|
5575 (require 'easymenu)
|
|
5576
|
207
|
5577 (easy-menu-define
|
155
|
5578 reftex-mode-menu reftex-mode-map
|
|
5579 "Menu used in RefTeX mode"
|
207
|
5580 `("Ref"
|
|
5581 ["Table of Contents" reftex-toc t]
|
155
|
5582 "----"
|
207
|
5583 ["\\label" reftex-label t]
|
|
5584 ["\\ref" reftex-reference t]
|
|
5585 ["\\cite" reftex-citation t]
|
|
5586 ["View Crossref" reftex-view-crossref t]
|
155
|
5587 "----"
|
207
|
5588 ("Parse Document"
|
|
5589 ["Only this File" reftex-parse-one t]
|
|
5590 ["Entire Document" reftex-parse-all (reftex-is-multi)]
|
|
5591 ["Save to File" (reftex-access-parse-file 'write)
|
|
5592 (> (length (symbol-value reftex-docstruct-symbol)) 0)]
|
|
5593 ["Restore from File" (reftex-access-parse-file 'restore)
|
|
5594 (reftex-access-parse-file 'readable)]
|
|
5595 "----"
|
|
5596 ["Enable Partial Scans"
|
|
5597 (setq reftex-enable-partial-scans (not reftex-enable-partial-scans))
|
|
5598 :style toggle :selected reftex-enable-partial-scans]
|
|
5599 ["Auto-Save Parse Info"
|
|
5600 (setq reftex-save-parse-info (not reftex-save-parse-info))
|
|
5601 :style toggle :selected reftex-save-parse-info]
|
|
5602 "---"
|
|
5603 ["Reset RefTeX Mode" reftex-reset-mode t])
|
|
5604 ("Multifile"
|
|
5605 ["Search Whole Document" reftex-search-document t]
|
|
5606 ["Replace in Document" reftex-query-replace-document t]
|
|
5607 ["Grep on Document" reftex-grep-document t]
|
|
5608 "----"
|
|
5609 ["Create TAGS File" reftex-create-tags-file t]
|
155
|
5610 "----"
|
207
|
5611 ["Find Duplicate Labels" reftex-find-duplicate-labels t]
|
|
5612 ["Change Label and Refs" reftex-change-label t])
|
|
5613 ("Citation Options"
|
|
5614 "Citation Style"
|
|
5615 ,@(mapcar
|
|
5616 (function
|
|
5617 (lambda (x)
|
|
5618 (vector
|
|
5619 (symbol-name (car x))
|
|
5620 (list 'setq 'reftex-cite-format (list 'quote (car x)))
|
|
5621 :style 'radio :selected
|
|
5622 (list 'eq 'reftex-cite-format (list 'quote (car x))))))
|
|
5623 reftex-cite-format-builtin)
|
155
|
5624 "----"
|
207
|
5625 "Bibinfo in Comments"
|
|
5626 ["Attach Comments"
|
|
5627 (setq reftex-comment-citations (not reftex-comment-citations))
|
|
5628 :style toggle :selected reftex-comment-citations]
|
|
5629 "---"
|
|
5630 "Sort Database Matches"
|
|
5631 ["by Author" (setq reftex-sort-bibtex-matches 'author)
|
|
5632 :style radio :selected (eq reftex-sort-bibtex-matches 'author)]
|
|
5633 ["by Year" (setq reftex-sort-bibtex-matches 'year)
|
|
5634 :style radio :selected (eq reftex-sort-bibtex-matches 'year)]
|
|
5635 ["by Year, reversed" (setq reftex-sort-bibtex-matches 'reverse-year)
|
|
5636 :style radio :selected (eq reftex-sort-bibtex-matches 'reverse-year)]
|
|
5637 ["Not" (setq reftex-sort-bibtex-matches nil)
|
|
5638 :style radio :selected (eq reftex-sort-bibtex-matches nil)])
|
155
|
5639 "----"
|
207
|
5640 ["Customize RefTeX" reftex-customize t]
|
|
5641 "----"
|
|
5642 ["Show Documentation" reftex-show-commentary t]))
|
155
|
5643
|
|
5644 ;;; Run Hook ------------------------------------------------------------------
|
|
5645
|
|
5646 (run-hooks 'reftex-load-hook)
|
|
5647
|
|
5648 ;;; That's it! ----------------------------------------------------------------
|
|
5649
|
207
|
5650 (provide 'reftex)
|
|
5651
|
155
|
5652 ; Make sure tabels are compiled
|
|
5653 (message "updating internal tables...")
|
|
5654 (reftex-compute-ref-cite-tables)
|
165
|
5655 (message "updating internal tables...done")
|
155
|
5656 (setq reftex-tables-dirty nil)
|
|
5657
|
|
5658 ;;;============================================================================
|
|
5659
|
207
|
5660 ;;; reftex.el ends here
|
|
5661
|