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