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