Mercurial > emacs
annotate lisp/textmodes/reftex-auc.el @ 94053:58a4ed015d25
Require 'cl when compiling.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Sun, 13 Apr 2008 00:25:41 +0000 |
parents | 1e3a407766b9 |
children | f4a69fedbd46 |
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 | |
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 | |
78225
b6d25790aab2
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
76672
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
27035 | 15 ;; any later version. |
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 | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
65638
e274642bf5d5
Update FSF street address; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65548
diff
changeset
|
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
e274642bf5d5
Update FSF street address; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65548
diff
changeset
|
25 ;; Boston, MA 02110-1301, USA. |
25280 | 26 |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
27 ;;; Commentary: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
28 |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
29 ;;; Code: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
30 |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
25280 | 32 (provide 'reftex-auc) |
33 (require 'reftex) | |
34 ;;; | |
35 | |
86851
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-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
|
37 (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
|
38 (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
|
39 (separator |
321f32eb4bf5
* erc.el (open-ssl-stream, open-tls-stream, erc-network-name):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
40 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
|
41 &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
|
42 (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
|
43 (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
|
44 (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
|
45 (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
|
46 (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
|
47 |
25280 | 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) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
52 (nth which reftex-plug-into-AUCTeX)))) |
25280 | 53 |
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'." | |
57 (let (label) | |
58 (cond | |
59 ((and definition (reftex-plug-flag 1)) | |
60 ;; Create a new label, with a temporary brace for `reftex-what-macro' | |
61 (unwind-protect | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
62 (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
|
63 (delete-backward-char 1))) |
25280 | 64 ((and (not definition) (reftex-plug-flag 2)) |
65 ;; Reference a label with RefTeX | |
66 (setq label (reftex-reference nil t))) | |
67 (t | |
68 ;; AUCTeX's default mechanism | |
69 (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
|
70 (LaTeX-label-list))))) |
25280 | 71 (if (and definition (not (string-equal "" label))) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
72 (LaTeX-add-labels label)) |
25280 | 73 (TeX-argument-insert label optional))) |
74 | |
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'." | |
78 (let (items) | |
79 (cond | |
80 ((and (not definition) (reftex-plug-flag 3)) | |
81 (setq items (list (or (reftex-citation t) "")))) | |
82 (t | |
83 (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
|
84 (if prompt prompt "Add key") |
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
85 " (default none): ")) |
25280 | 86 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) |
87 (apply 'LaTeX-add-bibitems items) | |
88 (TeX-argument-insert (mapconcat 'identity items ",") optional))) | |
89 | |
90 | |
91 (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
|
92 "Prompt for an index tag with completion. |
25280 | 93 This is the name of an index, not the entry." |
94 (let (tag taglist) | |
95 (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
|
96 (if prompt prompt "Index tag") |
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
97 " (default none): ")) |
25280 | 98 (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
|
99 ;; Use RefTeX completion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
100 (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
101 (reftex-access-scan-info nil) |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
102 (setq taglist |
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
103 (cdr (assoc 'index-tags |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
104 (symbol-value reftex-docstruct-symbol))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
105 tag (completing-read prompt (mapcar 'list taglist)))) |
25280 | 106 ;; Just ask like AUCTeX does. |
107 (setq tag (read-string prompt))) | |
108 (TeX-argument-insert tag optional))) | |
109 | |
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." | |
114 (let* (tag key) | |
115 (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
|
116 (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
117 (reftex-access-scan-info nil) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
118 (setq tag (reftex-what-index-tag) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
119 key (reftex-index-complete-key (or tag "idx")))) |
25280 | 120 (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
|
121 (LaTeX-index-entry-list)))) |
25280 | 122 (unless (string-equal "" key) |
123 (LaTeX-add-index-entries key)) | |
124 (TeX-argument-insert key optional))) | |
125 | |
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 | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
129 (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
|
130 (match-string 0)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
131 tag entry) |
25280 | 132 (when (and macro |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
133 (setq entry (assoc macro reftex-index-macro-alist))) |
25280 | 134 (setq tag (nth 1 entry)) |
135 (cond | |
136 ((stringp tag) tag) | |
137 ((integerp tag) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
138 (save-excursion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
139 (goto-char (match-end 1)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
140 (or (reftex-nth-arg tag (nth 6 entry)) "idx"))) |
25280 | 141 (t "idx"))))) |
142 | |
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'. | |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
148 |
25280 | 149 (if (reftex-plug-flag 0) |
150 (setq LaTeX-label-function 'reftex-label) | |
151 (setq LaTeX-label-function nil)) | |
152 | |
153 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2)) | |
154 (fboundp 'TeX-arg-label) | |
155 (fset 'TeX-arg-label 'reftex-arg-label)) | |
156 | |
157 (and (reftex-plug-flag 3) | |
158 (fboundp 'TeX-arg-cite) | |
159 (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
|
160 |
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
161 (and (reftex-plug-flag 4) |
25280 | 162 (fboundp 'TeX-arg-index-tag) |
163 (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
|
164 (and (reftex-plug-flag 4) |
25280 | 165 (fboundp 'TeX-arg-index) |
166 (fset 'TeX-arg-index 'reftex-arg-index))) | |
167 | |
168 (defun reftex-toggle-plug-into-AUCTeX () | |
169 "Toggle Interface between AUCTeX and RefTeX on and off." | |
170 (interactive) | |
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."))) | |
178 | |
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 | |
182 for details. | |
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 | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
192 (symbolp reftex-docstruct-symbol)) |
25280 | 193 (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
|
194 entry changed) |
25280 | 195 (while entry-list |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
196 (setq entry (pop entry-list)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
197 (unless (member entry list) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
198 (setq reftex-tables-dirty t |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
199 changed t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
200 (push entry list))) |
25280 | 201 (when changed |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
202 (put reftex-docstruct-symbol 'reftex-label-alist-style list))))) |
25280 | 203 (defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) |
204 | |
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 | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
213 (symbolp reftex-docstruct-symbol)) |
25280 | 214 (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
|
215 entry changed) |
25280 | 216 (while entry-list |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
217 (setq entry (pop entry-list)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
218 (unless (member entry list) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
219 (setq reftex-tables-dirty t |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
220 changed t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
221 (push entry list))) |
25280 | 222 (when changed |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
223 (put reftex-docstruct-symbol 'reftex-section-levels list))))) |
25280 | 224 |
225 (defun reftex-notice-new-section () | |
226 (reftex-notice-new 1 'force)) | |
227 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
228 ;; arch-tag: 4a798e68-3405-421c-a09b-0269aac64ab4 |
25280 | 229 ;;; reftex-auc.el ends here |