emacs/lisp/textmodes/reftex-auc.el

227 lines
8.6 KiB
EmacsLisp
Raw Normal View History

2004-08-22 11:03:22 +00:00
;;; reftex-auc.el --- RefTeX's interface to AUCTeX
2006-12-09 04:06:06 +00:00
;; Copyright (C) 1997-2011 Free Software Foundation, Inc.
1999-12-30 02:57:12 +00:00
2002-07-22 10:38:32 +00:00
;; Author: Carsten Dominik <dominik@science.uva.nl>
;; Maintainer: auctex-devel@gnu.org
2006-02-22 07:21:49 +00:00
;; Version: 4.31
;; Package: reftex
1999-12-30 02:57:12 +00:00
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
1999-12-30 02:57:12 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
1999-12-30 02:57:12 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
1999-08-16 07:42:41 +00:00
;;; Commentary:
;;; Code:
* reftex.el (reftex-compile-variables): respect new structure of `reftex-index-macro' (reftex-compile-variables): Use the changed structure of `reftex-label-alist'. * reftex-vars.el (reftex-index-math-format, (reftex-toc-max-level): New option. reftex-index-phrases-search-whole-words, reftex-index-phrases-case-fold-search, reftex-index-phrases-skip-indexed-matches, reftex-index-phrases-wrap-long-lines, reftex-index-phrases-sort-prefers-entry, reftex-index-phrases-sort-in-blocks): New options. (reftex-index-macros): Option structure changed. (reftex-index-macros-builtin): Added `repeat' item to each entry. (reftex-label-alist): Additional item in each entry to specify if the environment should be listed in the TOC. (eval-when-compile (require 'cl)) added. * reftex-index.el (reftex-index-selection-or-word): No longer deals with "repeat". (reftex-index): "repeat property in `reftex-index-macro-alist' is now used. (reftex-index-phrases-comment-regexp, reftex-index-phrases-macrodef-regexp, reftex-index-phrases-phrase-regexp1, reftex-index-phrases-phrase-regexp2, reftex-index-phrases-phrase-regexp12, reftex-index-phrases-help): New constants. (reftex-index-phrases-macro-data, reftex-index-phrases-files, reftex-index-phrases-font-lock-keywords, reftex-index-phrases-font-lock-defaults, reftex-index-phrases-map, reftex-index-phrases-restrict-file): New variables. (reftex-index-phrase-selection-or-word, reftex-index-visit-phrases-buffer, reftex-index-initialize-phrases-buffer, reftex-index-phrases-save-and-return, reftex-index-phrases-mode, reftex-index-next-phrase, reftex-index-this-phrase, reftex-index-all-phrases, reftex-index-region-phrases, reftex-index-phrases-parse-header, reftex-index-phrases-toggle-restricted, reftex-index-new-phrase, reftex-index-find-next-conflict-phrase, reftex-index-phrases-info, reftex-index-phrases-set-macro-key, reftex-index-sort-phrases, reftex-compare-phrase-lines, reftex-index-make-phrase-regexp, reftex-index-simplify-phrase, reftex-index-phrases-find-dup-re, reftex-index-make-replace-string, reftex-query-index-phrase-globally, reftex-query-index-phrase, reftex-index-phrase-match-is-indexed, reftex-index-phrases-fixup-line, reftex-index-phrases-replace-space, reftex-index-select-phrases-macro): New functions. (reftex-index-globalize, reftex-index-globally): functions removed (eval-when-compile (require 'cl)) added. * reftex-toc.el (reftex-toc-mode): Create new indicator for max level. (reftex-toc-max-level-indicator): New variable. (reftex-toc-max-level): New command. (reftex-toc-map): New keybinding `t'. (reftex-toc-help): Constant updated. (eval-when-compile (require 'cl)) added. * reftex-ref.el (reftex-offer-label-menu): Prefix to `t' command key can change `reftex-toc-max-level' (eval-when-compile (require 'cl)) added. * reftex-sel (reftex-insert-docstruct): Respect `reftex-toc-max-level' (eval-when-compile (require 'cl)) added. * reftex-auc.el (eval-when-compile (require 'cl)) added. * reftex-vcr.el (eval-when-compile (require 'cl)) added. * reftex-cite.el (reftex-citep, reftex-citet): New commands. (reftex-citation, reftex-do-citation, reftex-figure-out-cite-format): Additional argument FORMAT-KEY to preselect a citation format. (eval-when-compile (require 'cl)) added. * reftex-parse.el (reftex-context-substring): Optional parameter to-end (reftex-section-info): Deal with environment matches. (eval-when-compile (require 'cl)) added. * reftex-global.el (eval-when-compile (require 'cl)) added.
1999-12-15 17:02:38 +00:00
(eval-when-compile (require 'cl))
1999-08-16 07:42:41 +00:00
(provide 'reftex-auc)
(require 'reftex)
;;;
(declare-function TeX-argument-insert "ext:tex" (name optional &optional prefix))
(declare-function TeX-argument-prompt "ext:tex" (optional prompt default &optional complete))
(declare-function multi-prompt "ext:multi-prompt"
(separator
unique prompt table
&optional mp-predicate require-match initial history))
(declare-function LaTeX-add-index-entries "ext:tex" (&rest entries) t)
(declare-function LaTeX-add-labels "ext:tex" (&rest entries) t)
(declare-function LaTeX-bibitem-list "ext:tex" () t)
(declare-function LaTeX-index-entry-list "ext:tex" () t)
(declare-function LaTeX-label-list "ext:tex" () t)
1999-08-16 07:42:41 +00:00
(defun reftex-plug-flag (which)
;; Tell if a certain flag is set in reftex-plug-into-AUCTeX
(or (eq t reftex-plug-into-AUCTeX)
(and (listp reftex-plug-into-AUCTeX)
2003-08-11 12:27:02 +00:00
(nth which reftex-plug-into-AUCTeX))))
1999-08-16 07:42:41 +00:00
(defun reftex-arg-label (optional &optional prompt definition)
"Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg.
What is being used depends upon `reftex-plug-into-AUCTeX'."
(let (label)
(cond
((and definition (reftex-plug-flag 1))
;; Create a new label, with a temporary brace for `reftex-what-macro'
(unwind-protect
2003-08-11 12:27:02 +00:00
(progn (insert "{") (setq label (or (reftex-label nil t) "")))
(delete-char -1)))
1999-08-16 07:42:41 +00:00
((and (not definition) (reftex-plug-flag 2))
;; Reference a label with RefTeX
(setq label (reftex-reference nil t)))
(t
;; AUCTeX's default mechanism
(setq label (completing-read (TeX-argument-prompt optional prompt "Key")
2003-08-11 12:27:02 +00:00
(LaTeX-label-list)))))
1999-08-16 07:42:41 +00:00
(if (and definition (not (string-equal "" label)))
2003-08-11 12:27:02 +00:00
(LaTeX-add-labels label))
1999-08-16 07:42:41 +00:00
(TeX-argument-insert label optional)))
(defun reftex-arg-cite (optional &optional prompt definition)
"Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument.
What is being used depends upon `reftex-plug-into-AUCTeX'."
(let (items)
(cond
((and (not definition) (reftex-plug-flag 3))
(setq items (list (or (reftex-citation t) ""))))
(t
(setq prompt (concat (if optional "(Optional) " "")
2005-09-24 Emilio C. Lopes <eclig@gmx.net> * woman.el (woman-file-name): * wid-edit.el (widget-file-prompt-value) (widget-coding-system-prompt-value): * w32-fns.el (set-w32-system-coding-system): * vc.el (vc-version-diff, vc-annotate): * textmodes/reftex-auc.el (reftex-arg-cite) (reftex-arg-index-tag): * textmodes/refer.el (refer-get-bib-files): * textmodes/artist.el (artist-figlet-choose-font): * terminal.el (terminal-emulator): * replace.el (occur-read-primary-args): * rect.el (string-rectangle, string-insert-rectangle): * ps-print.el (ps-print-preprint): * progmodes/pascal.el (pascal-goto-defun): * progmodes/etags.el (visit-tags-table, visit-tags-table-buffer): * progmodes/compile.el (compilation-find-file): * printing.el (pr-interactive-n-up): * play/animate.el (animate-birthday-present): * net/rcompile.el (remote-compile): * man.el (man, Man-goto-section, Man-follow-manual-reference): * mail/rmailsum.el (rmail-summary-search-backward) (rmail-summary-search): * mail/rmailout.el (rmail-output-read-rmail-file-name) (rmail-output-read-file-name): * mail/rmail.el (rmail-search, rmail-search-backwards): * mail/mailabbrev.el (merge-mail-abbrevs, rebuild-mail-abbrevs): * locate.el (locate): * international/quail.el (quail-show-keyboard-layout): * international/mule.el (set-buffer-file-coding-system) (revert-buffer-with-coding-system, set-file-name-coding-system) (set-terminal-coding-system, set-keyboard-coding-system) (set-next-selection-coding-system): * international/mule-diag.el (describe-coding-system) (describe-font, describe-fontset): * international/mule-cmds.el (universal-coding-system-argument) (search-unencodable-char, describe-input-method) (set-language-environment, describe-language-environment): * international/codepage.el (codepage-setup): * international/code-pages.el (codepage-setup): * info.el (Info-search, Info-follow-reference) (Info-search-backward): * emacs-lisp/advice.el (ad-read-advised-function) (ad-read-advice-class, ad-clear-cache, ad-activate) (ad-deactivate, ad-update, ad-unadvise, ad-read-advice-name) (ad-enable-advice, ad-disable-advice, ad-remove-advice) (ad-read-regexp): * ediff-util.el (ediff-toggle-regexp-match): * ediff-ptch.el (ediff-prompt-for-patch-file): * dired-aux.el (dired-diff): * diff.el (diff): * cus-edit.el (custom-variable-prompt): * calendar/timeclock.el (timeclock-ask-for-project): * calc/calcalg3.el (calc-get-fit-variables): * calc/calc-store.el (calc-edit-variable) (calc-permanent-variable): * vc-mcvs.el (vc-mcvs-register): * shadowfile.el (shadow-define-literal-group): * woman.el (woman-file-name): * vc.el (vc-version-diff, vc-merge): * textmodes/reftex-index.el (reftex-index-complete-tag): * format.el (format-decode-buffer, format-decode-region): * emulation/viper-cmd.el (viper-read-string-with-history): * emacs-lisp/debug.el (cancel-debug-on-entry): * emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine): * ediff.el (ediff-merge-revisions) (ediff-merge-revisions-with-ancestor, ediff-revision): * completion.el (interactive-completion-string-reader): * calc/calc-prog.el (calc-user-define-formula): Follow convention for reading with the minibuffer.
2005-09-24 13:44:02 +00:00
(if prompt prompt "Add key")
" (default none): "))
1999-08-16 07:42:41 +00:00
(setq items (multi-prompt "," t prompt (LaTeX-bibitem-list)))))
(apply 'LaTeX-add-bibitems items)
(TeX-argument-insert (mapconcat 'identity items ",") optional)))
(defun reftex-arg-index-tag (optional &optional prompt &rest args)
2006-02-06 12:31:40 +00:00
"Prompt for an index tag with completion.
1999-08-16 07:42:41 +00:00
This is the name of an index, not the entry."
(let (tag taglist)
(setq prompt (concat (if optional "(Optional) " "")
2005-09-24 Emilio C. Lopes <eclig@gmx.net> * woman.el (woman-file-name): * wid-edit.el (widget-file-prompt-value) (widget-coding-system-prompt-value): * w32-fns.el (set-w32-system-coding-system): * vc.el (vc-version-diff, vc-annotate): * textmodes/reftex-auc.el (reftex-arg-cite) (reftex-arg-index-tag): * textmodes/refer.el (refer-get-bib-files): * textmodes/artist.el (artist-figlet-choose-font): * terminal.el (terminal-emulator): * replace.el (occur-read-primary-args): * rect.el (string-rectangle, string-insert-rectangle): * ps-print.el (ps-print-preprint): * progmodes/pascal.el (pascal-goto-defun): * progmodes/etags.el (visit-tags-table, visit-tags-table-buffer): * progmodes/compile.el (compilation-find-file): * printing.el (pr-interactive-n-up): * play/animate.el (animate-birthday-present): * net/rcompile.el (remote-compile): * man.el (man, Man-goto-section, Man-follow-manual-reference): * mail/rmailsum.el (rmail-summary-search-backward) (rmail-summary-search): * mail/rmailout.el (rmail-output-read-rmail-file-name) (rmail-output-read-file-name): * mail/rmail.el (rmail-search, rmail-search-backwards): * mail/mailabbrev.el (merge-mail-abbrevs, rebuild-mail-abbrevs): * locate.el (locate): * international/quail.el (quail-show-keyboard-layout): * international/mule.el (set-buffer-file-coding-system) (revert-buffer-with-coding-system, set-file-name-coding-system) (set-terminal-coding-system, set-keyboard-coding-system) (set-next-selection-coding-system): * international/mule-diag.el (describe-coding-system) (describe-font, describe-fontset): * international/mule-cmds.el (universal-coding-system-argument) (search-unencodable-char, describe-input-method) (set-language-environment, describe-language-environment): * international/codepage.el (codepage-setup): * international/code-pages.el (codepage-setup): * info.el (Info-search, Info-follow-reference) (Info-search-backward): * emacs-lisp/advice.el (ad-read-advised-function) (ad-read-advice-class, ad-clear-cache, ad-activate) (ad-deactivate, ad-update, ad-unadvise, ad-read-advice-name) (ad-enable-advice, ad-disable-advice, ad-remove-advice) (ad-read-regexp): * ediff-util.el (ediff-toggle-regexp-match): * ediff-ptch.el (ediff-prompt-for-patch-file): * dired-aux.el (dired-diff): * diff.el (diff): * cus-edit.el (custom-variable-prompt): * calendar/timeclock.el (timeclock-ask-for-project): * calc/calcalg3.el (calc-get-fit-variables): * calc/calc-store.el (calc-edit-variable) (calc-permanent-variable): * vc-mcvs.el (vc-mcvs-register): * shadowfile.el (shadow-define-literal-group): * woman.el (woman-file-name): * vc.el (vc-version-diff, vc-merge): * textmodes/reftex-index.el (reftex-index-complete-tag): * format.el (format-decode-buffer, format-decode-region): * emulation/viper-cmd.el (viper-read-string-with-history): * emacs-lisp/debug.el (cancel-debug-on-entry): * emacs-lisp/checkdoc.el (checkdoc-this-string-valid-engine): * ediff.el (ediff-merge-revisions) (ediff-merge-revisions-with-ancestor, ediff-revision): * completion.el (interactive-completion-string-reader): * calc/calc-prog.el (calc-user-define-formula): Follow convention for reading with the minibuffer.
2005-09-24 13:44:02 +00:00
(if prompt prompt "Index tag")
" (default none): "))
1999-08-16 07:42:41 +00:00
(if (and reftex-support-index (reftex-plug-flag 4))
2003-08-11 12:27:02 +00:00
;; Use RefTeX completion
(progn
(reftex-access-scan-info nil)
2006-02-06 12:31:40 +00:00
(setq taglist
(cdr (assoc 'index-tags
2003-08-11 12:27:02 +00:00
(symbol-value reftex-docstruct-symbol)))
tag (completing-read prompt (mapcar 'list taglist))))
1999-08-16 07:42:41 +00:00
;; Just ask like AUCTeX does.
(setq tag (read-string prompt)))
(TeX-argument-insert tag optional)))
(defun reftex-arg-index (optional &optional prompt &rest args)
"Prompt for an index entry completing with known entries.
Completion is specific for just one index, if the macro or a tag
argument identify one of multiple indices."
(let* (tag key)
(if (and reftex-support-index (reftex-plug-flag 4))
2003-08-11 12:27:02 +00:00
(progn
(reftex-access-scan-info nil)
(setq tag (reftex-what-index-tag)
key (reftex-index-complete-key (or tag "idx"))))
1999-08-16 07:42:41 +00:00
(setq key (completing-read (TeX-argument-prompt optional prompt "Key")
2003-08-11 12:27:02 +00:00
(LaTeX-index-entry-list))))
1999-08-16 07:42:41 +00:00
(unless (string-equal "" key)
(LaTeX-add-index-entries key))
(TeX-argument-insert key optional)))
(defun reftex-what-index-tag ()
;; Look backward to find out what index the macro at point belongs to
(let ((macro (save-excursion
2003-08-11 12:27:02 +00:00
(and (re-search-backward "\\\\[a-zA-Z*]+" nil t)
(match-string 0))))
tag entry)
1999-08-16 07:42:41 +00:00
(when (and macro
2003-08-11 12:27:02 +00:00
(setq entry (assoc macro reftex-index-macro-alist)))
1999-08-16 07:42:41 +00:00
(setq tag (nth 1 entry))
(cond
((stringp tag) tag)
((integerp tag)
2003-08-11 12:27:02 +00:00
(save-excursion
(goto-char (match-end 1))
(or (reftex-nth-arg tag (nth 6 entry)) "idx")))
1999-08-16 07:42:41 +00:00
(t "idx")))))
(defvar LaTeX-label-function)
(defun reftex-plug-into-AUCTeX ()
;; Replace AUCTeX functions with RefTeX functions.
;; Which functions are replaced is controlled by the variable
;; `reftex-plug-into-AUCTeX'.
2006-02-06 12:31:40 +00:00
1999-08-16 07:42:41 +00:00
(if (reftex-plug-flag 0)
(setq LaTeX-label-function 'reftex-label)
(setq LaTeX-label-function nil))
(and (or (reftex-plug-flag 1) (reftex-plug-flag 2))
(fboundp 'TeX-arg-label)
(fset 'TeX-arg-label 'reftex-arg-label))
(and (reftex-plug-flag 3)
(fboundp 'TeX-arg-cite)
(fset 'TeX-arg-cite 'reftex-arg-cite))
2006-02-06 12:31:40 +00:00
(and (reftex-plug-flag 4)
1999-08-16 07:42:41 +00:00
(fboundp 'TeX-arg-index-tag)
(fset 'TeX-arg-index-tag 'reftex-arg-index-tag))
2006-02-06 12:31:40 +00:00
(and (reftex-plug-flag 4)
1999-08-16 07:42:41 +00:00
(fboundp 'TeX-arg-index)
(fset 'TeX-arg-index 'reftex-arg-index)))
(defun reftex-toggle-plug-into-AUCTeX ()
"Toggle Interface between AUCTeX and RefTeX on and off."
(interactive)
(unless (and (featurep 'tex-site) (featurep 'latex))
(error "AUCTeX's LaTeX mode does not seem to be loaded"))
(setq reftex-plug-into-AUCTeX (not reftex-plug-into-AUCTeX))
(reftex-plug-into-AUCTeX)
(if reftex-plug-into-AUCTeX
(message "RefTeX has been plugged into AUCTeX.")
(message "RefTeX no longer interacts with AUCTeX.")))
(defun reftex-add-label-environments (entry-list)
"Add label environment descriptions to `reftex-label-alist-style'.
The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there
for details.
This function makes it possible to support RefTeX from AUCTeX style files.
The entries in ENTRY-LIST will be processed after the user settings in
`reftex-label-alist', and before the defaults (specified in
`reftex-default-label-alist-entries'). Any changes made to
`reftex-label-alist-style' will raise a flag to the effect that
the label information is recompiled on next use."
(unless reftex-docstruct-symbol
(reftex-tie-multifile-symbols))
(when (and reftex-docstruct-symbol
2003-08-11 12:27:02 +00:00
(symbolp reftex-docstruct-symbol))
1999-08-16 07:42:41 +00:00
(let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style))
2003-08-11 12:27:02 +00:00
entry changed)
1999-08-16 07:42:41 +00:00
(while entry-list
2003-08-11 12:27:02 +00:00
(setq entry (pop entry-list))
(unless (member entry list)
(setq reftex-tables-dirty t
changed t)
(push entry list)))
1999-08-16 07:42:41 +00:00
(when changed
2003-08-11 12:27:02 +00:00
(put reftex-docstruct-symbol 'reftex-label-alist-style list)))))
1999-08-16 07:42:41 +00:00
(defalias 'reftex-add-to-label-alist 'reftex-add-label-environments)
(defun reftex-add-section-levels (entry-list)
"Add entries to the value of `reftex-section-levels'.
The added values are kept local to the current document. The format
of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See
`reftex-section-levels' for an example."
(unless reftex-docstruct-symbol
(reftex-tie-multifile-symbols))
(when (and reftex-docstruct-symbol
2003-08-11 12:27:02 +00:00
(symbolp reftex-docstruct-symbol))
1999-08-16 07:42:41 +00:00
(let ((list (get reftex-docstruct-symbol 'reftex-section-levels))
2003-08-11 12:27:02 +00:00
entry changed)
1999-08-16 07:42:41 +00:00
(while entry-list
2003-08-11 12:27:02 +00:00
(setq entry (pop entry-list))
(unless (member entry list)
(setq reftex-tables-dirty t
changed t)
(push entry list)))
1999-08-16 07:42:41 +00:00
(when changed
2003-08-11 12:27:02 +00:00
(put reftex-docstruct-symbol 'reftex-section-levels list)))))
1999-08-16 07:42:41 +00:00
(defun reftex-notice-new-section ()
(reftex-notice-new 1 'force))
;;; reftex-auc.el ends here