Mercurial > emacs
annotate lisp/textmodes/reftex-auc.el @ 38381:377e83704c76
*** empty log message ***
author | Pavel Janík <Pavel@Janik.cz> |
---|---|
date | Thu, 12 Jul 2001 09:42:47 +0000 |
parents | 706af946b1e7 |
children | 7a94f1c588c4 |
rev | line source |
---|---|
25280 | 1 ;;; reftex-auc.el - RefTeX's interface to AUC TeX |
27192
f70a80cecdd3
New version number.
Carsten Dominik <dominik@science.uva.nl>
parents:
27035
diff
changeset
|
2 ;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
27035 | 3 |
4 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
5 ;; Version: 4.16 |
27192
f70a80cecdd3
New version number.
Carsten Dominik <dominik@science.uva.nl>
parents:
27035
diff
changeset
|
6 ;; |
27035 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
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 2, or (at your option) | |
13 ;; any later version. | |
14 | |
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. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
25280 | 24 |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
25 (eval-when-compile (require 'cl)) |
25280 | 26 (provide 'reftex-auc) |
27 (require 'reftex) | |
28 ;;; | |
29 | |
30 (defun reftex-plug-flag (which) | |
31 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX | |
32 (or (eq t reftex-plug-into-AUCTeX) | |
33 (and (listp reftex-plug-into-AUCTeX) | |
34 (nth which reftex-plug-into-AUCTeX)))) | |
35 | |
36 (defun reftex-arg-label (optional &optional prompt definition) | |
37 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. | |
38 What is being used depends upon `reftex-plug-into-AUCTeX'." | |
39 (let (label) | |
40 (cond | |
41 ((and definition (reftex-plug-flag 1)) | |
42 ;; Create a new label, with a temporary brace for `reftex-what-macro' | |
43 (unwind-protect | |
44 (progn (insert "{") (setq label (or (reftex-label nil t) ""))) | |
45 (delete-backward-char 1))) | |
46 ((and (not definition) (reftex-plug-flag 2)) | |
47 ;; Reference a label with RefTeX | |
48 (setq label (reftex-reference nil t))) | |
49 (t | |
50 ;; AUCTeX's default mechanism | |
51 (setq label (completing-read (TeX-argument-prompt optional prompt "Key") | |
52 (LaTeX-label-list))))) | |
53 (if (and definition (not (string-equal "" label))) | |
54 (LaTeX-add-labels label)) | |
55 (TeX-argument-insert label optional))) | |
56 | |
57 (defun reftex-arg-cite (optional &optional prompt definition) | |
58 "Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument. | |
59 What is being used depends upon `reftex-plug-into-AUCTeX'." | |
60 (let (items) | |
61 (cond | |
62 ((and (not definition) (reftex-plug-flag 3)) | |
63 (setq items (list (or (reftex-citation t) "")))) | |
64 (t | |
65 (setq prompt (concat (if optional "(Optional) " "") | |
66 (if prompt prompt "Add key") | |
67 ": (default none) ")) | |
68 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) | |
69 (apply 'LaTeX-add-bibitems items) | |
70 (TeX-argument-insert (mapconcat 'identity items ",") optional))) | |
71 | |
72 | |
73 (defun reftex-arg-index-tag (optional &optional prompt &rest args) | |
74 "Prompt for an index tag with completion. | |
75 This is the name of an index, not the entry." | |
76 (let (tag taglist) | |
77 (setq prompt (concat (if optional "(Optional) " "") | |
78 (if prompt prompt "Index tag") | |
79 ": (default none) ")) | |
80 (if (and reftex-support-index (reftex-plug-flag 4)) | |
81 ;; Use RefTeX completion | |
82 (progn | |
83 (reftex-access-scan-info nil) | |
84 (setq taglist | |
85 (cdr (assoc 'index-tags | |
86 (symbol-value reftex-docstruct-symbol))) | |
87 tag (completing-read prompt (mapcar 'list taglist)))) | |
88 ;; Just ask like AUCTeX does. | |
89 (setq tag (read-string prompt))) | |
90 (TeX-argument-insert tag optional))) | |
91 | |
92 (defun reftex-arg-index (optional &optional prompt &rest args) | |
93 "Prompt for an index entry completing with known entries. | |
94 Completion is specific for just one index, if the macro or a tag | |
95 argument identify one of multiple indices." | |
96 (let* (tag key) | |
97 (if (and reftex-support-index (reftex-plug-flag 4)) | |
98 (progn | |
99 (reftex-access-scan-info nil) | |
100 (setq tag (reftex-what-index-tag) | |
101 key (reftex-index-complete-key (or tag "idx")))) | |
102 (setq key (completing-read (TeX-argument-prompt optional prompt "Key") | |
103 (LaTeX-index-entry-list)))) | |
104 (unless (string-equal "" key) | |
105 (LaTeX-add-index-entries key)) | |
106 (TeX-argument-insert key optional))) | |
107 | |
108 (defun reftex-what-index-tag () | |
109 ;; Look backward to find out what index the macro at point belongs to | |
110 (let ((macro (save-excursion | |
111 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t) | |
112 (match-string 0)))) | |
113 tag entry) | |
114 (when (and macro | |
115 (setq entry (assoc macro reftex-index-macro-alist))) | |
116 (setq tag (nth 1 entry)) | |
117 (cond | |
118 ((stringp tag) tag) | |
119 ((integerp tag) | |
120 (save-excursion | |
121 (goto-char (match-end 1)) | |
122 (or (reftex-nth-arg tag (nth 6 entry)) "idx"))) | |
123 (t "idx"))))) | |
124 | |
125 (defvar LaTeX-label-function) | |
126 (defun reftex-plug-into-AUCTeX () | |
127 ;; Replace AUCTeX functions with RefTeX functions. | |
128 ;; Which functions are replaced is controlled by the variable | |
129 ;; `reftex-plug-into-AUCTeX'. | |
130 | |
131 (if (reftex-plug-flag 0) | |
132 (setq LaTeX-label-function 'reftex-label) | |
133 (setq LaTeX-label-function nil)) | |
134 | |
135 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2)) | |
136 (fboundp 'TeX-arg-label) | |
137 (fset 'TeX-arg-label 'reftex-arg-label)) | |
138 | |
139 (and (reftex-plug-flag 3) | |
140 (fboundp 'TeX-arg-cite) | |
141 (fset 'TeX-arg-cite 'reftex-arg-cite)) | |
142 | |
143 (and (reftex-plug-flag 4) | |
144 (fboundp 'TeX-arg-index-tag) | |
145 (fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) | |
146 (and (reftex-plug-flag 4) | |
147 (fboundp 'TeX-arg-index) | |
148 (fset 'TeX-arg-index 'reftex-arg-index))) | |
149 | |
150 (defun reftex-toggle-plug-into-AUCTeX () | |
151 "Toggle Interface between AUCTeX and RefTeX on and off." | |
152 (interactive) | |
153 (unless (and (featurep 'tex-site) (featurep 'latex)) | |
154 (error "AUCTeX's LaTeX mode does not seem to be loaded")) | |
155 (setq reftex-plug-into-AUCTeX (not reftex-plug-into-AUCTeX)) | |
156 (reftex-plug-into-AUCTeX) | |
157 (if reftex-plug-into-AUCTeX | |
158 (message "RefTeX has been plugged into AUCTeX.") | |
159 (message "RefTeX no longer interacts with AUCTeX."))) | |
160 | |
161 (defun reftex-add-label-environments (entry-list) | |
162 "Add label environment descriptions to `reftex-label-alist-style'. | |
163 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there | |
164 for details. | |
165 This function makes it possible to support RefTeX from AUCTeX style files. | |
166 The entries in ENTRY-LIST will be processed after the user settings in | |
167 `reftex-label-alist', and before the defaults (specified in | |
168 `reftex-default-label-alist-entries'). Any changes made to | |
169 `reftex-label-alist-style' will raise a flag to the effect that | |
170 the label information is recompiled on next use." | |
171 (unless reftex-docstruct-symbol | |
172 (reftex-tie-multifile-symbols)) | |
173 (when (and reftex-docstruct-symbol | |
174 (symbolp reftex-docstruct-symbol)) | |
175 (let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) | |
176 entry changed) | |
177 (while entry-list | |
178 (setq entry (pop entry-list)) | |
179 (unless (member entry list) | |
180 (setq reftex-tables-dirty t | |
181 changed t) | |
182 (push entry list))) | |
183 (when changed | |
184 (put reftex-docstruct-symbol 'reftex-label-alist-style list))))) | |
185 (defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) | |
186 | |
187 (defun reftex-add-section-levels (entry-list) | |
188 "Add entries to the value of `reftex-section-levels'. | |
189 The added values are kept local to the current document. The format | |
190 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See | |
191 `reftex-section-levels' for an example." | |
192 (unless reftex-docstruct-symbol | |
193 (reftex-tie-multifile-symbols)) | |
194 (when (and reftex-docstruct-symbol | |
195 (symbolp reftex-docstruct-symbol)) | |
196 (let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) | |
197 entry changed) | |
198 (while entry-list | |
199 (setq entry (pop entry-list)) | |
200 (unless (member entry list) | |
201 (setq reftex-tables-dirty t | |
202 changed t) | |
203 (push entry list))) | |
204 (when changed | |
205 (put reftex-docstruct-symbol 'reftex-section-levels list))))) | |
206 | |
207 (defun reftex-notice-new-section () | |
208 (reftex-notice-new 1 'force)) | |
209 | |
210 ;;; reftex-auc.el ends here |