1 ;;; reftex-auc.el --- RefTeX's interface to AUCTeX
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 ;; 2006, 2007, 2008 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 (declare-function TeX-argument-insert
"ext:tex" (name optional
&optional prefix
))
37 (declare-function TeX-argument-prompt
"ext:tex" (optional prompt default
&optional complete
))
38 (declare-function multi-prompt
"ext:multi-prompt"
41 &optional mp-predicate require-match initial history
))
42 (declare-function LaTeX-add-index-entries
"ext:tex" (&rest entries
) t
)
43 (declare-function LaTeX-add-labels
"ext:tex" (&rest entries
) t
)
44 (declare-function LaTeX-bibitem-list
"ext:tex" () t
)
45 (declare-function LaTeX-index-entry-list
"ext:tex" () t
)
46 (declare-function LaTeX-label-list
"ext:tex" () t
)
48 (defun reftex-plug-flag (which)
49 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX
50 (or (eq t reftex-plug-into-AUCTeX
)
51 (and (listp reftex-plug-into-AUCTeX
)
52 (nth which reftex-plug-into-AUCTeX
))))
54 (defun reftex-arg-label (optional &optional prompt definition
)
55 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg.
56 What is being used depends upon `reftex-plug-into-AUCTeX'."
59 ((and definition
(reftex-plug-flag 1))
60 ;; Create a new label, with a temporary brace for `reftex-what-macro'
62 (progn (insert "{") (setq label
(or (reftex-label nil t
) "")))
63 (delete-backward-char 1)))
64 ((and (not definition
) (reftex-plug-flag 2))
65 ;; Reference a label with RefTeX
66 (setq label
(reftex-reference nil t
)))
68 ;; AUCTeX's default mechanism
69 (setq label
(completing-read (TeX-argument-prompt optional prompt
"Key")
70 (LaTeX-label-list)))))
71 (if (and definition
(not (string-equal "" label
)))
72 (LaTeX-add-labels label
))
73 (TeX-argument-insert label optional
)))
75 (defun reftex-arg-cite (optional &optional prompt definition
)
76 "Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument.
77 What is being used depends upon `reftex-plug-into-AUCTeX'."
80 ((and (not definition
) (reftex-plug-flag 3))
81 (setq items
(list (or (reftex-citation t
) ""))))
83 (setq prompt
(concat (if optional
"(Optional) " "")
84 (if prompt prompt
"Add key")
86 (setq items
(multi-prompt "," t prompt
(LaTeX-bibitem-list)))))
87 (apply 'LaTeX-add-bibitems items
)
88 (TeX-argument-insert (mapconcat 'identity items
",") optional
)))
91 (defun reftex-arg-index-tag (optional &optional prompt
&rest args
)
92 "Prompt for an index tag with completion.
93 This is the name of an index, not the entry."
95 (setq prompt
(concat (if optional
"(Optional) " "")
96 (if prompt prompt
"Index tag")
98 (if (and reftex-support-index
(reftex-plug-flag 4))
99 ;; Use RefTeX completion
101 (reftex-access-scan-info nil
)
103 (cdr (assoc 'index-tags
104 (symbol-value reftex-docstruct-symbol
)))
105 tag
(completing-read prompt
(mapcar 'list taglist
))))
106 ;; Just ask like AUCTeX does.
107 (setq tag
(read-string prompt
)))
108 (TeX-argument-insert tag optional
)))
110 (defun reftex-arg-index (optional &optional prompt
&rest args
)
111 "Prompt for an index entry completing with known entries.
112 Completion is specific for just one index, if the macro or a tag
113 argument identify one of multiple indices."
115 (if (and reftex-support-index
(reftex-plug-flag 4))
117 (reftex-access-scan-info nil
)
118 (setq tag
(reftex-what-index-tag)
119 key
(reftex-index-complete-key (or tag
"idx"))))
120 (setq key
(completing-read (TeX-argument-prompt optional prompt
"Key")
121 (LaTeX-index-entry-list))))
122 (unless (string-equal "" key
)
123 (LaTeX-add-index-entries key
))
124 (TeX-argument-insert key optional
)))
126 (defun reftex-what-index-tag ()
127 ;; Look backward to find out what index the macro at point belongs to
128 (let ((macro (save-excursion
129 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t
)
133 (setq entry
(assoc macro reftex-index-macro-alist
)))
134 (setq tag
(nth 1 entry
))
139 (goto-char (match-end 1))
140 (or (reftex-nth-arg tag
(nth 6 entry
)) "idx")))
143 (defvar LaTeX-label-function
)
144 (defun reftex-plug-into-AUCTeX ()
145 ;; Replace AUCTeX functions with RefTeX functions.
146 ;; Which functions are replaced is controlled by the variable
147 ;; `reftex-plug-into-AUCTeX'.
149 (if (reftex-plug-flag 0)
150 (setq LaTeX-label-function
'reftex-label
)
151 (setq LaTeX-label-function nil
))
153 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2))
154 (fboundp 'TeX-arg-label
)
155 (fset 'TeX-arg-label
'reftex-arg-label
))
157 (and (reftex-plug-flag 3)
158 (fboundp 'TeX-arg-cite
)
159 (fset 'TeX-arg-cite
'reftex-arg-cite
))
161 (and (reftex-plug-flag 4)
162 (fboundp 'TeX-arg-index-tag
)
163 (fset 'TeX-arg-index-tag
'reftex-arg-index-tag
))
164 (and (reftex-plug-flag 4)
165 (fboundp 'TeX-arg-index
)
166 (fset 'TeX-arg-index
'reftex-arg-index
)))
168 (defun reftex-toggle-plug-into-AUCTeX ()
169 "Toggle Interface between AUCTeX and RefTeX on and off."
171 (unless (and (featurep 'tex-site
) (featurep 'latex
))
172 (error "AUCTeX's LaTeX mode does not seem to be loaded"))
173 (setq reftex-plug-into-AUCTeX
(not reftex-plug-into-AUCTeX
))
174 (reftex-plug-into-AUCTeX)
175 (if reftex-plug-into-AUCTeX
176 (message "RefTeX has been plugged into AUCTeX.")
177 (message "RefTeX no longer interacts with AUCTeX.")))
179 (defun reftex-add-label-environments (entry-list)
180 "Add label environment descriptions to `reftex-label-alist-style'.
181 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there
183 This function makes it possible to support RefTeX from AUCTeX style files.
184 The entries in ENTRY-LIST will be processed after the user settings in
185 `reftex-label-alist', and before the defaults (specified in
186 `reftex-default-label-alist-entries'). Any changes made to
187 `reftex-label-alist-style' will raise a flag to the effect that
188 the label information is recompiled on next use."
189 (unless reftex-docstruct-symbol
190 (reftex-tie-multifile-symbols))
191 (when (and reftex-docstruct-symbol
192 (symbolp reftex-docstruct-symbol
))
193 (let ((list (get reftex-docstruct-symbol
'reftex-label-alist-style
))
196 (setq entry
(pop entry-list
))
197 (unless (member entry list
)
198 (setq reftex-tables-dirty t
202 (put reftex-docstruct-symbol
'reftex-label-alist-style list
)))))
203 (defalias 'reftex-add-to-label-alist
'reftex-add-label-environments
)
205 (defun reftex-add-section-levels (entry-list)
206 "Add entries to the value of `reftex-section-levels'.
207 The added values are kept local to the current document. The format
208 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See
209 `reftex-section-levels' for an example."
210 (unless reftex-docstruct-symbol
211 (reftex-tie-multifile-symbols))
212 (when (and reftex-docstruct-symbol
213 (symbolp reftex-docstruct-symbol
))
214 (let ((list (get reftex-docstruct-symbol
'reftex-section-levels
))
217 (setq entry
(pop entry-list
))
218 (unless (member entry list
)
219 (setq reftex-tables-dirty t
223 (put reftex-docstruct-symbol
'reftex-section-levels list
)))))
225 (defun reftex-notice-new-section ()
226 (reftex-notice-new 1 'force
))
228 ;;; arch-tag: 4a798e68-3405-421c-a09b-0269aac64ab4
229 ;;; reftex-auc.el ends here