Merge branch 'master' into comment-cache
[emacs.git] / lisp / textmodes / reftex.el
blob18b35981f82249d138c224a724fe7762631c5112
1 ;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX
2 ;; Copyright (C) 1997-2000, 2003-2017 Free Software Foundation, Inc.
4 ;; Author: Carsten Dominik <dominik@science.uva.nl>
5 ;; Maintainer: auctex-devel@gnu.org
6 ;; Keywords: tex
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; 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.
34 ;; There is an extensive Texinfo document describing RefTeX in detail.
35 ;; One way to view this documentation is `M-x reftex-info RET'.
37 ;; The documentation in various formats is also available at
39 ;; http://www.gnu.org/software/auctex/manual/reftex.index.html
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
45 ;; http://www.gnu.org/software/auctex/reftex.html
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.
51 ;;; Code:
53 (eval-when-compile (require 'cl-lib))
55 ;; Stuff that needs to be there when we use defcustom
56 (require 'custom)
58 (require 'easymenu)
60 (defvar reftex-tables-dirty t
61 "Flag showing if tables need to be re-computed.")
63 (eval-and-compile
64 (defun reftex-set-dirty (symbol value)
65 (setq reftex-tables-dirty t)
66 (set symbol value)))
69 ;; Configuration variables
70 (require 'reftex-vars)
73 ;;; Autoloads to ensure loading of support files when necessary
74 (require 'reftex-loaddefs)
76 ;; We autoload tons of functions from these files, but some have
77 ;; a single function that needs to be globally autoloaded.
78 ;; The alternative is to use a Makefile rule + distinct autoload
79 ;; cookie (eg ;;;###reftex-autoload) for internal autoloads,
80 ;; as eg calendar/ does. But that seemed like overkill for 4 functions.
82 ;;;###autoload(autoload 'reftex-citation "reftex-cite" nil t)
83 ;;;###autoload(autoload 'reftex-all-document-files "reftex-parse")
84 ;;;###autoload(autoload 'reftex-isearch-minor-mode "reftex-global" nil t)
85 ;;;###autoload(autoload 'reftex-index-phrases-mode "reftex-index" nil t)
87 ;; Generated functions.
88 (autoload 'reftex-varioref-vref "reftex-ref"
89 "Make a varioref reference." t)
90 (autoload 'reftex-fancyref-fref "reftex-ref"
91 "Make a fancyref \\fref reference." t)
92 (autoload 'reftex-fancyref-Fref "reftex-ref"
93 "Make a fancyref \\Fref reference." t)
95 ;;; =========================================================================
96 ;;;
97 ;;; Define the formal stuff for a minor mode named RefTeX.
98 ;;;
100 (defconst reftex-version emacs-version
101 "Version string for RefTeX.")
103 (defvar reftex-mode-map
104 (let ((map (make-sparse-keymap)))
105 ;; The default bindings in the mode map.
106 (define-key map "\C-c=" 'reftex-toc)
107 (define-key map "\C-c-" 'reftex-toc-recenter)
108 (define-key map "\C-c(" 'reftex-label)
109 (define-key map "\C-c)" 'reftex-reference)
110 (define-key map "\C-c[" 'reftex-citation)
111 (define-key map "\C-c<" 'reftex-index)
112 (define-key map "\C-c>" 'reftex-display-index)
113 (define-key map "\C-c/" 'reftex-index-selection-or-word)
114 (define-key map "\C-c\\" 'reftex-index-phrase-selection-or-word)
115 (define-key map "\C-c|" 'reftex-index-visit-phrases-buffer)
116 (define-key map "\C-c&" 'reftex-view-crossref)
118 ;; Bind `reftex-mouse-view-crossref' only when the key is still free
119 (if (featurep 'xemacs)
120 (unless (key-binding [(shift button2)])
121 (define-key map [(shift button2)] 'reftex-mouse-view-crossref))
122 (unless (key-binding [(shift mouse-2)])
123 (define-key map [(shift mouse-2)] 'reftex-mouse-view-crossref)))
125 ;; For most of these commands there are already bindings in place.
126 ;; Setting `reftex-extra-bindings' really is only there to spare users
127 ;; the hassle of defining bindings in the user space themselves. This
128 ;; is why they violate the key binding recommendations.
129 (when reftex-extra-bindings
130 (define-key map "\C-ct" 'reftex-toc)
131 (define-key map "\C-cl" 'reftex-label)
132 (define-key map "\C-cr" 'reftex-reference)
133 (define-key map "\C-cc" 'reftex-citation)
134 (define-key map "\C-cv" 'reftex-view-crossref)
135 (define-key map "\C-cg" 'reftex-grep-document)
136 (define-key map "\C-cs" 'reftex-search-document))
138 map)
139 "Keymap for RefTeX mode.")
141 (defvar reftex-mode-menu nil)
142 (defvar reftex-syntax-table nil)
143 (defvar reftex-syntax-table-for-bib nil)
145 (defun reftex--prepare-syntax-tables ()
146 (setq reftex-syntax-table (copy-syntax-table))
147 (modify-syntax-entry ?\( "." reftex-syntax-table)
148 (modify-syntax-entry ?\) "." reftex-syntax-table)
150 (setq reftex-syntax-table-for-bib (copy-syntax-table))
151 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib)
152 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib)
153 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib)
154 (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib)
155 (modify-syntax-entry ?\( "." reftex-syntax-table-for-bib)
156 (modify-syntax-entry ?\) "." reftex-syntax-table-for-bib))
158 (unless (and reftex-syntax-table reftex-syntax-table-for-bib)
159 (reftex--prepare-syntax-tables))
161 ;; The following definitions are out of place, but I need them here
162 ;; to make the compilation of reftex-mode not complain.
163 (defvar reftex-auto-view-crossref-timer nil
164 "The timer used for auto-view-crossref.")
165 (defvar reftex-toc-auto-recenter-timer nil
166 "The idle timer used to recenter the toc window.")
168 ;;;###autoload
169 (defun turn-on-reftex ()
170 "Turn on RefTeX mode."
171 (reftex-mode t))
173 (put 'reftex-mode :included '(memq major-mode '(latex-mode tex-mode)))
174 (put 'reftex-mode :menu-tag "RefTeX Mode")
175 ;;;###autoload
176 (define-minor-mode reftex-mode
177 "Minor mode with distinct support for \\label, \\ref and \\cite in LaTeX.
179 \\<reftex-mode-map>A Table of Contents of the entire (multifile) document with browsing
180 capabilities is available with `\\[reftex-toc]'.
182 Labels can be created with `\\[reftex-label]' and referenced with `\\[reftex-reference]'.
183 When referencing, you get a menu with all labels of a given type and
184 context of the label definition. The selected label is inserted as a
185 \\ref macro.
187 Citations can be made with `\\[reftex-citation]' which will use a regular expression
188 to pull out a *formatted* list of articles from your BibTeX
189 database. The selected citation is inserted as a \\cite macro.
191 Index entries can be made with `\\[reftex-index-selection-or-word]' which indexes the word at point
192 or the current selection. More general index entries are created with
193 `\\[reftex-index]'. `\\[reftex-display-index]' displays the compiled index.
195 Most command have help available on the fly. This help is accessed by
196 pressing `?' to any prompt mentioning this feature.
198 Extensive documentation about RefTeX is available in Info format.
199 You can view this information with `\\[reftex-info]'.
201 \\{reftex-mode-map}
202 Under X, these and other functions will also be available as `Ref' menu
203 on the menu bar.
205 ------------------------------------------------------------------------------"
206 :lighter " Ref" :keymap reftex-mode-map
207 (if reftex-mode
208 (progn
209 ;; Mode was turned on
210 (easy-menu-add reftex-mode-menu)
211 (and reftex-plug-into-AUCTeX
212 (reftex-plug-into-AUCTeX))
213 (unless (get 'reftex-auto-view-crossref 'initialized)
214 (and reftex-auto-view-crossref
215 (reftex-toggle-auto-view-crossref))
216 (put 'reftex-auto-view-crossref 'initialized t))
217 (unless (get 'reftex-auto-recenter-toc 'initialized)
218 (and (eq reftex-auto-recenter-toc t)
219 (reftex-toggle-auto-toc-recenter))
220 (put 'reftex-auto-recenter-toc 'initialized t))
222 ;; Prepare the special syntax tables.
223 (reftex--prepare-syntax-tables)
225 (run-hooks 'reftex-mode-hook))
226 ;; Mode was turned off
227 (easy-menu-remove reftex-mode-menu)))
229 (defvar reftex-docstruct-symbol)
230 (defun reftex-kill-buffer-hook ()
231 "Save RefTeX's parse file for this buffer if the information has changed."
232 ;; Save the parsing information if it was modified.
233 ;; This function should be installed in `kill-buffer-hook'.
234 ;; We are careful to make sure nothing goes wrong in this function.
235 (when (and (boundp 'reftex-mode) reftex-mode
236 (boundp 'reftex-save-parse-info) reftex-save-parse-info
237 (boundp 'reftex-docstruct-symbol) reftex-docstruct-symbol
238 (symbol-value reftex-docstruct-symbol)
239 (get reftex-docstruct-symbol 'modified))
240 ;; Write the file.
241 (condition-case nil
242 (reftex-access-parse-file 'write)
243 (error nil))))
245 (defun reftex-kill-emacs-hook ()
246 "Call `reftex-kill-buffer-hook' on all buffers."
247 ;; This function should be installed in `kill-emacs-hook'.
248 (save-excursion
249 (mapcar (lambda (buf)
250 (set-buffer buf)
251 (reftex-kill-buffer-hook))
252 (buffer-list))))
254 ;;; =========================================================================
256 ;;; Silence warnings about variables in other packages.
257 (defvar TeX-master)
258 (defvar LaTeX-section-hook)
259 (defvar LaTeX-label-function)
260 (defvar tex-main-file)
261 (defvar outline-minor-mode)
262 (defvar font-lock-mode)
263 (defvar font-lock-keywords)
264 (defvar font-lock-fontify-region-function)
266 ;;; =========================================================================
268 ;;; Multibuffer Variables
270 ;; Technical notes: These work as follows: We keep just one list
271 ;; of labels for each master file - this can save a lot of memory.
272 ;; `reftex-master-index-list' is an alist which connects the true file name
273 ;; of each master file with the symbols holding the information on that
274 ;; document. Each buffer has local variables which point to these symbols.
276 ;; List of variables which handle the multifile stuff.
277 ;; This list is used to tie, untie, and reset these symbols.
278 (defconst reftex-multifile-symbols
279 '(reftex-docstruct-symbol))
281 ;; Alist connecting master file names with the corresponding lisp symbols.
282 (defvar reftex-master-index-list nil)
284 ;; Last index used for a master file.
285 (defvar reftex-multifile-index 0)
287 ;; Variable holding the symbol with the label list of the document.
288 (defvar reftex-docstruct-symbol nil)
289 (make-variable-buffer-local 'reftex-docstruct-symbol)
291 (defun reftex-next-multifile-index ()
292 ;; Return the next free index for multifile symbols.
293 (cl-incf reftex-multifile-index))
295 (defun reftex-tie-multifile-symbols ()
296 "Tie the buffer-local symbols to globals connected with the master file.
297 If the symbols for the current master file do not exist, they are created."
298 (let* ((master (file-truename (reftex-TeX-master-file)))
299 (index (assoc master reftex-master-index-list))
300 (symlist reftex-multifile-symbols)
301 symbol symname newflag)
302 ;; Find the correct index.
303 (if index
304 ;; Symbols do exist
305 (setq index (cdr index))
306 ;; Get a new index and add info to the alist.
307 (setq index (reftex-next-multifile-index)
308 newflag t)
309 (push (cons master index) reftex-master-index-list))
311 ;; Get/create symbols and tie them.
312 (while symlist
313 (setq symbol (car symlist)
314 symlist (cdr symlist)
315 symname (symbol-name symbol))
316 (set symbol (intern (concat symname "-" (int-to-string index))))
317 (put (symbol-value symbol) :master-index index)
318 ;; Initialize if new symbols.
319 (when newflag
320 (set (symbol-value symbol) nil)
321 (put (symbol-value symbol) 'reftex-index-macros-style '(default))
322 (put (symbol-value symbol) 'reftex-ref-style-list
323 reftex-ref-style-default-list)))
325 ;; Return t if the symbols did already exist, nil when we've made them.
326 (not newflag)))
328 (defun reftex-untie-multifile-symbols ()
329 "Remove ties from multifile symbols, so that next use makes new ones."
330 (let ((symlist reftex-multifile-symbols)
331 (symbol nil))
332 (while symlist
333 (setq symbol (car symlist)
334 symlist (cdr symlist))
335 (set symbol nil))))
337 (defun reftex-TeX-master-file ()
338 ;; Return the name of the master file associated with the current buffer.
339 ;; When AUCTeX is loaded, we will use it's more sophisticated method.
340 ;; We also support the default TeX and LaTeX modes by checking for a
341 ;; variable tex-main-file.
342 (let
343 ((master
344 (cond
345 ;; Test if we're in a subfile using the subfiles document
346 ;; class, e.g., \documentclass[main.tex]{subfiles}. It's
347 ;; argument is the main file, however it's not really the
348 ;; master file in `TeX-master-file' or `tex-main-file's
349 ;; sense. It should be used for references but not for
350 ;; compilation, thus subfiles use a setting of
351 ;; `TeX-master'/`tex-main-file' being themselves.
352 ((save-excursion
353 (goto-char (point-min))
354 (re-search-forward
355 "^[[:space:]]*\\\\documentclass\\[\\([[:word:].]+\\)\\]{subfiles}"
356 nil t))
357 (match-string-no-properties 1))
358 ;; AUCTeX is loaded. Use its mechanism.
359 ((fboundp 'TeX-master-file)
360 (condition-case nil
361 (TeX-master-file t)
362 (error (buffer-file-name))))
363 ;; Emacs LaTeX mode
364 ((fboundp 'tex-main-file) (tex-main-file))
365 ;; Check the `TeX-master' variable.
366 ((boundp 'TeX-master)
367 (cond
368 ((eq TeX-master t)
369 (buffer-file-name))
370 ((eq TeX-master 'shared)
371 (setq TeX-master (read-file-name "Master file: "
372 nil nil t nil)))
373 (TeX-master)
375 (setq TeX-master (read-file-name "Master file: "
376 nil nil t nil)))))
377 ;; Check the `tex-main-file' variable.
378 ((boundp 'tex-main-file)
379 ;; This is the variable from the default TeX modes.
380 (cond
381 ((stringp tex-main-file)
382 ;; ok, this must be it
383 tex-main-file)
385 ;; In this case, the buffer is its own master.
386 (buffer-file-name))))
387 ;; We know nothing about master file. Assume this is a
388 ;; master file.
390 (buffer-file-name)))))
391 (cond
392 ((null master)
393 (error "Need a filename for this buffer, please save it first"))
394 ((or (file-exists-p (concat master ".tex"))
395 (reftex-get-buffer-visiting (concat master ".tex")))
396 ;; Ahh, an extra .tex was missing...
397 (setq master (concat master ".tex")))
398 ((or (file-exists-p master)
399 (reftex-get-buffer-visiting master))
400 ;; We either see the file, or have a buffer on it. OK.
403 ;; Use buffer file name.
404 (setq master (buffer-file-name))))
405 (expand-file-name master)))
407 (defun reftex-is-multi ()
408 ;; Tell if this is a multifile document. When not sure, say yes.
409 (let ((entry (assq 'is-multi (symbol-value reftex-docstruct-symbol))))
410 (if entry
411 (nth 1 entry)
412 t)))
414 (defun reftex-set-cite-format (value)
415 "Set the document-local value of `reftex-cite-format'.
416 When such a value exists, it overwrites the setting given with
417 `reftex-cite-format'. See the documentation of `reftex-cite-format'
418 for possible values. This function should be used from AUCTeX style files."
419 (unless reftex-docstruct-symbol
420 (reftex-tie-multifile-symbols))
421 (when (and reftex-docstruct-symbol
422 (symbolp reftex-docstruct-symbol))
423 (put reftex-docstruct-symbol 'reftex-cite-format value)))
425 (defun reftex-get-cite-format ()
426 ;; Return the current citation format. Either the document-local value in
427 ;; reftex-cite-format-symbol, or the global value in reftex-cite-format.
428 (if (and reftex-docstruct-symbol
429 (symbolp reftex-docstruct-symbol)
430 (get reftex-docstruct-symbol 'reftex-cite-format))
431 (get reftex-docstruct-symbol 'reftex-cite-format)
432 reftex-cite-format))
434 (defun reftex-add-index-macros (entry-list)
435 "Add index macro descriptions to `reftex-index-macros-style'.
436 The format of ENTRY-LIST is exactly like `reftex-index-macros'. See there
437 for details.
438 This function makes it possible to support RefTeX from AUCTeX style files.
439 The entries in ENTRY-LIST will be processed after the user settings in
440 `reftex-index-entries', and before the defaults. Any changes made to
441 `reftex-index-macros-style' will raise a flag to the effect that
442 the label information is recompiled on next use."
443 (unless reftex-docstruct-symbol
444 (reftex-tie-multifile-symbols))
445 (when (and reftex-docstruct-symbol
446 (symbolp reftex-docstruct-symbol))
447 (let ((list (get reftex-docstruct-symbol 'reftex-index-macros-style))
448 entry changed)
449 (while entry-list
450 (setq entry (pop entry-list))
451 ;; When it is a symbol, remove all other symbols
452 (and (symbolp entry)
453 (not (memq entry list))
454 (setq list (reftex-remove-symbols-from-list list)))
455 ;; Add to list unless already member
456 (unless (member entry list)
457 (setq reftex-tables-dirty t
458 changed t)
459 (push entry list)))
460 (when changed
461 (put reftex-docstruct-symbol 'reftex-index-macros-style list)))))
463 (defun reftex-ref-style-activate (style)
464 "Activate the referencing style STYLE."
465 (reftex-ref-style-toggle style 'activate))
467 (defun reftex-ref-style-toggle (style &optional action)
468 "Activate or deactivate the referencing style STYLE.
469 With the optional argument ACTION a certain action can be forced.
470 The symbol `activate' will activate the style and `deactivate'
471 will deactivate it."
472 (unless reftex-docstruct-symbol
473 (reftex-tie-multifile-symbols))
474 (when (and reftex-docstruct-symbol
475 (symbolp reftex-docstruct-symbol))
476 (let ((list (get reftex-docstruct-symbol 'reftex-ref-style-list))
477 changed)
478 (cond ((eq action 'activate)
479 (unless (member style list)
480 (setq reftex-tables-dirty t
481 changed t)
482 (setq list (append list (list style)))))
483 ((eq action 'deactivate)
484 (when (member style list)
485 (setq reftex-tables-dirty t
486 changed t)
487 (setq list (delete style list))))
489 (if (member style list)
490 (delete style list)
491 (setq list (append list (list style))))
492 (setq reftex-tables-dirty t
493 changed t)))
494 (when changed
495 (put reftex-docstruct-symbol 'reftex-ref-style-list list)))))
497 (defun reftex-ref-style-list ()
498 "Return the list of referencing styles to be active at the moment."
499 ;; Initialize the value of `reftex-ref-style-list' and tie it to the
500 ;; docstruct symbol if necessary.
501 (unless reftex-docstruct-symbol
502 (reftex-tie-multifile-symbols))
503 (if (and reftex-docstruct-symbol
504 (symbolp reftex-docstruct-symbol)
505 (get reftex-docstruct-symbol 'reftex-ref-style-list))
506 (get reftex-docstruct-symbol 'reftex-ref-style-list)
507 reftex-ref-style-default-list))
509 ;;; =========================================================================
511 ;;; Functions to compile the tables, reset the mode etc.
513 ;; The following constants are derived from `reftex-label-alist'.
515 ;; Prompt used for label type queries directed to the user.
516 (defvar reftex-type-query-prompt nil)
518 ;; Help string for label type queries.
519 (defvar reftex-type-query-help nil)
521 ;; Alist relating label type to reference format.
522 (defvar reftex-typekey-to-format-alist nil)
524 ;; Alist relating label type to label prefix.
525 (defvar reftex-typekey-to-prefix-alist nil)
527 ;; Alist relating environments or macros to label type and context regexp.
528 (defvar reftex-env-or-mac-alist nil)
530 ;; List of special environment parser functions
531 (defvar reftex-special-env-parsers nil)
533 ;; List of macros carrying a label.
534 (defvar reftex-label-mac-list nil)
536 ;; List of environments carrying a label.
537 (defvar reftex-label-env-list nil)
539 ;; List of all typekey letters in use.
540 (defvar reftex-typekey-list nil)
542 ;; Alist relating magic words to a label type.
543 (defvar reftex-words-to-typekey-alist nil)
544 ;; Alist relating label prefixes to a label type.
545 (defvar reftex-prefix-to-typekey-alist nil)
547 ;; The last list-of-labels entry used in a reference.
548 (defvar reftex-last-used-reference (list nil nil nil nil))
550 ;; Alist relating index macros to other info.
551 (defvar reftex-key-to-index-macro-alist nil)
552 ;; Prompt for index macro queries
553 (defvar reftex-query-index-macro-prompt nil)
554 ;; Help string for index macro queries
555 (defvar reftex-query-index-macro-help nil)
557 ;; The message when follow-mode is suspended
558 (defvar reftex-no-follow-message
559 "No follow-mode into unvisited file. Press SPC to visit it.")
560 (defvar reftex-no-info-message
561 "%s: info not available, use `\\[reftex-view-crossref]' to get it.")
563 ;; Global variables used for communication between functions.
564 (defvar reftex-default-context-position nil)
565 (defvar reftex-location-start nil)
566 (defvar reftex-call-back-to-this-buffer nil)
567 (defvar reftex-select-return-marker (make-marker))
568 (defvar reftex-active-toc nil)
569 (defvar reftex-tex-path nil)
570 (defvar reftex-bib-path nil)
571 (defvar reftex-select-marked nil)
572 (defvar reftex-last-follow-point nil)
573 (defvar reftex-latex-syntax-table nil)
574 (defvar reftex-prefix nil)
575 (defvar reftex-section-levels-all nil)
576 (defvar reftex-buffers-with-changed-invisibility nil)
577 (defvar reftex-callback-fwd t)
578 (defvar reftex-last-toc-master nil
579 "Stores the name of the tex file that `reftex-toc' was last run on.")
580 ;; Marker for return point from recursive edit
581 (defvar reftex-recursive-edit-marker (make-marker))
583 ;; List of buffers created temporarily for lookup, which should be killed.
584 (defvar reftex-buffers-to-kill nil)
586 ;; Regexp to find anything.
587 (defvar reftex-section-regexp nil)
588 (defvar reftex-section-or-include-regexp nil)
589 (defvar reftex-index-macro-regexp nil)
590 (defvar reftex-index-level-re nil)
591 (defvar reftex-index-key-end-re nil)
592 (defvar reftex-find-index-entry-regexp-format nil)
593 (defvar reftex-everything-regexp nil)
594 (defvar reftex-everything-regexp-no-index nil)
595 (defvar reftex-index-re nil)
596 (defvar reftex-find-citation-regexp-format
597 "\\\\\\([a-zA-Z]*cite[*a-zA-Z]*\\*?\\|bibentry\\)\\(\\[[^]]*\\]\\|{[^}]*}\\)*{\\([^}]*,\\)?\\(%s\\)[},]")
598 (defvar reftex-find-reference-format
599 "\\\\\\(ref[a-zA-Z]*\\|[a-zA-Z]*ref\\(range\\)?\\)\\*?\\(\\[[^]]*\\]\\|{[^}]*}\\)*{\\(%s\\)}")
600 (defvar reftex-macros-with-labels nil)
601 (defvar reftex-macros-with-index nil)
602 (defvar reftex-index-macro-alist nil)
603 (defvar reftex-find-label-regexp-format nil)
604 (defvar reftex-find-label-regexp-format2 nil)
606 ;; Constants for making RefTeX open to Texinfo hooking
607 (defvar reftex-section-pre-regexp "\\\\")
608 ;; Including `\' as a character to be matched at the end of the regexp
609 ;; will allow stuff like \begin{foo}\label{bar} to be matched. This
610 ;; will make the parser to advance one char too much. Therefore
611 ;; `reftex-parse-from-file' will step one char back if a section is
612 ;; found.
613 (defvar reftex-section-post-regexp "\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n\\]")
614 (defvar reftex-section-info-function 'reftex-section-info)
616 (defvar reftex-memory nil
617 "Memorizes old variable values to indicate changes in these variables.")
619 ;; A list of all variables in the cache.
620 ;; The cache is used to save the compiled versions of some variables.
621 (defconst reftex-cache-variables
622 '(reftex-memory ;; This MUST ALWAYS be the first!
624 ;; Outline
625 reftex-section-levels-all
627 ;; Labels
628 reftex-env-or-mac-alist
629 reftex-special-env-parsers
630 reftex-macros-with-labels
631 reftex-label-mac-list
632 reftex-label-env-list
633 reftex-typekey-list
634 reftex-typekey-to-format-alist
635 reftex-typekey-to-prefix-alist
636 reftex-words-to-typekey-alist
637 reftex-prefix-to-typekey-alist
638 reftex-type-query-prompt
639 reftex-type-query-help
641 ;; Index
642 reftex-index-macro-alist
643 reftex-macros-with-index
644 reftex-query-index-macro-prompt
645 reftex-query-index-macro-help
646 reftex-key-to-index-macro-alist
648 ;; Regular expressions
649 reftex-section-regexp
650 reftex-section-or-include-regexp
651 reftex-index-re
652 reftex-everything-regexp
653 reftex-everything-regexp-no-index
654 reftex-find-label-regexp-format
655 reftex-find-label-regexp-format2
656 reftex-find-index-entry-regexp-format
659 (defun reftex-ensure-compiled-variables ()
660 ;; Recompile the label alist when necessary
661 (let* ((mem reftex-memory)
662 (cache (get reftex-docstruct-symbol 'reftex-cache))
663 (cmem (car cache))
664 (alist reftex-label-alist)
665 (levels (get reftex-docstruct-symbol 'reftex-section-levels))
666 (style (get reftex-docstruct-symbol 'reftex-label-alist-style))
667 (default reftex-default-label-alist-entries)
668 (index reftex-index-macros)
669 (istyle (get reftex-docstruct-symbol 'reftex-index-macros-style)))
670 (cond
671 (reftex-tables-dirty (reftex-compile-variables))
672 ((and (eq alist (nth 0 mem))
673 (eq levels (nth 1 mem))
674 (eq style (nth 2 mem))
675 (eq default (nth 3 mem))
676 (eq index (nth 4 mem))
677 (eq istyle (nth 5 mem)))) ;; everything is OK
678 ((and (eq alist (nth 0 cmem))
679 (eq levels (nth 1 cmem))
680 (eq style (nth 2 cmem))
681 (eq default (nth 2 cmem))
682 (eq index (nth 4 cmem))
683 (eq istyle (nth 5 cmem)))
684 ;; restore the cache
685 (message "Restoring cache")
686 (mapcar (lambda (sym) (set sym (pop cache))) reftex-cache-variables))
687 (t (reftex-compile-variables)))))
689 (defun reftex-reset-mode ()
690 "Reset RefTeX Mode.
691 This will re-compile the configuration information and remove all
692 current scanning information and the parse file to enforce a rescan
693 on next use."
694 (interactive)
696 ;; Reset the file search path variables
697 (dolist (prop '(status master-dir recursive-path rec-type))
698 (put 'reftex-tex-path prop nil)
699 (put 'reftex-bib-path prop nil))
701 ;; Kill temporary buffers associated with RefTeX - just in case they
702 ;; were not cleaned up properly
703 (save-excursion
704 (let ((buffer-list '("*RefTeX Help*" "*RefTeX Select*"
705 "*Duplicate Labels*" "*toc*" " *RefTeX-scratch*"))
706 buf)
707 (while (setq buf (pop buffer-list))
708 (if (get-buffer buf)
709 (kill-buffer buf))))
710 (reftex-erase-all-selection-and-index-buffers))
712 ;; Make sure the current document will be rescanned soon.
713 (reftex-reset-scanning-information)
715 ;; Remove any parse info file
716 (reftex-access-parse-file 'kill)
718 ;; Plug functions into AUCTeX if the user option says so.
719 (and reftex-plug-into-AUCTeX
720 (reftex-plug-into-AUCTeX))
722 (reftex-compile-variables))
724 ;;;###autoload
725 (defun reftex-reset-scanning-information ()
726 "Reset the symbols containing information from buffer scanning.
727 This enforces rescanning the buffer on next use."
728 (if (string= reftex-last-toc-master (reftex-TeX-master-file))
729 (reftex-erase-buffer "*toc*"))
730 (let ((symlist reftex-multifile-symbols)
731 symbol)
732 (while symlist
733 (setq symbol (car symlist)
734 symlist (cdr symlist))
735 (if (and (symbolp (symbol-value symbol))
736 (not (null (symbol-value symbol))))
737 (set (symbol-value symbol) nil)))))
739 (defun reftex-erase-all-selection-and-index-buffers ()
740 ;; Remove all selection buffers associated with current document.
741 (mapc
742 (lambda (type)
743 (reftex-erase-buffer (reftex-make-selection-buffer-name type)))
744 reftex-typekey-list)
745 ;; Kill all index buffers
746 (mapc
747 (lambda (tag)
748 (reftex-kill-buffer (reftex-make-index-buffer-name tag)))
749 (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))))
751 (defun reftex-compile-variables ()
752 ;; Compile the information in reftex-label-alist & Co.
754 (message "Compiling label environment definitions...")
756 ;; Update AUCTeX style information
757 (when (and (featurep 'tex-site) (fboundp 'TeX-update-style))
758 (condition-case nil (TeX-update-style) (error nil)))
760 ;; Record that we have done this, and what we have used.
761 (setq reftex-tables-dirty nil)
762 (setq reftex-memory
763 (list reftex-label-alist
764 (get reftex-docstruct-symbol 'reftex-section-levels)
765 (get reftex-docstruct-symbol 'reftex-label-alist-style)
766 reftex-default-label-alist-entries
767 reftex-index-macros
768 (get reftex-docstruct-symbol 'reftex-index-macros-style)))
770 ;; Compile information in reftex-label-alist
771 (let ((all (reftex-uniquify-by-car
772 (reftex-splice-symbols-into-list
773 (append reftex-label-alist
774 (get reftex-docstruct-symbol
775 'reftex-label-alist-style)
776 reftex-default-label-alist-entries)
777 reftex-label-alist-builtin)
778 '(nil)))
779 (all-index (reftex-uniquify-by-car
780 (reftex-splice-symbols-into-list
781 (append reftex-index-macros
782 (get reftex-docstruct-symbol
783 'reftex-index-macros-style)
784 '(default))
785 reftex-index-macros-builtin)))
786 entry env-or-mac typekeychar typekey prefix context word
787 fmt reffmt labelfmt wordlist qh-list macros-with-labels
788 nargs nlabel opt-args cell sum i
789 macro verify repeat nindex tag key toc-level toc-levels)
791 (setq reftex-words-to-typekey-alist nil
792 reftex-prefix-to-typekey-alist
793 '(("sec:" . "s") ("cha:" . "s") ("chap:" . "s"))
794 reftex-typekey-list nil
795 reftex-typekey-to-format-alist nil
796 reftex-typekey-to-prefix-alist nil
797 reftex-env-or-mac-alist nil
798 reftex-label-env-list nil
799 reftex-label-mac-list nil)
800 (while all
801 (catch 'next-entry
802 (setq entry (car all)
803 env-or-mac (car entry)
804 entry (cdr entry)
805 all (cdr all))
806 (if (null env-or-mac)
807 (setq env-or-mac ""))
808 (if (stringp (car entry))
809 ;; This is before version 2.00 - convert entry to new format
810 ;; This is just to keep old users happy
811 (setq entry (cons (string-to-char (car entry))
812 (cons (concat (car entry) ":")
813 (cdr entry)))))
814 (setq typekeychar (nth 0 entry)
815 typekey (if typekeychar (char-to-string typekeychar) nil)
816 prefix (nth 1 entry)
817 fmt (nth 2 entry)
818 context (nth 3 entry)
819 wordlist (nth 4 entry)
820 toc-level (nth 5 entry))
821 (if (stringp wordlist)
822 ;; This is before version 2.04 - convert to new format
823 (setq wordlist (nthcdr 4 entry)))
825 (if (and (stringp fmt)
826 (string-match "@" fmt))
827 ;; Special syntax for specifying a label format
828 (setq fmt (split-string fmt "@+"))
829 (setq fmt (list "\\label{%s}" fmt)))
830 (setq labelfmt (car fmt)
831 reffmt (nth 1 fmt))
832 ;; Note a new typekey
833 (if typekey
834 (cl-pushnew typekey reftex-typekey-list :test #'equal))
835 (if (and typekey prefix
836 (not (assoc prefix reftex-prefix-to-typekey-alist)))
837 (cl-pushnew (cons prefix typekey) reftex-prefix-to-typekey-alist
838 :test #'equal))
839 (if (and typekey prefix
840 (not (assoc typekey reftex-typekey-to-prefix-alist)))
841 (cl-pushnew (cons typekey prefix) reftex-typekey-to-prefix-alist
842 :test #'equal))
843 ;; Check if this is a macro or environment
844 (cond
845 ((symbolp env-or-mac)
846 ;; A special parser function
847 (unless (fboundp env-or-mac)
848 (message "Warning: %s does not seem to be a valid function"
849 env-or-mac))
850 (setq nargs nil nlabel nil opt-args nil)
851 (cl-pushnew env-or-mac reftex-special-env-parsers)
852 (setq env-or-mac (symbol-name env-or-mac)))
853 ((string-match "\\`\\\\" env-or-mac)
854 ;; It's a macro
855 (let ((result (reftex-parse-args env-or-mac)))
856 (setq env-or-mac (or (cl-first result) env-or-mac)
857 nargs (cl-second result)
858 nlabel (cl-third result)
859 opt-args (cl-fourth result))
860 (if nlabel (cl-pushnew env-or-mac macros-with-labels :test #'equal)))
861 (if typekey (cl-pushnew env-or-mac reftex-label-mac-list :test #'equal)))
863 ;; It's an environment
864 (setq nargs nil nlabel nil opt-args nil)
865 (cond ((string= env-or-mac "any"))
866 ((string= env-or-mac ""))
867 ((string= env-or-mac "section"))
869 (cl-pushnew env-or-mac reftex-label-env-list :test #'equal)
870 (if toc-level
871 (let ((string (format "begin{%s}" env-or-mac)))
872 (or (assoc string toc-levels)
873 (push (cons string toc-level) toc-levels))))))))
874 ;; Translate some special context cases
875 (when (assq context reftex-default-context-regexps)
876 (setq context
877 (format
878 (cdr (assq context reftex-default-context-regexps))
879 (regexp-quote env-or-mac))))
880 ;; See if this is the first format for this typekey
881 (and reffmt
882 (not (assoc typekey reftex-typekey-to-format-alist))
883 (push (cons typekey reffmt) reftex-typekey-to-format-alist))
884 ;; See if this is the first definition for this env-or-mac
885 (and (not (string= env-or-mac "any"))
886 (not (string= env-or-mac ""))
887 (not (assoc env-or-mac reftex-env-or-mac-alist))
888 (push (list env-or-mac typekey context labelfmt
889 nargs nlabel opt-args)
890 reftex-env-or-mac-alist))
891 ;; Are the magic words regular expressions? Quote normal words.
892 (if (eq (car wordlist) 'regexp)
893 (setq wordlist (cdr wordlist))
894 (setq wordlist (mapcar 'regexp-quote wordlist)))
895 ;; Remember the first association of each word.
896 (while (stringp (setq word (pop wordlist)))
897 (or (assoc word reftex-words-to-typekey-alist)
898 (push (cons word typekey) reftex-words-to-typekey-alist)))
899 (cond
900 ((string= "" env-or-mac) nil)
901 ((setq cell (assoc typekey qh-list))
902 (push env-or-mac (cdr cell)))
903 (typekey
904 (push (list typekey env-or-mac) qh-list)))))
906 (setq reftex-typekey-to-prefix-alist
907 (nreverse reftex-typekey-to-prefix-alist))
909 ;; Prepare the typekey query prompt and help string.
910 (setq qh-list
911 (sort qh-list
912 (lambda (x1 x2)
913 (string< (downcase (car x1)) (downcase (car x2))))))
914 (setq reftex-type-query-prompt
915 (concat "Label type: ["
916 (mapconcat (lambda(x) (format "%s" (car x)))
917 qh-list "")
918 "]"))
919 ;; In the help string, we need to wrap lines...
920 (setq reftex-type-query-help
921 (concat
922 "SELECT A LABEL TYPE:\n--------------------\n"
923 (mapconcat
924 (lambda(x)
925 (setq sum 0)
926 (format " [%s] %s"
927 (car x)
928 (mapconcat (lambda(env)
929 (setq sum (+ sum (length env)))
930 (if (< sum 60)
932 (setq sum 0)
933 (concat "\n " env)))
934 (cdr x) " ")))
935 qh-list "\n")))
937 ;; Convert magic words to regular expressions. We make regular expressions
938 ;; which allow for some chars from the ref format to be in the buffer.
939 ;; These characters will be seen and removed.
940 (setq reftex-words-to-typekey-alist
941 (mapcar
942 (lambda (x)
943 (setq word (car x)
944 typekey (cdr x)
945 fmt (cdr (assoc typekey reftex-typekey-to-format-alist)))
946 (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\("))
947 (setq i 0)
948 (while (and (< i 10) ; maximum number of format chars allowed
949 (< i (length fmt))
950 (not (member (aref fmt i) '(?%))))
951 (setq word (concat word "\\|" (regexp-quote
952 (substring fmt 0 (1+ i)))))
953 (cl-incf i))
954 (cons (concat word "\\)\\=") typekey))
955 (nreverse reftex-words-to-typekey-alist)))
957 ;; Parse the index macros
958 (setq reftex-index-macro-alist nil
959 reftex-key-to-index-macro-alist nil
960 reftex-macros-with-index nil)
961 (while all-index
962 (setq entry (car all-index)
963 macro (car entry)
964 tag (nth 1 entry)
965 key (nth 2 entry)
966 prefix (or (nth 3 entry) "")
967 verify (nth 4 entry)
968 ;; For repeat, we need to be compatible with older code
969 ;; This information used to be given only for the default macro,
970 ;; but later we required to have it for *every* index macro
971 repeat (cond ((> (length entry) 5) (nth 5 entry))
972 ((and (eq key (car reftex-index-default-macro))
973 (> (length reftex-index-default-macro) 2))
974 ;; User has old setting - respect it
975 (nth 2 reftex-index-default-macro))
976 (t t))
977 all-index (cdr all-index))
978 (let ((result (reftex-parse-args macro)))
979 (setq macro (or (cl-first result) macro)
980 nargs (cl-second result)
981 nindex (cl-third result)
982 opt-args (cl-fourth result))
983 (unless (member macro reftex-macros-with-index)
984 ;; 0 1 2 3 4 5 6 7
985 (push (list macro tag prefix verify nargs nindex opt-args repeat)
986 reftex-index-macro-alist)
987 (or (assoc key reftex-key-to-index-macro-alist)
988 (push (list key macro) reftex-key-to-index-macro-alist))
989 (push macro reftex-macros-with-index))))
990 ;; Make the prompt and help string for index macros query
991 (setq reftex-key-to-index-macro-alist
992 (sort reftex-key-to-index-macro-alist
993 (lambda (a b) (< (downcase (car a)) (downcase (car b))))))
994 (setq reftex-query-index-macro-prompt
995 (concat "Index macro: ["
996 (mapconcat (lambda (x) (char-to-string (car x)))
997 reftex-key-to-index-macro-alist "")
998 "]"))
999 (setq i 0
1000 reftex-query-index-macro-help
1001 (concat
1002 "SELECT A MACRO:\n---------------\n"
1003 (mapconcat
1004 (lambda(x)
1005 (format "[%c] %-20.20s%s" (car x) (nth 1 x)
1006 (if (= 0 (mod (cl-incf i) 3)) "\n" "")))
1007 reftex-key-to-index-macro-alist "")))
1009 ;; Make the full list of section levels
1010 (setq reftex-section-levels-all
1011 (append toc-levels
1012 (get reftex-docstruct-symbol 'reftex-section-levels)
1013 reftex-section-levels))
1015 ;; Calculate the regular expressions
1016 (let* (
1017 ; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
1018 (wbol "\\(^\\)%?[ \t]*") ; Need to keep the empty group because
1019 ; match numbers are hard coded
1020 (label-re (concat "\\(?:"
1021 (mapconcat 'identity reftex-label-regexps "\\|")
1022 "\\)"))
1023 (include-re (concat wbol
1024 "\\\\\\("
1025 (mapconcat 'identity
1026 reftex-include-file-commands "\\|")
1027 "\\)[{ \t]+\\([^} \t\n\r]+\\)"))
1028 (section-re
1029 (concat wbol reftex-section-pre-regexp "\\("
1030 (mapconcat (lambda (x) (regexp-quote (car x)))
1031 reftex-section-levels-all "\\|")
1032 "\\)" reftex-section-post-regexp))
1033 (appendix-re (concat wbol "\\(\\\\appendix\\)"))
1034 (macro-re
1035 (if macros-with-labels
1036 (concat "\\("
1037 (mapconcat 'regexp-quote macros-with-labels "\\|")
1038 "\\)[[{]")
1039 ""))
1040 (index-re
1041 (concat "\\("
1042 (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
1043 "\\)[[{]"))
1044 (find-index-re-format
1045 (concat "\\("
1046 (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
1047 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
1048 (find-label-re-format
1049 (concat "\\("
1050 "label[[:space:]]*=[[:space:]]*"
1051 "\\|"
1052 (mapconcat 'regexp-quote (append '("\\label")
1053 macros-with-labels) "\\|")
1054 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
1055 (index-level-re
1056 (regexp-quote (nth 0 reftex-index-special-chars)))
1057 (index-key-end-re ;; ^]- not allowed
1058 (concat "[^" (nth 3 reftex-index-special-chars) "]"
1059 "[" (nth 1 reftex-index-special-chars)
1060 (nth 2 reftex-index-special-chars) "]"))
1062 (setq reftex-section-regexp section-re
1063 reftex-section-or-include-regexp
1064 (concat section-re "\\|" include-re)
1065 reftex-everything-regexp
1066 (concat label-re "\\|" section-re "\\|" include-re
1067 "\\|" appendix-re
1068 "\\|" index-re
1069 (if macros-with-labels "\\|" "") macro-re)
1070 reftex-everything-regexp-no-index
1071 (concat label-re "\\|" section-re "\\|" include-re
1072 "\\|" appendix-re
1073 "\\|" "\\(\\\\6\\\\3\\\\1\\)" ; This is unlikely to match
1074 (if macros-with-labels "\\|" "") macro-re)
1075 reftex-index-re index-re
1076 reftex-index-level-re index-level-re
1077 reftex-index-key-end-re index-key-end-re
1078 reftex-macros-with-labels macros-with-labels
1079 reftex-find-index-entry-regexp-format find-index-re-format
1080 reftex-find-label-regexp-format find-label-re-format
1081 reftex-find-label-regexp-format2
1082 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]")
1083 (message "Compiling label environment definitions...done")))
1084 (put reftex-docstruct-symbol 'reftex-cache
1085 (mapcar 'symbol-value reftex-cache-variables)))
1087 (defun reftex-parse-args (macro)
1088 ;; Return a list of macro name, nargs, arg-nr which is label and a list of
1089 ;; optional argument indices.
1090 (if (string-match "[[{]\\*?[]}]" macro)
1091 (progn
1092 (let ((must-match (substring macro 0 (match-beginning 0)))
1093 (args (substring macro (match-beginning 0)))
1094 opt-list nlabel (cnt 0))
1095 (while (string-match "\\`[[{]\\(\\*\\)?[]}]" args)
1096 (cl-incf cnt)
1097 (when (eq ?\[ (string-to-char args))
1098 (push cnt opt-list))
1099 (when (and (match-end 1)
1100 (not nlabel))
1101 (setq nlabel cnt))
1102 (setq args (substring args (match-end 0))))
1103 (list must-match cnt nlabel opt-list)))
1104 nil))
1106 ;;; =========================================================================
1108 ;;; Accessing the parse information
1110 (defun reftex-access-scan-info (&optional rescan file)
1111 "Ensure access to the scanning info for the current file."
1112 ;; When the multifile symbols are not yet tied,
1113 ;; tie them. When they are empty or RESCAN is non-nil, scan the document.
1114 ;; But, when RESCAN is -1, don't rescan even if docstruct is empty.
1115 ;; When FILE is non-nil, parse only from that file.
1117 ;; Error out in a buffer without a file.
1118 (if (and reftex-mode
1119 (not (buffer-file-name)))
1120 (error "RefTeX works only in buffers visiting a file"))
1122 ;; Make sure we have the symbols tied
1123 (if (eq reftex-docstruct-symbol nil)
1124 ;; Symbols are not yet tied: Tie them.
1125 (reftex-tie-multifile-symbols))
1127 (reftex-ensure-compiled-variables)
1129 (when (or (null (symbol-value reftex-docstruct-symbol))
1130 (member rescan '(t 1 (4) (16))))
1131 ;; The docstruct will change: Remove selection buffers.
1132 (save-excursion
1133 (reftex-erase-buffer "*toc*")
1134 (reftex-erase-all-selection-and-index-buffers)))
1136 (if (and (null (symbol-value reftex-docstruct-symbol))
1137 (not (member rescan '(t 1 (4) (16))))
1138 reftex-save-parse-info)
1139 ;; Try to read the stuff from a file
1140 (reftex-access-parse-file 'read))
1142 (cond
1143 ((equal rescan -1)) ;; We are not allowed to scan.
1144 ((not (symbol-value reftex-docstruct-symbol))
1145 ;; Scan the whole document
1146 (reftex-do-parse 1 file))
1147 ((member rescan '(t 1 (4) (16)))
1148 ;; Scan whatever was required by the caller.
1149 (reftex-do-parse rescan file))))
1151 (defun reftex-scanning-info-available-p ()
1152 "Is the scanning info about the current document available?"
1153 (unless reftex-docstruct-symbol
1154 (reftex-tie-multifile-symbols))
1155 (and (symbolp reftex-docstruct-symbol)
1156 (symbol-value reftex-docstruct-symbol)
1159 (defun reftex-silence-toc-markers (list n)
1160 ;; Set all toc markers in the first N entries in list to nil
1161 (while (and list (> (cl-decf n) -1))
1162 (and (eq (car (car list)) 'toc)
1163 (markerp (nth 4 (car list)))
1164 (set-marker (nth 4 (car list)) nil))
1165 (pop list)))
1167 (defun reftex-access-parse-file (action)
1168 "Perform ACTION on the parse file (the .rel file).
1169 Valid actions are: readable, restore, read, kill, write."
1170 (let* ((list (symbol-value reftex-docstruct-symbol))
1171 (docstruct-symbol reftex-docstruct-symbol)
1172 (master (reftex-TeX-master-file))
1173 (enable-local-variables nil)
1174 (file (if (string-match "\\.[a-zA-Z]+\\'" master)
1175 (concat (substring master 0 (match-beginning 0))
1176 reftex-parse-file-extension)
1177 (concat master reftex-parse-file-extension))))
1178 (cond
1179 ((eq action 'readable)
1180 (file-readable-p file))
1181 ((eq action 'restore)
1182 (put reftex-docstruct-symbol 'modified nil)
1183 (if (eq reftex-docstruct-symbol nil)
1184 ;; Symbols are not yet tied: Tie them.
1185 (reftex-tie-multifile-symbols))
1186 (if (file-exists-p file)
1187 ;; load the file and return t for success
1188 (condition-case nil
1189 (progn (load-file file) t)
1190 (error (set reftex-docstruct-symbol nil)
1191 (error "Error while loading file %s" file)))
1192 ;; Throw an exception if the file does not exist
1193 (error "No restore file %s" file)))
1194 ((eq action 'read)
1195 (put reftex-docstruct-symbol 'modified nil)
1196 (if (file-exists-p file)
1197 ;; load the file and return t for success
1198 (condition-case nil
1199 (progn
1200 (load-file file)
1201 (reftex-check-parse-consistency)
1203 (error (message "Error while restoring file %s" file)
1204 (set reftex-docstruct-symbol nil)
1205 nil))
1206 ;; return nil for failure, but no exception
1207 nil))
1208 ((eq action 'kill)
1209 ;; Remove the file
1210 (when (and (file-exists-p file) (file-writable-p file))
1211 (message "Unlinking file %s" file)
1212 (delete-file file)))
1214 (put docstruct-symbol 'modified nil)
1215 (save-excursion
1216 (if (file-writable-p file)
1217 (with-temp-file file
1218 (message "Writing parse file %s" (abbreviate-file-name file))
1219 (insert (format ";; RefTeX parse info file\n"))
1220 (insert (format ";; File: %s\n" master))
1221 (insert (format ";; User: %s (%s)\n\n"
1222 (user-login-name) (user-full-name)))
1223 (insert "(set reftex-docstruct-symbol '(\n\n")
1224 (let ((standard-output (current-buffer)))
1225 (mapc
1226 (lambda (x)
1227 (cond ((eq (car x) 'toc)
1228 ;; A toc entry. Do not save the marker.
1229 ;; Save the markers position at position 8
1230 (print (list 'toc "toc" (nth 2 x) (nth 3 x)
1231 nil (nth 5 x) (nth 6 x) (nth 7 x)
1232 (or (and (markerp (nth 4 x))
1233 (marker-position (nth 4 x)))
1234 (nth 8 x)))))
1235 ((and (not (eq t reftex-support-index))
1236 (eq (car x) 'index))
1237 ;; Don't save index entries
1239 (t (print x))))
1240 list))
1241 (insert "))\n\n"))
1242 (error "Cannot write to file %s" file)))
1243 t))))
1245 (defun reftex-check-parse-consistency ()
1246 ;; Check if parse file is consistent, throw an error if not.
1248 ;; Check if the master is the same: when moving a document, this will see it.
1249 (let* ((real-master (reftex-TeX-master-file))
1250 (parsed-master
1251 (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol)))))
1252 (unless (string= (file-truename real-master) (file-truename parsed-master))
1253 (message "Master file name in load file is different: %s versus %s"
1254 parsed-master real-master)
1255 (error "Master file name error")))
1257 ;; Check for the existence of all document files
1258 ;;; (let* ((all (symbol-value reftex-docstruct-symbol)))
1259 ;;; (while all
1260 ;;; (when (and (eq (car (car all)) 'bof)
1261 ;;; (not (file-regular-p (nth 1 (car all)))))
1262 ;;; (message "File %s in saved parse info not available" (cdr (car all)))
1263 ;;; (error "File not found"))
1264 ;;; (setq all (cdr all))))
1267 (defun reftex-select-external-document (xr-alist xr-index)
1268 ;; Return index of an external document.
1269 (let* ((len (length xr-alist)) (highest (1- (+ ?0 len)))
1270 (prompt (format "[%c-%c] Select TAB: Read prefix with completion"
1271 ?0 highest))
1272 key prefix)
1273 (cond
1274 ((= len 1)
1275 (message "No external documents available")
1276 (ding) (sit-for 1) 0)
1277 ((= len 2)
1278 (- 1 xr-index))
1280 (save-excursion
1281 (let* ((length (apply 'max (mapcar
1282 (lambda(x) (length (car x))) xr-alist)))
1283 (fmt (format " [%%c] %%-%ds %%s\n" length))
1284 (n (1- ?0)))
1285 (setq key
1286 (reftex-select-with-char
1287 prompt
1288 (concat
1289 "SELECT EXTERNAL DOCUMENT\n------------------------\n"
1290 (mapconcat
1291 (lambda (x)
1292 (format fmt (cl-incf n) (or (car x) "")
1293 (abbreviate-file-name (cdr x))))
1294 xr-alist ""))
1295 nil t))
1296 (cond
1297 ((and (>= key ?0) (<= key highest)) (- key ?0))
1298 ((= key ?\C-i)
1299 (setq prefix (completing-read "Prefix: " xr-alist nil t))
1300 (- len (length (memq (assoc prefix xr-alist) xr-alist))))
1301 (t (error "Invalid document selection [%c]" key)))))))))
1303 ;;; =========================================================================
1305 ;;; Finding files
1307 (defun reftex-locate-file (file type master-dir &optional die)
1308 "Find FILE of type TYPE in MASTER-DIR or on the path associated with TYPE.
1309 If the file does not have any of the valid extensions for TYPE,
1310 try first the default extension and only then the naked file name.
1311 When DIE is non-nil, throw an error if file not found."
1312 (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
1313 (extensions (cdr (assoc type reftex-file-extensions)))
1314 (def-ext (car extensions))
1315 (ext-re (concat "\\("
1316 (mapconcat 'regexp-quote extensions "\\|")
1317 "\\)\\'"))
1318 (files (if (string-match ext-re file)
1319 (cons file nil)
1320 (if reftex-try-all-extensions
1321 (append (mapcar (lambda (x) (concat file x))
1322 extensions)
1323 (list file))
1324 (list (concat file def-ext) file))))
1325 path old-path file1 f fs)
1326 (cond
1327 ((file-name-absolute-p file)
1328 (while (setq f (pop files))
1329 (if (file-regular-p f)
1330 (setq file1 f files nil))))
1331 ((and reftex-use-external-file-finders
1332 (assoc type reftex-external-file-finders))
1333 (setq file1 (reftex-find-file-externally file type master-dir)))
1335 (while (and (null file1) rec-values)
1336 (setq path (reftex-access-search-path
1337 type (pop rec-values) master-dir file))
1338 (setq fs files)
1339 (while (and (null file1) (setq f (pop fs)))
1340 (when (or (null old-path)
1341 (not (eq old-path path)))
1342 (setq old-path path
1343 path (cons master-dir path))
1344 (setq file1 (reftex-find-file-on-path f path master-dir)))))))
1345 (cond (file1 file1)
1346 (die (error "No such file: %s" file) nil)
1347 (t (message "No such file: %s (ignored)" file) nil))))
1349 (defun reftex-find-file-externally (file type &optional master-dir)
1350 ;; Use external program to find FILE.
1351 ;; The program is taken from `reftex-external-file-finders'.
1352 ;; Interpret relative path definitions starting from MASTER-DIR.
1353 (let ((default-directory (or master-dir default-directory))
1354 (prg (cdr (assoc type reftex-external-file-finders)))
1355 out)
1356 (if (string-match "%f" prg)
1357 (setq prg (replace-match file t t prg)))
1358 (setq out (apply 'reftex-process-string (split-string prg)))
1359 (if (string-match "[ \t\n]+\\'" out) ; chomp
1360 (setq out (replace-match "" nil nil out)))
1361 (cond ((equal out "") nil)
1362 ((file-regular-p out) (expand-file-name out master-dir))
1363 (t nil))))
1365 (defun reftex-process-string (program &rest args)
1366 "Execute PROGRAM with arguments ARGS and return its STDOUT as a string."
1367 (let ((calling-dir default-directory)) ; remember default directory
1368 (with-output-to-string
1369 (with-current-buffer standard-output
1370 (let ((default-directory calling-dir)) ; set default directory
1371 (apply 'call-process program nil '(t nil) nil args))))))
1373 (defun reftex-access-search-path (type &optional recurse master-dir file)
1374 ;; Access path from environment variables. TYPE is either "tex" or "bib".
1375 ;; When RECURSE is t, expand path elements ending in `//' recursively.
1376 ;; Relative path elements are left as they are. However, relative recursive
1377 ;; elements are expanded with MASTER-DIR as default directory.
1378 ;; The expanded path is cached for the next search.
1379 ;; FILE is just for the progress message.
1380 ;; Returns the derived path.
1381 (let* ((pathvar (intern (concat "reftex-" type "-path"))))
1382 (when (null (get pathvar 'status))
1383 ;; Get basic path
1384 (set pathvar
1385 (reftex-uniquify
1386 (reftex-parse-colon-path
1387 (mapconcat
1388 (lambda(x)
1389 (if (string-match "^!" x)
1390 (apply 'reftex-process-string
1391 (split-string (substring x 1)))
1392 (or (getenv x) x)))
1393 ;; For consistency, the next line should look like this:
1394 ;; (cdr (assoc type reftex-path-environment))
1395 ;; However, historically we have separate options for the
1396 ;; environment variables, so we have to do this:
1397 (symbol-value (intern (concat "reftex-" type
1398 "path-environment-variables")))
1399 path-separator))))
1400 (put pathvar 'status 'split)
1401 ;; Check if we have recursive elements
1402 (let ((path (symbol-value pathvar)) dir rec)
1403 (while (setq dir (pop path))
1404 (when (string= (substring dir -2) "//")
1405 (if (file-name-absolute-p dir)
1406 (setq rec (or rec 'absolute))
1407 (setq rec 'relative))))
1408 (put pathvar 'rec-type rec)))
1410 (if recurse
1411 ;; Return the recursive expansion of the path
1412 (cond
1413 ((not (get pathvar 'rec-type))
1414 ;; Path does not contain recursive elements - use simple path
1415 (symbol-value pathvar))
1416 ((or (not (get pathvar 'recursive-path))
1417 (and (eq (get pathvar 'rec-type) 'relative)
1418 (not (equal master-dir (get pathvar 'master-dir)))))
1419 ;; Either: We don't have a recursive expansion yet.
1420 ;; or: Relative recursive path elements need to be expanded
1421 ;; relative to new default directory
1422 (message "Expanding search path to find %s file: %s ..." type file)
1423 (put pathvar 'recursive-path
1424 (reftex-expand-path (symbol-value pathvar) master-dir))
1425 (put pathvar 'master-dir master-dir)
1426 (get pathvar 'recursive-path))
1428 ;; Recursive path computed earlier is still OK.
1429 (get pathvar 'recursive-path)))
1430 ;; The simple path was requested
1431 (symbol-value pathvar))))
1433 (defun reftex-find-file-on-path (file path &optional def-dir)
1434 ;; Find FILE along the directory list PATH.
1435 ;; DEF-DIR is the default directory for expanding relative path elements.
1436 (catch 'exit
1437 (when (file-name-absolute-p file)
1438 (if (file-regular-p file)
1439 (throw 'exit file)
1440 (throw 'exit nil)))
1441 (let* ((thepath path) file1 dir)
1442 (while (setq dir (pop thepath))
1443 (when (string= (substring dir -2) "//")
1444 (setq dir (substring dir 0 -1)))
1445 (setq file1 (expand-file-name file (expand-file-name dir def-dir)))
1446 (if (file-regular-p file1)
1447 (throw 'exit file1)))
1448 ;; No such file
1449 nil)))
1451 (defun reftex-parse-colon-path (path)
1452 ;; Like parse-colon-parse, but // or /~ are left alone.
1453 ;; Trailing ! or !! will be converted into `//' (emTeX convention)
1454 (mapcar
1455 (lambda (dir)
1456 (if (string-match "\\(//+\\|/*!+\\)\\'" dir)
1457 (setq dir (replace-match "//" t t dir)))
1458 (file-name-as-directory dir))
1459 (delete "" (split-string path (concat path-separator "+")))))
1461 (defun reftex-expand-path (path &optional default-dir)
1462 ;; Expand parts of path ending in `//' recursively into directory list.
1463 ;; Relative recursive path elements are expanded relative to DEFAULT-DIR.
1464 (let (path1 dir recursive)
1465 (while (setq dir (pop path))
1466 (if (setq recursive (string= (substring dir -2) "//"))
1467 (setq dir (substring dir 0 -1)))
1468 (if (and recursive
1469 (not (file-name-absolute-p dir)))
1470 (setq dir (expand-file-name dir default-dir)))
1471 (if recursive
1472 ;; Expand recursively
1473 (setq path1 (append (reftex-recursive-directory-list dir) path1))
1474 ;; Keep unchanged
1475 (push dir path1)))
1476 (nreverse path1)))
1478 (defun reftex-recursive-directory-list (dir)
1479 ;; Return a list of all directories below DIR, including DIR itself
1480 (let ((path (list dir)) path1 file files)
1481 (while (setq dir (pop path))
1482 (when (file-directory-p dir)
1483 (setq files (nreverse (directory-files dir t "[^.]")))
1484 (while (setq file (pop files))
1485 (if (file-directory-p file)
1486 (push (file-name-as-directory file) path)))
1487 (push dir path1)))
1488 path1))
1490 ;;; =========================================================================
1492 ;;; Some generally useful functions
1494 (defun reftex-typekey-check (typekey conf-variable &optional n)
1495 ;; Check if CONF-VARIABLE is true or contains TYPEKEY
1496 (and n (setq conf-variable (nth n conf-variable)))
1497 (or (eq conf-variable t)
1498 (and (stringp conf-variable)
1499 (string-match (concat "[" conf-variable "]") typekey))))
1501 (defun reftex-check-recursive-edit ()
1502 ;; Check if we are already in a recursive edit. Abort with helpful
1503 ;; message if so.
1504 (if (marker-position reftex-recursive-edit-marker)
1505 (error
1506 (substitute-command-keys
1507 "In unfinished selection process. Finish, or abort with \\[abort-recursive-edit]"))))
1509 (defun reftex-in-comment ()
1510 "Return non-nil if point is in a comment."
1511 (save-excursion
1512 (save-match-data
1513 (let ((pos (point)))
1514 (beginning-of-line)
1515 (re-search-forward
1516 (or comment-start-skip
1517 ;; The parser may open files in fundamental mode if
1518 ;; `reftex-initialize-temporary-buffers' is nil, so here
1519 ;; is a default suitable for plain TeX and LaTeX.
1520 "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)\\(%+[ \t]*\\)")
1521 pos t)))))
1523 (defun reftex-no-props (string)
1524 ;; Return STRING with all text properties removed
1525 (and (stringp string)
1526 (set-text-properties 0 (length string) nil string))
1527 string)
1529 (defun reftex-match-string (n)
1530 ;; Match string without properties
1531 (when (match-beginning n)
1532 (buffer-substring-no-properties (match-beginning n) (match-end n))))
1534 (defun reftex-region-active-p ()
1535 "Should we operate on an active region?"
1536 (if (fboundp 'use-region-p)
1537 (use-region-p)
1538 ;; For XEmacs.
1539 (region-active-p)))
1541 (defun reftex-kill-buffer (buffer)
1542 ;; Kill buffer if it exists.
1543 (and (setq buffer (get-buffer buffer))
1544 (kill-buffer buffer)))
1546 (defun reftex-erase-buffer (&optional buffer)
1547 ;; Erase BUFFER if it exists. BUFFER defaults to current buffer.
1548 ;; This even erases read-only buffers.
1549 (cond
1550 ((null buffer)
1551 ;; erase current buffer
1552 (let ((buffer-read-only nil)) (erase-buffer)))
1553 ((setq buffer (get-buffer buffer))
1554 ;; buffer exists
1555 (with-current-buffer buffer
1556 (let ((inhibit-read-only t)) (erase-buffer))))))
1558 (defun reftex-this-word (&optional class)
1559 ;; Grab the word around point.
1560 (setq class (or class "-a-zA-Z0-9:_/.*;|"))
1561 (save-excursion
1562 (buffer-substring-no-properties
1563 (progn (skip-chars-backward class) (point))
1564 (progn (skip-chars-forward class) (point)))))
1566 (defun reftex-number (n unit &optional ending)
1567 (if (and (integerp n) (stringp unit))
1568 (format "%d %s%s" n unit (if (= n 1) "" (or ending "s")))
1569 ""))
1571 (defun reftex-all-assq (key list)
1572 ;; Return a list of all associations of KEY in LIST. Comparison with eq.
1573 (let (rtn)
1574 (while (setq list (memq (assq key list) list))
1575 (push (car list) rtn)
1576 (pop list))
1577 (nreverse rtn)))
1579 (defun reftex-all-assoc-string (key list)
1580 ;; Return a list of all associations of KEY in LIST. Comparison with string=.
1581 (let (rtn)
1582 (while list
1583 (if (string= (car (car list)) key)
1584 (push (car list) rtn))
1585 (pop list))
1586 (nreverse rtn)))
1588 (defun reftex-last-assoc-before-elt (key elt list &optional exclusive)
1589 ;; Find the last association of KEY in LIST before or at ELT
1590 ;; ELT is found in LIST with equal, not eq.
1591 ;; Returns nil when either KEY or elt are not found in LIST.
1592 ;; When EXCLUSIVE is non-nil, ELT cannot be the return value.
1593 ;; On success, returns the association.
1594 (let* ((elt (car (member elt list))) (ex (not exclusive)) ass last-ass)
1595 (while (and (setq ass (assoc key list))
1596 (setq list (memq ass list))
1597 (or ex (not (eq elt (car list))))
1598 (memq elt list))
1599 (setq last-ass ass
1600 list (cdr list)))
1601 last-ass))
1603 (defun reftex-sublist-nth (list nth predicate &optional completion)
1604 ;; Make a list of the NTH elements of all members of LIST which
1605 ;; fulfill PREDICATE.
1606 ;; When COMPLETION is non-nil, make all elements of the resulting
1607 ;; list also a list, so that the result can be used for completion.
1608 (let (rtn)
1609 (while list
1610 (if (funcall predicate (car list))
1611 (push (if completion
1612 (list (nth nth (car list)))
1613 (nth nth (car list)))
1614 rtn))
1615 (setq list (cdr list)))
1616 (nreverse rtn)))
1618 (defun reftex-make-selection-buffer-name (type &optional index)
1619 ;; Make unique name for a selection buffer.
1620 (format " *RefTeX[%s][%d]*"
1621 type (or index (get reftex-docstruct-symbol :master-index) 0)))
1623 (defun reftex-make-index-buffer-name (tag &optional cnt)
1624 ;; Make unique name for an index buffer.
1625 (format "*Index[%s][%d]*"
1626 tag (or cnt (get reftex-docstruct-symbol :master-index) 0)))
1628 (defun reftex-truncate (string ncols &optional ellipses padding)
1629 ;; Truncate STRING to NCOLS characters.
1630 ;; When PADDING is non-nil, and string is shorter than NCOLS, fill with
1631 ;; white space to NCOLS characters. When ELLIPSES is non-nil and the
1632 ;; string needs to be truncated, replace last 3 characters by dots.
1633 (setq string
1634 (if (<= (length string) ncols)
1635 string
1636 (if ellipses
1637 (concat (substring string 0 (- ncols 3)) "...")
1638 (substring string 0 ncols))))
1639 (if padding
1640 (format (format "%%-%ds" ncols) string)
1641 string))
1643 (defun reftex-nearest-match (regexp &optional max-length)
1644 ;; Find the nearest match of REGEXP. Set the match data.
1645 ;; If POS is given, calculate distances relative to it.
1646 ;; Return nil if there is no match.
1647 (let ((pos (point))
1648 (dist (or max-length (length regexp)))
1649 match1 match2 match)
1650 (goto-char (min (+ pos dist) (point-max)))
1651 (when (re-search-backward regexp nil t)
1652 (setq match1 (match-data)))
1653 (goto-char (max (- pos dist) (point-min)))
1654 (when (re-search-forward regexp nil t)
1655 (setq match2 (match-data)))
1656 (goto-char pos)
1657 (setq match
1658 (cond
1659 ((not match1) match2)
1660 ((not match2) match1)
1661 ((< (abs (- pos (car match1))) (abs (- pos (car match2)))) match1)
1662 (t match2)))
1663 (if match (progn (set-match-data match) t) nil)))
1665 (defun reftex-auto-mode-alist ()
1666 ;; Return an `auto-mode-alist' with only the .gz (etc) thingies.
1667 ;; Stolen from gnus nnheader.
1668 (let ((alist auto-mode-alist)
1669 out)
1670 (while alist
1671 (when (listp (cdr (car alist)))
1672 (push (car alist) out))
1673 (pop alist))
1674 (nreverse out)))
1676 (defun reftex-window-height ()
1677 (if (fboundp 'window-displayed-height)
1678 (window-displayed-height)
1679 (window-height)))
1681 (defun reftex-enlarge-to-fit (buf2 &optional keep-current)
1682 ;; Enlarge other window displaying buffer to show whole buffer if possible.
1683 ;; If KEEP-CURRENT in non-nil, current buffer must remain visible.
1684 (let* ((win1 (selected-window))
1685 (buf1 (current-buffer))
1686 (win2 (get-buffer-window buf2))) ;; Only on current frame.
1687 (when win2
1688 (select-window win2)
1689 (unless (and (pos-visible-in-window-p (point-min))
1690 (pos-visible-in-window-p (point-max)))
1691 (enlarge-window (1+ (- (count-lines (point-min) (point-max))
1692 (reftex-window-height))))))
1693 (cond
1694 ((window-live-p win1) (select-window win1))
1695 (keep-current
1696 ;; we must have the old buffer!
1697 (switch-to-buffer-other-window buf1)
1698 (shrink-window (- (window-height) window-min-height))))))
1700 (defun reftex-select-with-char (prompt help-string &optional delay-time scroll)
1701 ;; Offer to select something with PROMPT and, after DELAY-TIME seconds,
1702 ;; also with HELP-STRING.
1703 ;; When SCROLL is non-nil, use SPC and DEL to scroll help window.
1704 (let ((char ?\?))
1705 (save-window-excursion
1706 (catch 'exit
1707 (message "%s (?=Help)" prompt)
1708 (when (or (sit-for (or delay-time 0))
1709 (= ?\? (setq char (read-char-exclusive))))
1710 (reftex-kill-buffer "*RefTeX Select*")
1711 (switch-to-buffer-other-window "*RefTeX Select*")
1712 (insert help-string)
1713 (goto-char 1)
1714 (unless (and (pos-visible-in-window-p (point-min))
1715 (pos-visible-in-window-p (point-max)))
1716 (enlarge-window (1+ (- (count-lines (point-min) (point-max))
1717 (reftex-window-height)))))
1718 (setq truncate-lines t))
1719 (if (and (pos-visible-in-window-p (point-min))
1720 (pos-visible-in-window-p (point-max)))
1722 (setq prompt (concat prompt (if scroll " (SPC/DEL=Scroll)" ""))))
1723 (message "%s" prompt)
1724 (and (equal char ?\?) (setq char (read-char-exclusive)))
1725 (while t
1726 (cond ((equal char ?\C-g) (keyboard-quit))
1727 ((equal char ?\?))
1728 ((and scroll (equal char ?\ ))
1729 (condition-case nil (scroll-up) (error nil))
1730 (message "%s" prompt))
1731 ((and scroll (equal char ?\C-? ))
1732 (condition-case nil (scroll-down) (error nil))
1733 (message "%s" prompt))
1734 (t (message "")
1735 (reftex-kill-buffer "*RefTeX Select*")
1736 (throw 'exit char)))
1737 (setq char (read-char-exclusive)))))))
1740 (defun reftex-make-regexp-allow-for-ctrl-m (string)
1741 ;; convert STRING into a regexp, allowing ^M for \n and vice versa
1742 (let ((start -2))
1743 (setq string (regexp-quote string))
1744 (while (setq start (string-match "[\n\r]" string (+ 3 start)))
1745 (setq string (replace-match "[\n\r]" nil t string)))
1746 string))
1748 (defun reftex-get-buffer-visiting (file)
1749 ;; return a buffer visiting FILE
1750 (cond
1751 ((boundp 'find-file-compare-truenames) ; XEmacs
1752 (let ((find-file-compare-truenames t))
1753 (get-file-buffer file)))
1754 ((fboundp 'find-buffer-visiting) ; Emacs
1755 (find-buffer-visiting file))
1756 (t (error "This should not happen (reftex-get-buffer-visiting)"))))
1758 ;; Define `current-message' for compatibility with XEmacs prior to 20.4
1759 (defvar message-stack)
1760 (if (and (featurep 'xemacs)
1761 (not (fboundp 'current-message)))
1762 (defun current-message (&optional _frame)
1763 (cdr (car message-stack))))
1765 (defun reftex-visited-files (list)
1766 ;; Takes a list of filenames and returns the buffers of those already visited
1767 (delq nil (mapcar (lambda (x) (if (reftex-get-buffer-visiting x) x nil))
1768 list)))
1770 (defun reftex-get-file-buffer-force (file &optional mark-to-kill)
1771 ;; Return a buffer visiting file. Make one, if necessary.
1772 ;; If neither such a buffer nor the file exist, return nil.
1773 ;; If MARK-TO-KILL is t and there is no live buffer, visit the file with
1774 ;; initializations according to `reftex-initialize-temporary-buffers',
1775 ;; and mark the buffer to be killed after use.
1777 (let ((buf (reftex-get-buffer-visiting file)))
1779 (cond (buf
1780 ;; We have it already as a buffer - just return it
1781 buf)
1783 ((file-readable-p file)
1784 ;; At least there is such a file and we can read it.
1786 (if (or (not mark-to-kill)
1787 (eq t reftex-initialize-temporary-buffers))
1789 ;; Visit the file with full magic
1790 (setq buf (find-file-noselect file))
1792 ;; Else: Visit the file just briefly, without or
1793 ;; with limited Magic
1795 ;; The magic goes away
1796 (cl-letf ((format-alist nil)
1797 (auto-mode-alist (reftex-auto-mode-alist))
1798 ((default-value 'major-mode) 'fundamental-mode)
1799 (enable-local-variables nil)
1800 (after-insert-file-functions nil))
1801 (setq buf (find-file-noselect file)))
1803 ;; Is there a hook to run?
1804 (when (listp reftex-initialize-temporary-buffers)
1805 (with-current-buffer buf
1806 (run-hooks 'reftex-initialize-temporary-buffers))))
1808 ;; Let's see if we got a license to kill :-|
1809 (and mark-to-kill
1810 (cl-pushnew buf reftex-buffers-to-kill))
1812 ;; Return the new buffer
1813 buf)
1815 ;; If no such file exists, return nil
1816 (t nil))))
1818 (defun reftex-kill-temporary-buffers (&optional buffer)
1819 ;; Kill all buffers in the list reftex-kill-temporary-buffers.
1820 (cond
1821 (buffer
1822 (when (member buffer reftex-buffers-to-kill)
1823 (kill-buffer buffer)
1824 (setq reftex-buffers-to-kill
1825 (delete buffer reftex-buffers-to-kill))))
1827 (while (setq buffer (pop reftex-buffers-to-kill))
1828 (when (bufferp buffer)
1829 (and (buffer-modified-p buffer)
1830 (y-or-n-p (format "Save file %s? "
1831 (buffer-file-name buffer)))
1832 (with-current-buffer buffer
1833 (save-buffer)))
1834 (kill-buffer buffer))
1835 (pop reftex-buffers-to-kill)))))
1837 (defun reftex-splice-symbols-into-list (list alist)
1838 ;; Splice the association in ALIST of any symbols in LIST into the list.
1839 ;; Return new list.
1840 (let (rtn tmp)
1841 (while list
1842 (while (and (not (null (car list))) ;; keep list elements nil
1843 (symbolp (car list)))
1844 (setq tmp (car list))
1845 (cond
1846 ((assoc tmp alist)
1847 (setq list (append (nth 2 (assoc tmp alist)) (cdr list))))
1849 (error "Cannot treat symbol %s in reftex-label-alist"
1850 (symbol-name tmp)))))
1851 (push (pop list) rtn))
1852 (nreverse rtn)))
1854 (defun reftex-remove-symbols-from-list (list)
1855 ;; Remove all symbols from list
1856 (let (rtn)
1857 (while list
1858 (unless (symbolp (car list))
1859 (push (car list) rtn))
1860 (setq list (cdr list)))
1861 (nreverse rtn)))
1863 (defun reftex-uniquify (list &optional sort)
1864 ;; Return a list of all strings in LIST, but each only once, keeping order
1865 ;; unless SORT is set (faster!).
1866 (setq list (copy-sequence list))
1867 (if sort
1868 (progn
1869 (setq list (sort list 'string<))
1870 (let ((p list))
1871 (while (cdr p)
1872 (if (string= (car p) (car (cdr p)))
1873 (setcdr p (cdr (cdr p)))
1874 (setq p (cdr p)))))
1875 list)
1876 (let ((p list) lst elt)
1877 ;; push all sublists into lst in reverse(!) order
1878 (while p
1879 (push p lst)
1880 (setq p (cdr p)))
1881 ;; sort all sublists
1882 (setq lst (sort lst (lambda (x1 x2) (string< (car x1) (car x2)))))
1883 (while (cdr lst)
1884 (setq elt (car (car lst)))
1885 ;; for equal elements in the sorted sublist, replace the
1886 ;; last(!) original list member with nil
1887 (when (string= elt (car (cadr lst)))
1888 (setcar (pop lst) nil)
1889 (while (and (cdr lst) (string= elt (car (cadr lst))))
1890 (setcar (pop lst) nil)))
1891 (pop lst)))
1892 ;; weed out all nils and return.
1893 (delq nil list)))
1895 (defun reftex-uniquify-by-car (alist &optional keep-list sort)
1896 ;; Return a list of all elements in ALIST, but each car only once.
1897 ;; Elements of KEEP-LIST are not removed even if duplicate.
1898 ;; The order is kept unless SORT is set (faster!).
1899 (setq keep-list (sort (copy-sequence keep-list) #'string<)
1900 alist (copy-sequence alist))
1901 (if sort
1902 (let (lst elt)
1903 (setq alist (sort alist (lambda(a b) (string< (car a) (car b)))))
1904 (setq lst alist)
1905 (while (cdr lst)
1906 (setq elt (car (car lst)))
1907 (when (string= elt (car (cadr lst)))
1908 (while (and keep-list (string< (car keep-list) elt))
1909 (pop keep-list))
1910 (if (and keep-list (string= elt (car keep-list)))
1911 (progn
1912 (pop lst)
1913 (while (and (cdr lst)
1914 (string= elt (car (cadr lst))))
1915 (pop lst)))
1916 (setcdr lst (cdr (cdr lst)))
1917 (while (and (cdr lst)
1918 (string= elt (car (cadr lst))))
1919 (setcdr lst (cdr (cdr lst))))))
1920 (pop lst))
1921 alist)
1922 (let ((p alist) lst elt)
1923 (while p
1924 (push p lst)
1925 (setq p (cdr p)))
1926 (setq lst (sort lst (lambda(a b) (string< (car (car a))
1927 (car (car b))))))
1928 (while (cdr lst)
1929 (setq elt (car (car (car lst))))
1930 (when (string= elt (car (car (cadr lst))))
1931 (while (and keep-list (string< (car keep-list) elt))
1932 (pop keep-list))
1933 (if (and keep-list (string= elt (car keep-list)))
1934 (progn
1935 (pop lst)
1936 (while (and (cdr lst)
1937 (string= elt (car (car (cadr lst)))))
1938 (pop lst)))
1939 (setcar (pop lst) nil)
1940 (while (and (cdr lst)
1941 (string= elt (car (car (cadr lst)))))
1942 (setcar (pop lst) nil))))
1943 (pop lst)))
1944 (delq nil alist)))
1946 (defun reftex-remove-if (predicate list)
1947 "Nondestructively remove all items from LIST which satisfy PREDICATE."
1948 (let (result)
1949 (dolist (elt list (nreverse result))
1950 (unless (funcall predicate elt)
1951 (push elt result)))))
1953 (defun reftex-abbreviate-title (string)
1954 (reftex-convert-string string "[-~ \t\n\r,;]" nil t t
1955 5 40 nil 1 " " (nth 5 reftex-derive-label-parameters)))
1957 (defun reftex-convert-string (string split-re invalid-re dot keep-fp
1958 nwords maxchar invalid abbrev sep
1959 ignore-words &optional downcase)
1960 "Convert a string (a sentence) to something shorter.
1961 SPLIT-RE is the regular expression used to split the string into words.
1962 INVALID-RE matches characters which are invalid in the final string.
1963 DOT t means add dots to abbreviated words.
1964 KEEP-FP t means to keep a final punctuation when applicable.
1965 NWORDS Number of words to use.
1966 MAXCHAR Maximum number of characters in the final string.
1967 INVALID nil: Throw away any words containing stuff matched with INVALID-RE.
1968 t: Throw away only the matched part, not the whole word.
1969 ABBREV nil: Never abbreviate words.
1970 t: Always abbreviate words (see `reftex-abbrev-parameters').
1971 not t and not nil: Abbreviate words if necessary to shorten
1972 string below MAXCHAR.
1973 SEP String separating different words in the output string.
1974 IGNORE-WORDS List of words which should be removed from the string."
1976 (let* ((words0 (split-string string (or split-re "[ \t\n\r]")))
1977 (reftex-label-illegal-re (or invalid-re "\000"))
1978 (abbrev-re (concat
1979 "\\`\\("
1980 (make-string (nth 0 reftex-abbrev-parameters) ?.)
1981 "[" (nth 2 reftex-abbrev-parameters) "]*"
1982 "\\)"
1983 "[" (nth 3 reftex-abbrev-parameters) "]"
1984 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
1985 words word)
1987 ;; Remove words from the ignore list or with funny characters
1988 (while (setq word (pop words0))
1989 (if downcase (setq word (downcase word)))
1990 (cond
1991 ((member (downcase word) ignore-words))
1992 ((string-match reftex-label-illegal-re word)
1993 (when invalid
1994 (while (string-match reftex-label-illegal-re word)
1995 (setq word (replace-match "" nil nil word)))
1996 (push word words)))
1998 (push word words))))
1999 (setq words (nreverse words))
2001 ;; Restrict number of words
2002 (if (> (length words) nwords)
2003 (setcdr (nthcdr (1- nwords) words) nil))
2005 ;; First, try to use all words
2006 (setq string (mapconcat 'identity words sep))
2008 ;; Abbreviate words if enforced by user settings or string length
2009 (if (or (eq t abbrev)
2010 (and abbrev
2011 (> (length string) maxchar)))
2012 (setq words
2013 (mapcar
2014 (lambda (w) (if (string-match abbrev-re w)
2015 (if dot
2016 (concat (match-string 1 w) ".")
2017 (match-string 1 w))
2019 words)
2020 string (mapconcat 'identity words sep)))
2022 ;; Shorten if still to long
2023 (setq string
2024 (if (> (length string) maxchar)
2025 (substring string 0 maxchar)
2026 string))
2028 ;; Delete the final punctuation, if any
2029 (if (and (not keep-fp) (string-match "\\s.+\\'" string))
2030 (setq string (replace-match "" nil nil string)))
2031 string))
2033 (defun reftex-nicify-text (text)
2034 ;; Make TEXT nice for inclusion as context into label menu.
2035 ;; 1. remove line breaks and extra white space
2036 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text)
2037 (setq text (replace-match " " nil t text)))
2038 ;; 2. cut before the next `\end{' or `\item' or `\\'
2039 (if (string-match "\\(\\\\end{\\|\\\\item\\|\\\\\\\\\\).*" text)
2040 (setq text (replace-match "" nil t text)))
2041 ;; 3. kill the embedded label
2042 (if (string-match "\\\\label{[^}]*}" text)
2043 (setq text (replace-match "" nil t text)))
2044 ;; 4. remove leading garbage
2045 (if (string-match "\\`[ }]+" text)
2046 (setq text (replace-match "" nil t text)))
2047 ;; 5. limit length
2048 (cond
2049 ((> (length text) 100) (substring text 0 100))
2050 ((= (length text) 0) (make-string 1 ?\ ))
2051 (t text)))
2054 ;;; =========================================================================
2056 ;;; Fontification and Highlighting
2058 (defun reftex-use-fonts ()
2059 ;; Return t if we can and want to use fonts.
2060 (and ; window-system
2061 reftex-use-fonts
2062 (featurep 'font-lock)))
2064 (defun reftex-refontify ()
2065 ;; Return t if we need to refontify context
2066 (and (reftex-use-fonts)
2067 (or (eq t reftex-refontify-context)
2068 (and (eq 1 reftex-refontify-context)
2069 ;; Test of we use the font-lock version of x-symbol
2070 (and (featurep 'x-symbol-tex) (not (boundp 'x-symbol-mode)))))))
2072 (defvar font-lock-defaults-computed)
2073 (defun reftex-fontify-select-label-buffer (parent-buffer)
2074 ;; Fontify the `*RefTeX Select*' buffer. Buffer is temporarily renamed to
2075 ;; start with none-SPC char, because Font-Lock otherwise refuses operation.
2076 (run-hook-with-args 'reftex-pre-refontification-functions
2077 parent-buffer 'reftex-ref)
2078 (let* ((oldname (buffer-name))
2079 (newname (concat "Fontify-me-" oldname)))
2080 (unwind-protect
2081 (progn
2082 ;; Rename buffer temporarily to start w/o space (because of font-lock)
2083 (rename-buffer newname t)
2084 (cond
2085 ((fboundp 'font-lock-default-fontify-region)
2086 ;; Good: we have the indirection functions
2087 (set (make-local-variable 'font-lock-fontify-region-function)
2088 'reftex-select-font-lock-fontify-region)
2089 (let ((major-mode 'latex-mode))
2090 (font-lock-mode 1)))
2091 ((fboundp 'font-lock-set-defaults-1)
2092 ;; Looks like the XEmacs font-lock stuff.
2093 ;; FIXME: this is still kind of a hack, but it works.
2094 (set (make-local-variable 'font-lock-keywords) nil)
2095 (let ((major-mode 'latex-mode)
2096 (font-lock-defaults-computed nil))
2097 (font-lock-set-defaults-1)
2098 (reftex-select-font-lock-fontify-region (point-min) (point-max))))
2100 ;; Oops?
2101 (message "Sorry: cannot refontify RefTeX Select buffer."))))
2102 (rename-buffer oldname))))
2104 (defun reftex-select-font-lock-fontify-region (beg end &optional _loudly)
2105 ;; Fontify a region, but only lines starting with a dot.
2106 (let ((func (if (fboundp 'font-lock-default-fontify-region)
2107 'font-lock-default-fontify-region
2108 'font-lock-fontify-region))
2109 beg1 end1)
2110 (goto-char beg)
2111 (while (re-search-forward "^\\." end t)
2112 (setq beg1 (point) end1 (progn (skip-chars-forward "^\n") (point)))
2113 (funcall func beg1 end1 nil)
2114 (goto-char end1))))
2116 (defun reftex-select-font-lock-unfontify (&rest _ignore) t)
2118 (defun reftex-verified-face (&rest faces)
2119 ;; Return the first valid face in FACES, or nil if none is valid.
2120 ;; Also, when finding a nil element in FACES, return nil. This
2121 ;; function is just a safety net to catch name changes of builtin
2122 ;; fonts. Currently it is only used for reftex-label-face.
2123 (let (face)
2124 (catch 'exit
2125 (while (setq face (pop faces))
2126 (if (featurep 'xemacs)
2127 (if (find-face face) (throw 'exit face))
2128 (if (facep face) (throw 'exit face)))))))
2130 ;; Highlighting uses overlays. For XEmacs, we use extends.
2131 (defalias 'reftex-make-overlay
2132 (if (featurep 'xemacs) 'make-extent 'make-overlay))
2133 (defalias 'reftex-overlay-put
2134 (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
2135 (defalias 'reftex-move-overlay
2136 (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay))
2137 (defalias 'reftex-delete-overlay
2138 (if (featurep 'xemacs) 'detach-extent 'delete-overlay))
2140 ;; We keep a vector with several different overlays to do our highlighting.
2141 (defvar reftex-highlight-overlays [nil nil nil])
2143 ;; Initialize the overlays
2144 (aset reftex-highlight-overlays 0 (reftex-make-overlay 1 1))
2145 (reftex-overlay-put (aref reftex-highlight-overlays 0)
2146 'face 'highlight)
2147 (aset reftex-highlight-overlays 1 (reftex-make-overlay 1 1))
2148 (reftex-overlay-put (aref reftex-highlight-overlays 1)
2149 'face reftex-cursor-selected-face)
2150 (aset reftex-highlight-overlays 2 (reftex-make-overlay 1 1))
2151 (reftex-overlay-put (aref reftex-highlight-overlays 2)
2152 'face reftex-cursor-selected-face)
2154 ;; Two functions for activating and deactivation highlight overlays
2155 (defun reftex-highlight (index begin end &optional buffer)
2156 "Highlight a region with overlay INDEX."
2157 (reftex-move-overlay (aref reftex-highlight-overlays index)
2158 begin end (or buffer (current-buffer))))
2159 (defun reftex-unhighlight (index)
2160 "Detach overlay INDEX."
2161 (reftex-delete-overlay (aref reftex-highlight-overlays index)))
2163 (defun reftex-highlight-shall-die ()
2164 ;; Function used in pre-command-hook to remove highlights.
2165 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die)
2166 (reftex-unhighlight 0))
2168 ;;; =========================================================================
2170 ;;; Keybindings
2172 (defvar bibtex-mode-map)
2174 ;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map
2175 (eval-after-load
2176 "bibtex"
2177 '(define-key bibtex-mode-map "\C-c&" 'reftex-view-crossref-from-bibtex))
2179 ;;; =========================================================================
2181 ;;; Menu
2183 ;; Define a menu for the menu bar if Emacs is running under X
2185 (defvar reftex-isearch-minor-mode nil)
2186 (make-variable-buffer-local 'reftex-isearch-minor-mode)
2188 (easy-menu-define reftex-mode-menu reftex-mode-map
2189 "Menu used in RefTeX mode"
2190 `("Ref"
2191 ["Table of Contents" reftex-toc t]
2192 ["Recenter TOC" reftex-toc-recenter t]
2193 "--"
2194 ["\\label" reftex-label t]
2195 ["\\ref" reftex-reference t]
2196 ["\\cite" reftex-citation t]
2197 ("\\index"
2198 ["\\index" reftex-index t]
2199 ["\\index{THIS}" reftex-index-selection-or-word t]
2200 "--"
2201 ["Add THIS to Index Phrases" reftex-index-phrase-selection-or-word t]
2202 ["Visit Phrase Buffer" reftex-index-visit-phrases-buffer t]
2203 ["Apply Phrases to Region" reftex-index-phrases-apply-to-region t]
2204 "--"
2205 ["Display the Index" reftex-display-index t])
2206 "--"
2207 ["View Crossref" reftex-view-crossref t]
2208 "--"
2209 ("Parse Document"
2210 ["One File" reftex-parse-one reftex-enable-partial-scans]
2211 ["Entire Document" reftex-parse-all t]
2212 ["Save to File" (reftex-access-parse-file 'write)
2213 (> (length (symbol-value reftex-docstruct-symbol)) 0)]
2214 ["Restore from File" (reftex-access-parse-file 'restore) t])
2215 ("Global Actions"
2216 ["Search Whole Document" reftex-search-document t]
2217 ["Search Again" tags-loop-continue t]
2218 ["Replace in Document" reftex-query-replace-document t]
2219 ["Grep on Document" reftex-grep-document t]
2220 "--"
2221 ["Goto Label" reftex-goto-label t]
2222 ["Find Duplicate Labels" reftex-find-duplicate-labels t]
2223 ["Change Label and Refs" reftex-change-label t]
2224 ["Renumber Simple Labels" reftex-renumber-simple-labels t]
2225 "--"
2226 ["Create BibTeX File" reftex-create-bibtex-file t]
2227 "--"
2228 ["Create TAGS File" reftex-create-tags-file t]
2229 "--"
2230 ["Save Document" reftex-save-all-document-buffers t])
2231 "--"
2232 ("Options"
2233 "PARSER"
2234 ["Partial Scans"
2235 (setq reftex-enable-partial-scans (not reftex-enable-partial-scans))
2236 :style toggle :selected reftex-enable-partial-scans]
2237 ["Auto-Save Parse Info"
2238 (setq reftex-save-parse-info (not reftex-save-parse-info))
2239 :style toggle :selected reftex-save-parse-info]
2240 "--"
2241 "TOC RECENTER"
2242 ["Automatic Recenter" reftex-toggle-auto-toc-recenter
2243 :style toggle :selected reftex-toc-auto-recenter-timer]
2244 "--"
2245 "CROSSREF INFO"
2246 ["Automatic Info" reftex-toggle-auto-view-crossref
2247 :style toggle :selected reftex-auto-view-crossref-timer]
2248 ["...in Echo Area" (setq reftex-auto-view-crossref t)
2249 :style radio :selected (eq reftex-auto-view-crossref t)]
2250 ["...in Other Window" (setq reftex-auto-view-crossref 'window)
2251 :style radio :selected (eq reftex-auto-view-crossref 'window)]
2252 "--"
2253 "MISC"
2254 ["AUCTeX Interface" reftex-toggle-plug-into-AUCTeX
2255 :style toggle :selected reftex-plug-into-AUCTeX]
2256 ["isearch whole document" reftex-isearch-minor-mode
2257 :style toggle :selected reftex-isearch-minor-mode])
2258 ("Reference Style"
2259 ,@(let (list item)
2260 (dolist (elt reftex-ref-style-alist)
2261 (setq elt (car elt)
2262 item (vector
2264 `(reftex-ref-style-toggle ,elt)
2265 :style 'toggle
2266 :selected `(member ,elt (reftex-ref-style-list))))
2267 (unless (member item list)
2268 (setq list (append list (list item)))))
2269 list))
2270 ("Citation Style"
2271 ,@(mapcar
2272 (lambda (x)
2273 (vector
2274 (capitalize (symbol-name (car x)))
2275 (list 'reftex-set-cite-format (list 'quote (car x)))
2276 :style 'radio :selected
2277 (list 'eq (list 'reftex-get-cite-format) (list 'quote (car x)))))
2278 reftex-cite-format-builtin)
2279 "--"
2280 "Sort Database Matches"
2281 ["Not" (setq reftex-sort-bibtex-matches nil)
2282 :style radio :selected (eq reftex-sort-bibtex-matches nil)]
2283 ["by Author" (setq reftex-sort-bibtex-matches 'author)
2284 :style radio :selected (eq reftex-sort-bibtex-matches 'author)]
2285 ["by Year" (setq reftex-sort-bibtex-matches 'year)
2286 :style radio :selected (eq reftex-sort-bibtex-matches 'year)]
2287 ["by Year, reversed" (setq reftex-sort-bibtex-matches 'reverse-year)
2288 :style radio :selected (eq reftex-sort-bibtex-matches 'reverse-year)])
2289 ("Index Style"
2290 ,@(mapcar
2291 (lambda (x)
2292 (vector
2293 (capitalize (symbol-name (car x)))
2294 (list 'reftex-add-index-macros (list 'list (list 'quote (car x))))
2295 :style 'radio :selected
2296 (list 'memq (list 'quote (car x))
2297 (list 'get 'reftex-docstruct-symbol
2298 (list 'quote 'reftex-index-macros-style)))))
2299 reftex-index-macros-builtin))
2300 "--"
2301 ["Reset RefTeX Mode" reftex-reset-mode t]
2302 "--"
2303 ("Customize"
2304 ["Browse RefTeX Group" reftex-customize t]
2305 "--"
2306 ["Build Full Customize Menu" reftex-create-customize-menu
2307 (fboundp 'customize-menu-create)])
2308 ("Documentation"
2309 ["Info" reftex-info t]
2310 ["Commentary" reftex-show-commentary t])))
2312 (defun reftex-customize ()
2313 "Call the customize function with reftex as argument."
2314 (interactive)
2315 (customize-browse 'reftex))
2317 (defun reftex-create-customize-menu ()
2318 "Create a full customization menu for RefTeX, insert it into the menu."
2319 (interactive)
2320 (if (fboundp 'customize-menu-create)
2321 (progn
2322 (easy-menu-change
2323 '("Ref") "Customize"
2324 `(["Browse RefTeX group" reftex-customize t]
2325 "--"
2326 ,(customize-menu-create 'reftex)
2327 ["Set" Custom-set t]
2328 ["Save" Custom-save t]
2329 ["Reset to Current" Custom-reset-current t]
2330 ["Reset to Saved" Custom-reset-saved t]
2331 ["Reset to Standard Settings" Custom-reset-standard t]))
2332 (message "\"Ref\"-menu now contains full customization menu"))
2333 (error "Cannot expand menu (outdated version of cus-edit.el)")))
2336 ;;; Misc
2338 (defun reftex-show-commentary ()
2339 "Use the finder to view the file documentation from `reftex.el'."
2340 (interactive)
2341 (finder-commentary "reftex.el"))
2343 (defun reftex-info (&optional node)
2344 "Read documentation for RefTeX in the info system.
2345 With optional NODE, go directly to that node."
2346 (interactive)
2347 (info (format "(reftex)%s" (or node ""))))
2349 (defun reftex-report-bug ()
2350 "Report a bug in RefTeX.
2352 Don't hesitate to report any problems or inaccurate documentation.
2354 If you don't have setup sending mail from (X)Emacs, please copy the
2355 output buffer into your mail program, as it gives us important
2356 information about your RefTeX version and configuration."
2357 (interactive)
2358 (require 'reporter)
2359 (defvar reporter-prompt-for-summary-p)
2360 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
2361 (reporter-submit-bug-report
2362 "bug-auctex@gnu.org, bug-gnu-emacs@gnu.org"
2363 reftex-version
2364 (list 'window-system
2365 'reftex-plug-into-AUCTeX)
2366 nil nil
2367 "Remember to cover the basics, that is, what you expected to happen and
2368 what in fact did happen.
2370 Check if the bug is reproducible with an up-to-date version of
2371 RefTeX available from http://www.gnu.org/software/auctex/.
2373 If the bug is triggered by a specific \(La)TeX file, you should try
2374 to produce a minimal sample file showing the problem and include it
2375 in your report.
2377 Your bug report will be posted to the AUCTeX bug reporting list.
2378 ------------------------------------------------------------------------")))
2380 ;;; Install the kill-buffer and kill-emacs hooks ------------------------------
2382 (add-hook 'kill-buffer-hook 'reftex-kill-buffer-hook)
2383 (unless noninteractive
2384 (add-hook 'kill-emacs-hook 'reftex-kill-emacs-hook))
2386 ;;; Run Hook ------------------------------------------------------------------
2388 (run-hooks 'reftex-load-hook)
2390 ;;; That's it! ----------------------------------------------------------------
2392 (setq reftex-tables-dirty t) ; in case this file is evaluated by hand
2394 (provide 'reftex)
2396 ;;; reftex.el ends here