Mercurial > emacs
annotate lisp/textmodes/reftex-auc.el @ 81111:aab5b38eb929
*** empty log message ***
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Fri, 01 Jun 2007 00:17:08 +0000 |
parents | 690423f53b08 |
children | b6d25790aab2 4ef881a120fe |
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, | |
75347 | 4 ;; 2006, 2007 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 | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
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 | |
36 (defun reftex-plug-flag (which) | |
37 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX | |
38 (or (eq t reftex-plug-into-AUCTeX) | |
39 (and (listp reftex-plug-into-AUCTeX) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
40 (nth which reftex-plug-into-AUCTeX)))) |
25280 | 41 |
42 (defun reftex-arg-label (optional &optional prompt definition) | |
43 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. | |
44 What is being used depends upon `reftex-plug-into-AUCTeX'." | |
45 (let (label) | |
46 (cond | |
47 ((and definition (reftex-plug-flag 1)) | |
48 ;; Create a new label, with a temporary brace for `reftex-what-macro' | |
49 (unwind-protect | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
50 (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
|
51 (delete-backward-char 1))) |
25280 | 52 ((and (not definition) (reftex-plug-flag 2)) |
53 ;; Reference a label with RefTeX | |
54 (setq label (reftex-reference nil t))) | |
55 (t | |
56 ;; AUCTeX's default mechanism | |
57 (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
|
58 (LaTeX-label-list))))) |
25280 | 59 (if (and definition (not (string-equal "" label))) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
60 (LaTeX-add-labels label)) |
25280 | 61 (TeX-argument-insert label optional))) |
62 | |
63 (defun reftex-arg-cite (optional &optional prompt definition) | |
64 "Use `reftex-citation' or AUCTeX's code to insert a cite-key macro argument. | |
65 What is being used depends upon `reftex-plug-into-AUCTeX'." | |
66 (let (items) | |
67 (cond | |
68 ((and (not definition) (reftex-plug-flag 3)) | |
69 (setq items (list (or (reftex-citation t) "")))) | |
70 (t | |
71 (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
|
72 (if prompt prompt "Add key") |
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
73 " (default none): ")) |
25280 | 74 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) |
75 (apply 'LaTeX-add-bibitems items) | |
76 (TeX-argument-insert (mapconcat 'identity items ",") optional))) | |
77 | |
78 | |
79 (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
|
80 "Prompt for an index tag with completion. |
25280 | 81 This is the name of an index, not the entry." |
82 (let (tag taglist) | |
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 "Index tag") |
ed770a0a7846
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents:
65638
diff
changeset
|
85 " (default none): ")) |
25280 | 86 (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
|
87 ;; Use RefTeX completion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
88 (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
89 (reftex-access-scan-info nil) |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
90 (setq taglist |
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
91 (cdr (assoc 'index-tags |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
92 (symbol-value reftex-docstruct-symbol))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
93 tag (completing-read prompt (mapcar 'list taglist)))) |
25280 | 94 ;; Just ask like AUCTeX does. |
95 (setq tag (read-string prompt))) | |
96 (TeX-argument-insert tag optional))) | |
97 | |
98 (defun reftex-arg-index (optional &optional prompt &rest args) | |
99 "Prompt for an index entry completing with known entries. | |
100 Completion is specific for just one index, if the macro or a tag | |
101 argument identify one of multiple indices." | |
102 (let* (tag key) | |
103 (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
|
104 (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
105 (reftex-access-scan-info nil) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
106 (setq tag (reftex-what-index-tag) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
107 key (reftex-index-complete-key (or tag "idx")))) |
25280 | 108 (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
|
109 (LaTeX-index-entry-list)))) |
25280 | 110 (unless (string-equal "" key) |
111 (LaTeX-add-index-entries key)) | |
112 (TeX-argument-insert key optional))) | |
113 | |
114 (defun reftex-what-index-tag () | |
115 ;; Look backward to find out what index the macro at point belongs to | |
116 (let ((macro (save-excursion | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
117 (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
|
118 (match-string 0)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
119 tag entry) |
25280 | 120 (when (and macro |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
121 (setq entry (assoc macro reftex-index-macro-alist))) |
25280 | 122 (setq tag (nth 1 entry)) |
123 (cond | |
124 ((stringp tag) tag) | |
125 ((integerp tag) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
126 (save-excursion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
127 (goto-char (match-end 1)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
128 (or (reftex-nth-arg tag (nth 6 entry)) "idx"))) |
25280 | 129 (t "idx"))))) |
130 | |
131 (defvar LaTeX-label-function) | |
132 (defun reftex-plug-into-AUCTeX () | |
133 ;; Replace AUCTeX functions with RefTeX functions. | |
134 ;; Which functions are replaced is controlled by the variable | |
135 ;; `reftex-plug-into-AUCTeX'. | |
68648
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
136 |
25280 | 137 (if (reftex-plug-flag 0) |
138 (setq LaTeX-label-function 'reftex-label) | |
139 (setq LaTeX-label-function nil)) | |
140 | |
141 (and (or (reftex-plug-flag 1) (reftex-plug-flag 2)) | |
142 (fboundp 'TeX-arg-label) | |
143 (fset 'TeX-arg-label 'reftex-arg-label)) | |
144 | |
145 (and (reftex-plug-flag 3) | |
146 (fboundp 'TeX-arg-cite) | |
147 (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
|
148 |
067115a6e738
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
65680
diff
changeset
|
149 (and (reftex-plug-flag 4) |
25280 | 150 (fboundp 'TeX-arg-index-tag) |
151 (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
|
152 (and (reftex-plug-flag 4) |
25280 | 153 (fboundp 'TeX-arg-index) |
154 (fset 'TeX-arg-index 'reftex-arg-index))) | |
155 | |
156 (defun reftex-toggle-plug-into-AUCTeX () | |
157 "Toggle Interface between AUCTeX and RefTeX on and off." | |
158 (interactive) | |
159 (unless (and (featurep 'tex-site) (featurep 'latex)) | |
160 (error "AUCTeX's LaTeX mode does not seem to be loaded")) | |
161 (setq reftex-plug-into-AUCTeX (not reftex-plug-into-AUCTeX)) | |
162 (reftex-plug-into-AUCTeX) | |
163 (if reftex-plug-into-AUCTeX | |
164 (message "RefTeX has been plugged into AUCTeX.") | |
165 (message "RefTeX no longer interacts with AUCTeX."))) | |
166 | |
167 (defun reftex-add-label-environments (entry-list) | |
168 "Add label environment descriptions to `reftex-label-alist-style'. | |
169 The format of ENTRY-LIST is exactly like `reftex-label-alist'. See there | |
170 for details. | |
171 This function makes it possible to support RefTeX from AUCTeX style files. | |
172 The entries in ENTRY-LIST will be processed after the user settings in | |
173 `reftex-label-alist', and before the defaults (specified in | |
174 `reftex-default-label-alist-entries'). Any changes made to | |
175 `reftex-label-alist-style' will raise a flag to the effect that | |
176 the label information is recompiled on next use." | |
177 (unless reftex-docstruct-symbol | |
178 (reftex-tie-multifile-symbols)) | |
179 (when (and reftex-docstruct-symbol | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
180 (symbolp reftex-docstruct-symbol)) |
25280 | 181 (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
|
182 entry changed) |
25280 | 183 (while entry-list |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
184 (setq entry (pop entry-list)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
185 (unless (member entry list) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
186 (setq reftex-tables-dirty t |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
187 changed t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
188 (push entry list))) |
25280 | 189 (when changed |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
190 (put reftex-docstruct-symbol 'reftex-label-alist-style list))))) |
25280 | 191 (defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) |
192 | |
193 (defun reftex-add-section-levels (entry-list) | |
194 "Add entries to the value of `reftex-section-levels'. | |
195 The added values are kept local to the current document. The format | |
196 of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See | |
197 `reftex-section-levels' for an example." | |
198 (unless reftex-docstruct-symbol | |
199 (reftex-tie-multifile-symbols)) | |
200 (when (and reftex-docstruct-symbol | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
201 (symbolp reftex-docstruct-symbol)) |
25280 | 202 (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
|
203 entry changed) |
25280 | 204 (while entry-list |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
205 (setq entry (pop entry-list)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
206 (unless (member entry list) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
207 (setq reftex-tables-dirty t |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
208 changed t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
209 (push entry list))) |
25280 | 210 (when changed |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
49599
diff
changeset
|
211 (put reftex-docstruct-symbol 'reftex-section-levels list))))) |
25280 | 212 |
213 (defun reftex-notice-new-section () | |
214 (reftex-notice-new 1 'force)) | |
215 | |
52401 | 216 ;;; arch-tag: 4a798e68-3405-421c-a09b-0269aac64ab4 |
25280 | 217 ;;; reftex-auc.el ends here |