]> code.delx.au - gnu-emacs/blob - lisp/textmodes/reftex.el
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
[gnu-emacs] / lisp / textmodes / reftex.el
1 ;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX
2 ;; Copyright (C) 1997-2000, 2003-2015 Free Software Foundation, Inc.
3
4 ;; Author: Carsten Dominik <dominik@science.uva.nl>
5 ;; Maintainer: auctex-devel@gnu.org
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 3 of the License, or
13 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; RefTeX is a minor mode with distinct support for \ref, \label, \cite,
26 ;; and \index commands in (multi-file) LaTeX documents.
27 ;; - A table of contents provides easy access to any part of a document.
28 ;; - Labels are created semi-automatically.
29 ;; - Definition context of labels is provided when creating a reference.
30 ;; - Citations are simplified with efficient database lookup.
31 ;; - Text phrases can be collected in a file, for later global indexing.
32 ;; - The index preview buffer helps to check and edit index entries.
33 ;;
34 ;; There is an extensive Texinfo document describing RefTeX in detail.
35 ;; One way to view this documentation is `M-x reftex-info RET'.
36 ;;
37 ;; The documentation in various formats is also available at
38 ;;
39 ;; http://www.gnu.org/software/auctex/manual/reftex.index.html
40 ;;
41 ;; RefTeX is bundled with Emacs and available as a plug-in package for
42 ;; XEmacs 21.x. If you need to install it yourself, you can find a
43 ;; distribution at
44 ;;
45 ;; http://www.gnu.org/software/auctex/reftex.html
46 ;;
47 ;; RefTeX was written by Carsten Dominik <dominik@science.uva.nl> with
48 ;; contributions from Stephen Eglen. It is currently maintained by
49 ;; the AUCTeX project.
50
51 ;;; Code:
52
53 (eval-when-compile (require 'cl))
54
55 ;; Stuff that needs to be there when we use defcustom
56 (require 'custom)
57
58 (require 'easymenu)
59
60 (defvar reftex-tables-dirty t
61 "Flag showing if tables need to be re-computed.")
62
63 (eval-and-compile
64 (defun reftex-set-dirty (symbol value)
65 (setq reftex-tables-dirty t)
66 (set symbol value)))
67
68
69 ;; Configuration variables
70 (require 'reftex-vars)
71
72
73 ;;; Autoloads - see end for automatic autoloads
74
75 ;; We autoload tons of functions from these files, but some have
76 ;; a single function that needs to be globally autoloaded.
77 ;; The alternative is to use a Makefile rule + distinct autoload
78 ;; cookie (eg ;;;###reftex-autoload) for internal autoloads,
79 ;; as eg calendar/ does. But that seemed like overkill for 4 functions.
80
81 ;;;###autoload(autoload 'reftex-citation "reftex-cite" nil t)
82 ;;;###autoload(autoload 'reftex-all-document-files "reftex-parse")
83 ;;;###autoload(autoload 'reftex-isearch-minor-mode "reftex-global" nil t)
84 ;;;###autoload(autoload 'reftex-index-phrases-mode "reftex-index" nil t)
85
86 ;; Generated functions.
87 (autoload 'reftex-varioref-vref "reftex-ref"
88 "Make a varioref reference." t)
89 (autoload 'reftex-fancyref-fref "reftex-ref"
90 "Make a fancyref \\fref reference." t)
91 (autoload 'reftex-fancyref-Fref "reftex-ref"
92 "Make a fancyref \\Fref reference." t)
93
94 ;;; =========================================================================
95 ;;;
96 ;;; Define the formal stuff for a minor mode named RefTeX.
97 ;;;
98
99 (defconst reftex-version emacs-version
100 "Version string for RefTeX.")
101
102 (defvar reftex-mode-map (make-sparse-keymap)
103 "Keymap for RefTeX mode.")
104
105 (defvar reftex-mode-menu nil)
106 (defvar reftex-syntax-table nil)
107 (defvar reftex-syntax-table-for-bib nil)
108
109 (defun reftex--prepare-syntax-tables ()
110 (setq reftex-syntax-table (copy-syntax-table))
111 (modify-syntax-entry ?\( "." reftex-syntax-table)
112 (modify-syntax-entry ?\) "." reftex-syntax-table)
113
114 (setq reftex-syntax-table-for-bib (copy-syntax-table))
115 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib)
116 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib)
117 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib)
118 (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib)
119 (modify-syntax-entry ?\( "." reftex-syntax-table-for-bib)
120 (modify-syntax-entry ?\) "." reftex-syntax-table-for-bib))
121
122 (unless (and reftex-syntax-table reftex-syntax-table-for-bib)
123 (reftex--prepare-syntax-tables))
124
125 ;; The following definitions are out of place, but I need them here
126 ;; to make the compilation of reftex-mode not complain.
127 (defvar reftex-auto-view-crossref-timer nil
128 "The timer used for auto-view-crossref.")
129 (defvar reftex-toc-auto-recenter-timer nil
130 "The idle timer used to recenter the toc window.")
131
132 ;;;###autoload
133 (defun turn-on-reftex ()
134 "Turn on RefTeX mode."
135 (reftex-mode t))
136
137 (put 'reftex-mode :included '(memq major-mode '(latex-mode tex-mode)))
138 (put 'reftex-mode :menu-tag "RefTeX Mode")
139 ;;;###autoload
140 (define-minor-mode reftex-mode
141 "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX.
142
143 \\<reftex-mode-map>A Table of Contents of the entire (multifile) document with browsing
144 capabilities is available with `\\[reftex-toc]'.
145
146 Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'.
147 When referencing, you get a menu with all labels of a given type and
148 context of the label definition. The selected label is inserted as a
149 \\ref macro.
150
151 Citations can be made with `\\[reftex-citation]' which will use a regular expression
152 to pull out a *formatted* list of articles from your BibTeX
153 database. The selected citation is inserted as a \\cite macro.
154
155 Index entries can be made with `\\[reftex-index-selection-or-word]' which indexes the word at point
156 or the current selection. More general index entries are created with
157 `\\[reftex-index]'. `\\[reftex-display-index]' displays the compiled index.
158
159 Most command have help available on the fly. This help is accessed by
160 pressing `?' to any prompt mentioning this feature.
161
162 Extensive documentation about RefTeX is available in Info format.
163 You can view this information with `\\[reftex-info]'.
164
165 \\{reftex-mode-map}
166 Under X, these and other functions will also be available as `Ref' menu
167 on the menu bar.
168
169 ------------------------------------------------------------------------------"
170 :lighter " Ref" :keymap reftex-mode-map
171 (if reftex-mode
172 (progn
173 ;; Mode was turned on
174 (easy-menu-add reftex-mode-menu)
175 (and reftex-plug-into-AUCTeX
176 (reftex-plug-into-AUCTeX))
177 (unless (get 'reftex-auto-view-crossref 'initialized)
178 (and reftex-auto-view-crossref
179 (reftex-toggle-auto-view-crossref))
180 (put 'reftex-auto-view-crossref 'initialized t))
181 (unless (get 'reftex-auto-recenter-toc 'initialized)
182 (and (eq reftex-auto-recenter-toc t)
183 (reftex-toggle-auto-toc-recenter))
184 (put 'reftex-auto-recenter-toc 'initialized t))
185
186 ;; Prepare the special syntax tables.
187 (reftex--prepare-syntax-tables)
188
189 (run-hooks 'reftex-mode-hook))
190 ;; Mode was turned off
191 (easy-menu-remove reftex-mode-menu)))
192
193 (defvar reftex-docstruct-symbol)
194 (defun reftex-kill-buffer-hook ()
195 "Save RefTeX's parse file for this buffer if the information has changed."
196 ;; Save the parsing information if it was modified.
197 ;; This function should be installed in `kill-buffer-hook'.
198 ;; We are careful to make sure nothing goes wrong in this function.
199 (when (and (boundp 'reftex-mode) reftex-mode
200 (boundp 'reftex-save-parse-info) reftex-save-parse-info
201 (boundp 'reftex-docstruct-symbol) reftex-docstruct-symbol
202 (symbol-value reftex-docstruct-symbol)
203 (get reftex-docstruct-symbol 'modified))
204 ;; Write the file.
205 (condition-case nil
206 (reftex-access-parse-file 'write)
207 (error nil))))
208
209 (defun reftex-kill-emacs-hook ()
210 "Call `reftex-kill-buffer-hook' on all buffers."
211 ;; This function should be installed in `kill-emacs-hook'.
212 (save-excursion
213 (mapcar (lambda (buf)
214 (set-buffer buf)
215 (reftex-kill-buffer-hook))
216 (buffer-list))))
217
218 ;;; =========================================================================
219 ;;;
220 ;;; Silence warnings about variables in other packages.
221 (defvar TeX-master)
222 (defvar LaTeX-section-hook)
223 (defvar LaTeX-label-function)
224 (defvar tex-main-file)
225 (defvar outline-minor-mode)
226 (defvar font-lock-mode)
227 (defvar font-lock-keywords)
228 (defvar font-lock-fontify-region-function)
229
230 ;;; =========================================================================
231 ;;;
232 ;;; Multibuffer Variables
233 ;;;
234 ;; Technical notes: These work as follows: We keep just one list
235 ;; of labels for each master file - this can save a lot of memory.
236 ;; `reftex-master-index-list' is an alist which connects the true file name
237 ;; of each master file with the symbols holding the information on that
238 ;; document. Each buffer has local variables which point to these symbols.
239
240 ;; List of variables which handle the multifile stuff.
241 ;; This list is used to tie, untie, and reset these symbols.
242 (defconst reftex-multifile-symbols
243 '(reftex-docstruct-symbol))
244
245 ;; Alist connecting master file names with the corresponding lisp symbols.
246 (defvar reftex-master-index-list nil)
247
248 ;; Last index used for a master file.
249 (defvar reftex-multifile-index 0)
250
251 ;; Variable holding the symbol with the label list of the document.
252 (defvar reftex-docstruct-symbol nil)
253 (make-variable-buffer-local 'reftex-docstruct-symbol)
254
255 (defun reftex-next-multifile-index ()
256 ;; Return the next free index for multifile symbols.
257 (incf reftex-multifile-index))
258
259 (defun reftex-tie-multifile-symbols ()
260 "Tie the buffer-local symbols to globals connected with the master file.
261 If the symbols for the current master file do not exist, they are created."
262 (let* ((master (file-truename (reftex-TeX-master-file)))
263 (index (assoc master reftex-master-index-list))
264 (symlist reftex-multifile-symbols)
265 symbol symname newflag)
266 ;; Find the correct index.
267 (if index
268 ;; Symbols do exist
269 (setq index (cdr index))
270 ;; Get a new index and add info to the alist.
271 (setq index (reftex-next-multifile-index)
272 newflag t)
273 (push (cons master index) reftex-master-index-list))
274
275 ;; Get/create symbols and tie them.
276 (while symlist
277 (setq symbol (car symlist)
278 symlist (cdr symlist)
279 symname (symbol-name symbol))
280 (set symbol (intern (concat symname "-" (int-to-string index))))
281 (put (symbol-value symbol) :master-index index)
282 ;; Initialize if new symbols.
283 (when newflag
284 (set (symbol-value symbol) nil)
285 (put (symbol-value symbol) 'reftex-index-macros-style '(default))
286 (put (symbol-value symbol) 'reftex-ref-style-list
287 reftex-ref-style-default-list)))
288
289 ;; Return t if the symbols did already exist, nil when we've made them.
290 (not newflag)))
291
292 (defun reftex-untie-multifile-symbols ()
293 "Remove ties from multifile symbols, so that next use makes new ones."
294 (let ((symlist reftex-multifile-symbols)
295 (symbol nil))
296 (while symlist
297 (setq symbol (car symlist)
298 symlist (cdr symlist))
299 (set symbol nil))))
300
301 (defun reftex-TeX-master-file ()
302 ;; Return the name of the master file associated with the current buffer.
303 ;; When AUCTeX is loaded, we will use it's more sophisticated method.
304 ;; We also support the default TeX and LaTeX modes by checking for a
305 ;; variable tex-main-file.
306 (let
307 ((master
308 (cond
309 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism.
310 (condition-case nil
311 (TeX-master-file t)
312 (error (buffer-file-name))))
313 ((fboundp 'tex-main-file) (tex-main-file)) ; Emacs LaTeX mode
314 ((boundp 'TeX-master) ; The variable is defined - let's use it.
315 (cond
316 ((eq TeX-master t)
317 (buffer-file-name))
318 ((eq TeX-master 'shared)
319 (setq TeX-master (read-file-name "Master file: "
320 nil nil t nil)))
321 (TeX-master)
322 (t
323 (setq TeX-master (read-file-name "Master file: "
324 nil nil t nil)))))
325 ((boundp 'tex-main-file)
326 ;; This is the variable from the default TeX modes.
327 (cond
328 ((stringp tex-main-file)
329 ;; ok, this must be it
330 tex-main-file)
331 (t
332 ;; In this case, the buffer is its own master.
333 (buffer-file-name))))
334 (t
335 ;; Know nothing about master file. Assume this is a master file.
336 (buffer-file-name)))))
337 (cond
338 ((null master)
339 (error "Need a filename for this buffer, please save it first"))
340 ((or (file-exists-p (concat master ".tex"))
341 (reftex-get-buffer-visiting (concat master ".tex")))
342 ;; Ahh, an extra .tex was missing...
343 (setq master (concat master ".tex")))
344 ((or (file-exists-p master)
345 (reftex-get-buffer-visiting master))
346 ;; We either see the file, or have a buffer on it. OK.
347 )
348 (t
349 ;; Use buffer file name.
350 (setq master (buffer-file-name))))
351 (expand-file-name master)))
352
353 (defun reftex-is-multi ()
354 ;; Tell if this is a multifile document. When not sure, say yes.
355 (let ((entry (assq 'is-multi (symbol-value reftex-docstruct-symbol))))
356 (if entry
357 (nth 1 entry)
358 t)))
359
360 (defun reftex-set-cite-format (value)
361 "Set the document-local value of `reftex-cite-format'.
362 When such a value exists, it overwrites the setting given with
363 `reftex-cite-format'. See the documentation of `reftex-cite-format'
364 for possible values. This function should be used from AUCTeX style files."
365 (unless reftex-docstruct-symbol
366 (reftex-tie-multifile-symbols))
367 (when (and reftex-docstruct-symbol
368 (symbolp reftex-docstruct-symbol))
369 (put reftex-docstruct-symbol 'reftex-cite-format value)))
370
371 (defun reftex-get-cite-format ()
372 ;; Return the current citation format. Either the document-local value in
373 ;; reftex-cite-format-symbol, or the global value in reftex-cite-format.
374 (if (and reftex-docstruct-symbol
375 (symbolp reftex-docstruct-symbol)
376 (get reftex-docstruct-symbol 'reftex-cite-format))
377 (get reftex-docstruct-symbol 'reftex-cite-format)
378 reftex-cite-format))
379
380 (defun reftex-add-index-macros (entry-list)
381 "Add index macro descriptions to `reftex-index-macros-style'.
382 The format of ENTRY-LIST is exactly like `reftex-index-macros'. See there
383 for details.
384 This function makes it possible to support RefTeX from AUCTeX style files.
385 The entries in ENTRY-LIST will be processed after the user settings in
386 `reftex-index-entries', and before the defaults. Any changes made to
387 `reftex-index-macros-style' will raise a flag to the effect that
388 the label information is recompiled on next use."
389 (unless reftex-docstruct-symbol
390 (reftex-tie-multifile-symbols))
391 (when (and reftex-docstruct-symbol
392 (symbolp reftex-docstruct-symbol))
393 (let ((list (get reftex-docstruct-symbol 'reftex-index-macros-style))
394 entry changed)
395 (while entry-list
396 (setq entry (pop entry-list))
397 ;; When it is a symbol, remove all other symbols
398 (and (symbolp entry)
399 (not (memq entry list))
400 (setq list (reftex-remove-symbols-from-list list)))
401 ;; Add to list unless already member
402 (unless (member entry list)
403 (setq reftex-tables-dirty t
404 changed t)
405 (push entry list)))
406 (when changed
407 (put reftex-docstruct-symbol 'reftex-index-macros-style list)))))
408
409 (defun reftex-ref-style-activate (style)
410 "Activate the referencing style STYLE."
411 (reftex-ref-style-toggle style 'activate))
412
413 (defun reftex-ref-style-toggle (style &optional action)
414 "Activate or deactivate the referencing style STYLE.
415 With the optional argument ACTION a certain action can be forced.
416 The symbol `activate' will activate the style and `deactivate'
417 will deactivate it."
418 (unless reftex-docstruct-symbol
419 (reftex-tie-multifile-symbols))
420 (when (and reftex-docstruct-symbol
421 (symbolp reftex-docstruct-symbol))
422 (let ((list (get reftex-docstruct-symbol 'reftex-ref-style-list))
423 changed)
424 (cond ((eq action 'activate)
425 (unless (member style list)
426 (setq reftex-tables-dirty t
427 changed t)
428 (add-to-list 'list style t)))
429 ((eq action 'deactivate)
430 (when (member style list)
431 (setq reftex-tables-dirty t
432 changed t)
433 (setq list (delete style list))))
434 (t
435 (if (member style list)
436 (delete style list)
437 (add-to-list 'list style t))
438 (setq reftex-tables-dirty t
439 changed t)))
440 (when changed
441 (put reftex-docstruct-symbol 'reftex-ref-style-list list)))))
442
443 (defun reftex-ref-style-list ()
444 "Return the list of referencing styles to be active at the moment."
445 ;; Initialize the value of `reftex-ref-style-list' and tie it to the
446 ;; docstruct symbol if necessary.
447 (unless reftex-docstruct-symbol
448 (reftex-tie-multifile-symbols))
449 (if (and reftex-docstruct-symbol
450 (symbolp reftex-docstruct-symbol)
451 (get reftex-docstruct-symbol 'reftex-ref-style-list))
452 (get reftex-docstruct-symbol 'reftex-ref-style-list)
453 reftex-ref-style-default-list))
454
455 ;;; =========================================================================
456 ;;;
457 ;;; Functions to compile the tables, reset the mode etc.
458
459 ;; The following constants are derived from `reftex-label-alist'.
460
461 ;; Prompt used for label type queries directed to the user.
462 (defvar reftex-type-query-prompt nil)
463
464 ;; Help string for label type queries.
465 (defvar reftex-type-query-help nil)
466
467 ;; Alist relating label type to reference format.
468 (defvar reftex-typekey-to-format-alist nil)
469
470 ;; Alist relating label type to label prefix.
471 (defvar reftex-typekey-to-prefix-alist nil)
472
473 ;; Alist relating environments or macros to label type and context regexp.
474 (defvar reftex-env-or-mac-alist nil)
475
476 ;; List of special environment parser functions
477 (defvar reftex-special-env-parsers nil)
478
479 ;; List of macros carrying a label.
480 (defvar reftex-label-mac-list nil)
481
482 ;; List of environments carrying a label.
483 (defvar reftex-label-env-list nil)
484
485 ;; List of all typekey letters in use.
486 (defvar reftex-typekey-list nil)
487
488 ;; Alist relating magic words to a label type.
489 (defvar reftex-words-to-typekey-alist nil)
490 ;; Alist relating label prefixes to a label type.
491 (defvar reftex-prefix-to-typekey-alist nil)
492
493 ;; The last list-of-labels entry used in a reference.
494 (defvar reftex-last-used-reference (list nil nil nil nil))
495
496 ;; Alist relating index macros to other info.
497 (defvar reftex-key-to-index-macro-alist nil)
498 ;; Prompt for index macro queries
499 (defvar reftex-query-index-macro-prompt nil)
500 ;; Help string for index macro queries
501 (defvar reftex-query-index-macro-help nil)
502
503 ;; The message when follow-mode is suspended
504 (defvar reftex-no-follow-message
505 "No follow-mode into unvisited file. Press SPC to visit it.")
506 (defvar reftex-no-info-message
507 "%s: info not available, use `\\[reftex-view-crossref]' to get it.")
508
509 ;; Global variables used for communication between functions.
510 (defvar reftex-default-context-position nil)
511 (defvar reftex-location-start nil)
512 (defvar reftex-call-back-to-this-buffer nil)
513 (defvar reftex-select-return-marker (make-marker))
514 (defvar reftex-active-toc nil)
515 (defvar reftex-tex-path nil)
516 (defvar reftex-bib-path nil)
517 (defvar reftex-select-marked nil)
518 (defvar reftex-last-follow-point nil)
519 (defvar reftex-latex-syntax-table nil)
520 (defvar reftex-prefix nil)
521 (defvar reftex-section-levels-all nil)
522 (defvar reftex-buffers-with-changed-invisibility nil)
523 (defvar reftex-callback-fwd t)
524 (defvar reftex-last-toc-master nil
525 "Stores the name of the tex file that `reftex-toc' was last run on.")
526 ;; Marker for return point from recursive edit
527 (defvar reftex-recursive-edit-marker (make-marker))
528
529 ;; List of buffers created temporarily for lookup, which should be killed.
530 (defvar reftex-buffers-to-kill nil)
531
532 ;; Regexp to find anything.
533 (defvar reftex-section-regexp nil)
534 (defvar reftex-section-or-include-regexp nil)
535 (defvar reftex-index-macro-regexp nil)
536 (defvar reftex-index-level-re nil)
537 (defvar reftex-index-key-end-re nil)
538 (defvar reftex-find-index-entry-regexp-format nil)
539 (defvar reftex-everything-regexp nil)
540 (defvar reftex-everything-regexp-no-index nil)
541 (defvar reftex-index-re nil)
542 (defvar reftex-find-citation-regexp-format
543 "\\\\\\([a-zA-Z]*cite[*a-zA-Z]*\\*?\\|bibentry\\)\\(\\[[^]]*\\]\\|{[^}]*}\\)*{\\([^}]*,\\)?\\(%s\\)[},]")
544 (defvar reftex-find-reference-format
545 "\\\\\\(ref[a-zA-Z]*\\|[a-zA-Z]*ref\\(range\\)?\\)\\*?\\(\\[[^]]*\\]\\|{[^}]*}\\)*{\\(%s\\)}")
546 (defvar reftex-macros-with-labels nil)
547 (defvar reftex-macros-with-index nil)
548 (defvar reftex-index-macro-alist nil)
549 (defvar reftex-find-label-regexp-format nil)
550 (defvar reftex-find-label-regexp-format2 nil)
551
552 ;; Constants for making RefTeX open to Texinfo hooking
553 (defvar reftex-section-pre-regexp "\\\\")
554 ;; Including `\' as a character to be matched at the end of the regexp
555 ;; will allow stuff like \begin{foo}\label{bar} to be matched. This
556 ;; will make the parser to advance one char too much. Therefore
557 ;; `reftex-parse-from-file' will step one char back if a section is
558 ;; found.
559 (defvar reftex-section-post-regexp "\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n\\]")
560 (defvar reftex-section-info-function 'reftex-section-info)
561
562 (defvar reftex-memory nil
563 "Memorizes old variable values to indicate changes in these variables.")
564
565 ;; A list of all variables in the cache.
566 ;; The cache is used to save the compiled versions of some variables.
567 (defconst reftex-cache-variables
568 '(reftex-memory ;; This MUST ALWAYS be the first!
569
570 ;; Outline
571 reftex-section-levels-all
572
573 ;; Labels
574 reftex-env-or-mac-alist
575 reftex-special-env-parsers
576 reftex-macros-with-labels
577 reftex-label-mac-list
578 reftex-label-env-list
579 reftex-typekey-list
580 reftex-typekey-to-format-alist
581 reftex-typekey-to-prefix-alist
582 reftex-words-to-typekey-alist
583 reftex-prefix-to-typekey-alist
584 reftex-type-query-prompt
585 reftex-type-query-help
586
587 ;; Index
588 reftex-index-macro-alist
589 reftex-macros-with-index
590 reftex-query-index-macro-prompt
591 reftex-query-index-macro-help
592 reftex-key-to-index-macro-alist
593
594 ;; Regular expressions
595 reftex-section-regexp
596 reftex-section-or-include-regexp
597 reftex-index-re
598 reftex-everything-regexp
599 reftex-everything-regexp-no-index
600 reftex-find-label-regexp-format
601 reftex-find-label-regexp-format2
602 reftex-find-index-entry-regexp-format
603 ))
604
605 (defun reftex-ensure-compiled-variables ()
606 ;; Recompile the label alist when necessary
607 (let* ((mem reftex-memory)
608 (cache (get reftex-docstruct-symbol 'reftex-cache))
609 (cmem (car cache))
610 (alist reftex-label-alist)
611 (levels (get reftex-docstruct-symbol 'reftex-section-levels))
612 (style (get reftex-docstruct-symbol 'reftex-label-alist-style))
613 (default reftex-default-label-alist-entries)
614 (index reftex-index-macros)
615 (istyle (get reftex-docstruct-symbol 'reftex-index-macros-style)))
616 (cond
617 (reftex-tables-dirty (reftex-compile-variables))
618 ((and (eq alist (nth 0 mem))
619 (eq levels (nth 1 mem))
620 (eq style (nth 2 mem))
621 (eq default (nth 3 mem))
622 (eq index (nth 4 mem))
623 (eq istyle (nth 5 mem)))) ;; everything is OK
624 ((and (eq alist (nth 0 cmem))
625 (eq levels (nth 1 cmem))
626 (eq style (nth 2 cmem))
627 (eq default (nth 2 cmem))
628 (eq index (nth 4 cmem))
629 (eq istyle (nth 5 cmem)))
630 ;; restore the cache
631 (message "Restoring cache")
632 (mapcar (lambda (sym) (set sym (pop cache))) reftex-cache-variables))
633 (t (reftex-compile-variables)))))
634
635 (defun reftex-reset-mode ()
636 "Reset RefTeX Mode.
637 This will re-compile the configuration information and remove all
638 current scanning information and the parse file to enforce a rescan
639 on next use."
640 (interactive)
641
642 ;; Reset the file search path variables
643 (loop for prop in '(status master-dir recursive-path rec-type) do
644 (put 'reftex-tex-path prop nil)
645 (put 'reftex-bib-path prop nil))
646
647 ;; Kill temporary buffers associated with RefTeX - just in case they
648 ;; were not cleaned up properly
649 (save-excursion
650 (let ((buffer-list '("*RefTeX Help*" "*RefTeX Select*"
651 "*Duplicate Labels*" "*toc*" " *RefTeX-scratch*"))
652 buf)
653 (while (setq buf (pop buffer-list))
654 (if (get-buffer buf)
655 (kill-buffer buf))))
656 (reftex-erase-all-selection-and-index-buffers))
657
658 ;; Make sure the current document will be rescanned soon.
659 (reftex-reset-scanning-information)
660
661 ;; Remove any parse info file
662 (reftex-access-parse-file 'kill)
663
664 ;; Plug functions into AUCTeX if the user option says so.
665 (and reftex-plug-into-AUCTeX
666 (reftex-plug-into-AUCTeX))
667
668 (reftex-compile-variables))
669
670 ;;;###autoload
671 (defun reftex-reset-scanning-information ()
672 "Reset the symbols containing information from buffer scanning.
673 This enforces rescanning the buffer on next use."
674 (if (string= reftex-last-toc-master (reftex-TeX-master-file))
675 (reftex-erase-buffer "*toc*"))
676 (let ((symlist reftex-multifile-symbols)
677 symbol)
678 (while symlist
679 (setq symbol (car symlist)
680 symlist (cdr symlist))
681 (if (and (symbolp (symbol-value symbol))
682 (not (null (symbol-value symbol))))
683 (set (symbol-value symbol) nil)))))
684
685 (defun reftex-erase-all-selection-and-index-buffers ()
686 ;; Remove all selection buffers associated with current document.
687 (mapc
688 (lambda (type)
689 (reftex-erase-buffer (reftex-make-selection-buffer-name type)))
690 reftex-typekey-list)
691 ;; Kill all index buffers
692 (mapc
693 (lambda (tag)
694 (reftex-kill-buffer (reftex-make-index-buffer-name tag)))
695 (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))))
696
697 (defun reftex-compile-variables ()
698 ;; Compile the information in reftex-label-alist & Co.
699
700 (message "Compiling label environment definitions...")
701
702 ;; Update AUCTeX style information
703 (when (and (featurep 'tex-site) (fboundp 'TeX-update-style))
704 (condition-case nil (TeX-update-style) (error nil)))
705
706 ;; Record that we have done this, and what we have used.
707 (setq reftex-tables-dirty nil)
708 (setq reftex-memory
709 (list reftex-label-alist
710 (get reftex-docstruct-symbol 'reftex-section-levels)
711 (get reftex-docstruct-symbol 'reftex-label-alist-style)
712 reftex-default-label-alist-entries
713 reftex-index-macros
714 (get reftex-docstruct-symbol 'reftex-index-macros-style)))
715
716 ;; Compile information in reftex-label-alist
717 (let ((all (reftex-uniquify-by-car
718 (reftex-splice-symbols-into-list
719 (append reftex-label-alist
720 (get reftex-docstruct-symbol
721 'reftex-label-alist-style)
722 reftex-default-label-alist-entries)
723 reftex-label-alist-builtin)
724 '(nil)))
725 (all-index (reftex-uniquify-by-car
726 (reftex-splice-symbols-into-list
727 (append reftex-index-macros
728 (get reftex-docstruct-symbol
729 'reftex-index-macros-style)
730 '(default))
731 reftex-index-macros-builtin)))
732 entry env-or-mac typekeychar typekey prefix context word
733 fmt reffmt labelfmt wordlist qh-list macros-with-labels
734 nargs nlabel opt-args cell sum i
735 macro verify repeat nindex tag key toc-level toc-levels)
736
737 (setq reftex-words-to-typekey-alist nil
738 reftex-prefix-to-typekey-alist
739 '(("sec:" . "s") ("cha:" . "s") ("chap:" . "s"))
740 reftex-typekey-list nil
741 reftex-typekey-to-format-alist nil
742 reftex-typekey-to-prefix-alist nil
743 reftex-env-or-mac-alist nil
744 reftex-label-env-list nil
745 reftex-label-mac-list nil)
746 (while all
747 (catch 'next-entry
748 (setq entry (car all)
749 env-or-mac (car entry)
750 entry (cdr entry)
751 all (cdr all))
752 (if (null env-or-mac)
753 (setq env-or-mac ""))
754 (if (stringp (car entry))
755 ;; This is before version 2.00 - convert entry to new format
756 ;; This is just to keep old users happy
757 (setq entry (cons (string-to-char (car entry))
758 (cons (concat (car entry) ":")
759 (cdr entry)))))
760 (setq typekeychar (nth 0 entry)
761 typekey (if typekeychar (char-to-string typekeychar) nil)
762 prefix (nth 1 entry)
763 fmt (nth 2 entry)
764 context (nth 3 entry)
765 wordlist (nth 4 entry)
766 toc-level (nth 5 entry))
767 (if (stringp wordlist)
768 ;; This is before version 2.04 - convert to new format
769 (setq wordlist (nthcdr 4 entry)))
770
771 (if (and (stringp fmt)
772 (string-match "@" fmt))
773 ;; Special syntax for specifying a label format
774 (setq fmt (split-string fmt "@+"))
775 (setq fmt (list "\\label{%s}" fmt)))
776 (setq labelfmt (car fmt)
777 reffmt (nth 1 fmt))
778 ;; Note a new typekey
779 (if typekey
780 (add-to-list 'reftex-typekey-list typekey))
781 (if (and typekey prefix
782 (not (assoc prefix reftex-prefix-to-typekey-alist)))
783 (add-to-list 'reftex-prefix-to-typekey-alist
784 (cons prefix typekey)))
785 (if (and typekey prefix
786 (not (assoc typekey reftex-typekey-to-prefix-alist)))
787 (add-to-list 'reftex-typekey-to-prefix-alist
788 (cons typekey prefix)))
789 ;; Check if this is a macro or environment
790 (cond
791 ((symbolp env-or-mac)
792 ;; A special parser function
793 (unless (fboundp env-or-mac)
794 (message "Warning: %s does not seem to be a valid function"
795 env-or-mac))
796 (setq nargs nil nlabel nil opt-args nil)
797 (add-to-list 'reftex-special-env-parsers env-or-mac)
798 (setq env-or-mac (symbol-name env-or-mac)))
799 ((string-match "\\`\\\\" env-or-mac)
800 ;; It's a macro
801 (let ((result (reftex-parse-args env-or-mac)))
802 (setq env-or-mac (or (first result) env-or-mac)
803 nargs (second result)
804 nlabel (third result)
805 opt-args (fourth result))
806 (if nlabel (add-to-list 'macros-with-labels env-or-mac)))
807 (if typekey (add-to-list 'reftex-label-mac-list env-or-mac)))
808 (t
809 ;; It's an environment
810 (setq nargs nil nlabel nil opt-args nil)
811 (cond ((string= env-or-mac "any"))
812 ((string= env-or-mac ""))
813 ((string= env-or-mac "section"))
814 (t
815 (add-to-list 'reftex-label-env-list env-or-mac)
816 (if toc-level
817 (let ((string (format "begin{%s}" env-or-mac)))
818 (or (assoc string toc-levels)
819 (push (cons string toc-level) toc-levels))))))))
820 ;; Translate some special context cases
821 (when (assq context reftex-default-context-regexps)
822 (setq context
823 (format
824 (cdr (assq context reftex-default-context-regexps))
825 (regexp-quote env-or-mac))))
826 ;; See if this is the first format for this typekey
827 (and reffmt
828 (not (assoc typekey reftex-typekey-to-format-alist))
829 (push (cons typekey reffmt) reftex-typekey-to-format-alist))
830 ;; See if this is the first definition for this env-or-mac
831 (and (not (string= env-or-mac "any"))
832 (not (string= env-or-mac ""))
833 (not (assoc env-or-mac reftex-env-or-mac-alist))
834 (push (list env-or-mac typekey context labelfmt
835 nargs nlabel opt-args)
836 reftex-env-or-mac-alist))
837 ;; Are the magic words regular expressions? Quote normal words.
838 (if (eq (car wordlist) 'regexp)
839 (setq wordlist (cdr wordlist))
840 (setq wordlist (mapcar 'regexp-quote wordlist)))
841 ;; Remember the first association of each word.
842 (while (stringp (setq word (pop wordlist)))
843 (or (assoc word reftex-words-to-typekey-alist)
844 (push (cons word typekey) reftex-words-to-typekey-alist)))
845 (cond
846 ((string= "" env-or-mac) nil)
847 ((setq cell (assoc typekey qh-list))
848 (push env-or-mac (cdr cell)))
849 (typekey
850 (push (list typekey env-or-mac) qh-list)))))
851
852 (setq reftex-typekey-to-prefix-alist
853 (nreverse reftex-typekey-to-prefix-alist))
854
855 ;; Prepare the typekey query prompt and help string.
856 (setq qh-list
857 (sort qh-list
858 (lambda (x1 x2)
859 (string< (downcase (car x1)) (downcase (car x2))))))
860 (setq reftex-type-query-prompt
861 (concat "Label type: ["
862 (mapconcat (lambda(x) (format "%s" (car x)))
863 qh-list "")
864 "]"))
865 ;; In the help string, we need to wrap lines...
866 (setq reftex-type-query-help
867 (concat
868 "SELECT A LABEL TYPE:\n--------------------\n"
869 (mapconcat
870 (lambda(x)
871 (setq sum 0)
872 (format " [%s] %s"
873 (car x)
874 (mapconcat (lambda(env)
875 (setq sum (+ sum (length env)))
876 (if (< sum 60)
877 env
878 (setq sum 0)
879 (concat "\n " env)))
880 (cdr x) " ")))
881 qh-list "\n")))
882
883 ;; Convert magic words to regular expressions. We make regular expressions
884 ;; which allow for some chars from the ref format to be in the buffer.
885 ;; These characters will be seen and removed.
886 (setq reftex-words-to-typekey-alist
887 (mapcar
888 (lambda (x)
889 (setq word (car x)
890 typekey (cdr x)
891 fmt (cdr (assoc typekey reftex-typekey-to-format-alist)))
892 (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\("))
893 (setq i 0)
894 (while (and (< i 10) ; maximum number of format chars allowed
895 (< i (length fmt))
896 (not (member (aref fmt i) '(?%))))
897 (setq word (concat word "\\|" (regexp-quote
898 (substring fmt 0 (1+ i)))))
899 (incf i))
900 (cons (concat word "\\)\\=") typekey))
901 (nreverse reftex-words-to-typekey-alist)))
902
903 ;; Parse the index macros
904 (setq reftex-index-macro-alist nil
905 reftex-key-to-index-macro-alist nil
906 reftex-macros-with-index nil)
907 (while all-index
908 (setq entry (car all-index)
909 macro (car entry)
910 tag (nth 1 entry)
911 key (nth 2 entry)
912 prefix (or (nth 3 entry) "")
913 verify (nth 4 entry)
914 ;; For repeat, we need to be compatible with older code
915 ;; This information used to be given only for the default macro,
916 ;; but later we required to have it for *every* index macro
917 repeat (cond ((> (length entry) 5) (nth 5 entry))
918 ((and (eq key (car reftex-index-default-macro))
919 (> (length reftex-index-default-macro) 2))
920 ;; User has old setting - respect it
921 (nth 2 reftex-index-default-macro))
922 (t t))
923 all-index (cdr all-index))
924 (let ((result (reftex-parse-args macro)))
925 (setq macro (or (first result) macro)
926 nargs (second result)
927 nindex (third result)
928 opt-args (fourth result))
929 (unless (member macro reftex-macros-with-index)
930 ;; 0 1 2 3 4 5 6 7
931 (push (list macro tag prefix verify nargs nindex opt-args repeat)
932 reftex-index-macro-alist)
933 (or (assoc key reftex-key-to-index-macro-alist)
934 (push (list key macro) reftex-key-to-index-macro-alist))
935 (push macro reftex-macros-with-index))))
936 ;; Make the prompt and help string for index macros query
937 (setq reftex-key-to-index-macro-alist
938 (sort reftex-key-to-index-macro-alist
939 (lambda (a b) (< (downcase (car a)) (downcase (car b))))))
940 (setq reftex-query-index-macro-prompt
941 (concat "Index macro: ["
942 (mapconcat (lambda (x) (char-to-string (car x)))
943 reftex-key-to-index-macro-alist "")
944 "]"))
945 (setq i 0
946 reftex-query-index-macro-help
947 (concat
948 "SELECT A MACRO:\n---------------\n"
949 (mapconcat
950 (lambda(x)
951 (format "[%c] %-20.20s%s" (car x) (nth 1 x)
952 (if (= 0 (mod (incf i) 3)) "\n" "")))
953 reftex-key-to-index-macro-alist "")))
954
955 ;; Make the full list of section levels
956 (setq reftex-section-levels-all
957 (append toc-levels
958 (get reftex-docstruct-symbol 'reftex-section-levels)
959 reftex-section-levels))
960
961 ;; Calculate the regular expressions
962 (let* (
963 ; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
964 (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because
965 ; match numbers are hard coded
966 (label-re (concat "\\(?:"
967 (mapconcat 'identity reftex-label-regexps "\\|")
968 "\\)"))
969 (include-re (concat wbol
970 "\\\\\\("
971 (mapconcat 'identity
972 reftex-include-file-commands "\\|")
973 "\\)[{ \t]+\\([^} \t\n\r]+\\)"))
974 (section-re
975 (concat wbol reftex-section-pre-regexp "\\("
976 (mapconcat (lambda (x) (regexp-quote (car x)))
977 reftex-section-levels-all "\\|")
978 "\\)" reftex-section-post-regexp))
979 (appendix-re (concat wbol "\\(\\\\appendix\\)"))
980 (macro-re
981 (if macros-with-labels
982 (concat "\\("
983 (mapconcat 'regexp-quote macros-with-labels "\\|")
984 "\\)[[{]")
985 ""))
986 (index-re
987 (concat "\\("
988 (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
989 "\\)[[{]"))
990 (find-index-re-format
991 (concat "\\("
992 (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
993 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
994 (find-label-re-format
995 (concat "\\("
996 "label[[:space:]]*=[[:space:]]*"
997 "\\|"
998 (mapconcat 'regexp-quote (append '("\\label")
999 macros-with-labels) "\\|")
1000 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
1001 (index-level-re
1002 (regexp-quote (nth 0 reftex-index-special-chars)))
1003 (index-key-end-re ;; ^]- not allowed
1004 (concat "[^" (nth 3 reftex-index-special-chars) "]"
1005 "[" (nth 1 reftex-index-special-chars)
1006 (nth 2 reftex-index-special-chars) "]"))
1007 )
1008 (setq reftex-section-regexp section-re
1009 reftex-section-or-include-regexp
1010 (concat section-re "\\|" include-re)
1011 reftex-everything-regexp
1012 (concat label-re "\\|" section-re "\\|" include-re
1013 "\\|" appendix-re
1014 "\\|" index-re
1015 (if macros-with-labels "\\|" "") macro-re)
1016 reftex-everything-regexp-no-index
1017 (concat label-re "\\|" section-re "\\|" include-re
1018 "\\|" appendix-re
1019 "\\|" "\\(\\\\6\\\\3\\\\1\\)" ; This is unlikely to match
1020 (if macros-with-labels "\\|" "") macro-re)
1021 reftex-index-re index-re
1022 reftex-index-level-re index-level-re
1023 reftex-index-key-end-re index-key-end-re
1024 reftex-macros-with-labels macros-with-labels
1025 reftex-find-index-entry-regexp-format find-index-re-format
1026 reftex-find-label-regexp-format find-label-re-format
1027 reftex-find-label-regexp-format2
1028 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]")
1029 (message "Compiling label environment definitions...done")))
1030 (put reftex-docstruct-symbol 'reftex-cache
1031 (mapcar 'symbol-value reftex-cache-variables)))
1032
1033 (defun reftex-parse-args (macro)
1034 ;; Return a list of macro name, nargs, arg-nr which is label and a list of
1035 ;; optional argument indices.
1036 (if (string-match "[[{]\\*?[]}]" macro)
1037 (progn
1038 (let ((must-match (substring macro 0 (match-beginning 0)))
1039 (args (substring macro (match-beginning 0)))
1040 opt-list nlabel (cnt 0))
1041 (while (string-match "\\`[[{]\\(\\*\\)?[]}]" args)
1042 (incf cnt)
1043 (when (eq ?\[ (string-to-char args))
1044 (push cnt opt-list))
1045 (when (and (match-end 1)
1046 (not nlabel))
1047 (setq nlabel cnt))
1048 (setq args (substring args (match-end 0))))
1049 (list must-match cnt nlabel opt-list)))
1050 nil))
1051
1052 ;;; =========================================================================
1053 ;;;
1054 ;;; Accessing the parse information
1055
1056 (defun reftex-access-scan-info (&optional rescan file)
1057 "Ensure access to the scanning info for the current file."
1058 ;; When the multifile symbols are not yet tied,
1059 ;; tie them. When they are empty or RESCAN is non-nil, scan the document.
1060 ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
1061 ;; When FILE is non-nil, parse only from that file.
1062
1063 ;; Error out in a buffer without a file.
1064 (if (and reftex-mode
1065 (not (buffer-file-name)))
1066 (error "RefTeX works only in buffers visiting a file"))
1067
1068 ;; Make sure we have the symbols tied
1069 (if (eq reftex-docstruct-symbol nil)
1070 ;; Symbols are not yet tied: Tie them.
1071 (reftex-tie-multifile-symbols))
1072
1073 (reftex-ensure-compiled-variables)
1074
1075 (when (or (null (symbol-value reftex-docstruct-symbol))
1076 (member rescan '(t 1 (4) (16))))
1077 ;; The docstruct will change: Remove selection buffers.
1078 (save-excursion
1079 (reftex-erase-buffer "*toc*")
1080 (reftex-erase-all-selection-and-index-buffers)))
1081
1082 (if (and (null (symbol-value reftex-docstruct-symbol))
1083 (not (member rescan '(t 1 (4) (16))))
1084 reftex-save-parse-info)
1085 ;; Try to read the stuff from a file
1086 (reftex-access-parse-file 'read))
1087
1088 (cond
1089 ((equal rescan -1)) ;; We are not allowed to scan.
1090 ((not (symbol-value reftex-docstruct-symbol))
1091 ;; Scan the whole document
1092 (reftex-do-parse 1 file))
1093 ((member rescan '(t 1 (4) (16)))
1094 ;; Scan whatever was required by the caller.
1095 (reftex-do-parse rescan file))))
1096
1097 (defun reftex-scanning-info-available-p ()
1098 "Is the scanning info about the current document available?"
1099 (unless reftex-docstruct-symbol
1100 (reftex-tie-multifile-symbols))
1101 (and (symbolp reftex-docstruct-symbol)
1102 (symbol-value reftex-docstruct-symbol)
1103 t))
1104
1105 (defun reftex-silence-toc-markers (list n)
1106 ;; Set all toc markers in the first N entries in list to nil
1107 (while (and list (> (decf n) -1))
1108 (and (eq (car (car list)) 'toc)
1109 (markerp (nth 4 (car list)))
1110 (set-marker (nth 4 (car list)) nil))
1111 (pop list)))
1112
1113 (defun reftex-access-parse-file (action)
1114 "Perform ACTION on the parse file (the .rel file).
1115 Valid actions are: readable, restore, read, kill, write."
1116 (let* ((list (symbol-value reftex-docstruct-symbol))
1117 (docstruct-symbol reftex-docstruct-symbol)
1118 (master (reftex-TeX-master-file))
1119 (enable-local-variables nil)
1120 (file (if (string-match "\\.[a-zA-Z]+\\'" master)
1121 (concat (substring master 0 (match-beginning 0))
1122 reftex-parse-file-extension)
1123 (concat master reftex-parse-file-extension))))
1124 (cond
1125 ((eq action 'readable)
1126 (file-readable-p file))
1127 ((eq action 'restore)
1128 (put reftex-docstruct-symbol 'modified nil)
1129 (if (eq reftex-docstruct-symbol nil)
1130 ;; Symbols are not yet tied: Tie them.
1131 (reftex-tie-multifile-symbols))
1132 (if (file-exists-p file)
1133 ;; load the file and return t for success
1134 (condition-case nil
1135 (progn (load-file file) t)
1136 (error (set reftex-docstruct-symbol nil)
1137 (error "Error while loading file %s" file)))
1138 ;; Throw an exception if the file does not exist
1139 (error "No restore file %s" file)))
1140 ((eq action 'read)
1141 (put reftex-docstruct-symbol 'modified nil)
1142 (if (file-exists-p file)
1143 ;; load the file and return t for success
1144 (condition-case nil
1145 (progn
1146 (load-file file)
1147 (reftex-check-parse-consistency)
1148 t)
1149 (error (message "Error while restoring file %s" file)
1150 (set reftex-docstruct-symbol nil)
1151 nil))
1152 ;; return nil for failure, but no exception
1153 nil))
1154 ((eq action 'kill)
1155 ;; Remove the file
1156 (when (and (file-exists-p file) (file-writable-p file))
1157 (message "Unlinking file %s" file)
1158 (delete-file file)))
1159 (t
1160 (put docstruct-symbol 'modified nil)
1161 (save-excursion
1162 (if (file-writable-p file)
1163 (with-temp-file file
1164 (message "Writing parse file %s" (abbreviate-file-name file))
1165 (insert (format ";; RefTeX parse info file\n"))
1166 (insert (format ";; File: %s\n" master))
1167 (insert (format ";; User: %s (%s)\n\n"
1168 (user-login-name) (user-full-name)))
1169 (insert "(set reftex-docstruct-symbol '(\n\n")
1170 (let ((standard-output (current-buffer)))
1171 (mapc
1172 (lambda (x)
1173 (cond ((eq (car x) 'toc)
1174 ;; A toc entry. Do not save the marker.
1175 ;; Save the markers position at position 8
1176 (print (list 'toc "toc" (nth 2 x) (nth 3 x)
1177 nil (nth 5 x) (nth 6 x) (nth 7 x)
1178 (or (and (markerp (nth 4 x))
1179 (marker-position (nth 4 x)))
1180 (nth 8 x)))))
1181 ((and (not (eq t reftex-support-index))
1182 (eq (car x) 'index))
1183 ;; Don't save index entries
1184 )
1185 (t (print x))))
1186 list))
1187 (insert "))\n\n"))
1188 (error "Cannot write to file %s" file)))
1189 t))))
1190
1191 (defun reftex-check-parse-consistency ()
1192 ;; Check if parse file is consistent, throw an error if not.
1193
1194 ;; Check if the master is the same: when moving a document, this will see it.
1195 (let* ((real-master (reftex-TeX-master-file))
1196 (parsed-master
1197 (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol)))))
1198 (unless (string= (file-truename real-master) (file-truename parsed-master))
1199 (message "Master file name in load file is different: %s versus %s"
1200 parsed-master real-master)
1201 (error "Master file name error")))
1202
1203 ;; Check for the existence of all document files
1204 ;;; (let* ((all (symbol-value reftex-docstruct-symbol)))
1205 ;;; (while all
1206 ;;; (when (and (eq (car (car all)) 'bof)
1207 ;;; (not (file-regular-p (nth 1 (car all)))))
1208 ;;; (message "File %s in saved parse info not available" (cdr (car all)))
1209 ;;; (error "File not found"))
1210 ;;; (setq all (cdr all))))
1211 )
1212
1213 (defun reftex-select-external-document (xr-alist xr-index)
1214 ;; Return index of an external document.
1215 (let* ((len (length xr-alist)) (highest (1- (+ ?0 len)))
1216 (prompt (format "[%c-%c] Select TAB: Read prefix with completion"
1217 ?0 highest))
1218 key prefix)
1219 (cond
1220 ((= len 1)
1221 (message "No external documents available")
1222 (ding) (sit-for 1) 0)
1223 ((= len 2)
1224 (- 1 xr-index))
1225 (t
1226 (save-excursion
1227 (let* ((length (apply 'max (mapcar
1228 (lambda(x) (length (car x))) xr-alist)))
1229 (fmt (format " [%%c] %%-%ds %%s\n" length))
1230 (n (1- ?0)))
1231 (setq key
1232 (reftex-select-with-char
1233 prompt
1234 (concat
1235 "SELECT EXTERNAL DOCUMENT\n------------------------\n"
1236 (mapconcat
1237 (lambda (x)
1238 (format fmt (incf n) (or (car x) "")
1239 (abbreviate-file-name (cdr x))))
1240 xr-alist ""))
1241 nil t))
1242 (cond
1243 ((and (>= key ?0) (<= key highest)) (- key ?0))
1244 ((= key ?\C-i)
1245 (setq prefix (completing-read "Prefix: " xr-alist nil t))
1246 (- len (length (memq (assoc prefix xr-alist) xr-alist))))
1247 (t (error "Invalid document selection [%c]" key)))))))))
1248
1249 ;;; =========================================================================
1250 ;;;
1251 ;;; Finding files
1252
1253 (defun reftex-locate-file (file type master-dir &optional die)
1254 "Find FILE of type TYPE in MASTER-DIR or on the path associated with TYPE.
1255 If the file does not have any of the valid extensions for TYPE,
1256 try first the default extension and only then the naked file name.
1257 When DIE is non-nil, throw an error if file not found."
1258 (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
1259 (extensions (cdr (assoc type reftex-file-extensions)))
1260 (def-ext (car extensions))
1261 (ext-re (concat "\\("
1262 (mapconcat 'regexp-quote extensions "\\|")
1263 "\\)\\'"))
1264 (files (if (string-match ext-re file)
1265 (cons file nil)
1266 (if reftex-try-all-extensions
1267 (append (mapcar (lambda (x) (concat file x))
1268 extensions)
1269 (list file))
1270 (list (concat file def-ext) file))))
1271 path old-path file1 f fs)
1272 (cond
1273 ((file-name-absolute-p file)
1274 (while (setq f (pop files))
1275 (if (file-regular-p f)
1276 (setq file1 f files nil))))
1277 ((and reftex-use-external-file-finders
1278 (assoc type reftex-external-file-finders))
1279 (setq file1 (reftex-find-file-externally file type master-dir)))
1280 (t
1281 (while (and (null file1) rec-values)
1282 (setq path (reftex-access-search-path
1283 type (pop rec-values) master-dir file))
1284 (setq fs files)
1285 (while (and (null file1) (setq f (pop fs)))
1286 (when (or (null old-path)
1287 (not (eq old-path path)))
1288 (setq old-path path
1289 path (cons master-dir path))
1290 (setq file1 (reftex-find-file-on-path f path master-dir)))))))
1291 (cond (file1 file1)
1292 (die (error "No such file: %s" file) nil)
1293 (t (message "No such file: %s (ignored)" file) nil))))
1294
1295 (defun reftex-find-file-externally (file type &optional master-dir)
1296 ;; Use external program to find FILE.
1297 ;; The program is taken from `reftex-external-file-finders'.
1298 ;; Interpret relative path definitions starting from MASTER-DIR.
1299 (let ((default-directory (or master-dir default-directory))
1300 (prg (cdr (assoc type reftex-external-file-finders)))
1301 out)
1302 (if (string-match "%f" prg)
1303 (setq prg (replace-match file t t prg)))
1304 (setq out (apply 'reftex-process-string (split-string prg)))
1305 (if (string-match "[ \t\n]+\\'" out) ; chomp
1306 (setq out (replace-match "" nil nil out)))
1307 (cond ((equal out "") nil)
1308 ((file-regular-p out) (expand-file-name out master-dir))
1309 (t nil))))
1310
1311 (defun reftex-process-string (program &rest args)
1312 "Execute PROGRAM with arguments ARGS and return its STDOUT as a string."
1313 (let ((calling-dir default-directory)) ; remember default directory
1314 (with-output-to-string
1315 (with-current-buffer standard-output
1316 (let ((default-directory calling-dir)) ; set default directory
1317 (apply 'call-process program nil '(t nil) nil args))))))
1318
1319 (defun reftex-access-search-path (type &optional recurse master-dir file)
1320 ;; Access path from environment variables. TYPE is either "tex" or "bib".
1321 ;; When RECURSE is t, expand path elements ending in `//' recursively.
1322 ;; Relative path elements are left as they are. However, relative recursive
1323 ;; elements are expanded with MASTER-DIR as default directory.
1324 ;; The expanded path is cached for the next search.
1325 ;; FILE is just for the progress message.
1326 ;; Returns the derived path.
1327 (let* ((pathvar (intern (concat "reftex-" type "-path"))))
1328 (when (null (get pathvar 'status))
1329 ;; Get basic path
1330 (set pathvar
1331 (reftex-uniquify
1332 (reftex-parse-colon-path
1333 (mapconcat
1334 (lambda(x)
1335 (if (string-match "^!" x)
1336 (apply 'reftex-process-string
1337 (split-string (substring x 1)))
1338 (or (getenv x) x)))
1339 ;; For consistency, the next line should look like this:
1340 ;; (cdr (assoc type reftex-path-environment))
1341 ;; However, historically we have separate options for the
1342 ;; environment variables, so we have to do this:
1343 (symbol-value (intern (concat "reftex-" type
1344 "path-environment-variables")))
1345 path-separator))))
1346 (put pathvar 'status 'split)
1347 ;; Check if we have recursive elements
1348 (let ((path (symbol-value pathvar)) dir rec)
1349 (while (setq dir (pop path))
1350 (when (string= (substring dir -2) "//")
1351 (if (file-name-absolute-p dir)
1352 (setq rec (or rec 'absolute))
1353 (setq rec 'relative))))
1354 (put pathvar 'rec-type rec)))
1355
1356 (if recurse
1357 ;; Return the recursive expansion of the path
1358 (cond
1359 ((not (get pathvar 'rec-type))
1360 ;; Path does not contain recursive elements - use simple path
1361 (symbol-value pathvar))
1362 ((or (not (get pathvar 'recursive-path))
1363 (and (eq (get pathvar 'rec-type) 'relative)
1364 (not (equal master-dir (get pathvar 'master-dir)))))
1365 ;; Either: We don't have a recursive expansion yet.
1366 ;; or: Relative recursive path elements need to be expanded
1367 ;; relative to new default directory
1368 (message "Expanding search path to find %s file: %s ..." type file)
1369 (put pathvar 'recursive-path
1370 (reftex-expand-path (symbol-value pathvar) master-dir))
1371 (put pathvar 'master-dir master-dir)
1372 (get pathvar 'recursive-path))
1373 (t
1374 ;; Recursive path computed earlier is still OK.
1375 (get pathvar 'recursive-path)))
1376 ;; The simple path was requested
1377 (symbol-value pathvar))))
1378
1379 (defun reftex-find-file-on-path (file path &optional def-dir)
1380 ;; Find FILE along the directory list PATH.
1381 ;; DEF-DIR is the default directory for expanding relative path elements.
1382 (catch 'exit
1383 (when (file-name-absolute-p file)
1384 (if (file-regular-p file)
1385 (throw 'exit file)
1386 (throw 'exit nil)))
1387 (let* ((thepath path) file1 dir)
1388 (while (setq dir (pop thepath))
1389 (when (string= (substring dir -2) "//")
1390 (setq dir (substring dir 0 -1)))
1391 (setq file1 (expand-file-name file (expand-file-name dir def-dir)))
1392 (if (file-regular-p file1)
1393 (throw 'exit file1)))
1394 ;; No such file
1395 nil)))
1396
1397 (defun reftex-parse-colon-path (path)
1398 ;; Like parse-colon-parse, but // or /~ are left alone.
1399 ;; Trailing ! or !! will be converted into `//' (emTeX convention)
1400 (mapcar
1401 (lambda (dir)
1402 (if (string-match "\\(//+\\|/*!+\\)\\'" dir)
1403 (setq dir (replace-match "//" t t dir)))
1404 (file-name-as-directory dir))
1405 (delete "" (split-string path (concat path-separator "+")))))
1406
1407 (defun reftex-expand-path (path &optional default-dir)
1408 ;; Expand parts of path ending in `//' recursively into directory list.
1409 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
1410 (let (path1 dir recursive)
1411 (while (setq dir (pop path))
1412 (if (setq recursive (string= (substring dir -2) "//"))
1413 (setq dir (substring dir 0 -1)))
1414 (if (and recursive
1415 (not (file-name-absolute-p dir)))
1416 (setq dir (expand-file-name dir default-dir)))
1417 (if recursive
1418 ;; Expand recursively
1419 (setq path1 (append (reftex-recursive-directory-list dir) path1))
1420 ;; Keep unchanged
1421 (push dir path1)))
1422 (nreverse path1)))
1423
1424 (defun reftex-recursive-directory-list (dir)
1425 ;; Return a list of all directories below DIR, including DIR itself
1426 (let ((path (list dir)) path1 file files)
1427 (while (setq dir (pop path))
1428 (when (file-directory-p dir)
1429 (setq files (nreverse (directory-files dir t "[^.]")))
1430 (while (setq file (pop files))
1431 (if (file-directory-p file)
1432 (push (file-name-as-directory file) path)))
1433 (push dir path1)))
1434 path1))
1435
1436 ;;; =========================================================================
1437 ;;;
1438 ;;; Some generally useful functions
1439
1440 (defun reftex-typekey-check (typekey conf-variable &optional n)
1441 ;; Check if CONF-VARIABLE is true or contains TYPEKEY
1442 (and n (setq conf-variable (nth n conf-variable)))
1443 (or (eq conf-variable t)
1444 (and (stringp conf-variable)
1445 (string-match (concat "[" conf-variable "]") typekey))))
1446
1447 (defun reftex-check-recursive-edit ()
1448 ;; Check if we are already in a recursive edit. Abort with helpful
1449 ;; message if so.
1450 (if (marker-position reftex-recursive-edit-marker)
1451 (error
1452 (substitute-command-keys
1453 "In unfinished selection process. Finish, or abort with \\[abort-recursive-edit]"))))
1454
1455 (defun reftex-in-comment ()
1456 "Return non-nil if point is in a comment."
1457 (save-excursion
1458 (save-match-data
1459 (let ((pos (point)))
1460 (beginning-of-line)
1461 (re-search-forward
1462 (or comment-start-skip
1463 ;; The parser may open files in fundamental mode if
1464 ;; `reftex-initialize-temporary-buffers' is nil, so here
1465 ;; is a default suitable for plain TeX and LaTeX.
1466 "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)\\(%+[ \t]*\\)")
1467 pos t)))))
1468
1469 (defun reftex-no-props (string)
1470 ;; Return STRING with all text properties removed
1471 (and (stringp string)
1472 (set-text-properties 0 (length string) nil string))
1473 string)
1474
1475 (defun reftex-match-string (n)
1476 ;; Match string without properties
1477 (when (match-beginning n)
1478 (buffer-substring-no-properties (match-beginning n) (match-end n))))
1479
1480 (defun reftex-region-active-p ()
1481 "Should we operate on an active region?"
1482 (if (fboundp 'use-region-p)
1483 (use-region-p)
1484 ;; For XEmacs.
1485 (region-active-p)))
1486
1487 (defun reftex-kill-buffer (buffer)
1488 ;; Kill buffer if it exists.
1489 (and (setq buffer (get-buffer buffer))
1490 (kill-buffer buffer)))
1491
1492 (defun reftex-erase-buffer (&optional buffer)
1493 ;; Erase BUFFER if it exists. BUFFER defaults to current buffer.
1494 ;; This even erases read-only buffers.
1495 (cond
1496 ((null buffer)
1497 ;; erase current buffer
1498 (let ((buffer-read-only nil)) (erase-buffer)))
1499 ((setq buffer (get-buffer buffer))
1500 ;; buffer exists
1501 (with-current-buffer buffer
1502 (let ((inhibit-read-only t)) (erase-buffer))))))
1503
1504 (defun reftex-this-word (&optional class)
1505 ;; Grab the word around point.
1506 (setq class (or class "-a-zA-Z0-9:_/.*;|"))
1507 (save-excursion
1508 (buffer-substring-no-properties
1509 (progn (skip-chars-backward class) (point))
1510 (progn (skip-chars-forward class) (point)))))
1511
1512 (defun reftex-number (n unit &optional ending)
1513 (if (and (integerp n) (stringp unit))
1514 (format "%d %s%s" n unit (if (= n 1) "" (or ending "s")))
1515 ""))
1516
1517 (defun reftex-all-assq (key list)
1518 ;; Return a list of all associations of KEY in LIST. Comparison with eq.
1519 (let (rtn)
1520 (while (setq list (memq (assq key list) list))
1521 (push (car list) rtn)
1522 (pop list))
1523 (nreverse rtn)))
1524
1525 (defun reftex-all-assoc-string (key list)
1526 ;; Return a list of all associations of KEY in LIST. Comparison with string=.
1527 (let (rtn)
1528 (while list
1529 (if (string= (car (car list)) key)
1530 (push (car list) rtn))
1531 (pop list))
1532 (nreverse rtn)))
1533
1534 (defun reftex-last-assoc-before-elt (key elt list &optional exclusive)
1535 ;; Find the last association of KEY in LIST before or at ELT
1536 ;; ELT is found in LIST with equal, not eq.
1537 ;; Returns nil when either KEY or elt are not found in LIST.
1538 ;; When EXCLUSIVE is non-nil, ELT cannot be the return value.
1539 ;; On success, returns the association.
1540 (let* ((elt (car (member elt list))) (ex (not exclusive)) ass last-ass)
1541 (while (and (setq ass (assoc key list))
1542 (setq list (memq ass list))
1543 (or ex (not (eq elt (car list))))
1544 (memq elt list))
1545 (setq last-ass ass
1546 list (cdr list)))
1547 last-ass))
1548
1549 (defun reftex-sublist-nth (list nth predicate &optional completion)
1550 ;; Make a list of the NTH elements of all members of LIST which
1551 ;; fulfill PREDICATE.
1552 ;; When COMPLETION is non-nil, make all elements of the resulting
1553 ;; list also a list, so that the result can be used for completion.
1554 (let (rtn)
1555 (while list
1556 (if (funcall predicate (car list))
1557 (push (if completion
1558 (list (nth nth (car list)))
1559 (nth nth (car list)))
1560 rtn))
1561 (setq list (cdr list)))
1562 (nreverse rtn)))
1563
1564 (defun reftex-make-selection-buffer-name (type &optional index)
1565 ;; Make unique name for a selection buffer.
1566 (format " *RefTeX[%s][%d]*"
1567 type (or index (get reftex-docstruct-symbol :master-index) 0)))
1568
1569 (defun reftex-make-index-buffer-name (tag &optional cnt)
1570 ;; Make unique name for an index buffer.
1571 (format "*Index[%s][%d]*"
1572 tag (or cnt (get reftex-docstruct-symbol :master-index) 0)))
1573
1574 (defun reftex-truncate (string ncols &optional ellipses padding)
1575 ;; Truncate STRING to NCOLS characters.
1576 ;; When PADDING is non-nil, and string is shorter than NCOLS, fill with
1577 ;; white space to NCOLS characters. When ELLIPSES is non-nil and the
1578 ;; string needs to be truncated, replace last 3 characters by dots.
1579 (setq string
1580 (if (<= (length string) ncols)
1581 string
1582 (if ellipses
1583 (concat (substring string 0 (- ncols 3)) "...")
1584 (substring string 0 ncols))))
1585 (if padding
1586 (format (format "%%-%ds" ncols) string)
1587 string))
1588
1589 (defun reftex-nearest-match (regexp &optional max-length)
1590 ;; Find the nearest match of REGEXP. Set the match data.
1591 ;; If POS is given, calculate distances relative to it.
1592 ;; Return nil if there is no match.
1593 (let ((pos (point))
1594 (dist (or max-length (length regexp)))
1595 match1 match2 match)
1596 (goto-char (min (+ pos dist) (point-max)))
1597 (when (re-search-backward regexp nil t)
1598 (setq match1 (match-data)))
1599 (goto-char (max (- pos dist) (point-min)))
1600 (when (re-search-forward regexp nil t)
1601 (setq match2 (match-data)))
1602 (goto-char pos)
1603 (setq match
1604 (cond
1605 ((not match1) match2)
1606 ((not match2) match1)
1607 ((< (abs (- pos (car match1))) (abs (- pos (car match2)))) match1)
1608 (t match2)))
1609 (if match (progn (set-match-data match) t) nil)))
1610
1611 (defun reftex-auto-mode-alist ()
1612 ;; Return an `auto-mode-alist' with only the .gz (etc) thingies.
1613 ;; Stolen from gnus nnheader.
1614 (let ((alist auto-mode-alist)
1615 out)
1616 (while alist
1617 (when (listp (cdr (car alist)))
1618 (push (car alist) out))
1619 (pop alist))
1620 (nreverse out)))
1621
1622 (defun reftex-window-height ()
1623 (if (fboundp 'window-displayed-height)
1624 (window-displayed-height)
1625 (window-height)))
1626
1627 (defun reftex-enlarge-to-fit (buf2 &optional keep-current)
1628 ;; Enlarge other window displaying buffer to show whole buffer if possible.
1629 ;; If KEEP-CURRENT in non-nil, current buffer must remain visible.
1630 (let* ((win1 (selected-window))
1631 (buf1 (current-buffer))
1632 (win2 (get-buffer-window buf2))) ;; Only on current frame.
1633 (when win2
1634 (select-window win2)
1635 (unless (and (pos-visible-in-window-p (point-min))
1636 (pos-visible-in-window-p (point-max)))
1637 (enlarge-window (1+ (- (count-lines (point-min) (point-max))
1638 (reftex-window-height))))))
1639 (cond
1640 ((window-live-p win1) (select-window win1))
1641 (keep-current
1642 ;; we must have the old buffer!
1643 (switch-to-buffer-other-window buf1)
1644 (shrink-window (- (window-height) window-min-height))))))
1645
1646 (defun reftex-select-with-char (prompt help-string &optional delay-time scroll)
1647 ;; Offer to select something with PROMPT and, after DELAY-TIME seconds,
1648 ;; also with HELP-STRING.
1649 ;; When SCROLL is non-nil, use SPC and DEL to scroll help window.
1650 (let ((char ?\?))
1651 (save-window-excursion
1652 (catch 'exit
1653 (message "%s (?=Help)" prompt)
1654 (when (or (sit-for (or delay-time 0))
1655 (= ?\? (setq char (read-char-exclusive))))
1656 (reftex-kill-buffer "*RefTeX Select*")
1657 (switch-to-buffer-other-window "*RefTeX Select*")
1658 (insert help-string)
1659 (goto-char 1)
1660 (unless (and (pos-visible-in-window-p (point-min))
1661 (pos-visible-in-window-p (point-max)))
1662 (enlarge-window (1+ (- (count-lines (point-min) (point-max))
1663 (reftex-window-height)))))
1664 (setq truncate-lines t))
1665 (if (and (pos-visible-in-window-p (point-min))
1666 (pos-visible-in-window-p (point-max)))
1667 nil
1668 (setq prompt (concat prompt (if scroll " (SPC/DEL=Scroll)" ""))))
1669 (message "%s" prompt)
1670 (and (equal char ?\?) (setq char (read-char-exclusive)))
1671 (while t
1672 (cond ((equal char ?\C-g) (keyboard-quit))
1673 ((equal char ?\?))
1674 ((and scroll (equal char ?\ ))
1675 (condition-case nil (scroll-up) (error nil))
1676 (message "%s" prompt))
1677 ((and scroll (equal char ?\C-? ))
1678 (condition-case nil (scroll-down) (error nil))
1679 (message "%s" prompt))
1680 (t (message "")
1681 (reftex-kill-buffer "*RefTeX Select*")
1682 (throw 'exit char)))
1683 (setq char (read-char-exclusive)))))))
1684
1685
1686 (defun reftex-make-regexp-allow-for-ctrl-m (string)
1687 ;; convert STRING into a regexp, allowing ^M for \n and vice versa
1688 (let ((start -2))
1689 (setq string (regexp-quote string))
1690 (while (setq start (string-match "[\n\r]" string (+ 3 start)))
1691 (setq string (replace-match "[\n\r]" nil t string)))
1692 string))
1693
1694 (defun reftex-get-buffer-visiting (file)
1695 ;; return a buffer visiting FILE
1696 (cond
1697 ((boundp 'find-file-compare-truenames) ; XEmacs
1698 (let ((find-file-compare-truenames t))
1699 (get-file-buffer file)))
1700 ((fboundp 'find-buffer-visiting) ; Emacs
1701 (find-buffer-visiting file))
1702 (t (error "This should not happen (reftex-get-buffer-visiting)"))))
1703
1704 ;; Define `current-message' for compatibility with XEmacs prior to 20.4
1705 (defvar message-stack)
1706 (if (and (featurep 'xemacs)
1707 (not (fboundp 'current-message)))
1708 (defun current-message (&optional frame)
1709 (cdr (car message-stack))))
1710
1711 (defun reftex-visited-files (list)
1712 ;; Takes a list of filenames and returns the buffers of those already visited
1713 (delq nil (mapcar (lambda (x) (if (reftex-get-buffer-visiting x) x nil))
1714 list)))
1715
1716 (defun reftex-get-file-buffer-force (file &optional mark-to-kill)
1717 ;; Return a buffer visiting file. Make one, if necessary.
1718 ;; If neither such a buffer nor the file exist, return nil.
1719 ;; If MARK-TO-KILL is t and there is no live buffer, visit the file with
1720 ;; initializations according to `reftex-initialize-temporary-buffers',
1721 ;; and mark the buffer to be killed after use.
1722
1723 (let ((buf (reftex-get-buffer-visiting file)))
1724
1725 (cond (buf
1726 ;; We have it already as a buffer - just return it
1727 buf)
1728
1729 ((file-readable-p file)
1730 ;; At least there is such a file and we can read it.
1731
1732 (if (or (not mark-to-kill)
1733 (eq t reftex-initialize-temporary-buffers))
1734
1735 ;; Visit the file with full magic
1736 (setq buf (find-file-noselect file))
1737
1738 ;; Else: Visit the file just briefly, without or
1739 ;; with limited Magic
1740
1741 ;; The magic goes away
1742 (letf ((format-alist nil)
1743 (auto-mode-alist (reftex-auto-mode-alist))
1744 ((default-value 'major-mode) 'fundamental-mode)
1745 (enable-local-variables nil)
1746 (after-insert-file-functions nil))
1747 (setq buf (find-file-noselect file)))
1748
1749 ;; Is there a hook to run?
1750 (when (listp reftex-initialize-temporary-buffers)
1751 (with-current-buffer buf
1752 (run-hooks 'reftex-initialize-temporary-buffers))))
1753
1754 ;; Let's see if we got a license to kill :-|
1755 (and mark-to-kill
1756 (add-to-list 'reftex-buffers-to-kill buf))
1757
1758 ;; Return the new buffer
1759 buf)
1760
1761 ;; If no such file exists, return nil
1762 (t nil))))
1763
1764 (defun reftex-kill-temporary-buffers (&optional buffer)
1765 ;; Kill all buffers in the list reftex-kill-temporary-buffers.
1766 (cond
1767 (buffer
1768 (when (member buffer reftex-buffers-to-kill)
1769 (kill-buffer buffer)
1770 (setq reftex-buffers-to-kill
1771 (delete buffer reftex-buffers-to-kill))))
1772 (t
1773 (while (setq buffer (pop reftex-buffers-to-kill))
1774 (when (bufferp buffer)
1775 (and (buffer-modified-p buffer)
1776 (y-or-n-p (format "Save file %s? "
1777 (buffer-file-name buffer)))
1778 (with-current-buffer buffer
1779 (save-buffer)))
1780 (kill-buffer buffer))
1781 (pop reftex-buffers-to-kill)))))
1782
1783 (defun reftex-splice-symbols-into-list (list alist)
1784 ;; Splice the association in ALIST of any symbols in LIST into the list.
1785 ;; Return new list.
1786 (let (rtn tmp)
1787 (while list
1788 (while (and (not (null (car list))) ;; keep list elements nil
1789 (symbolp (car list)))
1790 (setq tmp (car list))
1791 (cond
1792 ((assoc tmp alist)
1793 (setq list (append (nth 2 (assoc tmp alist)) (cdr list))))
1794 (t
1795 (error "Cannot treat symbol %s in reftex-label-alist"
1796 (symbol-name tmp)))))
1797 (push (pop list) rtn))
1798 (nreverse rtn)))
1799
1800 (defun reftex-remove-symbols-from-list (list)
1801 ;; Remove all symbols from list
1802 (let (rtn)
1803 (while list
1804 (unless (symbolp (car list))
1805 (push (car list) rtn))
1806 (setq list (cdr list)))
1807 (nreverse rtn)))
1808
1809 (defun reftex-uniquify (list &optional sort)
1810 ;; Return a list of all strings in LIST, but each only once, keeping order
1811 ;; unless SORT is set (faster!).
1812 (setq list (copy-sequence list))
1813 (if sort
1814 (progn
1815 (setq list (sort list 'string<))
1816 (let ((p list))
1817 (while (cdr p)
1818 (if (string= (car p) (car (cdr p)))
1819 (setcdr p (cdr (cdr p)))
1820 (setq p (cdr p)))))
1821 list)
1822 (let ((p list) lst elt)
1823 ;; push all sublists into lst in reverse(!) order
1824 (while p
1825 (push p lst)
1826 (setq p (cdr p)))
1827 ;; sort all sublists
1828 (setq lst (sort lst (lambda (x1 x2) (string< (car x1) (car x2)))))
1829 (while (cdr lst)
1830 (setq elt (car (car lst)))
1831 ;; for equal elements in the sorted sublist, replace the
1832 ;; last(!) original list member with nil
1833 (when (string= elt (car (cadr lst)))
1834 (setcar (pop lst) nil)
1835 (while (and (cdr lst) (string= elt (car (cadr lst))))
1836 (setcar (pop lst) nil)))
1837 (pop lst)))
1838 ;; weed out all nils and return.
1839 (delq nil list)))
1840
1841 (defun reftex-uniquify-by-car (alist &optional keep-list sort)
1842 ;; Return a list of all elements in ALIST, but each car only once.
1843 ;; Elements of KEEP-LIST are not removed even if duplicate.
1844 ;; The order is kept unless SORT is set (faster!).
1845 (setq keep-list (sort (copy-sequence keep-list) #'string<)
1846 alist (copy-sequence alist))
1847 (if sort
1848 (let (lst elt)
1849 (setq alist (sort alist (lambda(a b) (string< (car a) (car b)))))
1850 (setq lst alist)
1851 (while (cdr lst)
1852 (setq elt (car (car lst)))
1853 (when (string= elt (car (cadr lst)))
1854 (while (and keep-list (string< (car keep-list) elt))
1855 (pop keep-list))
1856 (if (and keep-list (string= elt (car keep-list)))
1857 (progn
1858 (pop lst)
1859 (while (and (cdr lst)
1860 (string= elt (car (cadr lst))))
1861 (pop lst)))
1862 (setcdr lst (cdr (cdr lst)))
1863 (while (and (cdr lst)
1864 (string= elt (car (cadr lst))))
1865 (setcdr lst (cdr (cdr lst))))))
1866 (pop lst))
1867 alist)
1868 (let ((p alist) lst elt)
1869 (while p
1870 (push p lst)
1871 (setq p (cdr p)))
1872 (setq lst (sort lst (lambda(a b) (string< (car (car a))
1873 (car (car b))))))
1874 (while (cdr lst)
1875 (setq elt (car (car (car lst))))
1876 (when (string= elt (car (car (cadr lst))))
1877 (while (and keep-list (string< (car keep-list) elt))
1878 (pop keep-list))
1879 (if (and keep-list (string= elt (car keep-list)))
1880 (progn
1881 (pop lst)
1882 (while (and (cdr lst)
1883 (string= elt (car (car (cadr lst)))))
1884 (pop lst)))
1885 (setcar (pop lst) nil)
1886 (while (and (cdr lst)
1887 (string= elt (car (car (cadr lst)))))
1888 (setcar (pop lst) nil))))
1889 (pop lst)))
1890 (delq nil alist)))
1891
1892 (defun reftex-remove-if (predicate list)
1893 "Nondestructively remove all items from LIST which satisfy PREDICATE."
1894 (let (result)
1895 (dolist (elt list (nreverse result))
1896 (unless (funcall predicate elt)
1897 (push elt result)))))
1898
1899 (defun reftex-abbreviate-title (string)
1900 (reftex-convert-string string "[-~ \t\n\r,;]" nil t t
1901 5 40 nil 1 " " (nth 5 reftex-derive-label-parameters)))
1902
1903 (defun reftex-convert-string (string split-re invalid-re dot keep-fp
1904 nwords maxchar invalid abbrev sep
1905 ignore-words &optional downcase)
1906 "Convert a string (a sentence) to something shorter.
1907 SPLIT-RE is the regular expression used to split the string into words.
1908 INVALID-RE matches characters which are invalid in the final string.
1909 DOT t means add dots to abbreviated words.
1910 KEEP-FP t means to keep a final punctuation when applicable.
1911 NWORDS Number of words to use.
1912 MAXCHAR Maximum number of characters in the final string.
1913 INVALID nil: Throw away any words containing stuff matched with INVALID-RE.
1914 t: Throw away only the matched part, not the whole word.
1915 ABBREV nil: Never abbreviate words.
1916 t: Always abbreviate words (see `reftex-abbrev-parameters').
1917 not t and not nil: Abbreviate words if necessary to shorten
1918 string below MAXCHAR.
1919 SEP String separating different words in the output string.
1920 IGNORE-WORDS List of words which should be removed from the string."
1921
1922 (let* ((words0 (split-string string (or split-re "[ \t\n\r]")))
1923 (reftex-label-illegal-re (or invalid-re "\000"))
1924 (abbrev-re (concat
1925 "\\`\\("
1926 (make-string (nth 0 reftex-abbrev-parameters) ?.)
1927 "[" (nth 2 reftex-abbrev-parameters) "]*"
1928 "\\)"
1929 "[" (nth 3 reftex-abbrev-parameters) "]"
1930 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
1931 words word)
1932
1933 ;; Remove words from the ignore list or with funny characters
1934 (while (setq word (pop words0))
1935 (if downcase (setq word (downcase word)))
1936 (cond
1937 ((member (downcase word) ignore-words))
1938 ((string-match reftex-label-illegal-re word)
1939 (when invalid
1940 (while (string-match reftex-label-illegal-re word)
1941 (setq word (replace-match "" nil nil word)))
1942 (push word words)))
1943 (t
1944 (push word words))))
1945 (setq words (nreverse words))
1946
1947 ;; Restrict number of words
1948 (if (> (length words) nwords)
1949 (setcdr (nthcdr (1- nwords) words) nil))
1950
1951 ;; First, try to use all words
1952 (setq string (mapconcat 'identity words sep))
1953
1954 ;; Abbreviate words if enforced by user settings or string length
1955 (if (or (eq t abbrev)
1956 (and abbrev
1957 (> (length string) maxchar)))
1958 (setq words
1959 (mapcar
1960 (lambda (w) (if (string-match abbrev-re w)
1961 (if dot
1962 (concat (match-string 1 w) ".")
1963 (match-string 1 w))
1964 w))
1965 words)
1966 string (mapconcat 'identity words sep)))
1967
1968 ;; Shorten if still to long
1969 (setq string
1970 (if (> (length string) maxchar)
1971 (substring string 0 maxchar)
1972 string))
1973
1974 ;; Delete the final punctuation, if any
1975 (if (and (not keep-fp) (string-match "\\s.+\\'" string))
1976 (setq string (replace-match "" nil nil string)))
1977 string))
1978
1979 (defun reftex-nicify-text (text)
1980 ;; Make TEXT nice for inclusion as context into label menu.
1981 ;; 1. remove line breaks and extra white space
1982 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text)
1983 (setq text (replace-match " " nil t text)))
1984 ;; 2. cut before the next `\end{' or `\item' or `\\'
1985 (if (string-match "\\(\\\\end{\\|\\\\item\\|\\\\\\\\\\).*" text)
1986 (setq text (replace-match "" nil t text)))
1987 ;; 3. kill the embedded label
1988 (if (string-match "\\\\label{[^}]*}" text)
1989 (setq text (replace-match "" nil t text)))
1990 ;; 4. remove leading garbage
1991 (if (string-match "\\`[ }]+" text)
1992 (setq text (replace-match "" nil t text)))
1993 ;; 5. limit length
1994 (cond
1995 ((> (length text) 100) (substring text 0 100))
1996 ((= (length text) 0) (make-string 1 ?\ ))
1997 (t text)))
1998
1999
2000 ;;; =========================================================================
2001 ;;;
2002 ;;; Fontification and Highlighting
2003
2004 (defun reftex-use-fonts ()
2005 ;; Return t if we can and want to use fonts.
2006 (and ; window-system
2007 reftex-use-fonts
2008 (featurep 'font-lock)))
2009
2010 (defun reftex-refontify ()
2011 ;; Return t if we need to refontify context
2012 (and (reftex-use-fonts)
2013 (or (eq t reftex-refontify-context)
2014 (and (eq 1 reftex-refontify-context)
2015 ;; Test of we use the font-lock version of x-symbol
2016 (and (featurep 'x-symbol-tex) (not (boundp 'x-symbol-mode)))))))
2017
2018 (defvar font-lock-defaults-computed)
2019 (defun reftex-fontify-select-label-buffer (parent-buffer)
2020 ;; Fontify the `*RefTeX Select*' buffer. Buffer is temporarily renamed to
2021 ;; start with none-SPC char, because Font-Lock otherwise refuses operation.
2022 (run-hook-with-args 'reftex-pre-refontification-functions
2023 parent-buffer 'reftex-ref)
2024 (let* ((oldname (buffer-name))
2025 (newname (concat "Fontify-me-" oldname)))
2026 (unwind-protect
2027 (progn
2028 ;; Rename buffer temporarily to start w/o space (because of font-lock)
2029 (rename-buffer newname t)
2030 (cond
2031 ((fboundp 'font-lock-default-fontify-region)
2032 ;; Good: we have the indirection functions
2033 (set (make-local-variable 'font-lock-fontify-region-function)
2034 'reftex-select-font-lock-fontify-region)
2035 (let ((major-mode 'latex-mode))
2036 (font-lock-mode 1)))
2037 ((fboundp 'font-lock-set-defaults-1)
2038 ;; Looks like the XEmacs font-lock stuff.
2039 ;; FIXME: this is still kind of a hack, but it works.
2040 (set (make-local-variable 'font-lock-keywords) nil)
2041 (let ((major-mode 'latex-mode)
2042 (font-lock-defaults-computed nil))
2043 (font-lock-set-defaults-1)
2044 (reftex-select-font-lock-fontify-region (point-min) (point-max))))
2045 (t
2046 ;; Oops?
2047 (message "Sorry: cannot refontify RefTeX Select buffer."))))
2048 (rename-buffer oldname))))
2049
2050 (defun reftex-select-font-lock-fontify-region (beg end &optional loudly)
2051 ;; Fontify a region, but only lines starting with a dot.
2052 (let ((func (if (fboundp 'font-lock-default-fontify-region)
2053 'font-lock-default-fontify-region
2054 'font-lock-fontify-region))
2055 beg1 end1)
2056 (goto-char beg)
2057 (while (re-search-forward "^\\." end t)
2058 (setq beg1 (point) end1 (progn (skip-chars-forward "^\n") (point)))
2059 (funcall func beg1 end1 nil)
2060 (goto-char end1))))
2061
2062 (defun reftex-select-font-lock-unfontify (&rest ignore) t)
2063
2064 (defun reftex-verified-face (&rest faces)
2065 ;; Return the first valid face in FACES, or nil if none is valid.
2066 ;; Also, when finding a nil element in FACES, return nil. This
2067 ;; function is just a safety net to catch name changes of builtin
2068 ;; fonts. Currently it is only used for reftex-label-face.
2069 (let (face)
2070 (catch 'exit
2071 (while (setq face (pop faces))
2072 (if (featurep 'xemacs)
2073 (if (find-face face) (throw 'exit face))
2074 (if (facep face) (throw 'exit face)))))))
2075
2076 ;; Highlighting uses overlays. For XEmacs, we use extends.
2077 (defalias 'reftex-make-overlay
2078 (if (featurep 'xemacs) 'make-extent 'make-overlay))
2079 (defalias 'reftex-overlay-put
2080 (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
2081 (defalias 'reftex-move-overlay
2082 (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay))
2083 (defalias 'reftex-delete-overlay
2084 (if (featurep 'xemacs) 'detach-extent 'delete-overlay))
2085
2086 ;; We keep a vector with several different overlays to do our highlighting.
2087 (defvar reftex-highlight-overlays [nil nil nil])
2088
2089 ;; Initialize the overlays
2090 (aset reftex-highlight-overlays 0 (reftex-make-overlay 1 1))
2091 (reftex-overlay-put (aref reftex-highlight-overlays 0)
2092 'face 'highlight)
2093 (aset reftex-highlight-overlays 1 (reftex-make-overlay 1 1))
2094 (reftex-overlay-put (aref reftex-highlight-overlays 1)
2095 'face reftex-cursor-selected-face)
2096 (aset reftex-highlight-overlays 2 (reftex-make-overlay 1 1))
2097 (reftex-overlay-put (aref reftex-highlight-overlays 2)
2098 'face reftex-cursor-selected-face)
2099
2100 ;; Two functions for activating and deactivation highlight overlays
2101 (defun reftex-highlight (index begin end &optional buffer)
2102 "Highlight a region with overlay INDEX."
2103 (reftex-move-overlay (aref reftex-highlight-overlays index)
2104 begin end (or buffer (current-buffer))))
2105 (defun reftex-unhighlight (index)
2106 "Detach overlay INDEX."
2107 (reftex-delete-overlay (aref reftex-highlight-overlays index)))
2108
2109 (defun reftex-highlight-shall-die ()
2110 ;; Function used in pre-command-hook to remove highlights.
2111 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die)
2112 (reftex-unhighlight 0))
2113
2114 ;;; =========================================================================
2115 ;;;
2116 ;;; Keybindings
2117
2118 ;; The default bindings in the mode map.
2119 (loop for x in
2120 '(("\C-c=" . reftex-toc)
2121 ("\C-c-" . reftex-toc-recenter)
2122 ("\C-c(" . reftex-label)
2123 ("\C-c)" . reftex-reference)
2124 ("\C-c[" . reftex-citation)
2125 ("\C-c<" . reftex-index)
2126 ("\C-c>" . reftex-display-index)
2127 ("\C-c/" . reftex-index-selection-or-word)
2128 ("\C-c\\" . reftex-index-phrase-selection-or-word)
2129 ("\C-c|" . reftex-index-visit-phrases-buffer)
2130 ("\C-c&" . reftex-view-crossref))
2131 do (define-key reftex-mode-map (car x) (cdr x)))
2132
2133 ;; Bind `reftex-mouse-view-crossref' only when the key is still free
2134 (if (featurep 'xemacs)
2135 (unless (key-binding [(shift button2)])
2136 (define-key reftex-mode-map [(shift button2)]
2137 'reftex-mouse-view-crossref))
2138 (unless (key-binding [(shift mouse-2)])
2139 (define-key reftex-mode-map [(shift mouse-2)]
2140 'reftex-mouse-view-crossref)))
2141
2142 (defvar bibtex-mode-map)
2143
2144 ;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map
2145 (eval-after-load
2146 "bibtex"
2147 '(define-key bibtex-mode-map "\C-c&" 'reftex-view-crossref-from-bibtex))
2148
2149 ;; For most of these commands there are already bindings in place.
2150 ;; Setting `reftex-extra-bindings' really is only there to spare users
2151 ;; the hassle of defining bindings in the user space themselves. This
2152 ;; is why they violate the key binding recommendations.
2153 (when reftex-extra-bindings
2154 (loop for x in
2155 '(("\C-ct" . reftex-toc)
2156 ("\C-cl" . reftex-label)
2157 ("\C-cr" . reftex-reference)
2158 ("\C-cc" . reftex-citation)
2159 ("\C-cv" . reftex-view-crossref)
2160 ("\C-cg" . reftex-grep-document)
2161 ("\C-cs" . reftex-search-document))
2162 do (define-key reftex-mode-map (car x) (cdr x))))
2163
2164 ;;; =========================================================================
2165 ;;;
2166 ;;; Menu
2167
2168 ;; Define a menu for the menu bar if Emacs is running under X
2169
2170 (defvar reftex-isearch-minor-mode nil)
2171 (make-variable-buffer-local 'reftex-isearch-minor-mode)
2172
2173 (easy-menu-define reftex-mode-menu reftex-mode-map
2174 "Menu used in RefTeX mode"
2175 `("Ref"
2176 ["Table of Contents" reftex-toc t]
2177 ["Recenter TOC" reftex-toc-recenter t]
2178 "--"
2179 ["\\label" reftex-label t]
2180 ["\\ref" reftex-reference t]
2181 ["\\cite" reftex-citation t]
2182 ("\\index"
2183 ["\\index" reftex-index t]
2184 ["\\index{THIS}" reftex-index-selection-or-word t]
2185 "--"
2186 ["Add THIS to Index Phrases" reftex-index-phrase-selection-or-word t]
2187 ["Visit Phrase Buffer" reftex-index-visit-phrases-buffer t]
2188 ["Apply Phrases to Region" reftex-index-phrases-apply-to-region t]
2189 "--"
2190 ["Display the Index" reftex-display-index t])
2191 "--"
2192 ["View Crossref" reftex-view-crossref t]
2193 "--"
2194 ("Parse Document"
2195 ["One File" reftex-parse-one reftex-enable-partial-scans]
2196 ["Entire Document" reftex-parse-all t]
2197 ["Save to File" (reftex-access-parse-file 'write)
2198 (> (length (symbol-value reftex-docstruct-symbol)) 0)]
2199 ["Restore from File" (reftex-access-parse-file 'restore) t])
2200 ("Global Actions"
2201 ["Search Whole Document" reftex-search-document t]
2202 ["Search Again" tags-loop-continue t]
2203 ["Replace in Document" reftex-query-replace-document t]
2204 ["Grep on Document" reftex-grep-document t]
2205 "--"
2206 ["Goto Label" reftex-goto-label t]
2207 ["Find Duplicate Labels" reftex-find-duplicate-labels t]
2208 ["Change Label and Refs" reftex-change-label t]
2209 ["Renumber Simple Labels" reftex-renumber-simple-labels t]
2210 "--"
2211 ["Create BibTeX File" reftex-create-bibtex-file t]
2212 "--"
2213 ["Create TAGS File" reftex-create-tags-file t]
2214 "--"
2215 ["Save Document" reftex-save-all-document-buffers t])
2216 "--"
2217 ("Options"
2218 "PARSER"
2219 ["Partial Scans"
2220 (setq reftex-enable-partial-scans (not reftex-enable-partial-scans))
2221 :style toggle :selected reftex-enable-partial-scans]
2222 ["Auto-Save Parse Info"
2223 (setq reftex-save-parse-info (not reftex-save-parse-info))
2224 :style toggle :selected reftex-save-parse-info]
2225 "--"
2226 "TOC RECENTER"
2227 ["Automatic Recenter" reftex-toggle-auto-toc-recenter
2228 :style toggle :selected reftex-toc-auto-recenter-timer]
2229 "--"
2230 "CROSSREF INFO"
2231 ["Automatic Info" reftex-toggle-auto-view-crossref
2232 :style toggle :selected reftex-auto-view-crossref-timer]
2233 ["...in Echo Area" (setq reftex-auto-view-crossref t)
2234 :style radio :selected (eq reftex-auto-view-crossref t)]
2235 ["...in Other Window" (setq reftex-auto-view-crossref 'window)
2236 :style radio :selected (eq reftex-auto-view-crossref 'window)]
2237 "--"
2238 "MISC"
2239 ["AUCTeX Interface" reftex-toggle-plug-into-AUCTeX
2240 :style toggle :selected reftex-plug-into-AUCTeX]
2241 ["isearch whole document" reftex-isearch-minor-mode
2242 :style toggle :selected reftex-isearch-minor-mode])
2243 ("Reference Style"
2244 ,@(let (list item)
2245 (dolist (elt reftex-ref-style-alist)
2246 (setq elt (car elt)
2247 item (vector
2248 elt
2249 `(reftex-ref-style-toggle ,elt)
2250 :style 'toggle
2251 :selected `(member ,elt (reftex-ref-style-list))))
2252 (unless (member item list)
2253 (add-to-list 'list item t)))
2254 list))
2255 ("Citation Style"
2256 ,@(mapcar
2257 (lambda (x)
2258 (vector
2259 (capitalize (symbol-name (car x)))
2260 (list 'reftex-set-cite-format (list 'quote (car x)))
2261 :style 'radio :selected
2262 (list 'eq (list 'reftex-get-cite-format) (list 'quote (car x)))))
2263 reftex-cite-format-builtin)
2264 "--"
2265 "Sort Database Matches"
2266 ["Not" (setq reftex-sort-bibtex-matches nil)
2267 :style radio :selected (eq reftex-sort-bibtex-matches nil)]
2268 ["by Author" (setq reftex-sort-bibtex-matches 'author)
2269 :style radio :selected (eq reftex-sort-bibtex-matches 'author)]
2270 ["by Year" (setq reftex-sort-bibtex-matches 'year)
2271 :style radio :selected (eq reftex-sort-bibtex-matches 'year)]
2272 ["by Year, reversed" (setq reftex-sort-bibtex-matches 'reverse-year)
2273 :style radio :selected (eq reftex-sort-bibtex-matches 'reverse-year)])
2274 ("Index Style"
2275 ,@(mapcar
2276 (lambda (x)
2277 (vector
2278 (capitalize (symbol-name (car x)))
2279 (list 'reftex-add-index-macros (list 'list (list 'quote (car x))))
2280 :style 'radio :selected
2281 (list 'memq (list 'quote (car x))
2282 (list 'get 'reftex-docstruct-symbol
2283 (list 'quote 'reftex-index-macros-style)))))
2284 reftex-index-macros-builtin))
2285 "--"
2286 ["Reset RefTeX Mode" reftex-reset-mode t]
2287 "--"
2288 ("Customize"
2289 ["Browse RefTeX Group" reftex-customize t]
2290 "--"
2291 ["Build Full Customize Menu" reftex-create-customize-menu
2292 (fboundp 'customize-menu-create)])
2293 ("Documentation"
2294 ["Info" reftex-info t]
2295 ["Commentary" reftex-show-commentary t])))
2296
2297 (defun reftex-customize ()
2298 "Call the customize function with reftex as argument."
2299 (interactive)
2300 (customize-browse 'reftex))
2301
2302 (defun reftex-create-customize-menu ()
2303 "Create a full customization menu for RefTeX, insert it into the menu."
2304 (interactive)
2305 (if (fboundp 'customize-menu-create)
2306 (progn
2307 (easy-menu-change
2308 '("Ref") "Customize"
2309 `(["Browse RefTeX group" reftex-customize t]
2310 "--"
2311 ,(customize-menu-create 'reftex)
2312 ["Set" Custom-set t]
2313 ["Save" Custom-save t]
2314 ["Reset to Current" Custom-reset-current t]
2315 ["Reset to Saved" Custom-reset-saved t]
2316 ["Reset to Standard Settings" Custom-reset-standard t]))
2317 (message "\"Ref\"-menu now contains full customization menu"))
2318 (error "Cannot expand menu (outdated version of cus-edit.el)")))
2319
2320
2321 ;;; Misc
2322
2323 (defun reftex-show-commentary ()
2324 "Use the finder to view the file documentation from `reftex.el'."
2325 (interactive)
2326 (finder-commentary "reftex.el"))
2327
2328 (defun reftex-info (&optional node)
2329 "Read documentation for RefTeX in the info system.
2330 With optional NODE, go directly to that node."
2331 (interactive)
2332 (info (format "(reftex)%s" (or node ""))))
2333
2334 (defun reftex-report-bug ()
2335 "Report a bug in RefTeX.
2336
2337 Don't hesitate to report any problems or inaccurate documentation.
2338
2339 If you don't have setup sending mail from (X)Emacs, please copy the
2340 output buffer into your mail program, as it gives us important
2341 information about your RefTeX version and configuration."
2342 (interactive)
2343 (require 'reporter)
2344 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
2345 (reporter-submit-bug-report
2346 "bug-auctex@gnu.org, bug-gnu-emacs@gnu.org"
2347 reftex-version
2348 (list 'window-system
2349 'reftex-plug-into-AUCTeX)
2350 nil nil
2351 "Remember to cover the basics, that is, what you expected to happen and
2352 what in fact did happen.
2353
2354 Check if the bug is reproducible with an up-to-date version of
2355 RefTeX available from http://www.gnu.org/software/auctex/.
2356
2357 If the bug is triggered by a specific \(La)TeX file, you should try
2358 to produce a minimal sample file showing the problem and include it
2359 in your report.
2360
2361 Your bug report will be posted to the AUCTeX bug reporting list.
2362 ------------------------------------------------------------------------")))
2363
2364 ;;; Install the kill-buffer and kill-emacs hooks ------------------------------
2365
2366 (add-hook 'kill-buffer-hook 'reftex-kill-buffer-hook)
2367 (unless noninteractive
2368 (add-hook 'kill-emacs-hook 'reftex-kill-emacs-hook))
2369
2370 ;;; Run Hook ------------------------------------------------------------------
2371
2372 (run-hooks 'reftex-load-hook)
2373
2374 ;;; That's it! ----------------------------------------------------------------
2375
2376 (setq reftex-tables-dirty t) ; in case this file is evaluated by hand
2377
2378 \f
2379 ;;; Start of automatically extracted autoloads.
2380 \f
2381 ;;;### (autoloads nil "reftex-auc" "reftex-auc.el" "cf606f7918831321cb46f254436dc66e")
2382 ;;; Generated autoloads from reftex-auc.el
2383
2384 (autoload 'reftex-arg-label "reftex-auc" "\
2385 Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg.
2386 What is being used depends upon `reftex-plug-into-AUCTeX'.
2387
2388 \(fn OPTIONAL &optional PROMPT DEFINITION)" nil nil)
2389
2390 (autoload 'reftex-arg-cite "reftex-auc" "\
2391 Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument.
2392 What is being used depends upon `reftex-plug-into-AUCTeX'.
2393
2394 \(fn OPTIONAL &optional PROMPT DEFINITION)" nil nil)
2395
2396 (autoload 'reftex-arg-index-tag "reftex-auc" "\
2397 Prompt for an index tag with completion.
2398 This is the name of an index, not the entry.
2399
2400 \(fn OPTIONAL &optional PROMPT &rest ARGS)" nil nil)
2401
2402 (autoload 'reftex-arg-index "reftex-auc" "\
2403 Prompt for an index entry completing with known entries.
2404 Completion is specific for just one index, if the macro or a tag
2405 argument identify one of multiple indices.
2406
2407 \(fn OPTIONAL &optional PROMPT &rest ARGS)" nil nil)
2408
2409 (autoload 'reftex-plug-into-AUCTeX "reftex-auc" "\
2410
2411
2412 \(fn)" nil nil)
2413
2414 (autoload 'reftex-toggle-plug-into-AUCTeX "reftex-auc" "\
2415 Toggle Interface between AUCTeX and RefTeX on and off.
2416
2417 \(fn)" t nil)
2418
2419 (autoload 'reftex-add-label-environments "reftex-auc" "\
2420 Add label environment descriptions to `reftex-label-alist-style'.
2421 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there
2422 for details.
2423 This function makes it possible to support RefTeX from AUCTeX style files.
2424 The entries in ENTRY-LIST will be processed after the user settings in
2425 `reftex-label-alist', and before the defaults (specified in
2426 `reftex-default-label-alist-entries'). Any changes made to
2427 `reftex-label-alist-style' will raise a flag to the effect that
2428 the label information is recompiled on next use.
2429
2430 \(fn ENTRY-LIST)" nil nil)
2431
2432 (defalias 'reftex-add-to-label-alist 'reftex-add-label-environments)
2433
2434 (autoload 'reftex-add-section-levels "reftex-auc" "\
2435 Add entries to the value of `reftex-section-levels'.
2436 The added values are kept local to the current document. The format
2437 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See
2438 `reftex-section-levels' for an example.
2439
2440 \(fn ENTRY-LIST)" nil nil)
2441
2442 (autoload 'reftex-notice-new-section "reftex-auc" "\
2443
2444
2445 \(fn)" nil nil)
2446
2447 ;;;***
2448 \f
2449 ;;;### (autoloads nil "reftex-cite" "reftex-cite.el" "751df6ee674ea533b755e8cda4ad1cf8")
2450 ;;; Generated autoloads from reftex-cite.el
2451
2452 (autoload 'reftex-default-bibliography "reftex-cite" "\
2453 Return the expanded value of variable `reftex-default-bibliography'.
2454 The expanded value is cached.
2455
2456 \(fn)" nil nil)
2457
2458 (autoload 'reftex-bib-or-thebib "reftex-cite" "\
2459 Test if BibTeX or \begin{thebibliography} should be used for the citation.
2460 Find the bof of the current file
2461
2462 \(fn)" nil nil)
2463
2464 (autoload 'reftex-get-bibfile-list "reftex-cite" "\
2465 Return list of bibfiles for current document.
2466 When using the chapterbib or bibunits package you should either
2467 use the same database files everywhere, or separate parts using
2468 different databases into different files (included into the mater file).
2469 Then this function will return the applicable database files.
2470
2471 \(fn)" nil nil)
2472
2473 (autoload 'reftex-pop-to-bibtex-entry "reftex-cite" "\
2474 Find BibTeX KEY in any file in FILE-LIST in another window.
2475 If MARK-TO-KILL is non-nil, mark new buffer to kill.
2476 If HIGHLIGHT is non-nil, highlight the match.
2477 If ITEM in non-nil, search for bibitem instead of database entry.
2478 If RETURN is non-nil, just return the entry and restore point.
2479
2480 \(fn KEY FILE-LIST &optional MARK-TO-KILL HIGHLIGHT ITEM RETURN)" nil nil)
2481
2482 (autoload 'reftex-end-of-bib-entry "reftex-cite" "\
2483
2484
2485 \(fn ITEM)" nil nil)
2486
2487 (autoload 'reftex-parse-bibtex-entry "reftex-cite" "\
2488 Parse BibTeX ENTRY.
2489 If ENTRY is nil then parse the entry in current buffer between FROM and TO.
2490 If RAW is non-nil, keep double quotes/curly braces delimiting fields.
2491
2492 \(fn ENTRY &optional FROM TO RAW)" nil nil)
2493
2494 (autoload 'reftex-citation "reftex-cite" "\
2495 Make a citation using BibTeX database files.
2496 After prompting for a regular expression, scans the buffers with
2497 bibtex entries (taken from the \\bibliography command) and offers the
2498 matching entries for selection. The selected entry is formatted according
2499 to `reftex-cite-format' and inserted into the buffer.
2500
2501 If NO-INSERT is non-nil, nothing is inserted, only the selected key returned.
2502
2503 FORMAT-KEY can be used to pre-select a citation format.
2504
2505 When called with a `C-u' prefix, prompt for optional arguments in
2506 cite macros. When called with a numeric prefix, make that many
2507 citations. When called with point inside the braces of a `\\cite'
2508 command, it will add another key, ignoring the value of
2509 `reftex-cite-format'.
2510
2511 The regular expression uses an expanded syntax: && is interpreted as `and'.
2512 Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'.
2513 While entering the regexp, completion on knows citation keys is possible.
2514 `=' is a good regular expression to match all entries in all files.
2515
2516 \(fn &optional NO-INSERT FORMAT-KEY)" t nil)
2517
2518 (autoload 'reftex-citep "reftex-cite" "\
2519 Call `reftex-citation' with a format selector `?p'.
2520
2521 \(fn)" t nil)
2522
2523 (autoload 'reftex-citet "reftex-cite" "\
2524 Call `reftex-citation' with a format selector `?t'.
2525
2526 \(fn)" t nil)
2527
2528 (autoload 'reftex-make-cite-echo-string "reftex-cite" "\
2529 Format a bibtex ENTRY for the echo area and cache the result.
2530
2531 \(fn ENTRY DOCSTRUCT-SYMBOL)" nil nil)
2532
2533 (autoload 'reftex-create-bibtex-file "reftex-cite" "\
2534 Create a new BibTeX database BIBFILE with all entries referenced in document.
2535 The command prompts for a filename and writes the collected
2536 entries to that file. Only entries referenced in the current
2537 document with any \\cite-like macros are used. The sequence in
2538 the new file is the same as it was in the old database.
2539
2540 Entries referenced from other entries must appear after all
2541 referencing entries.
2542
2543 You can define strings to be used as header or footer for the
2544 created files in the variables `reftex-create-bibtex-header' or
2545 `reftex-create-bibtex-footer' respectively.
2546
2547 \(fn BIBFILE)" t nil)
2548
2549 ;;;***
2550 \f
2551 ;;;### (autoloads nil "reftex-dcr" "reftex-dcr.el" "08fc5bd6c35f9d6ab4a6ad336d3769c0")
2552 ;;; Generated autoloads from reftex-dcr.el
2553
2554 (autoload 'reftex-view-crossref "reftex-dcr" "\
2555 View cross reference of macro at point. Point must be on the KEY
2556 argument. When at a `\\ref' macro, show corresponding `\\label'
2557 definition, also in external documents (`xr'). When on a label, show
2558 a locations where KEY is referenced. Subsequent calls find additional
2559 locations. When on a `\\cite', show the associated `\\bibitem' macro or
2560 the BibTeX database entry. When on a `\\bibitem', show a `\\cite' macro
2561 which uses this KEY. When on an `\\index', show other locations marked
2562 by the same index entry.
2563 To define additional cross referencing items, use the option
2564 `reftex-view-crossref-extra'. See also `reftex-view-crossref-from-bibtex'.
2565 With one or two C-u prefixes, enforce rescanning of the document.
2566 With argument 2, select the window showing the cross reference.
2567 AUTO-HOW is only for the automatic crossref display and is handed through
2568 to the functions `reftex-view-cr-cite' and `reftex-view-cr-ref'.
2569
2570 \(fn &optional ARG AUTO-HOW FAIL-QUIETLY)" t nil)
2571
2572 (autoload 'reftex-mouse-view-crossref "reftex-dcr" "\
2573 View cross reference of \\ref or \\cite macro where you click.
2574 If the macro at point is a \\ref, show the corresponding label definition.
2575 If it is a \\cite, show the BibTeX database entry.
2576 If there is no such macro at point, search forward to find one.
2577 With argument, actually select the window showing the cross reference.
2578
2579 \(fn EV)" t nil)
2580
2581 (autoload 'reftex-toggle-auto-view-crossref "reftex-dcr" "\
2582 Toggle the automatic display of crossref information in the echo area.
2583 When active, leaving point idle in the argument of a \\ref or \\cite macro
2584 will display info in the echo area.
2585
2586 \(fn)" t nil)
2587
2588 (autoload 'reftex-view-crossref-from-bibtex "reftex-dcr" "\
2589 View location in a LaTeX document which cites the BibTeX entry at point.
2590 Since BibTeX files can be used by many LaTeX documents, this function
2591 prompts upon first use for a buffer in RefTeX mode. To reset this
2592 link to a document, call the function with a prefix arg.
2593 Calling this function several times find successive citation locations.
2594
2595 \(fn &optional ARG)" t nil)
2596
2597 ;;;***
2598 \f
2599 ;;;### (autoloads nil "reftex-global" "reftex-global.el" "5fdd9c2edced0882471f86baf4b4b234")
2600 ;;; Generated autoloads from reftex-global.el
2601
2602 (autoload 'reftex-create-tags-file "reftex-global" "\
2603 Create TAGS file by running `etags' on the current document.
2604 The TAGS file is also immediately visited with `visit-tags-table'.
2605
2606 \(fn)" t nil)
2607
2608 (autoload 'reftex-grep-document "reftex-global" "\
2609 Run grep query through all files related to this document.
2610 With prefix arg, force to rescan document.
2611 No active TAGS table is required.
2612
2613 \(fn GREP-CMD)" t nil)
2614
2615 (autoload 'reftex-search-document "reftex-global" "\
2616 Regexp search through all files of the current document.
2617 Starts always in the master file. Stops when a match is found.
2618 To continue searching for next match, use command \\[tags-loop-continue].
2619 No active TAGS table is required.
2620
2621 \(fn &optional REGEXP)" t nil)
2622
2623 (autoload 'reftex-query-replace-document "reftex-global" "\
2624 Do `query-replace-regexp' of FROM with TO over the entire document.
2625 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
2626 If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
2627 with the command \\[tags-loop-continue].
2628 No active TAGS table is required.
2629
2630 \(fn &optional FROM TO DELIMITED)" t nil)
2631
2632 (autoload 'reftex-find-duplicate-labels "reftex-global" "\
2633 Produce a list of all duplicate labels in the document.
2634
2635 \(fn)" t nil)
2636
2637 (autoload 'reftex-change-label "reftex-global" "\
2638 Run `query-replace-regexp' of FROM with TO in all macro arguments.
2639 Works on the entire multifile document.
2640 If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
2641 with the command \\[tags-loop-continue].
2642 No active TAGS table is required.
2643
2644 \(fn &optional FROM TO)" t nil)
2645
2646 (autoload 'reftex-renumber-simple-labels "reftex-global" "\
2647 Renumber all simple labels in the document to make them sequentially.
2648 Simple labels are the ones created by RefTeX, consisting only of the
2649 prefix and a number. After the command completes, all these labels will
2650 have sequential numbers throughout the document. Any references to
2651 the labels will be changed as well. For this, RefTeX looks at the
2652 arguments of any macros which either start or end in the string `ref'.
2653 This command should be used with care, in particular in multifile
2654 documents. You should not use it if another document refers to this
2655 one with the `xr' package.
2656
2657 \(fn)" t nil)
2658
2659 (autoload 'reftex-save-all-document-buffers "reftex-global" "\
2660 Save all documents associated with the current document.
2661 The function is useful after a global action like replacing or renumbering
2662 labels.
2663
2664 \(fn)" t nil)
2665
2666 (autoload 'reftex-isearch-minor-mode "reftex-global" "\
2667 When on, isearch searches the whole document, not only the current file.
2668 This minor mode allows isearch to search through all the files of
2669 the current TeX document.
2670
2671 With no argument, this command toggles
2672 `reftex-isearch-minor-mode'. With a prefix argument ARG, turn
2673 `reftex-isearch-minor-mode' on if ARG is positive, otherwise turn it off.
2674
2675 \(fn &optional ARG)" t nil)
2676
2677 ;;;***
2678 \f
2679 ;;;### (autoloads nil "reftex-index" "reftex-index.el" "29cb6e91c2e06592053e9d543f30f0ea")
2680 ;;; Generated autoloads from reftex-index.el
2681
2682 (autoload 'reftex-index-selection-or-word "reftex-index" "\
2683 Put selection or the word near point into the default index macro.
2684 This uses the information in `reftex-index-default-macro' to make an index
2685 entry. The phrase indexed is the current selection or the word near point.
2686 When called with one `C-u' prefix, let the user have a chance to edit the
2687 index entry. When called with 2 `C-u' as prefix, also ask for the index
2688 macro and other stuff.
2689 When called inside TeX math mode as determined by the `texmathp.el' library
2690 which is part of AUCTeX, the string is first processed with the
2691 `reftex-index-math-format', which see.
2692
2693 \(fn &optional ARG PHRASE)" t nil)
2694
2695 (autoload 'reftex-index "reftex-index" "\
2696 Query for an index macro and insert it along with its arguments.
2697 The index macros available are those defined in `reftex-index-macro' or
2698 by a call to `reftex-add-index-macros', typically from an AUCTeX style file.
2699 RefteX provides completion for the index tag and the index key, and
2700 will prompt for other arguments.
2701
2702 \(fn &optional CHAR KEY TAG SEL NO-INSERT)" t nil)
2703
2704 (autoload 'reftex-index-complete-tag "reftex-index" "\
2705
2706
2707 \(fn &optional ITAG OPT-ARGS)" nil nil)
2708
2709 (autoload 'reftex-index-select-tag "reftex-index" "\
2710
2711
2712 \(fn)" nil nil)
2713
2714 (autoload 'reftex-index-complete-key "reftex-index" "\
2715
2716
2717 \(fn &optional TAG OPTIONAL INITIAL)" nil nil)
2718
2719 (autoload 'reftex-index-show-entry "reftex-index" "\
2720
2721
2722 \(fn DATA &optional NO-REVISIT)" nil nil)
2723
2724 (autoload 'reftex-display-index "reftex-index" "\
2725 Display a buffer with an index compiled from the current document.
2726 When the document has multiple indices, first prompts for the correct one.
2727 When index support is turned off, offer to turn it on.
2728 With one or two `C-u' prefixes, rescan document first.
2729 With prefix 2, restrict index to current document section.
2730 With prefix 3, restrict index to region.
2731
2732 \(fn &optional TAG OVERRIDING-RESTRICTION REDO &rest LOCATIONS)" t nil)
2733
2734 (autoload 'reftex-index-phrase-selection-or-word "reftex-index" "\
2735 Add current selection or word at point to the phrases buffer.
2736 When you are in transient-mark-mode and the region is active, the
2737 selection will be used - otherwise the word at point.
2738 You get a chance to edit the entry in the phrases buffer - finish with
2739 `C-c C-c'.
2740
2741 \(fn ARG)" t nil)
2742
2743 (autoload 'reftex-index-visit-phrases-buffer "reftex-index" "\
2744 Switch to the phrases buffer, initialize if empty.
2745
2746 \(fn)" t nil)
2747
2748 (autoload 'reftex-index-phrases-mode "reftex-index" "\
2749 Major mode for managing the Index phrases of a LaTeX document.
2750 This buffer was created with RefTeX.
2751
2752 To insert new phrases, use
2753 - `C-c \\' in the LaTeX document to copy selection or word
2754 - `\\[reftex-index-new-phrase]' in the phrases buffer.
2755
2756 To index phrases use one of:
2757
2758 \\[reftex-index-this-phrase] index current phrase
2759 \\[reftex-index-next-phrase] index next phrase (or N with prefix arg)
2760 \\[reftex-index-all-phrases] index all phrases
2761 \\[reftex-index-remaining-phrases] index current and following phrases
2762 \\[reftex-index-region-phrases] index the phrases in the region
2763
2764 You can sort the phrases in this buffer with \\[reftex-index-sort-phrases].
2765 To display information about the phrase at point, use \\[reftex-index-phrases-info].
2766
2767 For more information see the RefTeX User Manual.
2768
2769 Here are all local bindings.
2770
2771 \\{reftex-index-phrases-mode-map}
2772
2773 \(fn)" t nil)
2774
2775 ;;;***
2776 \f
2777 ;;;### (autoloads nil "reftex-parse" "reftex-parse.el" "7bfdcb2f040dbe9a08d2c38c005c8f21")
2778 ;;; Generated autoloads from reftex-parse.el
2779
2780 (autoload 'reftex-parse-one "reftex-parse" "\
2781 Re-parse this file.
2782
2783 \(fn)" t nil)
2784
2785 (autoload 'reftex-parse-all "reftex-parse" "\
2786 Re-parse entire document.
2787
2788 \(fn)" t nil)
2789
2790 (autoload 'reftex-do-parse "reftex-parse" "\
2791 Do a document rescan.
2792 When allowed, do only a partial scan from FILE.
2793
2794 \(fn RESCAN &optional FILE)" nil nil)
2795
2796 (autoload 'reftex-everything-regexp "reftex-parse" "\
2797
2798
2799 \(fn)" nil nil)
2800
2801 (autoload 'reftex-all-document-files "reftex-parse" "\
2802 Return a list of all files belonging to the current document.
2803 When RELATIVE is non-nil, give file names relative to directory
2804 of master file.
2805
2806 \(fn &optional RELATIVE)" nil nil)
2807
2808 (autoload 'reftex-locate-bibliography-files "reftex-parse" "\
2809 Scan buffer for bibliography macros and return file list.
2810
2811 \(fn MASTER-DIR &optional FILES)" nil nil)
2812
2813 (autoload 'reftex-section-info "reftex-parse" "\
2814 Return a section entry for the current match.
2815 Careful: This function expects the match-data to be still in place!
2816
2817 \(fn FILE)" nil nil)
2818
2819 (autoload 'reftex-ensure-index-support "reftex-parse" "\
2820 When index support is turned off, ask to turn it on and
2821 set the current prefix argument so that `reftex-access-scan-info'
2822 will rescan the entire document.
2823
2824 \(fn &optional ABORT)" nil nil)
2825
2826 (autoload 'reftex-index-info-safe "reftex-parse" "\
2827
2828
2829 \(fn FILE)" nil nil)
2830
2831 (autoload 'reftex-index-info "reftex-parse" "\
2832 Return an index entry for the current match.
2833 Careful: This function expects the match-data to be still in place!
2834
2835 \(fn FILE)" nil nil)
2836
2837 (autoload 'reftex-short-context "reftex-parse" "\
2838 Get about one line of useful context for the label definition at point.
2839
2840 \(fn ENV PARSE &optional BOUND DERIVE)" nil nil)
2841
2842 (autoload 'reftex-where-am-I "reftex-parse" "\
2843 Return the docstruct entry above point.
2844 Actually returns a cons cell in which the cdr is a flag indicating
2845 if the information is exact (t) or approximate (nil).
2846
2847 \(fn)" nil nil)
2848
2849 (autoload 'reftex-notice-new "reftex-parse" "\
2850 Hook to handshake with RefTeX after something new has been inserted.
2851
2852 \(fn &optional N FORCE)" nil nil)
2853
2854 (autoload 'reftex-what-macro-safe "reftex-parse" "\
2855 Call `reftex-what-macro' with special syntax table.
2856
2857 \(fn WHICH &optional BOUND)" nil nil)
2858
2859 (autoload 'reftex-what-macro "reftex-parse" "\
2860 Find out if point is within the arguments of any TeX-macro.
2861 The return value is either (\"\\macro\" . (point)) or a list of them.
2862
2863 If WHICH is nil, immediately return nil.
2864 If WHICH is 1, return innermost enclosing macro.
2865 If WHICH is t, return list of all macros enclosing point.
2866 If WHICH is a list of macros, look only for those macros and return the
2867 name of the first macro in this list found to enclose point.
2868 If the optional BOUND is an integer, bound backwards directed
2869 searches to this point. If it is nil, limit to nearest \\section -
2870 like statement.
2871
2872 This function is pretty stable, but can be fooled if the text contains
2873 things like \\macro{aa}{bb} where \\macro is defined to take only one
2874 argument. As RefTeX cannot know this, the string \"bb\" would still be
2875 considered an argument of macro \\macro.
2876
2877 \(fn WHICH &optional BOUND)" nil nil)
2878
2879 (autoload 'reftex-what-environment "reftex-parse" "\
2880 Find out if point is inside a LaTeX environment.
2881 The return value is (e.g.) either (\"equation\" . (point)) or a list of
2882 them.
2883
2884 If WHICH is nil, immediately return nil.
2885 If WHICH is 1, return innermost enclosing environment.
2886 If WHICH is t, return list of all environments enclosing point.
2887 If WHICH is a list of environments, look only for those environments and
2888 return the name of the first environment in this list found to enclose
2889 point.
2890
2891 If the optional BOUND is an integer, bound backwards directed searches to
2892 this point. If it is nil, limit to nearest \\section - like statement.
2893
2894 \(fn WHICH &optional BOUND)" nil nil)
2895
2896 (autoload 'reftex-what-special-env "reftex-parse" "\
2897 Run the special environment parsers and return the matches.
2898
2899 The return value is (e.g.) either (\"my-parser-function\" . (point))
2900 or a list of them.
2901
2902 If WHICH is nil, immediately return nil.
2903 If WHICH is 1, return innermost enclosing environment.
2904 If WHICH is t, return list of all environments enclosing point.
2905 If WHICH is a list of environments, look only for those environments and
2906 return the name of the first environment in this list found to enclose
2907 point.
2908
2909 \(fn WHICH &optional BOUND)" nil nil)
2910
2911 (autoload 'reftex-nth-arg "reftex-parse" "\
2912 Return the Nth following {} or [] parentheses content.
2913 OPT-ARGS is a list of argument numbers which are optional.
2914
2915 \(fn N &optional OPT-ARGS)" nil nil)
2916
2917 (autoload 'reftex-move-over-touching-args "reftex-parse" "\
2918
2919
2920 \(fn)" nil nil)
2921
2922 (autoload 'reftex-init-section-numbers "reftex-parse" "\
2923 Initialize the section numbers with zeros or with what is found in the TOC-ENTRY.
2924
2925 \(fn &optional TOC-ENTRY APPENDIX)" nil nil)
2926
2927 (autoload 'reftex-section-number "reftex-parse" "\
2928 Return a string with the current section number.
2929 When LEVEL is non-nil, increase section numbers on that level.
2930
2931 \(fn &optional LEVEL STAR)" nil nil)
2932
2933 ;;;***
2934 \f
2935 ;;;### (autoloads nil "reftex-ref" "reftex-ref.el" "86c0a243e49d55bb33a32ddac613e189")
2936 ;;; Generated autoloads from reftex-ref.el
2937
2938 (autoload 'reftex-label-location "reftex-ref" "\
2939 Return the environment or macro which determines the label type at point.
2940 If optional BOUND is an integer, limit backward searches to that point.
2941
2942 \(fn &optional BOUND)" nil nil)
2943
2944 (autoload 'reftex-label-info-update "reftex-ref" "\
2945
2946
2947 \(fn CELL)" nil nil)
2948
2949 (autoload 'reftex-label-info "reftex-ref" "\
2950
2951
2952 \(fn LABEL &optional FILE BOUND DERIVE ENV-OR-MAC)" nil nil)
2953
2954 (autoload 'reftex-label "reftex-ref" "\
2955 Insert a unique label. Return the label.
2956 If ENVIRONMENT is given, don't bother to find out yourself.
2957 If NO-INSERT is non-nil, do not insert label into buffer.
2958 With prefix arg, force to rescan document first.
2959 When you are prompted to enter or confirm a label, and you reply with
2960 just the prefix or an empty string, no label at all will be inserted.
2961 A new label is also recorded into the label list.
2962 This function is controlled by the settings of reftex-insert-label-flags.
2963
2964 \(fn &optional ENVIRONMENT NO-INSERT)" t nil)
2965
2966 (autoload 'reftex-reference "reftex-ref" "\
2967 Make a LaTeX reference. Look only for labels of a certain TYPE.
2968 With prefix arg, force to rescan buffer for labels. This should only be
2969 necessary if you have recently entered labels yourself without using
2970 reftex-label. Rescanning of the buffer can also be requested from the
2971 label selection menu.
2972 The function returns the selected label or nil.
2973 If NO-INSERT is non-nil, do not insert \\ref command, just return label.
2974 When called with 2 C-u prefix args, disable magic word recognition.
2975
2976 \(fn &optional TYPE NO-INSERT CUT)" t nil)
2977
2978 (autoload 'reftex-query-label-type "reftex-ref" "\
2979
2980
2981 \(fn)" nil nil)
2982
2983 (autoload 'reftex-show-label-location "reftex-ref" "\
2984
2985
2986 \(fn DATA FORWARD NO-REVISIT &optional STAY ERROR)" nil nil)
2987
2988 (autoload 'reftex-goto-label "reftex-ref" "\
2989 Prompt for a label (with completion) and jump to the location of this label.
2990 Optional prefix argument OTHER-WINDOW goes to the label in another window.
2991
2992 \(fn &optional OTHER-WINDOW)" t nil)
2993
2994 ;;;***
2995 \f
2996 ;;;### (autoloads nil "reftex-sel" "reftex-sel.el" "faea36cbe37033efd3f9063187eef7ee")
2997 ;;; Generated autoloads from reftex-sel.el
2998
2999 (autoload 'reftex-select-label-mode "reftex-sel" "\
3000 Major mode for selecting a label in a LaTeX document.
3001 This buffer was created with RefTeX.
3002 It only has a meaningful keymap when you are in the middle of a
3003 selection process.
3004 To select a label, move the cursor to it and press RET.
3005 Press `?' for a summary of important key bindings.
3006
3007 During a selection process, these are the local bindings.
3008
3009 \\{reftex-select-label-mode-map}
3010
3011 \(fn)" t nil)
3012
3013 (autoload 'reftex-select-bib-mode "reftex-sel" "\
3014 Major mode for selecting a citation key in a LaTeX document.
3015 This buffer was created with RefTeX.
3016 It only has a meaningful keymap when you are in the middle of a
3017 selection process.
3018 In order to select a citation, move the cursor to it and press RET.
3019 Press `?' for a summary of important key bindings.
3020
3021 During a selection process, these are the local bindings.
3022
3023 \\{reftex-select-label-mode-map}
3024
3025 \(fn)" t nil)
3026
3027 (autoload 'reftex-get-offset "reftex-sel" "\
3028
3029
3030 \(fn BUF HERE-AM-I &optional TYPEKEY TOC INDEX FILE)" nil nil)
3031
3032 (autoload 'reftex-insert-docstruct "reftex-sel" "\
3033
3034
3035 \(fn BUF TOC LABELS INDEX-ENTRIES FILES CONTEXT COUNTER SHOW-COMMENTED HERE-I-AM XR-PREFIX TOC-BUFFER)" nil nil)
3036
3037 (autoload 'reftex-find-start-point "reftex-sel" "\
3038
3039
3040 \(fn FALLBACK &rest LOCATIONS)" nil nil)
3041
3042 (autoload 'reftex-select-item "reftex-sel" "\
3043
3044
3045 \(fn REFTEX-SELECT-PROMPT HELP-STRING KEYMAP &optional OFFSET CALL-BACK CB-FLAG)" nil nil)
3046
3047 ;;;***
3048 \f
3049 ;;;### (autoloads nil "reftex-toc" "reftex-toc.el" "db9b727d89e2a6ff01986e7c6aff1058")
3050 ;;; Generated autoloads from reftex-toc.el
3051
3052 (autoload 'reftex-toc "reftex-toc" "\
3053 Show the table of contents for the current document.
3054 When called with a raw C-u prefix, rescan the document first.
3055
3056 \(fn &optional REBUILD REUSE)" t nil)
3057
3058 (autoload 'reftex-toc-recenter "reftex-toc" "\
3059 Display the TOC window and highlight line corresponding to current position.
3060
3061 \(fn &optional ARG)" t nil)
3062
3063 (autoload 'reftex-toggle-auto-toc-recenter "reftex-toc" "\
3064 Toggle the automatic recentering of the TOC window.
3065 When active, leaving point idle will make the TOC window jump to the correct
3066 section.
3067
3068 \(fn)" t nil)
3069
3070 ;;;***
3071 \f
3072 ;;; End of automatically extracted autoloads.
3073
3074 (provide 'reftex)
3075
3076 ;;; reftex.el ends here