Mercurial > emacs
annotate lisp/textmodes/reftex-auc.el @ 96849:d049ef97c446
* print.c (print_object): Check print_depth before searching for
circularities.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Mon, 21 Jul 2008 05:02:31 +0000 |
parents | f4a69fedbd46 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
56756 | 1 ;;; reftex-auc.el --- RefTeX's interface to AUCTeX |
74509 | 2 |
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, | |
79719 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
27035 | 5 |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
6 ;; Author: Carsten Dominik <dominik@science.uva.nl> |
76672
690423f53b08
* textmodes/reftex.el: Add maintainer address.
David Kastrup <dak@gnu.org>
parents:
75347
diff
changeset
|
7 ;; Maintainer: auctex-devel@gnu.org |
69094
bfd5c5e60410
Version number change only
Carsten Dominik <dominik@science.uva.nl>
parents:
68648
diff
changeset
|
8 ;; Version: 4.31 |
27035 | 9 |
10 ;; This file is part of GNU Emacs. | |
11 | |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; GNU Emacs is free software: you can redistribute it and/or modify |
27035 | 13 ;; it under the terms of the GNU General Public License as published by |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; the Free Software Foundation, either version 3 of the License, or |
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
15 ;; (at your option) any later version. |
27035 | 16 |
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. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
25280 | 24 |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
25 ;;; Commentary: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
26 |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
27 ;;; Code: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
28 |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
25280 | 30 (provide 'reftex-auc) |
31 (require 'reftex) | |
32 ;;; | |
33 | |
86851
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
34 (declare-function TeX-argument-insert "ext:tex" (name optional &optional prefix)) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
35 (declare-function TeX-argument-prompt "ext:tex" (optional prompt default &optional complete)) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
36 (declare-function multi-prompt "ext:multi-prompt" |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
37 (separator |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
38 unique prompt table |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
39 &optional mp-predicate require-match initial history)) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
40 (declare-function LaTeX-add-index-entries "ext:tex" (&rest entries) t) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
41 (declare-function LaTeX-add-labels "ext:tex" (&rest entries) t) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
42 (declare-function LaTeX-bibitem-list "ext:tex" () t) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
43 (declare-function LaTeX-index-entry-list "ext:tex" () t) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
44 (declare-function LaTeX-label-list "ext:tex" () t) |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
45 |
25280 | 46 (defun reftex-plug-flag (which) |
47 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX | |
48 (or (eq t reftex-plug-into-AUCTeX) | |
49 (and (listp reftex-plug-into-AUCTeX) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
50 (nth which reftex-plug-into-AUCTeX)))) |
25280 | 51 |
52 (defun reftex-arg-label (optional &optional prompt definition) | |
53 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. | |
54 What is being used depends upon `reftex-plug-into-AUCTeX'." | |
55 (let (label) | |
56 (cond | |
57 ((and definition (reftex-plug-flag 1)) | |
58 ;; Create a new label, with a temporary brace for `reftex-what-macro' | |
59 (unwind-protect | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
60 (progn (insert "{") (setq label (or (reftex-label nil t) ""))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
61 (delete-backward-char 1))) |
25280 | 62 ((and (not definition) (reftex-plug-flag 2)) |
63 ;; Reference a label with RefTeX | |
64 (setq label (reftex-reference nil t))) | |
65 (t | |
66 ;; AUCTeX's default mechanism | |
67 (setq label (completing-read (TeX-argument-prompt optional prompt "Key") | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
68 (LaTeX-label-list))))) |
25280 | 69 (if (and definition (not (string-equal "" label))) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
70 (LaTeX-add-labels label)) |
25280 | 71 (TeX-argument-insert label optional))) |
72 | |
73 (defun reftex-arg-cite (optional &optional prompt definition) | |
74 "Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument. | |
75 What is being used depends upon `reftex-plug-into-AUCTeX'." | |
76 (let (items) | |
77 (cond | |
78 ((and (not definition) (reftex-plug-flag 3)) | |
79 (setq items (list (or (reftex-citation t) "")))) | |
80 (t | |
81 (setq prompt (concat (if optional "(Optional) " "") | |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
82 (if prompt prompt "Add key") |
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
83 " (default none): ")) |
25280 | 84 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) |
85 (apply 'LaTeX-add-bibitems items) | |
86 (TeX-argument-insert (mapconcat 'identity items ",") optional))) | |
87 | |
88 | |
89 (defun reftex-arg-index-tag (optional &optional prompt &rest args) | |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
90 "Prompt for an index tag with completion. |
25280 | 91 This is the name of an index, not the entry." |
92 (let (tag taglist) | |
93 (setq prompt (concat (if optional "(Optional) " "") | |
65680
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
94 (if prompt prompt "Index tag") |
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
95 " (default none): ")) |
25280 | 96 (if (and reftex-support-index (reftex-plug-flag 4)) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
97 ;; Use RefTeX completion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
98 (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
99 (reftex-access-scan-info nil) |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
100 (setq taglist |
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
101 (cdr (assoc 'index-tags |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
102 (symbol-value reftex-docstruct-symbol))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
103 tag (completing-read prompt (mapcar 'list taglist)))) |
25280 | 104 ;; Just ask like AUCTeX does. |
105 (setq tag (read-string prompt))) | |
106 (TeX-argument-insert tag optional))) | |
107 | |
108 (defun reftex-arg-index (optional &optional prompt &rest args) | |
109 "Prompt for an index entry completing with known entries. | |
110 Completion is specific for just one index, if the macro or a tag | |
111 argument identify one of multiple indices." | |
112 (let* (tag key) | |
113 (if (and reftex-support-index (reftex-plug-flag 4)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
114 (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
115 (reftex-access-scan-info nil) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
116 (setq tag (reftex-what-index-tag) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
117 key (reftex-index-complete-key (or tag "idx")))) |
25280 | 118 (setq key (completing-read (TeX-argument-prompt optional prompt "Key") |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
119 (LaTeX-index-entry-list)))) |
25280 | 120 (unless (string-equal "" key) |
121 (LaTeX-add-index-entries key)) | |
122 (TeX-argument-insert key optional))) | |
123 | |
124 (defun reftex-what-index-tag () | |
125 ;; Look backward to find out what index the macro at point belongs to | |
126 (let ((macro (save-excursion | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
127 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
128 (match-string 0)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
129 tag entry) |
25280 | 130 (when (and macro |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
131 (setq entry (assoc macro reftex-index-macro-alist))) |
25280 | 132 (setq tag (nth 1 entry)) |
133 (cond | |
134 ((stringp tag) tag) | |
135 ((integerp tag) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
136 (save-excursion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
137 (goto-char (match-end 1)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
138 (or (reftex-nth-arg tag (nth 6 entry)) "idx"))) |
25280 | 139 (t "idx"))))) |
140 | |
141 (defvar LaTeX-label-function) | |
142 (defun reftex-plug-into-AUCTeX () | |
143 ;; Replace AUCTeX functions with RefTeX functions. | |
144 ;; Which functions are replaced is controlled by the variable | |
145 ;; `reftex-plug-into-AUCTeX'. | |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
146 |
25280 | 147 (if (reftex-plug-flag 0) |
148 (setq LaTeX-label-function 'reftex-label) | |
149 (setq LaTeX-label-function nil)) | |
150 | |
151 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2)) | |
152 (fboundp 'TeX-arg-label) | |
153 (fset 'TeX-arg-label 'reftex-arg-label)) | |
154 | |
155 (and (reftex-plug-flag 3) | |
156 (fboundp 'TeX-arg-cite) | |
157 (fset 'TeX-arg-cite 'reftex-arg-cite)) | |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
158 |
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
159 (and (reftex-plug-flag 4) |
25280 | 160 (fboundp 'TeX-arg-index-tag) |
161 (fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) | |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
162 (and (reftex-plug-flag 4) |
25280 | 163 (fboundp 'TeX-arg-index) |
164 (fset 'TeX-arg-index 'reftex-arg-index))) | |
165 | |
166 (defun reftex-toggle-plug-into-AUCTeX () | |
167 "Toggle Interface between AUCTeX and RefTeX on and off." | |
168 (interactive) | |
169 (unless (and (featurep 'tex-site) (featurep 'latex)) | |
170 (error "AUCTeX's LaTeX mode does not seem to be loaded")) | |
171 (setq reftex-plug-into-AUCTeX (not reftex-plug-into-AUCTeX)) | |
172 (reftex-plug-into-AUCTeX) | |
173 (if reftex-plug-into-AUCTeX | |
174 (message "RefTeX has been plugged into AUCTeX.") | |
175 (message "RefTeX no longer interacts with AUCTeX."))) | |
176 | |
177 (defun reftex-add-label-environments (entry-list) | |
178 "Add label environment descriptions to `reftex-label-alist-style'. | |
179 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there | |
180 for details. | |
181 This function makes it possible to support RefTeX from AUCTeX style files. | |
182 The entries in ENTRY-LIST will be processed after the user settings in | |
183 `reftex-label-alist', and before the defaults (specified in | |
184 `reftex-default-label-alist-entries'). Any changes made to | |
185 `reftex-label-alist-style' will raise a flag to the effect that | |
186 the label information is recompiled on next use." | |
187 (unless reftex-docstruct-symbol | |
188 (reftex-tie-multifile-symbols)) | |
189 (when (and reftex-docstruct-symbol | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
190 (symbolp reftex-docstruct-symbol)) |
25280 | 191 (let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
192 entry changed) |
25280 | 193 (while entry-list |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
194 (setq entry (pop entry-list)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
195 (unless (member entry list) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
196 (setq reftex-tables-dirty t |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
197 changed t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
198 (push entry list))) |
25280 | 199 (when changed |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
200 (put reftex-docstruct-symbol 'reftex-label-alist-style list))))) |
25280 | 201 (defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) |
202 | |
203 (defun reftex-add-section-levels (entry-list) | |
204 "Add entries to the value of `reftex-section-levels'. | |
205 The added values are kept local to the current document. The format | |
206 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See | |
207 `reftex-section-levels' for an example." | |
208 (unless reftex-docstruct-symbol | |
209 (reftex-tie-multifile-symbols)) | |
210 (when (and reftex-docstruct-symbol | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
211 (symbolp reftex-docstruct-symbol)) |
25280 | 212 (let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
213 entry changed) |
25280 | 214 (while entry-list |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
215 (setq entry (pop entry-list)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
216 (unless (member entry list) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
217 (setq reftex-tables-dirty t |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
218 changed t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
219 (push entry list))) |
25280 | 220 (when changed |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
221 (put reftex-docstruct-symbol 'reftex-section-levels list))))) |
25280 | 222 |
223 (defun reftex-notice-new-section () | |
224 (reftex-notice-new 1 'force)) | |
225 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
226 ;; arch-tag: 4a798e68-3405-421c-a09b-0269aac64ab4 |
25280 | 227 ;;; reftex-auc.el ends here |