1 ;;; reftex-auc.el --- RefTeX's interface to AUCTeX
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007 Free Software Foundation, Inc.
6 ;; Author: Carsten Dominik <dominik@science.uva.nl>
7 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
31 (eval-when-compile (require 'cl
))
36 (defun reftex-plug-flag (which)
37 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX
38 (or (eq t reftex-plug-into-AUCTeX
)
39 (and (listp reftex-plug-into-AUCTeX
)
40 (nth which reftex-plug-into-AUCTeX
))))
42 (defun reftex-arg-label (optional &optional prompt definition
)
43 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg.
44 What is being used depends upon `reftex-plug-into-AUCTeX'."
47 ((and definition
(reftex-plug-flag 1))
48 ;; Create a new label, with a temporary brace for `reftex-what-macro'
50 (progn (insert "{") (setq label
(or (reftex-label nil t
) "")))
51 (delete-backward-char 1)))
52 ((and (not definition
) (reftex-plug-flag 2))
53 ;; Reference a label with RefTeX
54 (setq label
(reftex-reference nil t
)))
56 ;; AUCTeX's default mechanism
57 (setq label
(completing-read (TeX-argument-prompt optional prompt
"Key")
58 (LaTeX-label-list)))))
59 (if (and definition
(not (string-equal "" label
)))
60 (LaTeX-add-labels label
))
61 (TeX-argument-insert label optional
)))
63 (defun reftex-arg-cite (optional &optional prompt definition
)
64 "Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument.
65 What is being used depends upon `reftex-plug-into-AUCTeX'."
68 ((and (not definition
) (reftex-plug-flag 3))
69 (setq items
(list (or (reftex-citation t
) ""))))
71 (setq prompt
(concat (if optional
"(Optional) " "")
72 (if prompt prompt
"Add key")
74 (setq items
(multi-prompt "," t prompt
(LaTeX-bibitem-list)))))
75 (apply 'LaTeX-add-bibitems items
)
76 (TeX-argument-insert (mapconcat 'identity items
",") optional
)))
79 (defun reftex-arg-index-tag (optional &optional prompt
&rest args
)
80 "Prompt for an index tag with completion.
81 This is the name of an index, not the entry."
83 (setq prompt
(concat (if optional
"(Optional) " "")
84 (if prompt prompt
"Index tag")
86 (if (and reftex-support-index
(reftex-plug-flag 4))
87 ;; Use RefTeX completion
89 (reftex-access-scan-info nil
)
91 (cdr (assoc 'index-tags
92 (symbol-value reftex-docstruct-symbol
)))
93 tag
(completing-read prompt
(mapcar 'list taglist
))))
94 ;; Just ask like AUCTeX does.
95 (setq tag
(read-string prompt
)))
96 (TeX-argument-insert tag optional
)))
98 (defun reftex-arg-index (optional &optional prompt
&rest args
)
99 "Prompt for an index entry completing with known entries.
100 Completion is specific for just one index, if the macro or a tag
101 argument identify one of multiple indices."
103 (if (and reftex-support-index
(reftex-plug-flag 4))
105 (reftex-access-scan-info nil
)
106 (setq tag
(reftex-what-index-tag)
107 key
(reftex-index-complete-key (or tag
"idx"))))
108 (setq key
(completing-read (TeX-argument-prompt optional prompt
"Key")
109 (LaTeX-index-entry-list))))
110 (unless (string-equal "" key
)
111 (LaTeX-add-index-entries key
))
112 (TeX-argument-insert key optional
)))
114 (defun reftex-what-index-tag ()
115 ;; Look backward to find out what index the macro at point belongs to
116 (let ((macro (save-excursion
117 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t
)
121 (setq entry
(assoc macro reftex-index-macro-alist
)))
122 (setq tag
(nth 1 entry
))
127 (goto-char (match-end 1))
128 (or (reftex-nth-arg tag
(nth 6 entry
)) "idx")))
131 (defvar LaTeX-label-function
)
132 (defun reftex-plug-into-AUCTeX ()
133 ;; Replace AUCTeX functions with RefTeX functions.
134 ;; Which functions are replaced is controlled by the variable
135 ;; `reftex-plug-into-AUCTeX'.
137 (if (reftex-plug-flag 0)
138 (setq LaTeX-label-function
'reftex-label
)
139 (setq LaTeX-label-function nil
))
141 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2))
142 (fboundp 'TeX-arg-label
)
143 (fset 'TeX-arg-label
'reftex-arg-label
))
145 (and (reftex-plug-flag 3)
146 (fboundp 'TeX-arg-cite
)
147 (fset 'TeX-arg-cite
'reftex-arg-cite
))
149 (and (reftex-plug-flag 4)
150 (fboundp 'TeX-arg-index-tag
)
151 (fset 'TeX-arg-index-tag
'reftex-arg-index-tag
))
152 (and (reftex-plug-flag 4)
153 (fboundp 'TeX-arg-index
)
154 (fset 'TeX-arg-index
'reftex-arg-index
)))
156 (defun reftex-toggle-plug-into-AUCTeX ()
157 "Toggle Interface between AUCTeX and RefTeX on and off."
159 (unless (and (featurep 'tex-site
) (featurep 'latex
))
160 (error "AUCTeX's LaTeX mode does not seem to be loaded"))
161 (setq reftex-plug-into-AUCTeX
(not reftex-plug-into-AUCTeX
))
162 (reftex-plug-into-AUCTeX)
163 (if reftex-plug-into-AUCTeX
164 (message "RefTeX has been plugged into AUCTeX.")
165 (message "RefTeX no longer interacts with AUCTeX.")))
167 (defun reftex-add-label-environments (entry-list)
168 "Add label environment descriptions to `reftex-label-alist-style'.
169 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there
171 This function makes it possible to support RefTeX from AUCTeX style files.
172 The entries in ENTRY-LIST will be processed after the user settings in
173 `reftex-label-alist', and before the defaults (specified in
174 `reftex-default-label-alist-entries'). Any changes made to
175 `reftex-label-alist-style' will raise a flag to the effect that
176 the label information is recompiled on next use."
177 (unless reftex-docstruct-symbol
178 (reftex-tie-multifile-symbols))
179 (when (and reftex-docstruct-symbol
180 (symbolp reftex-docstruct-symbol
))
181 (let ((list (get reftex-docstruct-symbol
'reftex-label-alist-style
))
184 (setq entry
(pop entry-list
))
185 (unless (member entry list
)
186 (setq reftex-tables-dirty t
190 (put reftex-docstruct-symbol
'reftex-label-alist-style list
)))))
191 (defalias 'reftex-add-to-label-alist
'reftex-add-label-environments
)
193 (defun reftex-add-section-levels (entry-list)
194 "Add entries to the value of `reftex-section-levels'.
195 The added values are kept local to the current document. The format
196 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See
197 `reftex-section-levels' for an example."
198 (unless reftex-docstruct-symbol
199 (reftex-tie-multifile-symbols))
200 (when (and reftex-docstruct-symbol
201 (symbolp reftex-docstruct-symbol
))
202 (let ((list (get reftex-docstruct-symbol
'reftex-section-levels
))
205 (setq entry
(pop entry-list
))
206 (unless (member entry list
)
207 (setq reftex-tables-dirty t
211 (put reftex-docstruct-symbol
'reftex-section-levels list
)))))
213 (defun reftex-notice-new-section ()
214 (reftex-notice-new 1 'force
))
216 ;;; arch-tag: 4a798e68-3405-421c-a09b-0269aac64ab4
217 ;;; reftex-auc.el ends here