Add isearch-yank-symbol-or-char
[emacs.git] / lisp / textmodes / reftex.el
blobea28e09c7b1e3f81a9baaf58ebce34aab9c44cfd
1 ;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX
2 ;; Copyright (C) 1997-2000, 2003-2018 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 <https://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 ;; https://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 ;; https://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\\[\\([^]]+\\)\\]{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 (let ((case-fold-search nil))
1500 (string-match (concat "[" conf-variable "]") typekey)))))
1502 (defun reftex-check-recursive-edit ()
1503 ;; Check if we are already in a recursive edit. Abort with helpful
1504 ;; message if so.
1505 (if (marker-position reftex-recursive-edit-marker)
1506 (error
1507 (substitute-command-keys
1508 "In unfinished selection process. Finish, or abort with \\[abort-recursive-edit]"))))
1510 (defun reftex-in-comment ()
1511 "Return non-nil if point is in a comment."
1512 (save-excursion
1513 (save-match-data
1514 (let ((pos (point)))
1515 (beginning-of-line)
1516 (re-search-forward
1517 (or comment-start-skip
1518 ;; The parser may open files in fundamental mode if
1519 ;; `reftex-initialize-temporary-buffers' is nil, so here
1520 ;; is a default suitable for plain TeX and LaTeX.
1521 "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)\\(%+[ \t]*\\)")
1522 pos t)))))
1524 (defun reftex-no-props (string)
1525 ;; Return STRING with all text properties removed
1526 (and (stringp string)
1527 (set-text-properties 0 (length string) nil string))
1528 string)
1530 (defun reftex-match-string (n)
1531 ;; Match string without properties
1532 (when (match-beginning n)
1533 (buffer-substring-no-properties (match-beginning n) (match-end n))))
1535 (defun reftex-region-active-p ()
1536 "Should we operate on an active region?"
1537 (if (fboundp 'use-region-p)
1538 (use-region-p)
1539 ;; For XEmacs.
1540 (region-active-p)))
1542 (defun reftex-kill-buffer (buffer)
1543 ;; Kill buffer if it exists.
1544 (and (setq buffer (get-buffer buffer))
1545 (kill-buffer buffer)))
1547 (defun reftex-erase-buffer (&optional buffer)
1548 ;; Erase BUFFER if it exists. BUFFER defaults to current buffer.
1549 ;; This even erases read-only buffers.
1550 (cond
1551 ((null buffer)
1552 ;; erase current buffer
1553 (let ((buffer-read-only nil)) (erase-buffer)))
1554 ((setq buffer (get-buffer buffer))
1555 ;; buffer exists
1556 (with-current-buffer buffer
1557 (let ((inhibit-read-only t)) (erase-buffer))))))
1559 (defun reftex-this-word (&optional class)
1560 ;; Grab the word around point.
1561 (setq class (or class "-a-zA-Z0-9:_/.*;|"))
1562 (save-excursion
1563 (buffer-substring-no-properties
1564 (progn (skip-chars-backward class) (point))
1565 (progn (skip-chars-forward class) (point)))))
1567 (defun reftex-number (n unit &optional ending)
1568 (if (and (integerp n) (stringp unit))
1569 (format "%d %s%s" n unit (if (= n 1) "" (or ending "s")))
1570 ""))
1572 (defun reftex-all-assq (key list)
1573 ;; Return a list of all associations of KEY in LIST. Comparison with eq.
1574 (let (rtn)
1575 (while (setq list (memq (assq key list) list))
1576 (push (car list) rtn)
1577 (pop list))
1578 (nreverse rtn)))
1580 (defun reftex-all-assoc-string (key list)
1581 ;; Return a list of all associations of KEY in LIST. Comparison with string=.
1582 (let (rtn)
1583 (while list
1584 (if (string= (car (car list)) key)
1585 (push (car list) rtn))
1586 (pop list))
1587 (nreverse rtn)))
1589 (defun reftex-last-assoc-before-elt (key elt list &optional exclusive)
1590 ;; Find the last association of KEY in LIST before or at ELT
1591 ;; ELT is found in LIST with equal, not eq.
1592 ;; Returns nil when either KEY or elt are not found in LIST.
1593 ;; When EXCLUSIVE is non-nil, ELT cannot be the return value.
1594 ;; On success, returns the association.
1595 (let* ((elt (car (member elt list))) (ex (not exclusive)) ass last-ass)
1596 (while (and (setq ass (assoc key list))
1597 (setq list (memq ass list))
1598 (or ex (not (eq elt (car list))))
1599 (memq elt list))
1600 (setq last-ass ass
1601 list (cdr list)))
1602 last-ass))
1604 (defun reftex-sublist-nth (list nth predicate &optional completion)
1605 ;; Make a list of the NTH elements of all members of LIST which
1606 ;; fulfill PREDICATE.
1607 ;; When COMPLETION is non-nil, make all elements of the resulting
1608 ;; list also a list, so that the result can be used for completion.
1609 (let (rtn)
1610 (while list
1611 (if (funcall predicate (car list))
1612 (push (if completion
1613 (list (nth nth (car list)))
1614 (nth nth (car list)))
1615 rtn))
1616 (setq list (cdr list)))
1617 (nreverse rtn)))
1619 (defun reftex-make-selection-buffer-name (type &optional index)
1620 ;; Make unique name for a selection buffer.
1621 (format " *RefTeX[%s][%d]*"
1622 type (or index (get reftex-docstruct-symbol :master-index) 0)))
1624 (defun reftex-make-index-buffer-name (tag &optional cnt)
1625 ;; Make unique name for an index buffer.
1626 (format "*Index[%s][%d]*"
1627 tag (or cnt (get reftex-docstruct-symbol :master-index) 0)))
1629 (defun reftex-truncate (string ncols &optional ellipses padding)
1630 ;; Truncate STRING to NCOLS characters.
1631 ;; When PADDING is non-nil, and string is shorter than NCOLS, fill with
1632 ;; white space to NCOLS characters. When ELLIPSES is non-nil and the
1633 ;; string needs to be truncated, replace last 3 characters by dots.
1634 (setq string
1635 (if (<= (length string) ncols)
1636 string
1637 (if ellipses
1638 (concat (substring string 0 (- ncols 3)) "...")
1639 (substring string 0 ncols))))
1640 (if padding
1641 (format (format "%%-%ds" ncols) string)
1642 string))
1644 (defun reftex-nearest-match (regexp &optional max-length)
1645 ;; Find the nearest match of REGEXP. Set the match data.
1646 ;; If POS is given, calculate distances relative to it.
1647 ;; Return nil if there is no match.
1648 (let ((pos (point))
1649 (dist (or max-length (length regexp)))
1650 match1 match2 match)
1651 (goto-char (min (+ pos dist) (point-max)))
1652 (when (re-search-backward regexp nil t)
1653 (setq match1 (match-data)))
1654 (goto-char (max (- pos dist) (point-min)))
1655 (when (re-search-forward regexp nil t)
1656 (setq match2 (match-data)))
1657 (goto-char pos)
1658 (setq match
1659 (cond
1660 ((not match1) match2)
1661 ((not match2) match1)
1662 ((< (abs (- pos (car match1))) (abs (- pos (car match2)))) match1)
1663 (t match2)))
1664 (if match (progn (set-match-data match) t) nil)))
1666 (defun reftex-auto-mode-alist ()
1667 ;; Return an `auto-mode-alist' with only the .gz (etc) thingies.
1668 ;; Stolen from gnus nnheader.
1669 (let ((alist auto-mode-alist)
1670 out)
1671 (while alist
1672 (when (listp (cdr (car alist)))
1673 (push (car alist) out))
1674 (pop alist))
1675 (nreverse out)))
1677 (defun reftex-window-height ()
1678 (if (fboundp 'window-displayed-height)
1679 (window-displayed-height)
1680 (window-height)))
1682 (defun reftex-enlarge-to-fit (buf2 &optional keep-current)
1683 ;; Enlarge other window displaying buffer to show whole buffer if possible.
1684 ;; If KEEP-CURRENT in non-nil, current buffer must remain visible.
1685 (let* ((win1 (selected-window))
1686 (buf1 (current-buffer))
1687 (win2 (get-buffer-window buf2))) ;; Only on current frame.
1688 (when win2
1689 (select-window win2)
1690 (unless (and (pos-visible-in-window-p (point-min))
1691 (pos-visible-in-window-p (point-max)))
1692 (enlarge-window (1+ (- (count-lines (point-min) (point-max))
1693 (reftex-window-height))))))
1694 (cond
1695 ((window-live-p win1) (select-window win1))
1696 (keep-current
1697 ;; we must have the old buffer!
1698 (switch-to-buffer-other-window buf1)
1699 (shrink-window (- (window-height) window-min-height))))))
1701 (defun reftex-select-with-char (prompt help-string &optional delay-time scroll)
1702 ;; Offer to select something with PROMPT and, after DELAY-TIME seconds,
1703 ;; also with HELP-STRING.
1704 ;; When SCROLL is non-nil, use SPC and DEL to scroll help window.
1705 (let ((char ?\?))
1706 (save-window-excursion
1707 (catch 'exit
1708 (message "%s (?=Help)" prompt)
1709 (when (or (sit-for (or delay-time 0))
1710 (= ?\? (setq char (read-char-exclusive))))
1711 (reftex-kill-buffer "*RefTeX Select*")
1712 (switch-to-buffer-other-window "*RefTeX Select*")
1713 (insert help-string)
1714 (goto-char 1)
1715 (unless (and (pos-visible-in-window-p (point-min))
1716 (pos-visible-in-window-p (point-max)))
1717 (enlarge-window (1+ (- (count-lines (point-min) (point-max))
1718 (reftex-window-height)))))
1719 (setq truncate-lines t))
1720 (if (and (pos-visible-in-window-p (point-min))
1721 (pos-visible-in-window-p (point-max)))
1723 (setq prompt (concat prompt (if scroll " (SPC/DEL=Scroll)" ""))))
1724 (message "%s" prompt)
1725 (and (equal char ?\?) (setq char (read-char-exclusive)))
1726 (while t
1727 (cond ((equal char ?\C-g) (keyboard-quit))
1728 ((equal char ?\?))
1729 ((and scroll (equal char ?\ ))
1730 (condition-case nil (scroll-up) (error nil))
1731 (message "%s" prompt))
1732 ((and scroll (equal char ?\C-? ))
1733 (condition-case nil (scroll-down) (error nil))
1734 (message "%s" prompt))
1735 (t (message "")
1736 (reftex-kill-buffer "*RefTeX Select*")
1737 (throw 'exit char)))
1738 (setq char (read-char-exclusive)))))))
1741 (defun reftex-make-regexp-allow-for-ctrl-m (string)
1742 ;; convert STRING into a regexp, allowing ^M for \n and vice versa
1743 (let ((start -2))
1744 (setq string (regexp-quote string))
1745 (while (setq start (string-match "[\n\r]" string (+ 3 start)))
1746 (setq string (replace-match "[\n\r]" nil t string)))
1747 string))
1749 (defun reftex-get-buffer-visiting (file)
1750 ;; return a buffer visiting FILE
1751 (cond
1752 ((boundp 'find-file-compare-truenames) ; XEmacs
1753 (let ((find-file-compare-truenames t))
1754 (get-file-buffer file)))
1755 ((fboundp 'find-buffer-visiting) ; Emacs
1756 (find-buffer-visiting file))
1757 (t (error "This should not happen (reftex-get-buffer-visiting)"))))
1759 ;; Define `current-message' for compatibility with XEmacs prior to 20.4
1760 (defvar message-stack)
1761 (if (and (featurep 'xemacs)
1762 (not (fboundp 'current-message)))
1763 (defun current-message (&optional _frame)
1764 (cdr (car message-stack))))
1766 (defun reftex-visited-files (list)
1767 ;; Takes a list of filenames and returns the buffers of those already visited
1768 (delq nil (mapcar (lambda (x) (if (reftex-get-buffer-visiting x) x nil))
1769 list)))
1771 (defun reftex-get-file-buffer-force (file &optional mark-to-kill)
1772 ;; Return a buffer visiting file. Make one, if necessary.
1773 ;; If neither such a buffer nor the file exist, return nil.
1774 ;; If MARK-TO-KILL is t and there is no live buffer, visit the file with
1775 ;; initializations according to `reftex-initialize-temporary-buffers',
1776 ;; and mark the buffer to be killed after use.
1778 (let ((buf (reftex-get-buffer-visiting file)))
1780 (cond (buf
1781 ;; We have it already as a buffer - just return it
1782 buf)
1784 ((file-readable-p file)
1785 ;; At least there is such a file and we can read it.
1787 (if (or (not mark-to-kill)
1788 (eq t reftex-initialize-temporary-buffers))
1790 ;; Visit the file with full magic
1791 (setq buf (find-file-noselect file))
1793 ;; Else: Visit the file just briefly, without or
1794 ;; with limited Magic
1796 ;; The magic goes away
1797 (cl-letf ((format-alist nil)
1798 (auto-mode-alist (reftex-auto-mode-alist))
1799 ((default-value 'major-mode) 'fundamental-mode)
1800 (enable-local-variables nil)
1801 (after-insert-file-functions nil))
1802 (setq buf (find-file-noselect file)))
1804 ;; Is there a hook to run?
1805 (when (listp reftex-initialize-temporary-buffers)
1806 (with-current-buffer buf
1807 (run-hooks 'reftex-initialize-temporary-buffers))))
1809 ;; Let's see if we got a license to kill :-|
1810 (and mark-to-kill
1811 (cl-pushnew buf reftex-buffers-to-kill))
1813 ;; Return the new buffer
1814 buf)
1816 ;; If no such file exists, return nil
1817 (t nil))))
1819 (defun reftex-kill-temporary-buffers (&optional buffer)
1820 ;; Kill all buffers in the list reftex-kill-temporary-buffers.
1821 (cond
1822 (buffer
1823 (when (member buffer reftex-buffers-to-kill)
1824 (kill-buffer buffer)
1825 (setq reftex-buffers-to-kill
1826 (delete buffer reftex-buffers-to-kill))))
1828 (while (setq buffer (pop reftex-buffers-to-kill))
1829 (when (bufferp buffer)
1830 (and (buffer-modified-p buffer)
1831 (y-or-n-p (format "Save file %s? "
1832 (buffer-file-name buffer)))
1833 (with-current-buffer buffer
1834 (save-buffer)))
1835 (kill-buffer buffer))
1836 (pop reftex-buffers-to-kill)))))
1838 (defun reftex-splice-symbols-into-list (list alist)
1839 ;; Splice the association in ALIST of any symbols in LIST into the list.
1840 ;; Return new list.
1841 (let (rtn tmp)
1842 (while list
1843 (while (and (not (null (car list))) ;; keep list elements nil
1844 (symbolp (car list)))
1845 (setq tmp (car list))
1846 (cond
1847 ((assoc tmp alist)
1848 (setq list (append (nth 2 (assoc tmp alist)) (cdr list))))
1850 (error "Cannot treat symbol %s in reftex-label-alist"
1851 (symbol-name tmp)))))
1852 (push (pop list) rtn))
1853 (nreverse rtn)))
1855 (defun reftex-remove-symbols-from-list (list)
1856 ;; Remove all symbols from list
1857 (let (rtn)
1858 (while list
1859 (unless (symbolp (car list))
1860 (push (car list) rtn))
1861 (setq list (cdr list)))
1862 (nreverse rtn)))
1864 (defun reftex-uniquify (list &optional sort)
1865 ;; Return a list of all strings in LIST, but each only once, keeping order
1866 ;; unless SORT is set (faster!).
1867 (setq list (copy-sequence list))
1868 (if sort
1869 (progn
1870 (setq list (sort list 'string<))
1871 (let ((p list))
1872 (while (cdr p)
1873 (if (string= (car p) (car (cdr p)))
1874 (setcdr p (cdr (cdr p)))
1875 (setq p (cdr p)))))
1876 list)
1877 (let ((p list) lst elt)
1878 ;; push all sublists into lst in reverse(!) order
1879 (while p
1880 (push p lst)
1881 (setq p (cdr p)))
1882 ;; sort all sublists
1883 (setq lst (sort lst (lambda (x1 x2) (string< (car x1) (car x2)))))
1884 (while (cdr lst)
1885 (setq elt (car (car lst)))
1886 ;; for equal elements in the sorted sublist, replace the
1887 ;; last(!) original list member with nil
1888 (when (string= elt (car (cadr lst)))
1889 (setcar (pop lst) nil)
1890 (while (and (cdr lst) (string= elt (car (cadr lst))))
1891 (setcar (pop lst) nil)))
1892 (pop lst)))
1893 ;; weed out all nils and return.
1894 (delq nil list)))
1896 (defun reftex-uniquify-by-car (alist &optional keep-list sort)
1897 ;; Return a list of all elements in ALIST, but each car only once.
1898 ;; Elements of KEEP-LIST are not removed even if duplicate.
1899 ;; The order is kept unless SORT is set (faster!).
1900 (setq keep-list (sort (copy-sequence keep-list) #'string<)
1901 alist (copy-sequence alist))
1902 (if sort
1903 (let (lst elt)
1904 (setq alist (sort alist (lambda(a b) (string< (car a) (car b)))))
1905 (setq lst alist)
1906 (while (cdr lst)
1907 (setq elt (car (car lst)))
1908 (when (string= elt (car (cadr lst)))
1909 (while (and keep-list (string< (car keep-list) elt))
1910 (pop keep-list))
1911 (if (and keep-list (string= elt (car keep-list)))
1912 (progn
1913 (pop lst)
1914 (while (and (cdr lst)
1915 (string= elt (car (cadr lst))))
1916 (pop lst)))
1917 (setcdr lst (cdr (cdr lst)))
1918 (while (and (cdr lst)
1919 (string= elt (car (cadr lst))))
1920 (setcdr lst (cdr (cdr lst))))))
1921 (pop lst))
1922 alist)
1923 (let ((p alist) lst elt)
1924 (while p
1925 (push p lst)
1926 (setq p (cdr p)))
1927 (setq lst (sort lst (lambda(a b) (string< (car (car a))
1928 (car (car b))))))
1929 (while (cdr lst)
1930 (setq elt (car (car (car lst))))
1931 (when (string= elt (car (car (cadr lst))))
1932 (while (and keep-list (string< (car keep-list) elt))
1933 (pop keep-list))
1934 (if (and keep-list (string= elt (car keep-list)))
1935 (progn
1936 (pop lst)
1937 (while (and (cdr lst)
1938 (string= elt (car (car (cadr lst)))))
1939 (pop lst)))
1940 (setcar (pop lst) nil)
1941 (while (and (cdr lst)
1942 (string= elt (car (car (cadr lst)))))
1943 (setcar (pop lst) nil))))
1944 (pop lst)))
1945 (delq nil alist)))
1947 (defun reftex-remove-if (predicate list)
1948 "Nondestructively remove all items from LIST which satisfy PREDICATE."
1949 (let (result)
1950 (dolist (elt list (nreverse result))
1951 (unless (funcall predicate elt)
1952 (push elt result)))))
1954 (defun reftex-abbreviate-title (string)
1955 (reftex-convert-string string "[-~ \t\n\r,;]" nil t t
1956 5 40 nil 1 " " (nth 5 reftex-derive-label-parameters)))
1958 (defun reftex-convert-string (string split-re invalid-re dot keep-fp
1959 nwords maxchar invalid abbrev sep
1960 ignore-words &optional downcase)
1961 "Convert a string (a sentence) to something shorter.
1962 SPLIT-RE is the regular expression used to split the string into words.
1963 INVALID-RE matches characters which are invalid in the final string.
1964 DOT t means add dots to abbreviated words.
1965 KEEP-FP t means to keep a final punctuation when applicable.
1966 NWORDS Number of words to use.
1967 MAXCHAR Maximum number of characters in the final string.
1968 INVALID nil: Throw away any words containing stuff matched with INVALID-RE.
1969 t: Throw away only the matched part, not the whole word.
1970 ABBREV nil: Never abbreviate words.
1971 t: Always abbreviate words (see `reftex-abbrev-parameters').
1972 not t and not nil: Abbreviate words if necessary to shorten
1973 string below MAXCHAR.
1974 SEP String separating different words in the output string.
1975 IGNORE-WORDS List of words which should be removed from the string."
1977 (let* ((words0 (split-string string (or split-re "[ \t\n\r]")))
1978 (reftex-label-illegal-re (or invalid-re "\000"))
1979 (abbrev-re (concat
1980 "\\`\\("
1981 (make-string (nth 0 reftex-abbrev-parameters) ?.)
1982 "[" (nth 2 reftex-abbrev-parameters) "]*"
1983 "\\)"
1984 "[" (nth 3 reftex-abbrev-parameters) "]"
1985 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
1986 words word)
1988 ;; Remove words from the ignore list or with funny characters
1989 (while (setq word (pop words0))
1990 (if downcase (setq word (downcase word)))
1991 (cond
1992 ((member (downcase word) ignore-words))
1993 ((string-match reftex-label-illegal-re word)
1994 (when invalid
1995 (while (string-match reftex-label-illegal-re word)
1996 (setq word (replace-match "" nil nil word)))
1997 (push word words)))
1999 (push word words))))
2000 (setq words (nreverse words))
2002 ;; Restrict number of words
2003 (if (> (length words) nwords)
2004 (setcdr (nthcdr (1- nwords) words) nil))
2006 ;; First, try to use all words
2007 (setq string (mapconcat 'identity words sep))
2009 ;; Abbreviate words if enforced by user settings or string length
2010 (if (or (eq t abbrev)
2011 (and abbrev
2012 (> (length string) maxchar)))
2013 (setq words
2014 (mapcar
2015 (lambda (w) (if (string-match abbrev-re w)
2016 (if dot
2017 (concat (match-string 1 w) ".")
2018 (match-string 1 w))
2020 words)
2021 string (mapconcat 'identity words sep)))
2023 ;; Shorten if still to long
2024 (setq string
2025 (if (> (length string) maxchar)
2026 (substring string 0 maxchar)
2027 string))
2029 ;; Delete the final punctuation, if any
2030 (if (and (not keep-fp) (string-match "\\s.+\\'" string))
2031 (setq string (replace-match "" nil nil string)))
2032 string))
2034 (defun reftex-nicify-text (text)
2035 ;; Make TEXT nice for inclusion as context into label menu.
2036 ;; 1. remove line breaks and extra white space
2037 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text)
2038 (setq text (replace-match " " nil t text)))
2039 ;; 2. cut before the next `\end{' or `\item' or `\\'
2040 (if (string-match "\\(\\\\end{\\|\\\\item\\|\\\\\\\\\\).*" text)
2041 (setq text (replace-match "" nil t text)))
2042 ;; 3. kill the embedded label
2043 (if (string-match "\\\\label{[^}]*}" text)
2044 (setq text (replace-match "" nil t text)))
2045 ;; 4. remove leading garbage
2046 (if (string-match "\\`[ }]+" text)
2047 (setq text (replace-match "" nil t text)))
2048 ;; 5. limit length
2049 (cond
2050 ((> (length text) 100) (substring text 0 100))
2051 ((= (length text) 0) (make-string 1 ?\ ))
2052 (t text)))
2055 ;;; =========================================================================
2057 ;;; Fontification and Highlighting
2059 (defun reftex-use-fonts ()
2060 ;; Return t if we can and want to use fonts.
2061 (and ; window-system
2062 reftex-use-fonts
2063 (featurep 'font-lock)))
2065 (defun reftex-refontify ()
2066 ;; Return t if we need to refontify context
2067 (and (reftex-use-fonts)
2068 (or (eq t reftex-refontify-context)
2069 (and (eq 1 reftex-refontify-context)
2070 ;; Test of we use the font-lock version of x-symbol
2071 (and (featurep 'x-symbol-tex) (not (boundp 'x-symbol-mode)))))))
2073 (defvar font-lock-defaults-computed)
2074 (defun reftex-fontify-select-label-buffer (parent-buffer)
2075 ;; Fontify the `*RefTeX Select*' buffer. Buffer is temporarily renamed to
2076 ;; start with none-SPC char, because Font-Lock otherwise refuses operation.
2077 (run-hook-with-args 'reftex-pre-refontification-functions
2078 parent-buffer 'reftex-ref)
2079 (let* ((oldname (buffer-name))
2080 (newname (concat "Fontify-me-" oldname)))
2081 (unwind-protect
2082 (progn
2083 ;; Rename buffer temporarily to start w/o space (because of font-lock)
2084 (rename-buffer newname t)
2085 (cond
2086 ((fboundp 'font-lock-default-fontify-region)
2087 ;; Good: we have the indirection functions
2088 (set (make-local-variable 'font-lock-fontify-region-function)
2089 'reftex-select-font-lock-fontify-region)
2090 (let ((major-mode 'latex-mode))
2091 (font-lock-mode 1)))
2092 ((fboundp 'font-lock-set-defaults-1)
2093 ;; Looks like the XEmacs font-lock stuff.
2094 ;; FIXME: this is still kind of a hack, but it works.
2095 (set (make-local-variable 'font-lock-keywords) nil)
2096 (let ((major-mode 'latex-mode)
2097 (font-lock-defaults-computed nil))
2098 (font-lock-set-defaults-1)
2099 (reftex-select-font-lock-fontify-region (point-min) (point-max))))
2101 ;; Oops?
2102 (message "Sorry: cannot refontify RefTeX Select buffer."))))
2103 (rename-buffer oldname))))
2105 (defun reftex-select-font-lock-fontify-region (beg end &optional _loudly)
2106 ;; Fontify a region, but only lines starting with a dot.
2107 (let ((func (if (fboundp 'font-lock-default-fontify-region)
2108 'font-lock-default-fontify-region
2109 'font-lock-fontify-region))
2110 beg1 end1)
2111 (goto-char beg)
2112 (while (re-search-forward "^\\." end t)
2113 (setq beg1 (point) end1 (progn (skip-chars-forward "^\n") (point)))
2114 (funcall func beg1 end1 nil)
2115 (goto-char end1))))
2117 (defun reftex-select-font-lock-unfontify (&rest _ignore) t)
2119 (defun reftex-verified-face (&rest faces)
2120 ;; Return the first valid face in FACES, or nil if none is valid.
2121 ;; Also, when finding a nil element in FACES, return nil. This
2122 ;; function is just a safety net to catch name changes of builtin
2123 ;; fonts. Currently it is only used for reftex-label-face.
2124 (let (face)
2125 (catch 'exit
2126 (while (setq face (pop faces))
2127 (if (featurep 'xemacs)
2128 (if (find-face face) (throw 'exit face))
2129 (if (facep face) (throw 'exit face)))))))
2131 ;; Highlighting uses overlays. For XEmacs, we use extends.
2132 (defalias 'reftex-make-overlay
2133 (if (featurep 'xemacs) 'make-extent 'make-overlay))
2134 (defalias 'reftex-overlay-put
2135 (if (featurep 'xemacs) 'set-extent-property 'overlay-put))
2136 (defalias 'reftex-move-overlay
2137 (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay))
2138 (defalias 'reftex-delete-overlay
2139 (if (featurep 'xemacs) 'detach-extent 'delete-overlay))
2141 ;; We keep a vector with several different overlays to do our highlighting.
2142 (defvar reftex-highlight-overlays [nil nil nil])
2144 ;; Initialize the overlays
2145 (aset reftex-highlight-overlays 0 (reftex-make-overlay 1 1))
2146 (reftex-overlay-put (aref reftex-highlight-overlays 0)
2147 'face 'highlight)
2148 (aset reftex-highlight-overlays 1 (reftex-make-overlay 1 1))
2149 (reftex-overlay-put (aref reftex-highlight-overlays 1)
2150 'face reftex-cursor-selected-face)
2151 (aset reftex-highlight-overlays 2 (reftex-make-overlay 1 1))
2152 (reftex-overlay-put (aref reftex-highlight-overlays 2)
2153 'face reftex-cursor-selected-face)
2155 ;; Two functions for activating and deactivation highlight overlays
2156 (defun reftex-highlight (index begin end &optional buffer)
2157 "Highlight a region with overlay INDEX."
2158 (reftex-move-overlay (aref reftex-highlight-overlays index)
2159 begin end (or buffer (current-buffer))))
2160 (defun reftex-unhighlight (index)
2161 "Detach overlay INDEX."
2162 (reftex-delete-overlay (aref reftex-highlight-overlays index)))
2164 (defun reftex-highlight-shall-die ()
2165 ;; Function used in pre-command-hook to remove highlights.
2166 (remove-hook 'pre-command-hook 'reftex-highlight-shall-die)
2167 (reftex-unhighlight 0))
2169 ;;; =========================================================================
2171 ;;; Keybindings
2173 (defvar bibtex-mode-map)
2175 ;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map
2176 (eval-after-load
2177 "bibtex"
2178 '(define-key bibtex-mode-map "\C-c&" 'reftex-view-crossref-from-bibtex))
2180 ;;; =========================================================================
2182 ;;; Menu
2184 ;; Define a menu for the menu bar if Emacs is running under X
2186 (defvar reftex-isearch-minor-mode nil)
2187 (make-variable-buffer-local 'reftex-isearch-minor-mode)
2189 (easy-menu-define reftex-mode-menu reftex-mode-map
2190 "Menu used in RefTeX mode"
2191 `("Ref"
2192 ["Table of Contents" reftex-toc t]
2193 ["Recenter TOC" reftex-toc-recenter t]
2194 "--"
2195 ["\\label" reftex-label t]
2196 ["\\ref" reftex-reference t]
2197 ["\\cite" reftex-citation t]
2198 ("\\index"
2199 ["\\index" reftex-index t]
2200 ["\\index{THIS}" reftex-index-selection-or-word t]
2201 "--"
2202 ["Add THIS to Index Phrases" reftex-index-phrase-selection-or-word t]
2203 ["Visit Phrase Buffer" reftex-index-visit-phrases-buffer t]
2204 ["Apply Phrases to Region" reftex-index-phrases-apply-to-region t]
2205 "--"
2206 ["Display the Index" reftex-display-index t])
2207 "--"
2208 ["View Crossref" reftex-view-crossref t]
2209 "--"
2210 ("Parse Document"
2211 ["One File" reftex-parse-one reftex-enable-partial-scans]
2212 ["Entire Document" reftex-parse-all t]
2213 ["Save to File" (reftex-access-parse-file 'write)
2214 (> (length (symbol-value reftex-docstruct-symbol)) 0)]
2215 ["Restore from File" (reftex-access-parse-file 'restore) t])
2216 ("Global Actions"
2217 ["Search Whole Document" reftex-search-document t]
2218 ["Search Again" tags-loop-continue t]
2219 ["Replace in Document" reftex-query-replace-document t]
2220 ["Grep on Document" reftex-grep-document t]
2221 "--"
2222 ["Goto Label" reftex-goto-label t]
2223 ["Find Duplicate Labels" reftex-find-duplicate-labels t]
2224 ["Change Label and Refs" reftex-change-label t]
2225 ["Renumber Simple Labels" reftex-renumber-simple-labels t]
2226 "--"
2227 ["Create BibTeX File" reftex-create-bibtex-file t]
2228 "--"
2229 ["Create TAGS File" reftex-create-tags-file t]
2230 "--"
2231 ["Save Document" reftex-save-all-document-buffers t])
2232 "--"
2233 ("Options"
2234 "PARSER"
2235 ["Partial Scans"
2236 (setq reftex-enable-partial-scans (not reftex-enable-partial-scans))
2237 :style toggle :selected reftex-enable-partial-scans]
2238 ["Auto-Save Parse Info"
2239 (setq reftex-save-parse-info (not reftex-save-parse-info))
2240 :style toggle :selected reftex-save-parse-info]
2241 "--"
2242 "TOC RECENTER"
2243 ["Automatic Recenter" reftex-toggle-auto-toc-recenter
2244 :style toggle :selected reftex-toc-auto-recenter-timer]
2245 "--"
2246 "CROSSREF INFO"
2247 ["Automatic Info" reftex-toggle-auto-view-crossref
2248 :style toggle :selected reftex-auto-view-crossref-timer]
2249 ["...in Echo Area" (setq reftex-auto-view-crossref t)
2250 :style radio :selected (eq reftex-auto-view-crossref t)]
2251 ["...in Other Window" (setq reftex-auto-view-crossref 'window)
2252 :style radio :selected (eq reftex-auto-view-crossref 'window)]
2253 "--"
2254 "MISC"
2255 ["AUCTeX Interface" reftex-toggle-plug-into-AUCTeX
2256 :style toggle :selected reftex-plug-into-AUCTeX]
2257 ["isearch whole document" reftex-isearch-minor-mode
2258 :style toggle :selected reftex-isearch-minor-mode])
2259 ("Reference Style"
2260 ,@(let (list item)
2261 (dolist (elt reftex-ref-style-alist)
2262 (setq elt (car elt)
2263 item (vector
2265 `(reftex-ref-style-toggle ,elt)
2266 :style 'toggle
2267 :selected `(member ,elt (reftex-ref-style-list))))
2268 (unless (member item list)
2269 (setq list (append list (list item)))))
2270 list))
2271 ("Citation Style"
2272 ,@(mapcar
2273 (lambda (x)
2274 (vector
2275 (capitalize (symbol-name (car x)))
2276 (list 'reftex-set-cite-format (list 'quote (car x)))
2277 :style 'radio :selected
2278 (list 'eq (list 'reftex-get-cite-format) (list 'quote (car x)))))
2279 reftex-cite-format-builtin)
2280 "--"
2281 "Sort Database Matches"
2282 ["Not" (setq reftex-sort-bibtex-matches nil)
2283 :style radio :selected (eq reftex-sort-bibtex-matches nil)]
2284 ["by Author" (setq reftex-sort-bibtex-matches 'author)
2285 :style radio :selected (eq reftex-sort-bibtex-matches 'author)]
2286 ["by Year" (setq reftex-sort-bibtex-matches 'year)
2287 :style radio :selected (eq reftex-sort-bibtex-matches 'year)]
2288 ["by Year, reversed" (setq reftex-sort-bibtex-matches 'reverse-year)
2289 :style radio :selected (eq reftex-sort-bibtex-matches 'reverse-year)])
2290 ("Index Style"
2291 ,@(mapcar
2292 (lambda (x)
2293 (vector
2294 (capitalize (symbol-name (car x)))
2295 (list 'reftex-add-index-macros (list 'list (list 'quote (car x))))
2296 :style 'radio :selected
2297 (list 'memq (list 'quote (car x))
2298 (list 'get 'reftex-docstruct-symbol
2299 (list 'quote 'reftex-index-macros-style)))))
2300 reftex-index-macros-builtin))
2301 "--"
2302 ["Reset RefTeX Mode" reftex-reset-mode t]
2303 "--"
2304 ("Customize"
2305 ["Browse RefTeX Group" reftex-customize t]
2306 "--"
2307 ["Build Full Customize Menu" reftex-create-customize-menu
2308 (fboundp 'customize-menu-create)])
2309 ("Documentation"
2310 ["Info" reftex-info t]
2311 ["Commentary" reftex-show-commentary t])))
2313 (defun reftex-customize ()
2314 "Call the customize function with reftex as argument."
2315 (interactive)
2316 (customize-browse 'reftex))
2318 (defun reftex-create-customize-menu ()
2319 "Create a full customization menu for RefTeX, insert it into the menu."
2320 (interactive)
2321 (if (fboundp 'customize-menu-create)
2322 (progn
2323 (easy-menu-change
2324 '("Ref") "Customize"
2325 `(["Browse RefTeX group" reftex-customize t]
2326 "--"
2327 ,(customize-menu-create 'reftex)
2328 ["Set" Custom-set t]
2329 ["Save" Custom-save t]
2330 ["Reset to Current" Custom-reset-current t]
2331 ["Reset to Saved" Custom-reset-saved t]
2332 ["Reset to Standard Settings" Custom-reset-standard t]))
2333 (message "\"Ref\"-menu now contains full customization menu"))
2334 (error "Cannot expand menu (outdated version of cus-edit.el)")))
2337 ;;; Misc
2339 (defun reftex-show-commentary ()
2340 "Use the finder to view the file documentation from `reftex.el'."
2341 (interactive)
2342 (finder-commentary "reftex.el"))
2344 (defun reftex-info (&optional node)
2345 "Read documentation for RefTeX in the info system.
2346 With optional NODE, go directly to that node."
2347 (interactive)
2348 (info (format "(reftex)%s" (or node ""))))
2350 (defun reftex-report-bug ()
2351 "Report a bug in RefTeX.
2353 Don't hesitate to report any problems or inaccurate documentation.
2355 If you don't have setup sending mail from (X)Emacs, please copy the
2356 output buffer into your mail program, as it gives us important
2357 information about your RefTeX version and configuration."
2358 (interactive)
2359 (require 'reporter)
2360 (defvar reporter-prompt-for-summary-p)
2361 (let ((reporter-prompt-for-summary-p "Bug report subject: "))
2362 (reporter-submit-bug-report
2363 "bug-auctex@gnu.org, bug-gnu-emacs@gnu.org"
2364 reftex-version
2365 (list 'window-system
2366 'reftex-plug-into-AUCTeX)
2367 nil nil
2368 "Remember to cover the basics, that is, what you expected to happen and
2369 what in fact did happen.
2371 Check if the bug is reproducible with an up-to-date version of
2372 RefTeX available from https://www.gnu.org/software/auctex/.
2374 If the bug is triggered by a specific \(La)TeX file, you should try
2375 to produce a minimal sample file showing the problem and include it
2376 in your report.
2378 Your bug report will be posted to the AUCTeX bug reporting list.
2379 ------------------------------------------------------------------------")))
2381 ;;; Install the kill-buffer and kill-emacs hooks ------------------------------
2383 (add-hook 'kill-buffer-hook 'reftex-kill-buffer-hook)
2384 (unless noninteractive
2385 (add-hook 'kill-emacs-hook 'reftex-kill-emacs-hook))
2387 ;;; Run Hook ------------------------------------------------------------------
2389 (run-hooks 'reftex-load-hook)
2391 ;;; That's it! ----------------------------------------------------------------
2393 (setq reftex-tables-dirty t) ; in case this file is evaluated by hand
2395 (provide 'reftex)
2397 ;;; reftex.el ends here