X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/771f48f0638f4832c882b2eab1bbc11e36ed5cf5..114f9c96795aff3b51b9060d7c9c1b77debcc99a:/lisp/textmodes/reftex.el diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el index 0c1beb1776..66dec462b8 100644 --- a/lisp/textmodes/reftex.el +++ b/lisp/textmodes/reftex.el @@ -1,6 +1,6 @@ ;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX ;; Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, -;; 2006, 2007 Free Software Foundation, Inc. +;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. ;; Author: Carsten Dominik ;; Maintainer: auctex-devel@gnu.org @@ -9,10 +9,10 @@ ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,14 +20,12 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;--------------------------------------------------------------------------- ;; ;;; Commentary: -;; +;; ;; RefTeX is a minor mode with distinct support for \ref, \label, \cite, ;; and \index commands in (multi-file) LaTeX documents. ;; - A table of contents provides easy access to any part of a document. @@ -72,7 +70,7 @@ ;; ;; Introduction ;; ************ -;; +;; ;; RefTeX is a specialized package for support of labels, references, ;; citations, and the index in LaTeX. RefTeX wraps itself round 4 LaTeX ;; macros: `\label', `\ref', `\cite', and `\index'. Using these macros @@ -81,13 +79,13 @@ ;; time-consuming tasks almost entirely. It also provides functions to ;; display the structure of a document and to move around in this ;; structure quickly. -;; +;; ;; *Note Imprint::, for information about who to contact for help, bug ;; reports or suggestions. -;; +;; ;; Environment ;; =========== -;; +;; ;; RefTeX needs to access all files which are part of a multifile ;; document, and the BibTeX database files requested by the ;; `\bibliography' command. To find these files, RefTeX will require a @@ -96,26 +94,26 @@ ;; which are also used by RefTeX. However, on some systems these ;; variables do not contain the full search path. If RefTeX does not work ;; for you because it cannot find some files, read *Note Finding Files::. -;; +;; ;; Entering RefTeX Mode ;; ==================== -;; +;; ;; To turn RefTeX Mode on and off in a particular buffer, use `M-x ;; reftex-mode'. To turn on RefTeX Mode for all LaTeX files, add the ;; following lines to your `.emacs' file: -;; +;; ;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode ;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode -;; +;; ;; RefTeX in a Nutshell ;; ==================== -;; +;; ;; 1. Table of Contents ;; Typing `C-c =' (`reftex-toc') will show a table of contents of the ;; document. This buffer can display sections, labels and index ;; entries defined in the document. From the buffer, you can jump ;; quickly to every part of your document. Press `?' to get help. -;; +;; ;; 2. Labels and References ;; RefTeX helps to create unique labels and to find the correct key ;; for references quickly. It distinguishes labels for different @@ -123,7 +121,7 @@ ;; others), and can be configured to recognize any additional labeled ;; environments you have defined yourself (variable ;; `reftex-label-alist'). -;; +;; ;; * Creating Labels ;; Type `C-c (' (`reftex-label') to insert a label at point. ;; RefTeX will either @@ -132,17 +130,17 @@ ;; tables) or ;; - insert a simple label made of a prefix and a number (all ;; other environments) -;; +;; ;; Which labels are created how is configurable with the variable ;; `reftex-insert-label-flags'. -;; +;; ;; * Referencing Labels ;; To make a reference, type `C-c )' (`reftex-reference'). This ;; shows an outline of the document with all labels of a certain ;; type (figure, equation,...) and some label context. ;; Selecting a label inserts a `\ref{LABEL}' macro into the ;; original buffer. -;; +;; ;; 3. Citations ;; Typing `C-c [' (`reftex-citation') will let you specify a regular ;; expression to search in current BibTeX database files (as @@ -151,7 +149,7 @@ ;; sorted. The selected article is referenced as `\cite{KEY}' (see ;; the variable `reftex-cite-format' if you want to insert different ;; macros). -;; +;; ;; 4. Index Support ;; RefTeX helps to enter index entries. It also compiles all entries ;; into an alphabetically sorted `*Index*' buffer which you can use @@ -159,25 +157,25 @@ ;; index macros and can be configured to recognize any additional ;; macros you have defined (`reftex-index-macros'). Multiple indices ;; are supported. -;; +;; ;; * Creating Index Entries ;; To index the current selection or the word at point, type ;; `C-c /' (`reftex-index-selection-or-word'). The default macro ;; `reftex-index-default-macro' will be used. For a more ;; complex entry type `C-c <' (`reftex-index'), select any of ;; the index macros and enter the arguments with completion. -;; +;; ;; * The Index Phrases File (Delayed Indexing) ;; Type `C-c \' (`reftex-index-phrase-selection-or-word') to add ;; the current word or selection to a special _index phrase ;; file_. RefTeX can later search the document for occurrences ;; of these phrases and let you interactively index the matches. -;; +;; ;; * Displaying and Editing the Index ;; To display the compiled index in a special buffer, type `C-c ;; >' (`reftex-display-index'). From that buffer you can check ;; and edit all entries. -;; +;; ;; 5. Viewing Cross-References ;; When point is on the KEY argument of a cross-referencing macro ;; (`\label', `\ref', `\cite', `\bibitem', `\index', and variations) @@ -187,14 +185,14 @@ ;; When the enclosing macro is `\cite' or `\ref' and no other message ;; occupies the echo area, information about the citation or label ;; will automatically be displayed in the echo area. -;; +;; ;; 6. Multifile Documents ;; Multifile Documents are fully supported. The included files must ;; have a file variable `TeX-master' or `tex-main-file' pointing to ;; the master file. RefTeX provides cross-referencing information ;; from all parts of the document, and across document borders ;; (`xr.sty'). -;; +;; ;; 7. Document Parsing ;; RefTeX needs to parse the document in order to find labels and ;; other information. It does it automatically once and updates its @@ -203,23 +201,23 @@ ;; with a raw `C-u' prefix, or press the `r' key in the label ;; selection buffer, the table of contents buffer, or the index ;; buffer. -;; +;; ;; 8. AUCTeX ;; If your major LaTeX mode is AUCTeX, RefTeX can cooperate with it ;; (see variable `reftex-plug-into-AUCTeX'). AUCTeX contains style ;; files which trigger appropriate settings in RefTeX, so that for ;; many of the popular LaTeX packages no additional customizations ;; will be necessary. -;; +;; ;; 9. Useful Settings ;; To make RefTeX faster for large documents, try these: ;; (setq reftex-enable-partial-scans t) ;; (setq reftex-save-parse-info t) ;; (setq reftex-use-multiple-selection-buffers t) -;; +;; ;; To integrate with AUCTeX, use ;; (setq reftex-plug-into-AUCTeX t) -;; +;; ;; To make your own LaTeX macro definitions known to RefTeX, ;; customize the variables ;; `reftex-label-alist' (for label macros/environments) @@ -229,7 +227,7 @@ ;; `reftex-index-default-macro' (to set the default macro) ;; If you have a large number of macros defined, you may want to write ;; an AUCTeX style file to support them with both AUCTeX and RefTeX. -;; +;; ;; 10. Where Next? ;; Go ahead and use RefTeX. Use its menus until you have picked up ;; the key bindings. For an overview of what you can do in each of @@ -238,7 +236,7 @@ ;; The first part of the manual explains in a tutorial way how to use ;; and customize RefTeX. The second part is a command and variable ;; reference. -;; +;; ;;--------------------------------------------------------------------------- ;; ;; AUTHOR @@ -322,7 +320,7 @@ (setq reftex-syntax-table (copy-syntax-table)) (modify-syntax-entry ?\( "." reftex-syntax-table) (modify-syntax-entry ?\) "." reftex-syntax-table)) - + (unless reftex-syntax-table-for-bib (setq reftex-syntax-table-for-bib (copy-syntax-table reftex-syntax-table)) @@ -338,6 +336,169 @@ (defvar reftex-toc-auto-recenter-timer nil "The idle timer used to recenter the toc window.") +;;; ========================================================================= +;;; +;;; Parser functions + +(autoload 'reftex-parse-one "reftex-parse" + "Re-parse this file." t) +(autoload 'reftex-parse-all "reftex-parse" + "Re-parse entire document." t) +(autoload 'reftex-do-parse "reftex-parse") +(autoload 'reftex-where-am-I "reftex-parse") +(autoload 'reftex-init-section-numbers "reftex-parse") +(autoload 'reftex-section-info "reftex-parse") +(autoload 'reftex-section-number "reftex-parse") +(autoload 'reftex-what-macro "reftex-parse") +(autoload 'reftex-what-macro-safe "reftex-parse") +(autoload 'reftex-index-info "reftex-parse") +(autoload 'reftex-index-info-safe "reftex-parse") +(autoload 'reftex-short-context "reftex-parse") +(autoload 'reftex-what-environment "reftex-parse") +(autoload 'reftex-what-special-env "reftex-parse") +(autoload 'reftex-move-over-touching-args "reftex-parse") +(autoload 'reftex-notice-new "reftex-parse") +(autoload 'reftex-nth-arg "reftex-parse") +(autoload 'reftex-locate-bibliography-files "reftex-parse") +(autoload 'reftex-ensure-index-support "reftex-parse") +(autoload 'reftex-everything-regexp "reftex-parse") + + +;;; ========================================================================= +;;; +;;; Labels and References + +(autoload 'reftex-label-location "reftex-ref") +(autoload 'reftex-label-info-update "reftex-ref") +(autoload 'reftex-label-info "reftex-ref") +(autoload 'reftex-label "reftex-ref" + "Insert a unique label." t) +(autoload 'reftex-reference "reftex-ref" + "Make a LaTeX reference." t) +(autoload 'reftex-varioref-vref "reftex-ref" + "Make a varioref reference." t) +(autoload 'reftex-fancyref-fref "reftex-ref" + "Make a fancyref \\fref reference." t) +(autoload 'reftex-fancyref-Fref "reftex-ref" + "Make a fancyref \\Fref reference." t) +(autoload 'reftex-show-label-location "reftex-ref") +(autoload 'reftex-query-label-type "reftex-ref") +(autoload 'reftex-goto-label "reftex-ref" + "Prompt for label name and go to that location." t) + +;;; ========================================================================= +;;; +;;; Table of contents + +(autoload 'reftex-toc "reftex-toc" + "Show the table of contents for the current document." t) +(autoload 'reftex-toc-recenter "reftex-toc" + "Display the TOC window and highlight line corresponding to current position." t) +(autoload 'reftex-toggle-auto-toc-recenter "reftex-toc" + "Toggle automatic recentering of TOC window." t) + +;;; ========================================================================= +;;; +;;; BibTeX citations. + +(autoload 'reftex-citep "reftex-cite") +(autoload 'reftex-citet "reftex-cite") +(autoload 'reftex-make-cite-echo-string "reftex-cite") +(autoload 'reftex-get-bibfile-list "reftex-cite") +(autoload 'reftex-pop-to-bibtex-entry "reftex-cite") +(autoload 'reftex-end-of-bib-entry "reftex-cite") +(autoload 'reftex-parse-bibtex-entry "reftex-cite") +(autoload 'reftex-citation "reftex-cite" + "Make a citation using BibTeX database files." t) +(autoload 'reftex-default-bibliography "reftex-cite") +(autoload 'reftex-bib-or-thebib "reftex-cite") +(autoload 'reftex-create-bibtex-file "reftex-cite") + +;;; ========================================================================= +;;; +;;; Selection + +(autoload 'reftex-select-label-mode "reftex-sel") +(autoload 'reftex-select-bib-mode "reftex-sel") +(autoload 'reftex-find-start-point "reftex-sel") +(autoload 'reftex-insert-docstruct "reftex-sel") +(autoload 'reftex-get-offset "reftex-sel") +(autoload 'reftex-select-item "reftex-sel") + + +;;; ========================================================================= +;;; +;;; Index support + +(autoload 'reftex-index "reftex-index" + "Query for an index macro and insert it along with its arguments." t) +(autoload 'reftex-index-selection-or-word "reftex-index" + "Put selection or the word near point into the default index macro." t) +(autoload 'reftex-index-phrase-selection-or-word "reftex-index" + "Put selection or the word near point into Index Phrases File." t) +(autoload 'reftex-display-index "reftex-index" + "Display a buffer with an index compiled from the current document." t) +(autoload 'reftex-index-visit-phrases-buffer "reftex-index" + "Visit the Index Phrases File." t) +(autoload 'reftex-index-phrases-mode "reftex-index" + "Major mode for managing the Index phrases of a LaTeX document." t) +(autoload 'reftex-index-complete-tag "reftex-index") +(autoload 'reftex-index-complete-key "reftex-index") +(autoload 'reftex-index-show-entry "reftex-index") +(autoload 'reftex-index-select-tag "reftex-index") + + +;;; ========================================================================= +;;; +;;; View cross references + +(autoload 'reftex-view-crossref "reftex-dcr" + "View cross reference of \\ref or \\cite macro at point." t) +(autoload 'reftex-mouse-view-crossref "reftex-dcr" + "View cross reference of \\ref or \\cite macro where you click." t) +(autoload 'reftex-toggle-auto-view-crossref "reftex-dcr") +(autoload 'reftex-view-crossref-from-bibtex "reftex-dcr" + "View location in a LaTeX document which cites the BibTeX entry at point." t) + + +;;; ========================================================================= +;;; +;;; Operations on entire Multifile documents + +(autoload 'reftex-create-tags-file "reftex-global" + "Create TAGS file by running `etags' on the current document." t) +(autoload 'reftex-grep-document "reftex-global" + "Run grep query through all files related to this document." t) +(autoload 'reftex-search-document "reftex-global" + "Regexp search through all files of the current TeX document." t) +(autoload 'reftex-query-replace-document "reftex-global" + "Run a query-replace-regexp of FROM with TO over the entire TeX document." t) +(autoload 'reftex-find-duplicate-labels "reftex-global" + "Produce a list of all duplicate labels in the document." t) +(autoload 'reftex-change-label "reftex-global" + "Query replace FROM with TO in all \\label and \\ref commands." t) +(autoload 'reftex-renumber-simple-labels "reftex-global" + "Renumber all simple labels in the document to make them sequentially." t) +(autoload 'reftex-save-all-document-buffers "reftex-global" + "Save all documents associated with the current document." t) + + +;;; ========================================================================= +;;; +;;; AUCTeX Interface + +(autoload 'reftex-arg-label "reftex-auc") +(autoload 'reftex-arg-cite "reftex-auc") +(autoload 'reftex-arg-index-tag "reftex-auc") +(autoload 'reftex-arg-index "reftex-auc") +(autoload 'reftex-plug-into-AUCTeX "reftex-auc") +(autoload 'reftex-toggle-plug-into-AUCTeX "reftex-auc" + "Toggle Interface between AUCTeX and RefTeX on and off." t) +(autoload 'reftex-add-label-environments "reftex-auc") +(autoload 'reftex-add-to-label-alist "reftex-auc") +(autoload 'reftex-add-section-levels "reftex-auc") +(autoload 'reftex-notice-new-section "reftex-auc") + ;;;###autoload (defun turn-on-reftex () "Turn on RefTeX mode." @@ -398,7 +559,7 @@ on the menu bar. (setq reftex-syntax-table (copy-syntax-table (syntax-table))) (modify-syntax-entry ?\( "." reftex-syntax-table) (modify-syntax-entry ?\) "." reftex-syntax-table) - + (setq reftex-syntax-table-for-bib (copy-syntax-table reftex-syntax-table)) (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) @@ -450,16 +611,15 @@ on the menu bar. ;;; ========================================================================= ;;; ;;; Silence warnings about variables in other packages. -(eval-when-compile - (defvar TeX-master) - (defvar LaTeX-section-hook) - (defvar LaTeX-label-function) - (defvar tex-main-file) - (defvar outline-minor-mode) - (defvar font-lock-mode) - (defvar font-lock-keywords) - (defvar font-lock-fontify-region-function) - (defvar font-lock-syntactic-keywords)) +(defvar TeX-master) +(defvar LaTeX-section-hook) +(defvar LaTeX-label-function) +(defvar tex-main-file) +(defvar outline-minor-mode) +(defvar font-lock-mode) +(defvar font-lock-keywords) +(defvar font-lock-fontify-region-function) +(defvar font-lock-syntactic-keywords) ;;; ========================================================================= ;;; @@ -540,7 +700,7 @@ on the menu bar. ((master (cond ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism. - (condition-case nil + (condition-case nil (TeX-master-file t) (error (buffer-file-name)))) ((fboundp 'tex-main-file) (tex-main-file)) ; Emacs LaTeX mode @@ -741,14 +901,14 @@ the label information is recompiled on next use." ;; A list of all variables in the cache. ;; The cache is used to save the compiled versions of some variables. -(defconst reftex-cache-variables +(defconst reftex-cache-variables '(reftex-memory ;; This MUST ALWAYS be the first! - + ;; Outline reftex-section-levels-all ;; Labels - reftex-env-or-mac-alist + reftex-env-or-mac-alist reftex-special-env-parsers reftex-macros-with-labels reftex-label-mac-list @@ -765,7 +925,7 @@ the label information is recompiled on next use." reftex-index-macro-alist reftex-macros-with-index reftex-query-index-macro-prompt - reftex-query-index-macro-help + reftex-query-index-macro-help reftex-key-to-index-macro-alist ;; Regular expressions @@ -810,7 +970,7 @@ the label information is recompiled on next use." (t (reftex-compile-variables))))) (defun reftex-reset-mode () - "Reset RefTeX Mode. + "Reset RefTeX Mode. This will re-compile the configuration information and remove all current scanning information and the parse file to enforce a rescan on next use." @@ -882,7 +1042,7 @@ This enforces rescanning the buffer on next use." ;; Record that we have done this, and what we have used. (setq reftex-tables-dirty nil) - (setq reftex-memory + (setq reftex-memory (list reftex-label-alist (get reftex-docstruct-symbol 'reftex-section-levels) (get reftex-docstruct-symbol 'reftex-label-alist-style) @@ -901,7 +1061,7 @@ This enforces rescanning the buffer on next use." '(nil))) (all-index (reftex-uniquify-by-car (reftex-splice-symbols-into-list - (append reftex-index-macros + (append reftex-index-macros (get reftex-docstruct-symbol 'reftex-index-macros-style) '(default)) @@ -912,7 +1072,7 @@ This enforces rescanning the buffer on next use." macro verify repeat nindex tag key toc-level toc-levels) (setq reftex-words-to-typekey-alist nil - reftex-prefix-to-typekey-alist + reftex-prefix-to-typekey-alist '(("sec:" . "s") ("cha:" . "s") ("chap:" . "s")) reftex-typekey-list nil reftex-typekey-to-format-alist nil @@ -968,7 +1128,7 @@ This enforces rescanning the buffer on next use." ((symbolp env-or-mac) ;; A special parser function (unless (fboundp env-or-mac) - (message "Warning: %s does not seem to be a valid function" + (message "Warning: %s does not seem to be a valid function" env-or-mac)) (setq nargs nil nlabel nil opt-args nil) (add-to-list 'reftex-special-env-parsers env-or-mac) @@ -996,8 +1156,8 @@ This enforces rescanning the buffer on next use." (push (cons string toc-level) toc-levels)))))))) ;; Translate some special context cases (when (assq context reftex-default-context-regexps) - (setq context - (format + (setq context + (format (cdr (assq context reftex-default-context-regexps)) (regexp-quote env-or-mac)))) ;; See if this is the first format for this typekey @@ -1030,7 +1190,7 @@ This enforces rescanning the buffer on next use." (nreverse reftex-typekey-to-prefix-alist)) ;; Prepare the typekey query prompt and help string. - (setq qh-list + (setq qh-list (sort qh-list (lambda (x1 x2) (string< (downcase (car x1)) (downcase (car x2)))))) @@ -1041,7 +1201,7 @@ This enforces rescanning the buffer on next use." "]")) ;; In the help string, we need to wrap lines... (setq reftex-type-query-help - (concat + (concat "SELECT A LABEL TYPE:\n--------------------\n" (mapconcat (lambda(x) @@ -1061,7 +1221,7 @@ This enforces rescanning the buffer on next use." ;; which allow for some chars from the ref format to be in the buffer. ;; These characters will be seen and removed. (setq reftex-words-to-typekey-alist - (mapcar + (mapcar (lambda (x) (setq word (car x) typekey (cdr x) @@ -1114,18 +1274,18 @@ This enforces rescanning the buffer on next use." (setq reftex-key-to-index-macro-alist (sort reftex-key-to-index-macro-alist (lambda (a b) (< (downcase (car a)) (downcase (car b)))))) - (setq reftex-query-index-macro-prompt + (setq reftex-query-index-macro-prompt (concat "Index macro: [" (mapconcat (lambda (x) (char-to-string (car x))) reftex-key-to-index-macro-alist "") "]")) (setq i 0 reftex-query-index-macro-help - (concat + (concat "SELECT A MACRO:\n---------------\n" (mapconcat (lambda(x) - (format "[%c] %-20.20s%s" (car x) (nth 1 x) + (format "[%c] %-20.20s%s" (car x) (nth 1 x) (if (= 0 (mod (incf i) 3)) "\n" ""))) reftex-key-to-index-macro-alist ""))) @@ -1139,11 +1299,11 @@ This enforces rescanning the buffer on next use." (let* ( ; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*") (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because - ;;; because match number are hard coded + ;;; because match number are hard coded (label-re "\\\\label{\\([^}]*\\)}") - (include-re (concat wbol + (include-re (concat wbol "\\\\\\(" - (mapconcat 'identity + (mapconcat 'identity reftex-include-file-commands "\\|") "\\)[{ \t]+\\([^} \t\n\r]+\\)")) (section-re @@ -1197,7 +1357,7 @@ This enforces rescanning the buffer on next use." reftex-macros-with-labels macros-with-labels reftex-find-index-entry-regexp-format find-index-re-format reftex-find-label-regexp-format find-label-re-format - reftex-find-label-regexp-format2 + reftex-find-label-regexp-format2 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]") (message "Compiling label environment definitions...done"))) (put reftex-docstruct-symbol 'reftex-cache @@ -1274,7 +1434,7 @@ This enforces rescanning the buffer on next use." (and (symbolp reftex-docstruct-symbol) (symbol-value reftex-docstruct-symbol) t)) - + (defun reftex-silence-toc-markers (list n) ;; Set all toc markers in the first N entries in list to nil (while (and list (> (decf n) -1)) @@ -1291,7 +1451,7 @@ Valid actions are: readable, restore, read, kill, write." (master (reftex-TeX-master-file)) (enable-local-variables nil) (file (if (string-match "\\.[a-zA-Z]+\\'" master) - (concat (substring master 0 (match-beginning 0)) + (concat (substring master 0 (match-beginning 0)) reftex-parse-file-extension) (concat master reftex-parse-file-extension)))) (cond @@ -1366,7 +1526,7 @@ Valid actions are: readable, restore, read, kill, write." ;; Check if the master is the same: when moving a document, this will see it. (let* ((real-master (reftex-TeX-master-file)) - (parsed-master + (parsed-master (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol))))) (unless (string= (file-truename real-master) (file-truename parsed-master)) (message "Master file name in load file is different: %s versus %s" @@ -1386,7 +1546,7 @@ Valid actions are: readable, restore, read, kill, write." (defun reftex-select-external-document (xr-alist xr-index) ;; Return index of an external document. (let* ((len (length xr-alist)) (highest (1- (+ ?0 len))) - (prompt (format "[%c-%c] Select TAB: Read prefix with completion" + (prompt (format "[%c-%c] Select TAB: Read prefix with completion" ?0 highest)) key prefix) (cond @@ -1397,7 +1557,7 @@ Valid actions are: readable, restore, read, kill, write." (- 1 xr-index)) (t (save-excursion - (let* ((length (apply 'max (mapcar + (let* ((length (apply 'max (mapcar (lambda(x) (length (car x))) xr-alist))) (fmt (format " [%%c] %%-%ds %%s\n" length)) (n (1- ?0))) @@ -1407,7 +1567,7 @@ Valid actions are: readable, restore, read, kill, write." (concat "SELECT EXTERNAL DOCUMENT\n------------------------\n" (mapconcat - (lambda (x) + (lambda (x) (format fmt (incf n) (or (car x) "") (abbreviate-file-name (cdr x)))) xr-alist "")) @@ -1431,7 +1591,7 @@ When DIE is non-nil, throw an error if file not found." (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t))) (extensions (cdr (assoc type reftex-file-extensions))) (def-ext (car extensions)) - (ext-re (concat "\\(" + (ext-re (concat "\\(" (mapconcat 'regexp-quote extensions "\\|") "\\)\\'")) (files (if (string-match ext-re file) @@ -1504,7 +1664,7 @@ When DIE is non-nil, throw an error if file not found." (reftex-uniquify (reftex-parse-colon-path (mapconcat - (lambda(x) + (lambda(x) (if (string-match "^!" x) (apply 'reftex-process-string (split-string (substring x 1))) @@ -1513,7 +1673,7 @@ When DIE is non-nil, throw an error if file not found." ;; (cdr (assoc type reftex-path-environment)) ;; However, historically we have separate options for the ;; environment variables, so we have to do this: - (symbol-value (intern (concat "reftex-" type + (symbol-value (intern (concat "reftex-" type "path-environment-variables"))) path-separator)))) (put pathvar 'status 'split) @@ -1539,11 +1699,11 @@ When DIE is non-nil, throw an error if file not found." ;; or: Relative recursive path elements need to be expanded ;; relative to new default directory (message "Expanding search path to find %s file: %s ..." type file) - (put pathvar 'recursive-path + (put pathvar 'recursive-path (reftex-expand-path (symbol-value pathvar) master-dir)) (put pathvar 'master-dir master-dir) (get pathvar 'recursive-path)) - (t + (t ;; Recursive path computed earlier is still OK. (get pathvar 'recursive-path))) ;; The simple path was requested @@ -1572,7 +1732,7 @@ When DIE is non-nil, throw an error if file not found." ;; Trailing ! or !! will be converted into `//' (emTeX convention) (mapcar (lambda (dir) - (if (string-match "\\(//+\\|/*!+\\)\\'" dir) + (if (string-match "\\(//+\\|/*!+\\)\\'" dir) (setq dir (replace-match "//" t t dir))) (file-name-as-directory dir)) (delete "" (split-string path (concat path-separator "+"))))) @@ -1601,174 +1761,11 @@ When DIE is non-nil, throw an error if file not found." (when (file-directory-p dir) (setq files (nreverse (directory-files dir t "[^.]"))) (while (setq file (pop files)) - (if (file-directory-p file) + (if (file-directory-p file) (push (file-name-as-directory file) path))) (push dir path1))) path1)) -;;; ========================================================================= -;;; -;;; Parser functions - -(autoload 'reftex-parse-one "reftex-parse" - "Re-parse this file." t) -(autoload 'reftex-parse-all "reftex-parse" - "Re-parse entire document." t) -(autoload 'reftex-do-parse "reftex-parse") -(autoload 'reftex-where-am-I "reftex-parse") -(autoload 'reftex-init-section-numbers "reftex-parse") -(autoload 'reftex-section-info "reftex-parse") -(autoload 'reftex-section-number "reftex-parse") -(autoload 'reftex-what-macro "reftex-parse") -(autoload 'reftex-what-macro-safe "reftex-parse") -(autoload 'reftex-index-info "reftex-parse") -(autoload 'reftex-index-info-safe "reftex-parse") -(autoload 'reftex-short-context "reftex-parse") -(autoload 'reftex-what-environment "reftex-parse") -(autoload 'reftex-what-special-env "reftex-parse") -(autoload 'reftex-move-over-touching-args "reftex-parse") -(autoload 'reftex-notice-new "reftex-parse") -(autoload 'reftex-nth-arg "reftex-parse") -(autoload 'reftex-locate-bibliography-files "reftex-parse") -(autoload 'reftex-ensure-index-support "reftex-parse") -(autoload 'reftex-everything-regexp "reftex-parse") - - -;;; ========================================================================= -;;; -;;; Labels and References - -(autoload 'reftex-label-location "reftex-ref") -(autoload 'reftex-label-info-update "reftex-ref") -(autoload 'reftex-label-info "reftex-ref") -(autoload 'reftex-label "reftex-ref" - "Insert a unique label." t) -(autoload 'reftex-reference "reftex-ref" - "Make a LaTeX reference." t) -(autoload 'reftex-varioref-vref "reftex-ref" - "Make a varioref reference." t) -(autoload 'reftex-fancyref-fref "reftex-ref" - "Make a fancyref \\fref reference." t) -(autoload 'reftex-fancyref-Fref "reftex-ref" - "Make a fancyref \\Fref reference." t) -(autoload 'reftex-show-label-location "reftex-ref") -(autoload 'reftex-query-label-type "reftex-ref") -(autoload 'reftex-goto-label "reftex-ref" - "Prompt for label name and go to that location." t) - -;;; ========================================================================= -;;; -;;; Table of contents - -(autoload 'reftex-toc "reftex-toc" - "Show the table of contents for the current document." t) -(autoload 'reftex-toc-recenter "reftex-toc" - "Display the TOC window and highlight line corresponding to current position." t) -(autoload 'reftex-toggle-auto-toc-recenter "reftex-toc" - "Toggle automatic recentering of TOC window." t) - -;;; ========================================================================= -;;; -;;; BibTeX citations. - -(autoload 'reftex-citep "reftex-cite") -(autoload 'reftex-citet "reftex-cite") -(autoload 'reftex-make-cite-echo-string "reftex-cite") -(autoload 'reftex-get-bibfile-list "reftex-cite") -(autoload 'reftex-pop-to-bibtex-entry "reftex-cite") -(autoload 'reftex-end-of-bib-entry "reftex-cite") -(autoload 'reftex-parse-bibtex-entry "reftex-cite") -(autoload 'reftex-citation "reftex-cite" - "Make a citation using BibTeX database files." t) -(autoload 'reftex-default-bibliography "reftex-cite") -(autoload 'reftex-bib-or-thebib "reftex-cite") -(autoload 'reftex-create-bibtex-file "reftex-cite") - -;;; ========================================================================= -;;; -;;; Selection - -(autoload 'reftex-select-label-mode "reftex-sel") -(autoload 'reftex-select-bib-mode "reftex-sel") -(autoload 'reftex-find-start-point "reftex-sel") -(autoload 'reftex-insert-docstruct "reftex-sel") -(autoload 'reftex-get-offset "reftex-sel") -(autoload 'reftex-select-item "reftex-sel") - - -;;; ========================================================================= -;;; -;;; Index support - -(autoload 'reftex-index "reftex-index" - "Query for an index macro and insert it along with its argments." t) -(autoload 'reftex-index-selection-or-word "reftex-index" - "Put selection or the word near point into the default index macro." t) -(autoload 'reftex-index-phrase-selection-or-word "reftex-index" - "Put selection or the word near point into Index Phrases File." t) -(autoload 'reftex-display-index "reftex-index" - "Display a buffer with an index compiled from the current document." t) -(autoload 'reftex-index-visit-phrases-buffer "reftex-index" - "Visit the Index Phrases File." t) -(autoload 'reftex-index-phrases-mode "reftex-index" - "Major mode for managing the Index phrases of a LaTeX document." t) -(autoload 'reftex-index-complete-tag "reftex-index") -(autoload 'reftex-index-complete-key "reftex-index") -(autoload 'reftex-index-show-entry "reftex-index") -(autoload 'reftex-index-select-tag "reftex-index") - - -;;; ========================================================================= -;;; -;;; View cross references - -(autoload 'reftex-view-crossref "reftex-dcr" - "View cross reference of \\ref or \\cite macro at point." t) -(autoload 'reftex-mouse-view-crossref "reftex-dcr" - "View cross reference of \\ref or \\cite macro where you click." t) -(autoload 'reftex-toggle-auto-view-crossref "reftex-dcr") -(autoload 'reftex-view-crossref-from-bibtex "reftex-dcr" - "View location in a LaTeX document which cites the BibTeX entry at point." t) - - -;;; ========================================================================= -;;; -;;; Operations on entire Multifile documents - -(autoload 'reftex-create-tags-file "reftex-global" - "Create TAGS file by running `etags' on the current document." t) -(autoload 'reftex-grep-document "reftex-global" - "Run grep query through all files related to this document." t) -(autoload 'reftex-search-document "reftex-global" - "Regexp search through all files of the current TeX document." t) -(autoload 'reftex-query-replace-document "reftex-global" - "Run a query-replace-regexp of FROM with TO over the entire TeX document." t) -(autoload 'reftex-find-duplicate-labels "reftex-global" - "Produce a list of all duplicate labels in the document." t) -(autoload 'reftex-change-label "reftex-global" - "Query replace FROM with TO in all \\label and \\ref commands." t) -(autoload 'reftex-renumber-simple-labels "reftex-global" - "Renumber all simple labels in the document to make them sequentially." t) -(autoload 'reftex-save-all-document-buffers "reftex-global" - "Save all documents associated with the current document." t) - - -;;; ========================================================================= -;;; -;;; AUCTeX Interface - -(autoload 'reftex-arg-label "reftex-auc") -(autoload 'reftex-arg-cite "reftex-auc") -(autoload 'reftex-arg-index-tag "reftex-auc") -(autoload 'reftex-arg-index "reftex-auc") -(autoload 'reftex-plug-into-AUCTeX "reftex-auc") -(autoload 'reftex-toggle-plug-into-AUCTeX "reftex-auc" - "Toggle Interface between AUCTeX and RefTeX on and off." t) -(autoload 'reftex-add-label-environments "reftex-auc") -(autoload 'reftex-add-to-label-alist "reftex-auc") -(autoload 'reftex-add-section-levels "reftex-auc") -(autoload 'reftex-notice-new-section "reftex-auc") - ;;; ========================================================================= ;;; ;;; Some generally useful functions @@ -1805,11 +1802,11 @@ When DIE is non-nil, throw an error if file not found." (buffer-substring-no-properties (match-beginning n) (match-end n)))) (defun reftex-region-active-p () - "Is transient-mark-mode on and the region active? -Works on both Emacs and XEmacs." - (if (featurep 'xemacs) - (and zmacs-regions (region-active-p)) - (and transient-mark-mode mark-active))) + "Should we operate on an active region?" + (if (fboundp 'use-region-p) + (use-region-p) + ;; For XEmacs. + (region-active-p))) (defun reftex-kill-buffer (buffer) ;; Kill buffer if it exists. @@ -1825,9 +1822,8 @@ Works on both Emacs and XEmacs." (let ((buffer-read-only nil)) (erase-buffer))) ((setq buffer (get-buffer buffer)) ;; buffer exists - (save-excursion - (set-buffer buffer) - (let ((buffer-read-only nil)) (erase-buffer)))))) + (with-current-buffer buffer + (let ((inhibit-read-only t)) (erase-buffer)))))) (defun reftex-this-word (&optional class) ;; Grab the word around point. @@ -1883,7 +1879,7 @@ Works on both Emacs and XEmacs." (while list (if (funcall predicate (car list)) (push (if completion - (list (nth nth (car list))) + (list (nth nth (car list))) (nth nth (car list))) rtn)) (setq list (cdr list))) @@ -1919,7 +1915,7 @@ Works on both Emacs and XEmacs." ;; If POS is given, calculate distances relative to it. ;; Return nil if there is no match. (let ((pos (point)) - (dist (or max-length (length regexp))) + (dist (or max-length (length regexp))) match1 match2 match) (goto-char (min (+ pos dist) (point-max))) (when (re-search-backward regexp nil t) @@ -1978,7 +1974,7 @@ Works on both Emacs and XEmacs." (let ((char ?\?)) (save-window-excursion (catch 'exit - (message (concat prompt " (?=Help)")) + (message "%s (?=Help)" prompt) (when (or (sit-for (or delay-time 0)) (= ?\? (setq char (read-char-exclusive)))) (reftex-kill-buffer "*RefTeX Select*") @@ -1994,21 +1990,21 @@ Works on both Emacs and XEmacs." (pos-visible-in-window-p (point-max))) nil (setq prompt (concat prompt (if scroll " (SPC/DEL=Scroll)" "")))) - (message prompt) + (message "%s" prompt) (and (equal char ?\?) (setq char (read-char-exclusive))) (while t (cond ((equal char ?\C-g) (keyboard-quit)) ((equal char ?\?)) ((and scroll (equal char ?\ )) (condition-case nil (scroll-up) (error nil)) - (message prompt)) + (message "%s" prompt)) ((and scroll (equal char ?\C-? )) (condition-case nil (scroll-down) (error nil)) - (message prompt)) - (t (message "") + (message "%s" prompt)) + (t (message "") (throw 'exit char))) (setq char (read-char-exclusive))))))) - + (defun reftex-make-regexp-allow-for-ctrl-m (string) ;; convert STRING into a regexp, allowing ^M for \n and vice versa @@ -2066,17 +2062,16 @@ Works on both Emacs and XEmacs." ;; with limited Magic ;; The magic goes away - (let ((format-alist nil) - (auto-mode-alist (reftex-auto-mode-alist)) - (default-major-mode 'fundamental-mode) - (enable-local-variables nil) - (after-insert-file-functions nil)) + (letf ((format-alist nil) + (auto-mode-alist (reftex-auto-mode-alist)) + ((default-value 'major-mode) 'fundamental-mode) + (enable-local-variables nil) + (after-insert-file-functions nil)) (setq buf (find-file-noselect file))) ;; Is there a hook to run? (when (listp reftex-initialize-temporary-buffers) - (save-excursion - (set-buffer buf) + (with-current-buffer buf (run-hooks 'reftex-initialize-temporary-buffers)))) ;; Lets see if we got a license to kill :-| @@ -2103,8 +2098,7 @@ Works on both Emacs and XEmacs." (and (buffer-modified-p buffer) (y-or-n-p (format "Save file %s? " (buffer-file-name buffer))) - (save-excursion - (set-buffer buffer) + (with-current-buffer buffer (save-buffer))) (kill-buffer buffer)) (pop reftex-buffers-to-kill))))) @@ -2206,10 +2200,10 @@ IGNORE-WORDS List of words which should be removed from the string." ;; Restrict number of words (if (> (length words) nwords) (setcdr (nthcdr (1- nwords) words) nil)) - + ;; First, try to use all words (setq string (mapconcat 'identity words sep)) - + ;; Abbreviate words if enforced by user settings or string length (if (or (eq t abbrev) (and abbrev @@ -2301,7 +2295,7 @@ IGNORE-WORDS List of words which should be removed from the string." (font-lock-set-defaults-1) (reftex-select-font-lock-fontify-region (point-min) (point-max)))) (t - ;; Oops? + ;; Oops? (message "Sorry: cannot refontify RefTeX Select buffer.")))) (rename-buffer oldname)))) @@ -2334,23 +2328,21 @@ IGNORE-WORDS List of words which should be removed from the string." (if (facep face) (throw 'exit face))))))) ;; Highlighting uses overlays. For XEmacs, we use extends. -(if (featurep 'xemacs) - (progn - (defalias 'reftex-make-overlay 'make-extent) - (defalias 'reftex-overlay-put 'set-extent-property) - (defalias 'reftex-move-overlay 'set-extent-endpoints) - (defalias 'reftex-delete-overlay 'detach-extent)) - (defalias 'reftex-make-overlay 'make-overlay) - (defalias 'reftex-overlay-put 'overlay-put) - (defalias 'reftex-move-overlay 'move-overlay) - (defalias 'reftex-delete-overlay 'delete-overlay)) +(defalias 'reftex-make-overlay + (if (featurep 'xemacs) 'make-extent 'make-overlay)) +(defalias 'reftex-overlay-put + (if (featurep 'xemacs) 'set-extent-property 'overlay-put)) +(defalias 'reftex-move-overlay + (if (featurep 'xemacs) 'set-extent-endpoints 'move-overlay)) +(defalias 'reftex-delete-overlay + (if (featurep 'xemacs) 'detach-extent 'delete-overlay)) ;; We keep a vector with several different overlays to do our highlighting. (defvar reftex-highlight-overlays [nil nil nil]) ;; Initialize the overlays (aset reftex-highlight-overlays 0 (reftex-make-overlay 1 1)) -(reftex-overlay-put (aref reftex-highlight-overlays 0) +(reftex-overlay-put (aref reftex-highlight-overlays 0) 'face 'highlight) (aset reftex-highlight-overlays 1 (reftex-make-overlay 1 1)) (reftex-overlay-put (aref reftex-highlight-overlays 1) @@ -2375,7 +2367,7 @@ IGNORE-WORDS List of words which should be removed from the string." ;;; ========================================================================= ;;; -;;; Keybindings +;;; Keybindings ;; The default bindings in the mode map. (loop for x in @@ -2395,10 +2387,10 @@ IGNORE-WORDS List of words which should be removed from the string." ;; Bind `reftex-mouse-view-crossref' only when the key is still free (if (featurep 'xemacs) (unless (key-binding [(shift button2)]) - (define-key reftex-mode-map [(shift button2)] + (define-key reftex-mode-map [(shift button2)] 'reftex-mouse-view-crossref)) (unless (key-binding [(shift mouse-2)]) - (define-key reftex-mode-map [(shift mouse-2)] + (define-key reftex-mode-map [(shift mouse-2)] 'reftex-mouse-view-crossref))) ;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map @@ -2407,16 +2399,27 @@ IGNORE-WORDS List of words which should be removed from the string." '(define-key bibtex-mode-map "\C-c&" 'reftex-view-crossref-from-bibtex)) ;; If the user requests so, she can have a few more bindings: +;; For most of these commands there are already bindings in place. +;; Setting `reftex-extra-bindings' really is only there to spare users +;; the hassle of defining bindings in the user space themselves. This +;; is why they violate the key binding recommendations. +(defvar reftex-extra-bindings-map + (let ((map (make-sparse-keymap))) + (define-key map "t" 'reftex-toc) + (define-key map "l" 'reftex-label) + (define-key map "r" 'reftex-reference) + (define-key map "c" 'reftex-citation) + (define-key map "v" 'reftex-view-crossref) + (define-key map "g" 'reftex-grep-document) + (define-key map "s" 'reftex-search-document) + map) + "Reftex extra bindings map") + (when reftex-extra-bindings - (loop for x in - '(("\C-ct" . reftex-toc) - ("\C-cl" . reftex-label) - ("\C-cr" . reftex-reference) - ("\C-cc" . reftex-citation) - ("\C-cv" . reftex-view-crossref) - ("\C-cg" . reftex-grep-document) - ("\C-cs" . reftex-search-document)) - do (define-key reftex-mode-map (car x) (cdr x)))) + (define-key reftex-mode-map + reftex-extra-bindings-prefix + reftex-extra-bindings-map)) + ;;; ========================================================================= ;;; @@ -2500,7 +2503,7 @@ IGNORE-WORDS List of words which should be removed from the string." ("Reference Style" ["Default" (setq reftex-vref-is-default nil reftex-fref-is-default nil) - :style radio :selected (not (or reftex-vref-is-default + :style radio :selected (not (or reftex-vref-is-default reftex-fref-is-default))] ["Varioref" (setq reftex-vref-is-default t reftex-fref-is-default nil) @@ -2535,7 +2538,7 @@ IGNORE-WORDS List of words which should be removed from the string." (list 'reftex-add-index-macros (list 'list (list 'quote (car x)))) :style 'radio :selected (list 'memq (list 'quote (car x)) - (list 'get 'reftex-docstruct-symbol + (list 'get 'reftex-docstruct-symbol (list 'quote 'reftex-index-macros-style))))) reftex-index-macros-builtin)) "--" @@ -2544,7 +2547,7 @@ IGNORE-WORDS List of words which should be removed from the string." ("Customize" ["Browse RefTeX Group" reftex-customize t] "--" - ["Build Full Customize Menu" reftex-create-customize-menu + ["Build Full Customize Menu" reftex-create-customize-menu (fboundp 'customize-menu-create)]) ("Documentation" ["Info" reftex-info t] @@ -2560,7 +2563,7 @@ IGNORE-WORDS List of words which should be removed from the string." (interactive) (if (fboundp 'customize-menu-create) (progn - (easy-menu-change + (easy-menu-change '("Ref") "Customize" `(["Browse RefTeX group" reftex-customize t] "--" @@ -2576,15 +2579,13 @@ IGNORE-WORDS List of words which should be removed from the string." (defun reftex-show-commentary () "Use the finder to view the file documentation from `reftex.el'." (interactive) - (require 'finder) (finder-commentary "reftex.el")) (defun reftex-info (&optional node) "Read documentation for RefTeX in the info system. With optional NODE, go directly to that node." (interactive) - (eval-and-compile (require 'info)) - (Info-goto-node (format "(reftex)%s" (or node "")))) + (info (format "(reftex)%s" (or node "")))) ;;; Install the kill-buffer and kill-emacs hooks ------------------------------ @@ -2598,9 +2599,9 @@ With optional NODE, go directly to that node." ;;; That's it! ---------------------------------------------------------------- (setq reftex-tables-dirty t) ; in case this file is evaluated by hand -(provide 'reftex) +(provide 'reftex) ;;;============================================================================ -;;; arch-tag: 49e0da4e-bd5e-4cfc-a717-fb444fccb9e6 +;; arch-tag: 49e0da4e-bd5e-4cfc-a717-fb444fccb9e6 ;;; reftex.el ends here