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