Mercurial > emacs
annotate lisp/textmodes/reftex-parse.el @ 46677:86e8d59e2e49
*** empty log message ***
author | Dave Love <fx@gnu.org> |
---|---|
date | Wed, 24 Jul 2002 23:01:32 +0000 |
parents | ba53f9632b14 |
children | 060f433ebf11 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
1 ;;; reftex-parse.el --- parser functions for RefTeX |
27192
f70a80cecdd3
New version number.
Carsten Dominik <dominik@science.uva.nl>
parents:
27035
diff
changeset
|
2 ;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
27035 | 3 |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
4 ;; Author: Carsten Dominik <dominik@science.uva.nl> |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
5 ;; Version: 4.17 |
27192
f70a80cecdd3
New version number.
Carsten Dominik <dominik@science.uva.nl>
parents:
27035
diff
changeset
|
6 ;; |
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:
25803
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
25280 | 30 (provide 'reftex-parse) |
31 (require 'reftex) | |
32 | |
33 (defmacro reftex-with-special-syntax (&rest body) | |
34 `(let ((saved-syntax (syntax-table))) | |
35 (unwind-protect | |
36 (progn | |
37 (set-syntax-table reftex-syntax-table) | |
27602
7f69a3b899d8
(reftex-with-special-syntax): Bind `case-fold-search' to nil.
Carsten Dominik <dominik@science.uva.nl>
parents:
27192
diff
changeset
|
38 (let ((case-fold-search nil)) |
7f69a3b899d8
(reftex-with-special-syntax): Bind `case-fold-search' to nil.
Carsten Dominik <dominik@science.uva.nl>
parents:
27192
diff
changeset
|
39 ,@body)) |
25280 | 40 (set-syntax-table saved-syntax)))) |
41 | |
42 (defun reftex-parse-one () | |
43 "Re-parse this file." | |
44 (interactive) | |
45 (let ((reftex-enable-partial-scans t)) | |
46 (reftex-access-scan-info '(4)))) | |
47 | |
48 (defun reftex-parse-all () | |
49 "Re-parse entire document." | |
50 (interactive) | |
51 (reftex-access-scan-info '(16))) | |
52 | |
53 (defun reftex-do-parse (rescan &optional file) | |
54 "Do a document rescan. When allowed, do only a partial scan from FILE." | |
55 | |
56 ;; Normalize the rescan argument | |
57 (setq rescan (cond ((eq rescan t) t) | |
58 ((eq rescan 1) 1) | |
59 ((equal rescan '(4)) t) | |
60 ((equal rescan '(16)) 1) | |
61 (t 1))) | |
62 | |
63 ;; Partial scans only when allowed | |
64 (unless reftex-enable-partial-scans | |
65 (setq rescan 1)) | |
66 | |
67 ;; Do the scanning. | |
68 | |
69 (let* ((old-list (symbol-value reftex-docstruct-symbol)) | |
70 (master (reftex-TeX-master-file)) | |
71 (true-master (file-truename master)) | |
72 (master-dir (file-name-as-directory (file-name-directory master))) | |
73 (file (or file (buffer-file-name))) | |
74 (true-file (file-truename file)) | |
75 (bibview-cache (assq 'bibview-cache old-list)) | |
76 (index-tags (cdr (assq 'index-tags old-list))) | |
77 from-file appendix docstruct tmp) | |
78 | |
79 ;; Make sure replacement is really an option here | |
80 (when (and (eq rescan t) | |
81 (not (and (member (list 'bof file) old-list) | |
82 (member (list 'eof file) old-list)))) | |
83 ;; Scan whole document because no such file section exists | |
84 (setq rescan 1)) | |
85 (when (string= true-file true-master) | |
86 ;; Scan whole document because this file is the master | |
87 (setq rescan 1)) | |
88 | |
89 ;; From which file do we start? | |
90 (setq from-file | |
91 (cond ((eq rescan t) (or file master)) | |
92 ((eq rescan 1) master) | |
93 (t (error "This should not happen (reftex-do-parse)")))) | |
94 | |
95 ;; Reset index-tags if we scan everything | |
96 (if (equal rescan 1) (setq index-tags nil)) | |
97 | |
98 ;; Find active toc entry and initialize section-numbers | |
99 (setq reftex-active-toc (reftex-last-assoc-before-elt | |
100 'toc (list 'bof from-file) old-list) | |
101 appendix (reftex-last-assoc-before-elt | |
102 'appendix (list 'bof from-file) old-list)) | |
103 | |
104 (reftex-init-section-numbers reftex-active-toc appendix) | |
105 | |
106 (if (eq rescan 1) | |
107 (message "Scanning entire document...") | |
108 (message "Scanning document from %s..." from-file)) | |
109 | |
110 (reftex-with-special-syntax | |
111 (save-window-excursion | |
112 (save-excursion | |
113 (unwind-protect | |
114 (setq docstruct | |
115 (reftex-parse-from-file | |
116 from-file docstruct master-dir)) | |
117 (reftex-kill-temporary-buffers))))) | |
118 | |
119 (message "Scanning document... done") | |
120 | |
121 ;; Turn the list around. | |
122 (setq docstruct (nreverse docstruct)) | |
123 | |
124 ;; Set or insert | |
125 (setq docstruct (reftex-replace-label-list-segment | |
126 old-list docstruct (eq rescan 1))) | |
127 | |
128 ;; Add all missing information | |
129 (unless (assq 'label-numbers docstruct) | |
130 (push (cons 'label-numbers nil) docstruct)) | |
131 (unless (assq 'master-dir docstruct) | |
132 (push (cons 'master-dir master-dir) docstruct)) | |
133 (unless (assq 'bibview-cache docstruct) | |
134 (push (cons 'bibview-cache (cdr bibview-cache)) docstruct)) | |
135 (let* ((bof1 (memq (assq 'bof docstruct) docstruct)) | |
136 (bof2 (assq 'bof (cdr bof1))) | |
137 (is-multi (not (not (and bof1 bof2)))) | |
138 (entry (or (assq 'is-multi docstruct) | |
139 (car (push (list 'is-multi is-multi) docstruct))))) | |
140 (setcdr entry (cons is-multi nil))) | |
141 (and index-tags (setq index-tags (sort index-tags 'string<))) | |
142 (let ((index-tag-cell (assq 'index-tags docstruct))) | |
143 (if index-tag-cell | |
144 (setcdr index-tag-cell index-tags) | |
145 (push (cons 'index-tags index-tags) docstruct))) | |
146 (unless (assq 'xr docstruct) | |
147 (let* ((allxr (reftex-all-assq 'xr-doc docstruct)) | |
148 (alist (mapcar | |
149 (lambda (x) | |
150 (if (setq tmp (reftex-locate-file (nth 2 x) "tex" | |
151 master-dir)) | |
152 (cons (nth 1 x) tmp) | |
153 (message "Can't find external document %s" | |
154 (nth 2 x)) | |
155 nil)) | |
156 allxr)) | |
157 (alist (delq nil alist)) | |
158 (allprefix (delq nil (mapcar 'car alist))) | |
159 (regexp (if allprefix | |
160 (concat "\\`\\(" | |
161 (mapconcat 'identity allprefix "\\|") | |
162 "\\)") | |
163 "\\\\\\\\\\\\"))) ; this will never match | |
164 (push (list 'xr alist regexp) docstruct))) | |
165 | |
166 (set reftex-docstruct-symbol docstruct) | |
167 (put reftex-docstruct-symbol 'modified t))) | |
168 | |
169 (defun reftex-everything-regexp () | |
170 (if reftex-support-index | |
171 reftex-everything-regexp | |
172 reftex-everything-regexp-no-index)) | |
173 | |
174 (defun reftex-all-document-files (&optional relative) | |
175 "Return a list of all files belonging to the current document. | |
176 When RELATIVE is non-nil, give file names relative to directory | |
177 of master file." | |
178 (let* ((all (symbol-value reftex-docstruct-symbol)) | |
179 (master-dir (file-name-directory (reftex-TeX-master-file))) | |
180 (re (concat "\\`" (regexp-quote master-dir))) | |
181 file-list tmp file) | |
182 (while (setq tmp (assoc 'bof all)) | |
183 (setq file (nth 1 tmp) | |
184 all (cdr (memq tmp all))) | |
185 (and relative | |
186 (string-match re file) | |
187 (setq file (substring file (match-end 0)))) | |
188 (push file file-list)) | |
189 (nreverse file-list))) | |
190 | |
191 (defun reftex-parse-from-file (file docstruct master-dir) | |
192 ;; Scan the buffer for labels and save them in a list. | |
193 (let ((regexp (reftex-everything-regexp)) | |
194 (bound 0) | |
195 file-found tmp include-file | |
196 (level 1) | |
197 (highest-level 100) | |
198 toc-entry index-entry next-buf buf) | |
199 | |
200 (catch 'exit | |
201 (setq file-found (reftex-locate-file file "tex" master-dir)) | |
202 (if (and (not file-found) | |
203 (setq buf (reftex-get-buffer-visiting file))) | |
204 (setq file-found (buffer-file-name buf))) | |
205 | |
206 (unless file-found | |
207 (push (list 'file-error file) docstruct) | |
208 (throw 'exit nil)) | |
209 | |
210 (save-excursion | |
211 | |
212 (message "Scanning file %s" file) | |
213 (set-buffer | |
214 (setq next-buf | |
215 (reftex-get-file-buffer-force | |
216 file-found | |
217 (not (eq t reftex-keep-temporary-buffers))))) | |
218 | |
219 ;; Begin of file mark | |
220 (setq file (buffer-file-name)) | |
221 (push (list 'bof file) docstruct) | |
222 | |
223 (reftex-with-special-syntax | |
224 (save-excursion | |
225 (save-restriction | |
226 (widen) | |
227 (goto-char 1) | |
228 | |
229 (while (re-search-forward regexp nil t) | |
230 | |
231 (cond | |
232 | |
233 ((match-end 1) | |
234 ;; It is a label | |
235 (push (reftex-label-info (reftex-match-string 1) file bound) | |
236 docstruct)) | |
237 | |
238 ((match-end 3) | |
239 ;; It is a section | |
240 (setq bound (point)) | |
241 | |
242 ;; Insert in List | |
243 (setq toc-entry (reftex-section-info file)) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
244 (when toc-entry |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
245 ;; It can happen that section info returns nil |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
246 (setq level (nth 5 toc-entry)) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
247 (setq highest-level (min highest-level level)) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
248 (if (= level highest-level) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
249 (message |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
250 "Scanning %s %s ..." |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
251 (car (rassoc level reftex-section-levels-all)) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
252 (nth 6 toc-entry))) |
25280 | 253 |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
254 (push toc-entry docstruct) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
255 (setq reftex-active-toc toc-entry))) |
25280 | 256 |
257 ((match-end 7) | |
258 ;; It's an include or input | |
259 (setq include-file (reftex-match-string 7)) | |
260 ;; Test if this file should be ignored | |
261 (unless (delq nil (mapcar | |
262 (lambda (x) (string-match x include-file)) | |
263 reftex-no-include-regexps)) | |
264 ;; Parse it | |
265 (setq docstruct | |
266 (reftex-parse-from-file | |
267 include-file | |
268 docstruct master-dir)))) | |
269 | |
270 ((match-end 9) | |
271 ;; Appendix starts here | |
272 (reftex-init-section-numbers nil t) | |
273 (push (cons 'appendix t) docstruct)) | |
274 | |
275 ((match-end 10) | |
276 ;; Index entry | |
277 (when reftex-support-index | |
278 (setq index-entry (reftex-index-info file)) | |
279 (when index-entry | |
280 (add-to-list 'index-tags (nth 1 index-entry)) | |
281 (push index-entry docstruct)))) | |
282 | |
283 ((match-end 11) | |
284 ;; A macro with label | |
285 (save-excursion | |
286 (let* ((mac (reftex-match-string 11)) | |
287 (label (progn (goto-char (match-end 11)) | |
288 (save-match-data | |
289 (reftex-no-props | |
290 (reftex-nth-arg-wrapper | |
291 mac))))) | |
292 (typekey (nth 1 (assoc mac reftex-env-or-mac-alist))) | |
293 (entry (progn (if typekey | |
294 ;; A typing macro | |
295 (goto-char (match-end 0)) | |
296 ;; A neutral macro | |
297 (goto-char (match-end 11)) | |
298 (reftex-move-over-touching-args)) | |
299 (reftex-label-info | |
300 label file bound nil nil)))) | |
301 (push entry docstruct)))) | |
302 (t (error "This should not happen (reftex-parse-from-file)"))) | |
303 ) | |
304 | |
305 ;; Find bibliography statement | |
306 (when (setq tmp (reftex-locate-bibliography-files master-dir)) | |
307 (push (cons 'bib tmp) docstruct)) | |
308 | |
309 (goto-char 1) | |
310 (when (re-search-forward | |
311 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) | |
312 (push (cons 'thebib file) docstruct)) | |
313 | |
314 ;; Find external document specifications | |
315 (goto-char 1) | |
316 (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t) | |
317 (push (list 'xr-doc (reftex-match-string 2) | |
318 (reftex-match-string 3)) | |
319 docstruct)) | |
320 | |
321 ;; End of file mark | |
322 (push (list 'eof file) docstruct))))) | |
323 | |
324 ;; Kill the scanned buffer | |
325 (reftex-kill-temporary-buffers next-buf)) | |
326 | |
327 ;; Return the list | |
328 docstruct)) | |
329 | |
330 (defun reftex-locate-bibliography-files (master-dir &optional files) | |
331 ;; Scan buffer for bibliography macro and return file list. | |
332 | |
333 (unless files | |
334 (save-excursion | |
335 (goto-char (point-min)) | |
336 (if (re-search-forward | |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
337 (concat |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
338 "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\(" |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
339 (mapconcat 'identity reftex-bibliography-commands "\\|") |
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
340 "\\){[ \t]*\\([^}]+\\)") nil t) |
25280 | 341 (setq files |
29775
31536c6cf2e3
* textmodes/reftex.el (reftex-find-citation-regexp-format):
Carsten Dominik <dominik@science.uva.nl>
parents:
27602
diff
changeset
|
342 (split-string (reftex-match-string 3) |
25280 | 343 "[ \t\n\r]*,[ \t\n\r]*"))))) |
344 (when files | |
345 (setq files | |
346 (mapcar | |
347 (lambda (x) | |
348 (if (or (member x reftex-bibfile-ignore-list) | |
349 (delq nil (mapcar (lambda (re) (string-match re x)) | |
350 reftex-bibfile-ignore-regexps))) | |
351 ;; excluded file | |
352 nil | |
353 ;; find the file | |
354 (reftex-locate-file x "bib" master-dir))) | |
355 files)) | |
356 (delq nil files))) | |
357 | |
358 (defun reftex-replace-label-list-segment (old insert &optional entirely) | |
359 ;; Replace the segment in OLD which corresponds to INSERT. | |
360 ;; Works with side effects, directly changes old. | |
361 ;; If entirely is t, just return INSERT. | |
362 ;; This function also makes sure the old toc markers do not point anywhere. | |
363 | |
364 (cond | |
365 (entirely | |
366 (reftex-silence-toc-markers old (length old)) | |
367 insert) | |
368 (t (let* ((new old) | |
369 (file (nth 1 (car insert))) | |
370 (eof-list (member (list 'eof file) old)) | |
371 (bof-list (member (list 'bof file) old)) | |
372 n) | |
373 (if (not (and bof-list eof-list)) | |
374 (error "Cannot splice") | |
375 ;; Splice | |
376 (reftex-silence-toc-markers bof-list (- (length bof-list) | |
377 (length eof-list))) | |
378 (setq n (- (length old) (length bof-list))) | |
379 (setcdr (nthcdr n new) (cdr insert)) | |
380 (setcdr (nthcdr (1- (length new)) new) (cdr eof-list))) | |
381 new)))) | |
382 | |
383 (defun reftex-section-info (file) | |
384 ;; Return a section entry for the current match. | |
385 ;; Carefull: This function expects the match-data to be still in place! | |
386 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3)))) | |
387 (macro (reftex-match-string 3)) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
388 (prefix (save-match-data |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
389 (if (string-match "begin{\\([^}]+\\)}" macro) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
390 (match-string 1 macro)))) |
25803
8b032ca83ce6
(reftex-parse-from-file): Scan for multiple thebibliography
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
391 (level-exp (cdr (assoc macro reftex-section-levels-all))) |
8b032ca83ce6
(reftex-parse-from-file): Scan for multiple thebibliography
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
392 (level (if (symbolp level-exp) |
8b032ca83ce6
(reftex-parse-from-file): Scan for multiple thebibliography
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
393 (save-match-data (funcall level-exp)) |
8b032ca83ce6
(reftex-parse-from-file): Scan for multiple thebibliography
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
394 level-exp)) |
8b032ca83ce6
(reftex-parse-from-file): Scan for multiple thebibliography
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
395 (star (= ?* (char-after (match-end 3)))) |
25280 | 396 (unnumbered (or star (< level 0))) |
397 (level (abs level)) | |
398 (section-number (reftex-section-number level unnumbered)) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
399 (text1 (save-match-data |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
400 (save-excursion |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
401 (reftex-context-substring prefix)))) |
25280 | 402 (literal (buffer-substring-no-properties |
403 (1- (match-beginning 3)) | |
404 (min (point-max) (+ (match-end 0) (length text1) 1)))) | |
405 ;; Literal can be too short since text1 too short. No big problem. | |
406 (text (reftex-nicify-text text1))) | |
407 | |
408 ;; Add section number and indentation | |
409 (setq text | |
410 (concat | |
411 (make-string (* reftex-level-indent level) ?\ ) | |
412 (if (nth 1 reftex-label-menu-flags) ; section number flag | |
413 (concat section-number " ")) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
414 (if prefix (concat (capitalize prefix) ": ") "") |
25280 | 415 text)) |
416 (list 'toc "toc" text file marker level section-number | |
417 literal (marker-position marker)))) | |
418 | |
419 (defun reftex-ensure-index-support (&optional abort) | |
420 ;; When index support is turned off, ask to turn it on and | |
421 ;; set the current prefix argument so that `reftex-access-scan-info' | |
422 ;; will rescan the entire document. | |
423 (cond | |
424 (reftex-support-index t) | |
425 ((y-or-n-p "Turn on index support and rescan entire document? ") | |
426 (setq reftex-support-index 'demanded | |
427 current-prefix-arg '(16))) | |
428 (t (if abort | |
429 (error "No index support") | |
430 (message "No index support") | |
431 (ding) | |
432 (sit-for 1))))) | |
433 | |
434 (defun reftex-index-info-safe (file) | |
435 (reftex-with-special-syntax | |
436 (reftex-index-info file))) | |
437 | |
438 (defvar test-dummy) | |
439 (defun reftex-index-info (file) | |
440 ;; Return an index entry for the current match. | |
441 ;; Carefull: This function expects the match-data to be still in place! | |
442 (catch 'exit | |
443 (let* ((macro (reftex-match-string 10)) | |
444 (bom (match-beginning 10)) | |
445 (boa (match-end 10)) | |
446 (entry (or (assoc macro reftex-index-macro-alist) | |
447 (throw 'exit nil))) | |
448 (exclude (nth 3 entry)) | |
449 ;; The following is a test if this match should be excluded | |
450 (test-dummy (and (fboundp exclude) | |
451 (funcall exclude) | |
452 (throw 'exit nil))) | |
453 (itag (nth 1 entry)) | |
454 (prefix (nth 2 entry)) | |
455 (index-tag | |
456 (cond ((stringp itag) itag) | |
457 ((integerp itag) | |
458 (progn (goto-char boa) | |
459 (or (reftex-nth-arg itag (nth 6 entry)) "idx"))) | |
460 (t "idx"))) | |
461 (arg (or (progn (goto-char boa) | |
462 (reftex-nth-arg (nth 5 entry) (nth 6 entry))) | |
463 "")) | |
464 (end-of-args (progn (goto-char boa) | |
465 (reftex-move-over-touching-args) | |
466 (point))) | |
467 (end-of-context (progn (skip-chars-forward "^ \t\n\r") (point))) | |
468 (begin-of-context | |
469 (progn (goto-char bom) | |
470 (skip-chars-backward "^ \t\r\n") | |
471 (point))) | |
472 (context (buffer-substring-no-properties | |
473 begin-of-context end-of-context)) | |
474 (key-end (if (string-match reftex-index-key-end-re arg) | |
475 (1+ (match-beginning 0)))) | |
476 (rawkey (substring arg 0 key-end)) | |
477 | |
478 (key (if prefix (concat prefix rawkey) rawkey)) | |
479 (sortkey (downcase key)) | |
480 (showkey (mapconcat 'identity | |
481 (split-string key reftex-index-level-re) | |
482 " ! "))) | |
483 (goto-char end-of-args) | |
484 ;; 0 1 2 3 4 5 6 7 8 9 | |
485 (list 'index index-tag context file bom arg key showkey sortkey key-end)))) | |
486 | |
487 (defun reftex-short-context (env parse &optional bound derive) | |
488 ;; Get about one line of useful context for the label definition at point. | |
489 | |
490 (if (consp parse) | |
491 (setq parse (if derive (cdr parse) (car parse)))) | |
492 | |
493 (reftex-nicify-text | |
494 | |
495 (cond | |
496 | |
497 ((null parse) | |
498 (save-excursion | |
499 (reftex-context-substring))) | |
500 | |
501 ((eq parse t) | |
502 (if (string= env "section") | |
503 ;; special treatment for section labels | |
504 (save-excursion | |
505 (if (and (re-search-backward reftex-section-or-include-regexp | |
506 (point-min) t) | |
507 (match-end 2)) | |
508 (progn | |
509 (goto-char (match-end 0)) | |
510 (reftex-context-substring)) | |
511 (if reftex-active-toc | |
512 (progn | |
513 (string-match "{\\([^}]*\\)" (nth 7 reftex-active-toc)) | |
514 (match-string 1 (nth 7 reftex-active-toc))) | |
515 "SECTION HEADING NOT FOUND"))) | |
516 (save-excursion | |
517 (goto-char reftex-default-context-position) | |
518 (unless (eq (string-to-char env) ?\\) | |
519 (reftex-move-over-touching-args)) | |
520 (reftex-context-substring)))) | |
521 | |
522 ((stringp parse) | |
523 (save-excursion | |
524 (if (re-search-backward parse bound t) | |
525 (progn | |
526 (goto-char (match-end 0)) | |
527 (reftex-context-substring)) | |
528 "NO MATCH FOR CONTEXT REGEXP"))) | |
529 | |
530 ((integerp parse) | |
531 (or (save-excursion | |
532 (goto-char reftex-default-context-position) | |
533 (reftex-nth-arg | |
534 parse | |
535 (nth 6 (assoc env reftex-env-or-mac-alist)))) | |
536 "")) | |
537 | |
538 ((fboundp parse) | |
539 ;; A hook function. Call it. | |
540 (save-excursion | |
541 (condition-case error-var | |
542 (funcall parse env) | |
543 (error (format "HOOK ERROR: %s" (cdr error-var)))))) | |
544 (t | |
545 "ILLEGAL VALUE OF PARSE")))) | |
546 | |
547 (defun reftex-where-am-I () | |
548 ;; Return the docstruct entry above point. Actually returns a cons | |
549 ;; cell in which the cdr is a flag indicating if the information is | |
550 ;; exact (t) or approximate (nil). | |
551 | |
552 (let ((docstruct (symbol-value reftex-docstruct-symbol)) | |
553 (cnt 0) rtn | |
554 found) | |
555 (save-excursion | |
556 (while (not rtn) | |
557 (incf cnt) | |
558 (setq found (re-search-backward (reftex-everything-regexp) nil t)) | |
559 (setq rtn | |
560 (cond | |
561 ((not found) | |
562 ;; no match | |
563 (or | |
564 (car (member (list 'bof (buffer-file-name)) docstruct)) | |
565 (not (setq cnt 2)) | |
566 (assq 'bof docstruct) ;; for safety reasons | |
567 'corrupted)) | |
568 ((match-end 1) | |
569 ;; Label | |
570 (assoc (reftex-match-string 1) | |
571 (symbol-value reftex-docstruct-symbol))) | |
572 ((match-end 3) | |
573 ;; Section | |
574 (goto-char (1- (match-beginning 3))) | |
575 (let* ((list (member (list 'bof (buffer-file-name)) | |
576 docstruct)) | |
577 (endelt (car (member (list 'eof (buffer-file-name)) | |
578 list))) | |
579 rtn1) | |
580 (while (and list (not (eq endelt (car list)))) | |
581 (if (and (eq (car (car list)) 'toc) | |
582 (string= (buffer-file-name) | |
583 (nth 3 (car list)))) | |
584 (cond | |
585 ((equal (point) | |
586 (or (and (markerp (nth 4 (car list))) | |
587 (marker-position (nth 4 (car list)))) | |
588 (nth 8 (car list)))) | |
589 ;; Fits with marker position or recorded position | |
590 (setq rtn1 (car list) list nil)) | |
591 ((looking-at (reftex-make-regexp-allow-for-ctrl-m | |
592 (nth 7 (car list)))) | |
593 ;; Same title | |
594 (setq rtn1 (car list) list nil cnt 2)))) | |
595 (pop list)) | |
596 rtn1)) | |
597 ((match-end 7) | |
598 ;; Input or include... | |
599 (car | |
600 (member (list 'eof (reftex-locate-file | |
601 (reftex-match-string 7) "tex" | |
602 (cdr (assq 'master-dir docstruct)))) | |
603 docstruct))) | |
604 ((match-end 9) | |
605 (assq 'appendix (symbol-value reftex-docstruct-symbol))) | |
606 ((match-end 10) | |
607 ;; Index entry | |
608 (when reftex-support-index | |
609 (let* ((index-info (save-excursion | |
610 (reftex-index-info-safe nil))) | |
611 (list (member (list 'bof (buffer-file-name)) | |
612 docstruct)) | |
613 (endelt (car (member (list 'eof (buffer-file-name)) | |
614 list))) | |
615 dist last-dist last (n 0)) | |
616 ;; Check all index entries with equal text | |
617 (while (and list (not (eq endelt (car list)))) | |
618 (when (and (eq (car (car list)) 'index) | |
619 (string= (nth 2 index-info) | |
620 (nth 2 (car list)))) | |
621 (incf n) | |
622 (setq dist (abs (- (point) (nth 4 (car list))))) | |
623 (if (or (not last-dist) (< dist last-dist)) | |
624 (setq last-dist dist last (car list)))) | |
625 (setq list (cdr list))) | |
626 ;; We are sure if we have only one, or a zero distance | |
627 (cond ((or (= n 1) (= dist 0)) last) | |
628 ((> n 1) (setq cnt 2) last) | |
629 (t nil))))) | |
630 ((match-end 11) | |
631 (save-excursion | |
632 (goto-char (match-end 11)) | |
633 (assoc (reftex-no-props | |
634 (reftex-nth-arg-wrapper | |
635 (reftex-match-string 11))) | |
636 (symbol-value reftex-docstruct-symbol)))) | |
637 (t | |
638 (error "This should not happen (reftex-where-am-I)")))))) | |
639 (cons rtn (eq cnt 1)))) | |
640 | |
641 (defun reftex-notice-new (&optional n force) | |
642 "Hook to handshake with RefTeX after something new has been inserted." | |
643 ;; Add a new entry to the docstruct list. If it is a section, renumber | |
644 ;; the following sections. | |
645 ;; FIXME: Put in a WHAT parameter | |
646 ;; When N is given, go back that many matches of reftex-everything-regexp | |
647 ;; When FORCE is non-nil, also insert if `reftex-where-am-I' was uncertain. | |
648 (condition-case nil | |
649 (catch 'exit | |
650 (unless reftex-mode (throw 'exit nil)) | |
651 (reftex-access-scan-info) | |
652 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) | |
653 here-I-am appendix tail entry star level | |
654 section-number context) | |
655 | |
656 (save-excursion | |
657 (when (re-search-backward (reftex-everything-regexp) nil t (or n 1)) | |
658 | |
659 ;; Find where we are | |
660 (setq here-I-am (reftex-where-am-I)) | |
661 (or here-I-am (throw 'exit nil)) | |
662 (unless (or force (cdr here-I-am)) (throw 'exit nil)) | |
663 (setq tail (memq (car here-I-am) docstruct)) | |
664 (or tail (throw 'exit nil)) | |
665 (setq reftex-active-toc (reftex-last-assoc-before-elt | |
666 'toc (car here-I-am) docstruct) | |
667 appendix (reftex-last-assoc-before-elt | |
668 'appendix (car here-I-am) docstruct)) | |
669 | |
670 ;; Initialize section numbers | |
671 (if (eq (car (car here-I-am)) 'appendix) | |
672 (reftex-init-section-numbers nil t) | |
673 (reftex-init-section-numbers reftex-active-toc appendix)) | |
674 | |
675 ;; Match the section command | |
676 (when (re-search-forward (reftex-everything-regexp) nil t) | |
677 (cond | |
678 ((match-end 1) | |
679 (push (reftex-label-info (reftex-match-string 1) buffer-file-name) | |
680 (cdr tail))) | |
681 | |
682 ((match-end 3) | |
683 (setq star (= ?* (char-after (match-end 3))) | |
684 entry (reftex-section-info (buffer-file-name)) | |
685 level (nth 5 entry)) | |
686 ;; Insert the section info | |
687 (push entry (cdr tail)) | |
688 | |
689 ;; We are done unless we use section numbers | |
690 (unless (nth 1 reftex-label-menu-flags) (throw 'exit nil)) | |
691 | |
692 ;; Update the remaining toc items | |
693 (setq tail (cdr tail)) | |
694 (while (and (setq tail (memq (assq 'toc (cdr tail)) tail)) | |
695 (setq entry (car tail)) | |
696 (>= (nth 5 entry) level)) | |
697 (setq star (string-match "\\*" (nth 6 entry)) | |
698 context (nth 2 entry) | |
699 section-number | |
700 (reftex-section-number (nth 5 entry) star)) | |
701 (when (string-match "\\`\\([ \t]*\\)\\([.0-9A-Z]+\\)\\(.*\\)" | |
702 context) | |
703 (when (and (not appendix) | |
704 (>= (string-to-char (match-string 2)) ?A)) | |
705 ;; Just entered the appendex. Get out. | |
706 (throw 'exit nil)) | |
707 | |
708 ;; Change the section number. | |
709 (setf (nth 2 entry) | |
710 (concat (match-string 1 context) | |
711 section-number | |
712 (match-string 3 context)))))) | |
713 ((match-end 10) | |
714 ;; Index entry | |
715 (and reftex-support-index | |
716 (setq entry (reftex-index-info-safe buffer-file-name)) | |
717 ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry)) | |
718 (push entry (cdr tail)))))))))) | |
719 | |
720 (error nil)) | |
721 ) | |
722 | |
723 (defsubst reftex-move-to-previous-arg (&optional bound) | |
724 ;; Assuming that we are in front of a macro argument, | |
725 ;; move backward to the closing parenthesis of the previous argument. | |
726 ;; This function understands the splitting of macros over several lines | |
727 ;; in TeX. | |
728 (cond | |
729 ;; Just to be quick: | |
730 ((memq (preceding-char) '(?\] ?\}))) | |
731 ;; Do a search | |
732 ((and reftex-allow-detached-macro-args | |
733 (re-search-backward | |
734 "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t)) | |
735 (goto-char (1+ (match-beginning 0))) | |
736 t) | |
737 (t nil))) | |
738 | |
739 (defun reftex-what-macro-safe (which &optional bound) | |
740 ;; reftex-what-macro with special syntax table. | |
741 (reftex-with-special-syntax | |
742 (reftex-what-macro which bound))) | |
743 | |
744 (defun reftex-what-macro (which &optional bound) | |
745 ;; Find out if point is within the arguments of any TeX-macro. | |
746 ;; The return value is either ("\\macro" . (point)) or a list of them. | |
747 | |
748 ;; If WHICH is nil, immediately return nil. | |
749 ;; If WHICH is 1, return innermost enclosing macro. | |
750 ;; If WHICH is t, return list of all macros enclosing point. | |
751 ;; If WHICH is a list of macros, look only for those macros and return the | |
752 ;; name of the first macro in this list found to enclose point. | |
753 ;; If the optional BOUND is an integer, bound backwards directed | |
754 ;; searches to this point. If it is nil, limit to nearest \section - | |
755 ;; like statement. | |
756 | |
757 ;; This function is pretty stable, but can be fooled if the text contains | |
758 ;; things like \macro{aa}{bb} where \macro is defined to take only one | |
759 ;; argument. As RefTeX cannot know this, the string "bb" would still be | |
760 ;; considered an argument of macro \macro. | |
761 | |
762 (unless reftex-section-regexp (reftex-compile-variables)) | |
763 (catch 'exit | |
764 (if (null which) (throw 'exit nil)) | |
765 (let ((bound (or bound (save-excursion (re-search-backward | |
766 reftex-section-regexp nil 1) | |
767 (point)))) | |
768 pos cmd-list cmd cnt cnt-opt entry) | |
769 (save-restriction | |
770 (save-excursion | |
771 (narrow-to-region (max 1 bound) (point-max)) | |
772 ;; move back out of the current parenthesis | |
773 (while (condition-case nil | |
774 (progn (up-list -1) t) | |
775 (error nil)) | |
776 (setq cnt 1 cnt-opt 0) | |
777 ;; move back over any touching sexps | |
778 (while (and (reftex-move-to-previous-arg bound) | |
779 (condition-case nil | |
780 (progn (backward-sexp) t) | |
781 (error nil))) | |
782 (if (eq (following-char) ?\[) (incf cnt-opt)) | |
783 (incf cnt)) | |
784 (setq pos (point)) | |
785 (when (and (or (= (following-char) ?\[) | |
786 (= (following-char) ?\{)) | |
787 (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t)) | |
788 (setq cmd (reftex-match-string 0)) | |
789 (when (looking-at "\\\\begin{[^}]*}") | |
790 (setq cmd (reftex-match-string 0) | |
791 cnt (1- cnt))) | |
792 ;; This does ignore optional arguments. Very hard to fix. | |
793 (when (setq entry (assoc cmd reftex-env-or-mac-alist)) | |
794 (if (> cnt (or (nth 4 entry) 100)) | |
795 (setq cmd nil))) | |
796 (cond | |
797 ((null cmd)) | |
798 ((eq t which) | |
799 (push (cons cmd (point)) cmd-list)) | |
800 ((or (eq 1 which) (member cmd which)) | |
801 (throw 'exit (cons cmd (point)))))) | |
802 (goto-char pos))) | |
803 (nreverse cmd-list))))) | |
804 | |
805 (defun reftex-what-environment (which &optional bound) | |
806 ;; Find out if point is inside a LaTeX environment. | |
807 ;; The return value is (e.g.) either ("equation" . (point)) or a list of | |
808 ;; them. | |
809 | |
810 ;; If WHICH is nil, immediately return nil. | |
811 ;; If WHICH is 1, return innermost enclosing environment. | |
812 ;; If WHICH is t, return list of all environments enclosing point. | |
813 ;; If WHICH is a list of environments, look only for those environments and | |
814 ;; return the name of the first environment in this list found to enclose | |
815 ;; point. | |
816 | |
817 ;; If the optional BOUND is an integer, bound backwards directed searches to | |
818 ;; this point. If it is nil, limit to nearest \section - like statement. | |
819 | |
820 (unless reftex-section-regexp (reftex-compile-variables)) | |
821 (catch 'exit | |
822 (save-excursion | |
823 (if (null which) (throw 'exit nil)) | |
824 (let ((bound (or bound (save-excursion (re-search-backward | |
825 reftex-section-regexp nil 1) | |
826 (point)))) | |
827 env-list end-list env) | |
828 (while (re-search-backward "\\\\\\(begin\\|end\\){\\([^}]+\\)}" | |
829 bound t) | |
830 (setq env (buffer-substring-no-properties | |
831 (match-beginning 2) (match-end 2))) | |
832 (cond | |
833 ((string= (match-string 1) "end") | |
834 (push env end-list)) | |
835 ((equal env (car end-list)) | |
836 (setq end-list (cdr end-list))) | |
837 ((eq t which) | |
838 (push (cons env (point)) env-list)) | |
839 ((or (eq 1 which) (member env which)) | |
840 (throw 'exit (cons env (point)))))) | |
841 (nreverse env-list))))) | |
842 | |
843 (defun reftex-what-special-env (which &optional bound) | |
844 ;; Run the special environment parsers and return the matches. | |
845 ;; | |
846 ;; The return value is (e.g.) either ("my-parser-function" . (point)) | |
847 ;; or a list of them. | |
848 | |
849 ;; If WHICH is nil, immediately return nil. | |
850 ;; If WHICH is 1, return innermost enclosing environment. | |
851 ;; If WHICH is t, return list of all environments enclosing point. | |
852 ;; If WHICH is a list of environments, look only for those environments and | |
853 ;; return the name of the first environment in this list found to enclose | |
854 ;; point. | |
855 | |
856 (unless reftex-section-regexp (reftex-compile-variables)) | |
857 (catch 'exit | |
858 (save-excursion | |
859 (if (null reftex-special-env-parsers) (throw 'exit nil)) | |
860 (if (null which) (throw 'exit nil)) | |
861 (let ((bound (or bound (save-excursion (re-search-backward | |
862 reftex-section-regexp nil 1) | |
863 (point)))) | |
864 (fun-list (if (listp which) | |
865 (mapcar (lambda (x) (if (memq x which) x nil)) | |
866 reftex-special-env-parsers) | |
867 reftex-special-env-parsers)) | |
868 specials rtn) | |
869 ;; Call all functions | |
870 (setq specials (mapcar | |
871 (lambda (fun) | |
872 (save-excursion | |
873 (setq rtn (and fun (funcall fun bound))) | |
874 (if rtn (cons (symbol-name fun) rtn) nil))) | |
875 fun-list)) | |
876 ;; Delete the non-matches | |
877 (setq specials (delq nil specials)) | |
878 ;; Sort | |
879 (setq specials (sort specials (lambda (a b) (> (cdr a) (cdr b))))) | |
880 (if (eq which t) | |
881 specials | |
882 (car specials)))))) | |
883 | |
884 (defsubst reftex-move-to-next-arg (&optional ignore) | |
885 ;; Assuming that we are at the end of a macro name or a macro argument, | |
886 ;; move forward to the opening parenthesis of the next argument. | |
887 ;; This function understands the splitting of macros over several lines | |
888 ;; in TeX. | |
889 (cond | |
890 ;; Just to be quick: | |
891 ((memq (following-char) '(?\[ ?\{))) | |
892 ;; Do a search | |
893 ((and reftex-allow-detached-macro-args | |
894 (looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]")) | |
895 (goto-char (1- (match-end 0))) | |
896 t) | |
897 (t nil))) | |
898 | |
899 (defun reftex-nth-arg-wrapper (key) | |
900 (let ((entry (assoc key reftex-env-or-mac-alist))) | |
901 (reftex-nth-arg (nth 5 entry) (nth 6 entry)))) | |
902 | |
903 (defun reftex-nth-arg (n &optional opt-args) | |
904 ;; Return the nth following {} or [] parentheses content. | |
905 ;; OPT-ARGS is a list of argument numbers which are optional. | |
906 | |
907 ;; If we are sitting at a macro start, skip to end of macro name. | |
908 (and (eq (following-char) ?\\) (skip-chars-forward "a-zA-Z*\\\\")) | |
909 | |
910 (if (= n 1000) | |
911 ;; Special case: Skip all touching arguments | |
912 (progn | |
913 (reftex-move-over-touching-args) | |
914 (reftex-context-substring)) | |
915 | |
916 ;; Do the real thing. | |
917 (let ((cnt 1)) | |
918 | |
919 (when (reftex-move-to-next-arg) | |
920 | |
921 (while (< cnt n) | |
922 (while (and (member cnt opt-args) | |
923 (eq (following-char) ?\{)) | |
924 (incf cnt)) | |
925 (when (< cnt n) | |
926 (unless (and (condition-case nil | |
927 (or (forward-list 1) t) | |
928 (error nil)) | |
929 (reftex-move-to-next-arg) | |
930 (incf cnt)) | |
931 (setq cnt 1000)))) | |
932 | |
933 (while (and (memq cnt opt-args) | |
934 (eq (following-char) ?\{)) | |
935 (incf cnt))) | |
936 (if (and (= n cnt) | |
937 (> (skip-chars-forward "{\\[") 0)) | |
938 (reftex-context-substring) | |
939 nil)))) | |
940 | |
941 (defun reftex-move-over-touching-args () | |
942 (condition-case nil | |
943 (while (memq (following-char) '(?\[ ?\{)) | |
944 (forward-list 1)) | |
945 (error nil))) | |
946 | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
947 (defun reftex-context-substring (&optional to-end) |
25280 | 948 ;; Return up to 150 chars from point |
949 ;; When point is just after a { or [, limit string to matching parenthesis | |
950 (cond | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
951 (to-end |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
952 ;; Environment - find next \end |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
953 (buffer-substring-no-properties |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
954 (point) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
955 (min (+ (point) 150) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
956 (save-match-data |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
957 ;; FIXME: THis is not perfect |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
958 (if (re-search-forward "\\\\end{" nil t) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
959 (match-beginning 0) |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25803
diff
changeset
|
960 (point-max)))))) |
25280 | 961 ((or (= (preceding-char) ?\{) |
962 (= (preceding-char) ?\[)) | |
963 ;; Inside a list - get only the list. | |
964 (buffer-substring-no-properties | |
965 (point) | |
966 (min (+ (point) 150) | |
967 (point-max) | |
968 (condition-case nil | |
969 (progn | |
970 (up-list 1) | |
971 (1- (point))) | |
972 (error (point-max)))))) | |
973 (t | |
974 ;; no list - just grab 150 characters | |
975 (buffer-substring-no-properties (point) | |
976 (min (+ (point) 150) (point-max)))))) | |
977 | |
978 ;; Variable holding the vector with section numbers | |
25803
8b032ca83ce6
(reftex-parse-from-file): Scan for multiple thebibliography
Carsten Dominik <dominik@science.uva.nl>
parents:
25280
diff
changeset
|
979 (defvar reftex-section-numbers (make-vector reftex-max-section-depth 0)) |
25280 | 980 |
981 (defun reftex-init-section-numbers (&optional toc-entry appendix) | |
982 ;; Initialize the section numbers with zeros or with what is found | |
983 ;; in the toc entry. | |
984 (let* ((level (or (nth 5 toc-entry) -1)) | |
985 (numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\."))) | |
986 (depth (1- (length reftex-section-numbers))) | |
987 (i depth) number-string) | |
988 (while (>= i 0) | |
989 (if (> i level) | |
990 (aset reftex-section-numbers i 0) | |
991 (setq number-string (or (car numbers) "0")) | |
992 (if (string-match "\\`[A-Z]\\'" number-string) | |
993 (aset reftex-section-numbers i | |
994 (- (string-to-char number-string) ?A -1)) | |
995 (aset reftex-section-numbers i (string-to-int number-string))) | |
996 (pop numbers)) | |
997 (decf i))) | |
998 (put 'reftex-section-numbers 'appendix appendix)) | |
999 | |
1000 (defun reftex-section-number (&optional level star) | |
1001 ;; Return a string with the current section number. | |
1002 ;; When LEVEL is non-nil, increase section numbers on that level. | |
1003 (let* ((depth (1- (length reftex-section-numbers))) idx n (string "") | |
1004 (appendix (get 'reftex-section-numbers 'appendix))) | |
1005 (when level | |
1006 (when (and (> level -1) (not star)) | |
1007 (aset reftex-section-numbers | |
1008 level (1+ (aref reftex-section-numbers level)))) | |
1009 (setq idx (1+ level)) | |
1010 (when (not star) | |
1011 (while (<= idx depth) | |
1012 (aset reftex-section-numbers idx 0) | |
1013 (incf idx)))) | |
1014 (setq idx 0) | |
1015 (while (<= idx depth) | |
1016 (setq n (aref reftex-section-numbers idx)) | |
1017 (setq string (concat string (if (not (string= string "")) "." "") | |
1018 (int-to-string n))) | |
1019 (incf idx)) | |
1020 (save-match-data | |
1021 (if (string-match "\\`\\([@0]\\.\\)+" string) | |
1022 (setq string (replace-match "" nil nil string))) | |
1023 (if (string-match "\\(\\.0\\)+\\'" string) | |
1024 (setq string (replace-match "" nil nil string))) | |
1025 (if (and appendix | |
1026 (string-match "\\`[0-9]+" string)) | |
1027 (setq string | |
1028 (concat | |
1029 (char-to-string | |
1030 (1- (+ ?A (string-to-int (match-string 0 string))))) | |
1031 (substring string (match-end 0)))))) | |
1032 (if star | |
1033 (concat (make-string (1- (length string)) ?\ ) "*") | |
1034 string))) | |
1035 | |
1036 ;;; reftex-parse.el ends here |