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