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