aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes/reftex-parse.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/textmodes/reftex-parse.el')
-rw-r--r--lisp/textmodes/reftex-parse.el869
1 files changed, 434 insertions, 435 deletions
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 534775bf5a5..a03c5b6646b 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -1,8 +1,8 @@
1;;; reftex-parse.el --- parser functions for RefTeX 1;;; reftex-parse.el --- parser functions for RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6;; 6;;
7 7
8;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
@@ -33,10 +33,10 @@
33(defmacro reftex-with-special-syntax (&rest body) 33(defmacro reftex-with-special-syntax (&rest body)
34 `(let ((saved-syntax (syntax-table))) 34 `(let ((saved-syntax (syntax-table)))
35 (unwind-protect 35 (unwind-protect
36 (progn 36 (progn
37 (set-syntax-table reftex-syntax-table) 37 (set-syntax-table reftex-syntax-table)
38 (let ((case-fold-search nil)) 38 (let ((case-fold-search nil))
39 ,@body)) 39 ,@body))
40 (set-syntax-table saved-syntax)))) 40 (set-syntax-table saved-syntax))))
41 41
42(defun reftex-parse-one () 42(defun reftex-parse-one ()
@@ -68,12 +68,12 @@
68 68
69 (let* ((old-list (symbol-value reftex-docstruct-symbol)) 69 (let* ((old-list (symbol-value reftex-docstruct-symbol))
70 (master (reftex-TeX-master-file)) 70 (master (reftex-TeX-master-file))
71 (true-master (file-truename master)) 71 (true-master (file-truename master))
72 (master-dir (file-name-as-directory (file-name-directory master))) 72 (master-dir (file-name-as-directory (file-name-directory master)))
73 (file (or file (buffer-file-name))) 73 (file (or file (buffer-file-name)))
74 (true-file (file-truename file)) 74 (true-file (file-truename file))
75 (bibview-cache (assq 'bibview-cache old-list)) 75 (bibview-cache (assq 'bibview-cache old-list))
76 (index-tags (cdr (assq 'index-tags old-list))) 76 (index-tags (cdr (assq 'index-tags old-list)))
77 from-file appendix docstruct tmp) 77 from-file appendix docstruct tmp)
78 78
79 ;; Make sure replacement is really an option here 79 ;; Make sure replacement is really an option here
@@ -97,9 +97,9 @@
97 97
98 ;; Find active toc entry and initialize section-numbers 98 ;; Find active toc entry and initialize section-numbers
99 (setq reftex-active-toc (reftex-last-assoc-before-elt 99 (setq reftex-active-toc (reftex-last-assoc-before-elt
100 'toc (list 'bof from-file) old-list) 100 'toc (list 'bof from-file) old-list)
101 appendix (reftex-last-assoc-before-elt 101 appendix (reftex-last-assoc-before-elt
102 'appendix (list 'bof from-file) old-list)) 102 'appendix (list 'bof from-file) old-list))
103 103
104 (reftex-init-section-numbers reftex-active-toc appendix) 104 (reftex-init-section-numbers reftex-active-toc appendix)
105 105
@@ -110,11 +110,11 @@
110 (reftex-with-special-syntax 110 (reftex-with-special-syntax
111 (save-window-excursion 111 (save-window-excursion
112 (save-excursion 112 (save-excursion
113 (unwind-protect 113 (unwind-protect
114 (setq docstruct 114 (setq docstruct
115 (reftex-parse-from-file 115 (reftex-parse-from-file
116 from-file docstruct master-dir)) 116 from-file docstruct master-dir))
117 (reftex-kill-temporary-buffers))))) 117 (reftex-kill-temporary-buffers)))))
118 118
119 (message "Scanning document... done") 119 (message "Scanning document... done")
120 120
@@ -141,27 +141,27 @@
141 (and index-tags (setq index-tags (sort index-tags 'string<))) 141 (and index-tags (setq index-tags (sort index-tags 'string<)))
142 (let ((index-tag-cell (assq 'index-tags docstruct))) 142 (let ((index-tag-cell (assq 'index-tags docstruct)))
143 (if index-tag-cell 143 (if index-tag-cell
144 (setcdr index-tag-cell index-tags) 144 (setcdr index-tag-cell index-tags)
145 (push (cons 'index-tags index-tags) docstruct))) 145 (push (cons 'index-tags index-tags) docstruct)))
146 (unless (assq 'xr docstruct) 146 (unless (assq 'xr docstruct)
147 (let* ((allxr (reftex-all-assq 'xr-doc docstruct)) 147 (let* ((allxr (reftex-all-assq 'xr-doc docstruct))
148 (alist (mapcar 148 (alist (mapcar
149 (lambda (x) 149 (lambda (x)
150 (if (setq tmp (reftex-locate-file (nth 2 x) "tex" 150 (if (setq tmp (reftex-locate-file (nth 2 x) "tex"
151 master-dir)) 151 master-dir))
152 (cons (nth 1 x) tmp) 152 (cons (nth 1 x) tmp)
153 (message "Can't find external document %s" 153 (message "Can't find external document %s"
154 (nth 2 x)) 154 (nth 2 x))
155 nil)) 155 nil))
156 allxr)) 156 allxr))
157 (alist (delq nil alist)) 157 (alist (delq nil alist))
158 (allprefix (delq nil (mapcar 'car alist))) 158 (allprefix (delq nil (mapcar 'car alist)))
159 (regexp (if allprefix 159 (regexp (if allprefix
160 (concat "\\`\\(" 160 (concat "\\`\\("
161 (mapconcat 'identity allprefix "\\|") 161 (mapconcat 'identity allprefix "\\|")
162 "\\)") 162 "\\)")
163 "\\\\\\\\\\\\"))) ; this will never match 163 "\\\\\\\\\\\\"))) ; this will never match
164 (push (list 'xr alist regexp) docstruct))) 164 (push (list 'xr alist regexp) docstruct)))
165 165
166 (set reftex-docstruct-symbol docstruct) 166 (set reftex-docstruct-symbol docstruct)
167 (put reftex-docstruct-symbol 'modified t))) 167 (put reftex-docstruct-symbol 'modified t)))
@@ -201,8 +201,8 @@ of master file."
201 (catch 'exit 201 (catch 'exit
202 (setq file-found (reftex-locate-file file "tex" master-dir)) 202 (setq file-found (reftex-locate-file file "tex" master-dir))
203 (if (and (not file-found) 203 (if (and (not file-found)
204 (setq buf (reftex-get-buffer-visiting file))) 204 (setq buf (reftex-get-buffer-visiting file)))
205 (setq file-found (buffer-file-name buf))) 205 (setq file-found (buffer-file-name buf)))
206 206
207 (unless file-found 207 (unless file-found
208 (push (list 'file-error file) docstruct) 208 (push (list 'file-error file) docstruct)
@@ -221,106 +221,106 @@ of master file."
221 (setq file (buffer-file-name)) 221 (setq file (buffer-file-name))
222 (push (list 'bof file) docstruct) 222 (push (list 'bof file) docstruct)
223 223
224 (reftex-with-special-syntax 224 (reftex-with-special-syntax
225 (save-excursion 225 (save-excursion
226 (save-restriction 226 (save-restriction
227 (widen) 227 (widen)
228 (goto-char 1) 228 (goto-char 1)
229 229
230 (while (re-search-forward regexp nil t) 230 (while (re-search-forward regexp nil t)
231 231
232 (cond 232 (cond
233 233
234 ((match-end 1) 234 ((match-end 1)
235 ;; It is a label 235 ;; It is a label
236 (push (reftex-label-info (reftex-match-string 1) file bound) 236 (push (reftex-label-info (reftex-match-string 1) file bound)
237 docstruct)) 237 docstruct))
238 238
239 ((match-end 3) 239 ((match-end 3)
240 ;; It is a section 240 ;; It is a section
241 (setq bound (point)) 241 (setq bound (point))
242 242
243 ;; Insert in List 243 ;; Insert in List
244 (setq toc-entry (reftex-section-info file)) 244 (setq toc-entry (reftex-section-info file))
245 (when toc-entry 245 (when toc-entry
246 ;; It can happen that section info returns nil 246 ;; It can happen that section info returns nil
247 (setq level (nth 5 toc-entry)) 247 (setq level (nth 5 toc-entry))
248 (setq highest-level (min highest-level level)) 248 (setq highest-level (min highest-level level))
249 (if (= level highest-level) 249 (if (= level highest-level)
250 (message 250 (message
251 "Scanning %s %s ..." 251 "Scanning %s %s ..."
252 (car (rassoc level reftex-section-levels-all)) 252 (car (rassoc level reftex-section-levels-all))
253 (nth 6 toc-entry))) 253 (nth 6 toc-entry)))
254 254
255 (push toc-entry docstruct) 255 (push toc-entry docstruct)
256 (setq reftex-active-toc toc-entry))) 256 (setq reftex-active-toc toc-entry)))
257 257
258 ((match-end 7) 258 ((match-end 7)
259 ;; It's an include or input 259 ;; It's an include or input
260 (setq include-file (reftex-match-string 7)) 260 (setq include-file (reftex-match-string 7))
261 ;; Test if this file should be ignored 261 ;; Test if this file should be ignored
262 (unless (delq nil (mapcar 262 (unless (delq nil (mapcar
263 (lambda (x) (string-match x include-file)) 263 (lambda (x) (string-match x include-file))
264 reftex-no-include-regexps)) 264 reftex-no-include-regexps))
265 ;; Parse it 265 ;; Parse it
266 (setq docstruct 266 (setq docstruct
267 (reftex-parse-from-file 267 (reftex-parse-from-file
268 include-file 268 include-file
269 docstruct master-dir)))) 269 docstruct master-dir))))
270 270
271 ((match-end 9) 271 ((match-end 9)
272 ;; Appendix starts here 272 ;; Appendix starts here
273 (reftex-init-section-numbers nil t) 273 (reftex-init-section-numbers nil t)
274 (push (cons 'appendix t) docstruct)) 274 (push (cons 'appendix t) docstruct))
275 275
276 ((match-end 10) 276 ((match-end 10)
277 ;; Index entry 277 ;; Index entry
278 (when reftex-support-index 278 (when reftex-support-index
279 (setq index-entry (reftex-index-info file)) 279 (setq index-entry (reftex-index-info file))
280 (when index-entry 280 (when index-entry
281 (add-to-list 'index-tags (nth 1 index-entry)) 281 (add-to-list 'index-tags (nth 1 index-entry))
282 (push index-entry docstruct)))) 282 (push index-entry docstruct))))
283 283
284 ((match-end 11) 284 ((match-end 11)
285 ;; A macro with label 285 ;; A macro with label
286 (save-excursion 286 (save-excursion
287 (let* ((mac (reftex-match-string 11)) 287 (let* ((mac (reftex-match-string 11))
288 (label (progn (goto-char (match-end 11)) 288 (label (progn (goto-char (match-end 11))
289 (save-match-data 289 (save-match-data
290 (reftex-no-props 290 (reftex-no-props
291 (reftex-nth-arg-wrapper 291 (reftex-nth-arg-wrapper
292 mac))))) 292 mac)))))
293 (typekey (nth 1 (assoc mac reftex-env-or-mac-alist))) 293 (typekey (nth 1 (assoc mac reftex-env-or-mac-alist)))
294 (entry (progn (if typekey 294 (entry (progn (if typekey
295 ;; A typing macro 295 ;; A typing macro
296 (goto-char (match-end 0)) 296 (goto-char (match-end 0))
297 ;; A neutral macro 297 ;; A neutral macro
298 (goto-char (match-end 11)) 298 (goto-char (match-end 11))
299 (reftex-move-over-touching-args)) 299 (reftex-move-over-touching-args))
300 (reftex-label-info 300 (reftex-label-info
301 label file bound nil nil)))) 301 label file bound nil nil))))
302 (push entry docstruct)))) 302 (push entry docstruct))))
303 (t (error "This should not happen (reftex-parse-from-file)"))) 303 (t (error "This should not happen (reftex-parse-from-file)")))
304 ) 304 )
305 305
306 ;; Find bibliography statement 306 ;; Find bibliography statement
307 (when (setq tmp (reftex-locate-bibliography-files master-dir)) 307 (when (setq tmp (reftex-locate-bibliography-files master-dir))
308 (push (cons 'bib tmp) docstruct)) 308 (push (cons 'bib tmp) docstruct))
309 309
310 (goto-char 1) 310 (goto-char 1)
311 (when (re-search-forward 311 (when (re-search-forward
312 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) 312 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t)
313 (push (cons 'thebib file) docstruct)) 313 (push (cons 'thebib file) docstruct))
314 314
315 ;; Find external document specifications 315 ;; Find external document specifications
316 (goto-char 1) 316 (goto-char 1)
317 (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t) 317 (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t)
318 (push (list 'xr-doc (reftex-match-string 2) 318 (push (list 'xr-doc (reftex-match-string 2)
319 (reftex-match-string 3)) 319 (reftex-match-string 3))
320 docstruct)) 320 docstruct))
321 321
322 ;; End of file mark 322 ;; End of file mark
323 (push (list 'eof file) docstruct))))) 323 (push (list 'eof file) docstruct)))))
324 324
325 ;; Kill the scanned buffer 325 ;; Kill the scanned buffer
326 (reftex-kill-temporary-buffers next-buf)) 326 (reftex-kill-temporary-buffers next-buf))
@@ -330,31 +330,31 @@ of master file."
330 330
331(defun reftex-locate-bibliography-files (master-dir &optional files) 331(defun reftex-locate-bibliography-files (master-dir &optional files)
332 ;; Scan buffer for bibliography macro and return file list. 332 ;; Scan buffer for bibliography macro and return file list.
333 333
334 (unless files 334 (unless files
335 (save-excursion 335 (save-excursion
336 (goto-char (point-min)) 336 (goto-char (point-min))
337 (if (re-search-forward 337 (if (re-search-forward
338 (concat 338 (concat
339; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\(" 339; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
340 "\\(^\\)[^%\n\r]*\\\\\\(" 340 "\\(^\\)[^%]*\\\\\\("
341 (mapconcat 'identity reftex-bibliography-commands "\\|") 341 (mapconcat 'identity reftex-bibliography-commands "\\|")
342 "\\){[ \t]*\\([^}]+\\)") nil t) 342 "\\){[ \t]*\\([^}]+\\)") nil t)
343 (setq files 343 (setq files
344 (split-string (reftex-match-string 3) 344 (split-string (reftex-match-string 3)
345 "[ \t\n\r]*,[ \t\n\r]*"))))) 345 "[ \t\n\r]*,[ \t\n\r]*")))))
346 (when files 346 (when files
347 (setq files 347 (setq files
348 (mapcar 348 (mapcar
349 (lambda (x) 349 (lambda (x)
350 (if (or (member x reftex-bibfile-ignore-list) 350 (if (or (member x reftex-bibfile-ignore-list)
351 (delq nil (mapcar (lambda (re) (string-match re x)) 351 (delq nil (mapcar (lambda (re) (string-match re x))
352 reftex-bibfile-ignore-regexps))) 352 reftex-bibfile-ignore-regexps)))
353 ;; excluded file 353 ;; excluded file
354 nil 354 nil
355 ;; find the file 355 ;; find the file
356 (reftex-locate-file x "bib" master-dir))) 356 (reftex-locate-file x "bib" master-dir)))
357 files)) 357 files))
358 (delq nil files))) 358 (delq nil files)))
359 359
360(defun reftex-replace-label-list-segment (old insert &optional entirely) 360(defun reftex-replace-label-list-segment (old insert &optional entirely)
@@ -387,24 +387,24 @@ of master file."
387 ;; Carefull: This function expects the match-data to be still in place! 387 ;; Carefull: This function expects the match-data to be still in place!
388 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3)))) 388 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3))))
389 (macro (reftex-match-string 3)) 389 (macro (reftex-match-string 3))
390 (prefix (save-match-data 390 (prefix (save-match-data
391 (if (string-match "begin{\\([^}]+\\)}" macro) 391 (if (string-match "begin{\\([^}]+\\)}" macro)
392 (match-string 1 macro)))) 392 (match-string 1 macro))))
393 (level-exp (cdr (assoc macro reftex-section-levels-all))) 393 (level-exp (cdr (assoc macro reftex-section-levels-all)))
394 (level (if (symbolp level-exp) 394 (level (if (symbolp level-exp)
395 (save-match-data (funcall level-exp)) 395 (save-match-data (funcall level-exp))
396 level-exp)) 396 level-exp))
397 (star (= ?* (char-after (match-end 3)))) 397 (star (= ?* (char-after (match-end 3))))
398 (unnumbered (or star (< level 0))) 398 (unnumbered (or star (< level 0)))
399 (level (abs level)) 399 (level (abs level))
400 (section-number (reftex-section-number level unnumbered)) 400 (section-number (reftex-section-number level unnumbered))
401 (text1 (save-match-data 401 (text1 (save-match-data
402 (save-excursion 402 (save-excursion
403 (reftex-context-substring prefix)))) 403 (reftex-context-substring prefix))))
404 (literal (buffer-substring-no-properties 404 (literal (buffer-substring-no-properties
405 (1- (match-beginning 3)) 405 (1- (match-beginning 3))
406 (min (point-max) (+ (match-end 0) (length text1) 1)))) 406 (min (point-max) (+ (match-end 0) (length text1) 1))))
407 ;; Literal can be too short since text1 too short. No big problem. 407 ;; Literal can be too short since text1 too short. No big problem.
408 (text (reftex-nicify-text text1))) 408 (text (reftex-nicify-text text1)))
409 409
410 ;; Add section number and indentation 410 ;; Add section number and indentation
@@ -413,7 +413,7 @@ of master file."
413 (make-string (* reftex-level-indent level) ?\ ) 413 (make-string (* reftex-level-indent level) ?\ )
414 (if (nth 1 reftex-label-menu-flags) ; section number flag 414 (if (nth 1 reftex-label-menu-flags) ; section number flag
415 (concat section-number " ")) 415 (concat section-number " "))
416 (if prefix (concat (capitalize prefix) ": ") "") 416 (if prefix (concat (capitalize prefix) ": ") "")
417 text)) 417 text))
418 (list 'toc "toc" text file marker level section-number 418 (list 'toc "toc" text file marker level section-number
419 literal (marker-position marker)))) 419 literal (marker-position marker))))
@@ -426,12 +426,12 @@ of master file."
426 (reftex-support-index t) 426 (reftex-support-index t)
427 ((y-or-n-p "Turn on index support and rescan entire document? ") 427 ((y-or-n-p "Turn on index support and rescan entire document? ")
428 (setq reftex-support-index 'demanded 428 (setq reftex-support-index 'demanded
429 current-prefix-arg '(16))) 429 current-prefix-arg '(16)))
430 (t (if abort 430 (t (if abort
431 (error "No index support") 431 (error "No index support")
432 (message "No index support") 432 (message "No index support")
433 (ding) 433 (ding)
434 (sit-for 1))))) 434 (sit-for 1)))))
435 435
436(defun reftex-index-info-safe (file) 436(defun reftex-index-info-safe (file)
437 (reftex-with-special-syntax 437 (reftex-with-special-syntax
@@ -443,49 +443,49 @@ of master file."
443 ;; Carefull: This function expects the match-data to be still in place! 443 ;; Carefull: This function expects the match-data to be still in place!
444 (catch 'exit 444 (catch 'exit
445 (let* ((macro (reftex-match-string 10)) 445 (let* ((macro (reftex-match-string 10))
446 (bom (match-beginning 10)) 446 (bom (match-beginning 10))
447 (boa (match-end 10)) 447 (boa (match-end 10))
448 (entry (or (assoc macro reftex-index-macro-alist) 448 (entry (or (assoc macro reftex-index-macro-alist)
449 (throw 'exit nil))) 449 (throw 'exit nil)))
450 (exclude (nth 3 entry)) 450 (exclude (nth 3 entry))
451 ;; The following is a test if this match should be excluded 451 ;; The following is a test if this match should be excluded
452 (test-dummy (and (fboundp exclude) 452 (test-dummy (and (fboundp exclude)
453 (funcall exclude) 453 (funcall exclude)
454 (throw 'exit nil))) 454 (throw 'exit nil)))
455 (itag (nth 1 entry)) 455 (itag (nth 1 entry))
456 (prefix (nth 2 entry)) 456 (prefix (nth 2 entry))
457 (index-tag 457 (index-tag
458 (cond ((stringp itag) itag) 458 (cond ((stringp itag) itag)
459 ((integerp itag) 459 ((integerp itag)
460 (progn (goto-char boa) 460 (progn (goto-char boa)
461 (or (reftex-nth-arg itag (nth 6 entry)) "idx"))) 461 (or (reftex-nth-arg itag (nth 6 entry)) "idx")))
462 (t "idx"))) 462 (t "idx")))
463 (arg (or (progn (goto-char boa) 463 (arg (or (progn (goto-char boa)
464 (reftex-nth-arg (nth 5 entry) (nth 6 entry))) 464 (reftex-nth-arg (nth 5 entry) (nth 6 entry)))
465 "")) 465 ""))
466 (end-of-args (progn (goto-char boa) 466 (end-of-args (progn (goto-char boa)
467 (reftex-move-over-touching-args) 467 (reftex-move-over-touching-args)
468 (point))) 468 (point)))
469 (end-of-context (progn (skip-chars-forward "^ \t\n\r") (point))) 469 (end-of-context (progn (skip-chars-forward "^ \t\n\r") (point)))
470 (begin-of-context 470 (begin-of-context
471 (progn (goto-char bom) 471 (progn (goto-char bom)
472 (skip-chars-backward "^ \t\r\n") 472 (skip-chars-backward "^ \t\r\n")
473 (point))) 473 (point)))
474 (context (buffer-substring-no-properties 474 (context (buffer-substring-no-properties
475 begin-of-context end-of-context)) 475 begin-of-context end-of-context))
476 (key-end (if (string-match reftex-index-key-end-re arg) 476 (key-end (if (string-match reftex-index-key-end-re arg)
477 (1+ (match-beginning 0)))) 477 (1+ (match-beginning 0))))
478 (rawkey (substring arg 0 key-end)) 478 (rawkey (substring arg 0 key-end))
479 479
480 (key (if prefix (concat prefix rawkey) rawkey)) 480 (key (if prefix (concat prefix rawkey) rawkey))
481 (sortkey (downcase key)) 481 (sortkey (downcase key))
482 (showkey (mapconcat 'identity 482 (showkey (mapconcat 'identity
483 (split-string key reftex-index-level-re) 483 (split-string key reftex-index-level-re)
484 " ! "))) 484 " ! ")))
485 (goto-char end-of-args) 485 (goto-char end-of-args)
486 ;; 0 1 2 3 4 5 6 7 8 9 486 ;; 0 1 2 3 4 5 6 7 8 9
487 (list 'index index-tag context file bom arg key showkey sortkey key-end)))) 487 (list 'index index-tag context file bom arg key showkey sortkey key-end))))
488 488
489(defun reftex-short-context (env parse &optional bound derive) 489(defun reftex-short-context (env parse &optional bound derive)
490 ;; Get about one line of useful context for the label definition at point. 490 ;; Get about one line of useful context for the label definition at point.
491 491
@@ -516,9 +516,9 @@ of master file."
516 (match-string 1 (nth 7 reftex-active-toc))) 516 (match-string 1 (nth 7 reftex-active-toc)))
517 "SECTION HEADING NOT FOUND"))) 517 "SECTION HEADING NOT FOUND")))
518 (save-excursion 518 (save-excursion
519 (goto-char reftex-default-context-position) 519 (goto-char reftex-default-context-position)
520 (unless (eq (string-to-char env) ?\\) 520 (unless (eq (string-to-char env) ?\\)
521 (reftex-move-over-touching-args)) 521 (reftex-move-over-touching-args))
522 (reftex-context-substring)))) 522 (reftex-context-substring))))
523 523
524 ((stringp parse) 524 ((stringp parse)
@@ -593,7 +593,7 @@ of master file."
593 ((looking-at (reftex-make-regexp-allow-for-ctrl-m 593 ((looking-at (reftex-make-regexp-allow-for-ctrl-m
594 (nth 7 (car list)))) 594 (nth 7 (car list))))
595 ;; Same title: remember, but keep looking 595 ;; Same title: remember, but keep looking
596 (setq rtn-if-no-other (car list))))) 596 (setq rtn-if-no-other (car list)))))
597 (pop list)) 597 (pop list))
598 rtn1)) 598 rtn1))
599 ((match-end 7) 599 ((match-end 7)
@@ -601,35 +601,35 @@ of master file."
601 (car 601 (car
602 (member (list 'eof (reftex-locate-file 602 (member (list 'eof (reftex-locate-file
603 (reftex-match-string 7) "tex" 603 (reftex-match-string 7) "tex"
604 (cdr (assq 'master-dir docstruct)))) 604 (cdr (assq 'master-dir docstruct))))
605 docstruct))) 605 docstruct)))
606 ((match-end 9) 606 ((match-end 9)
607 (assq 'appendix (symbol-value reftex-docstruct-symbol))) 607 (assq 'appendix (symbol-value reftex-docstruct-symbol)))
608 ((match-end 10) 608 ((match-end 10)
609 ;; Index entry 609 ;; Index entry
610 (when reftex-support-index 610 (when reftex-support-index
611 (let* ((index-info (save-excursion 611 (let* ((index-info (save-excursion
612 (reftex-index-info-safe nil))) 612 (reftex-index-info-safe nil)))
613 (list (member (list 'bof (buffer-file-name)) 613 (list (member (list 'bof (buffer-file-name))
614 docstruct)) 614 docstruct))
615 (endelt (car (member (list 'eof (buffer-file-name)) 615 (endelt (car (member (list 'eof (buffer-file-name))
616 list))) 616 list)))
617 dist last-dist last (n 0)) 617 dist last-dist last (n 0))
618 ;; Check all index entries with equal text 618 ;; Check all index entries with equal text
619 (while (and list (not (eq endelt (car list)))) 619 (while (and list (not (eq endelt (car list))))
620 (when (and (eq (car (car list)) 'index) 620 (when (and (eq (car (car list)) 'index)
621 (string= (nth 2 index-info) 621 (string= (nth 2 index-info)
622 (nth 2 (car list)))) 622 (nth 2 (car list))))
623 (incf n) 623 (incf n)
624 (setq dist (abs (- (point) (nth 4 (car list))))) 624 (setq dist (abs (- (point) (nth 4 (car list)))))
625 (if (or (not last-dist) (< dist last-dist)) 625 (if (or (not last-dist) (< dist last-dist))
626 (setq last-dist dist last (car list)))) 626 (setq last-dist dist last (car list))))
627 (setq list (cdr list))) 627 (setq list (cdr list)))
628 ;; We are sure if we have only one, or a zero distance 628 ;; We are sure if we have only one, or a zero distance
629 (cond ((or (= n 1) (equal dist 0)) last) 629 (cond ((or (= n 1) (= dist 0)) last)
630 ((> n 1) (setq cnt 2) last) 630 ((> n 1) (setq cnt 2) last)
631 (t nil))))) 631 (t nil)))))
632 ((match-end 11) 632 ((match-end 11)
633 (save-excursion 633 (save-excursion
634 (goto-char (match-end 11)) 634 (goto-char (match-end 11))
635 (assoc (reftex-no-props 635 (assoc (reftex-no-props
@@ -641,88 +641,88 @@ of master file."
641 ;; Check if there was only a by-name match for the section. 641 ;; Check if there was only a by-name match for the section.
642 (when (and (not rtn) rtn-if-no-other) 642 (when (and (not rtn) rtn-if-no-other)
643 (setq rtn rtn-if-no-other 643 (setq rtn rtn-if-no-other
644 cnt 2)) 644 cnt 2))
645 (cons rtn (eq cnt 1)))) 645 (cons rtn (eq cnt 1))))
646 646
647(defun reftex-notice-new (&optional n force) 647(defun reftex-notice-new (&optional n force)
648 "Hook to handshake with RefTeX after something new has been inserted." 648 "Hook to handshake with RefTeX after something new has been inserted."
649 ;; Add a new entry to the docstruct list. If it is a section, renumber 649 ;; Add a new entry to the docstruct list. If it is a section, renumber
650 ;; the following sections. 650 ;; the following sections.
651 ;; FIXME: Put in a WHAT parameter and search backward until one is found. 651 ;; FIXME: Put in a WHAT parameter
652 ;; When N is given, go back that many matches of reftex-everything-regexp 652 ;; When N is given, go back that many matches of reftex-everything-regexp
653 ;; When FORCE is non-nil, also insert if `reftex-where-am-I' was uncertain. 653 ;; When FORCE is non-nil, also insert if `reftex-where-am-I' was uncertain.
654 (condition-case nil 654 (condition-case nil
655 (catch 'exit 655 (catch 'exit
656 (unless reftex-mode (throw 'exit nil)) 656 (unless reftex-mode (throw 'exit nil))
657 (reftex-access-scan-info) 657 (reftex-access-scan-info)
658 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) 658 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
659 here-I-am appendix tail entry star level 659 here-I-am appendix tail entry star level
660 section-number context) 660 section-number context)
661 661
662 (save-excursion 662 (save-excursion
663 (when (re-search-backward (reftex-everything-regexp) nil t (or n 1)) 663 (when (re-search-backward (reftex-everything-regexp) nil t (or n 1))
664 664
665 ;; Find where we are 665 ;; Find where we are
666 (setq here-I-am (reftex-where-am-I)) 666 (setq here-I-am (reftex-where-am-I))
667 (or here-I-am (throw 'exit nil)) 667 (or here-I-am (throw 'exit nil))
668 (unless (or force (cdr here-I-am)) (throw 'exit nil)) 668 (unless (or force (cdr here-I-am)) (throw 'exit nil))
669 (setq tail (memq (car here-I-am) docstruct)) 669 (setq tail (memq (car here-I-am) docstruct))
670 (or tail (throw 'exit nil)) 670 (or tail (throw 'exit nil))
671 (setq reftex-active-toc (reftex-last-assoc-before-elt 671 (setq reftex-active-toc (reftex-last-assoc-before-elt
672 'toc (car here-I-am) docstruct) 672 'toc (car here-I-am) docstruct)
673 appendix (reftex-last-assoc-before-elt 673 appendix (reftex-last-assoc-before-elt
674 'appendix (car here-I-am) docstruct)) 674 'appendix (car here-I-am) docstruct))
675 675
676 ;; Initialize section numbers 676 ;; Initialize section numbers
677 (if (eq (car (car here-I-am)) 'appendix) 677 (if (eq (car (car here-I-am)) 'appendix)
678 (reftex-init-section-numbers nil t) 678 (reftex-init-section-numbers nil t)
679 (reftex-init-section-numbers reftex-active-toc appendix)) 679 (reftex-init-section-numbers reftex-active-toc appendix))
680 680
681 ;; Match the section command 681 ;; Match the section command
682 (when (re-search-forward (reftex-everything-regexp) nil t) 682 (when (re-search-forward (reftex-everything-regexp) nil t)
683 (cond 683 (cond
684 ((match-end 1) 684 ((match-end 1)
685 (push (reftex-label-info (reftex-match-string 1) buffer-file-name) 685 (push (reftex-label-info (reftex-match-string 1) buffer-file-name)
686 (cdr tail))) 686 (cdr tail)))
687 687
688 ((match-end 3) 688 ((match-end 3)
689 (setq star (= ?* (char-after (match-end 3))) 689 (setq star (= ?* (char-after (match-end 3)))
690 entry (reftex-section-info (buffer-file-name)) 690 entry (reftex-section-info (buffer-file-name))
691 level (nth 5 entry)) 691 level (nth 5 entry))
692 ;; Insert the section info 692 ;; Insert the section info
693 (push entry (cdr tail)) 693 (push entry (cdr tail))
694 694
695 ;; We are done unless we use section numbers 695 ;; We are done unless we use section numbers
696 (unless (nth 1 reftex-label-menu-flags) (throw 'exit nil)) 696 (unless (nth 1 reftex-label-menu-flags) (throw 'exit nil))
697 697
698 ;; Update the remaining toc items 698 ;; Update the remaining toc items
699 (setq tail (cdr tail)) 699 (setq tail (cdr tail))
700 (while (and (setq tail (memq (assq 'toc (cdr tail)) tail)) 700 (while (and (setq tail (memq (assq 'toc (cdr tail)) tail))
701 (setq entry (car tail)) 701 (setq entry (car tail))
702 (>= (nth 5 entry) level)) 702 (>= (nth 5 entry) level))
703 (setq star (string-match "\\*" (nth 6 entry)) 703 (setq star (string-match "\\*" (nth 6 entry))
704 context (nth 2 entry) 704 context (nth 2 entry)
705 section-number 705 section-number
706 (reftex-section-number (nth 5 entry) star)) 706 (reftex-section-number (nth 5 entry) star))
707 (when (string-match "\\`\\([ \t]*\\)\\([.0-9A-Z]+\\)\\(.*\\)" 707 (when (string-match "\\`\\([ \t]*\\)\\([.0-9A-Z]+\\)\\(.*\\)"
708 context) 708 context)
709 (when (and (not appendix) 709 (when (and (not appendix)
710 (>= (string-to-char (match-string 2)) ?A)) 710 (>= (string-to-char (match-string 2)) ?A))
711 ;; Just entered the appendex. Get out. 711 ;; Just entered the appendex. Get out.
712 (throw 'exit nil)) 712 (throw 'exit nil))
713 713
714 ;; Change the section number. 714 ;; Change the section number.
715 (setf (nth 2 entry) 715 (setf (nth 2 entry)
716 (concat (match-string 1 context) 716 (concat (match-string 1 context)
717 section-number 717 section-number
718 (match-string 3 context)))))) 718 (match-string 3 context))))))
719 ((match-end 10) 719 ((match-end 10)
720 ;; Index entry 720 ;; Index entry
721 (and reftex-support-index 721 (and reftex-support-index
722 (setq entry (reftex-index-info-safe buffer-file-name)) 722 (setq entry (reftex-index-info-safe buffer-file-name))
723 ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry)) 723 ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry))
724 (push entry (cdr tail)))))))))) 724 (push entry (cdr tail))))))))))
725 725
726 (error nil)) 726 (error nil))
727 ) 727 )
728 728
@@ -736,8 +736,8 @@ of master file."
736 ((memq (preceding-char) '(?\] ?\}))) 736 ((memq (preceding-char) '(?\] ?\})))
737 ;; Do a search 737 ;; Do a search
738 ((and reftex-allow-detached-macro-args 738 ((and reftex-allow-detached-macro-args
739 (re-search-backward 739 (re-search-backward
740 "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t)) 740 "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t))
741 (goto-char (1+ (match-beginning 0))) 741 (goto-char (1+ (match-beginning 0)))
742 t) 742 t)
743 (t nil))) 743 (t nil)))
@@ -774,7 +774,7 @@ of master file."
774 pos cmd-list cmd cnt cnt-opt entry) 774 pos cmd-list cmd cnt cnt-opt entry)
775 (save-restriction 775 (save-restriction
776 (save-excursion 776 (save-excursion
777 (narrow-to-region (max 1 bound) (point-max)) 777 (narrow-to-region (max (point-min) bound) (point-max))
778 ;; move back out of the current parenthesis 778 ;; move back out of the current parenthesis
779 (while (condition-case nil 779 (while (condition-case nil
780 (progn (up-list -1) t) 780 (progn (up-list -1) t)
@@ -782,29 +782,29 @@ of master file."
782 (setq cnt 1 cnt-opt 0) 782 (setq cnt 1 cnt-opt 0)
783 ;; move back over any touching sexps 783 ;; move back over any touching sexps
784 (while (and (reftex-move-to-previous-arg bound) 784 (while (and (reftex-move-to-previous-arg bound)
785 (condition-case nil 785 (condition-case nil
786 (progn (backward-sexp) t) 786 (progn (backward-sexp) t)
787 (error nil))) 787 (error nil)))
788 (if (eq (following-char) ?\[) (incf cnt-opt)) 788 (if (eq (following-char) ?\[) (incf cnt-opt))
789 (incf cnt)) 789 (incf cnt))
790 (setq pos (point)) 790 (setq pos (point))
791 (when (and (or (= (following-char) ?\[) 791 (when (and (or (= (following-char) ?\[)
792 (= (following-char) ?\{)) 792 (= (following-char) ?\{))
793 (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t)) 793 (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
794 (setq cmd (reftex-match-string 0)) 794 (setq cmd (reftex-match-string 0))
795 (when (looking-at "\\\\begin{[^}]*}") 795 (when (looking-at "\\\\begin{[^}]*}")
796 (setq cmd (reftex-match-string 0) 796 (setq cmd (reftex-match-string 0)
797 cnt (1- cnt))) 797 cnt (1- cnt)))
798 ;; This does ignore optional arguments. Very hard to fix. 798 ;; This does ignore optional arguments. Very hard to fix.
799 (when (setq entry (assoc cmd reftex-env-or-mac-alist)) 799 (when (setq entry (assoc cmd reftex-env-or-mac-alist))
800 (if (> cnt (or (nth 4 entry) 100)) 800 (if (> cnt (or (nth 4 entry) 100))
801 (setq cmd nil))) 801 (setq cmd nil)))
802 (cond 802 (cond
803 ((null cmd)) 803 ((null cmd))
804 ((eq t which) 804 ((eq t which)
805 (push (cons cmd (point)) cmd-list)) 805 (push (cons cmd (point)) cmd-list))
806 ((or (eq 1 which) (member cmd which)) 806 ((or (eq 1 which) (member cmd which))
807 (throw 'exit (cons cmd (point)))))) 807 (throw 'exit (cons cmd (point))))))
808 (goto-char pos))) 808 (goto-char pos)))
809 (nreverse cmd-list))))) 809 (nreverse cmd-list)))))
810 810
@@ -837,7 +837,7 @@ of master file."
837 (match-beginning 2) (match-end 2))) 837 (match-beginning 2) (match-end 2)))
838 (cond 838 (cond
839 ((string= (match-string 1) "end") 839 ((string= (match-string 1) "end")
840 (push env end-list)) 840 (push env end-list))
841 ((equal env (car end-list)) 841 ((equal env (car end-list))
842 (setq end-list (cdr end-list))) 842 (setq end-list (cdr end-list)))
843 ((eq t which) 843 ((eq t which)
@@ -867,25 +867,25 @@ of master file."
867 (let ((bound (or bound (save-excursion (re-search-backward 867 (let ((bound (or bound (save-excursion (re-search-backward
868 reftex-section-regexp nil 1) 868 reftex-section-regexp nil 1)
869 (point)))) 869 (point))))
870 (fun-list (if (listp which) 870 (fun-list (if (listp which)
871 (mapcar (lambda (x) (if (memq x which) x nil)) 871 (mapcar (lambda (x) (if (memq x which) x nil))
872 reftex-special-env-parsers) 872 reftex-special-env-parsers)
873 reftex-special-env-parsers)) 873 reftex-special-env-parsers))
874 specials rtn) 874 specials rtn)
875 ;; Call all functions 875 ;; Call all functions
876 (setq specials (mapcar 876 (setq specials (mapcar
877 (lambda (fun) 877 (lambda (fun)
878 (save-excursion 878 (save-excursion
879 (setq rtn (and fun (funcall fun bound))) 879 (setq rtn (and fun (funcall fun bound)))
880 (if rtn (cons (symbol-name fun) rtn) nil))) 880 (if rtn (cons (symbol-name fun) rtn) nil)))
881 fun-list)) 881 fun-list))
882 ;; Delete the non-matches 882 ;; Delete the non-matches
883 (setq specials (delq nil specials)) 883 (setq specials (delq nil specials))
884 ;; Sort 884 ;; Sort
885 (setq specials (sort specials (lambda (a b) (> (cdr a) (cdr b))))) 885 (setq specials (sort specials (lambda (a b) (> (cdr a) (cdr b)))))
886 (if (eq which t) 886 (if (eq which t)
887 specials 887 specials
888 (car specials)))))) 888 (car specials))))))
889 889
890(defsubst reftex-move-to-next-arg (&optional ignore) 890(defsubst reftex-move-to-next-arg (&optional ignore)
891 ;; Assuming that we are at the end of a macro name or a macro argument, 891 ;; Assuming that we are at the end of a macro name or a macro argument,
@@ -897,7 +897,7 @@ of master file."
897 ((memq (following-char) '(?\[ ?\{))) 897 ((memq (following-char) '(?\[ ?\{)))
898 ;; Do a search 898 ;; Do a search
899 ((and reftex-allow-detached-macro-args 899 ((and reftex-allow-detached-macro-args
900 (looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]")) 900 (looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]"))
901 (goto-char (1- (match-end 0))) 901 (goto-char (1- (match-end 0)))
902 t) 902 t)
903 (t nil))) 903 (t nil)))
@@ -916,39 +916,39 @@ of master file."
916 (if (= n 1000) 916 (if (= n 1000)
917 ;; Special case: Skip all touching arguments 917 ;; Special case: Skip all touching arguments
918 (progn 918 (progn
919 (reftex-move-over-touching-args) 919 (reftex-move-over-touching-args)
920 (reftex-context-substring)) 920 (reftex-context-substring))
921 921
922 ;; Do the real thing. 922 ;; Do the real thing.
923 (let ((cnt 1)) 923 (let ((cnt 1))
924 924
925 (when (reftex-move-to-next-arg) 925 (when (reftex-move-to-next-arg)
926 926
927 (while (< cnt n) 927 (while (< cnt n)
928 (while (and (member cnt opt-args) 928 (while (and (member cnt opt-args)
929 (eq (following-char) ?\{)) 929 (eq (following-char) ?\{))
930 (incf cnt)) 930 (incf cnt))
931 (when (< cnt n) 931 (when (< cnt n)
932 (unless (and (condition-case nil 932 (unless (and (condition-case nil
933 (or (forward-list 1) t) 933 (or (forward-list 1) t)
934 (error nil)) 934 (error nil))
935 (reftex-move-to-next-arg) 935 (reftex-move-to-next-arg)
936 (incf cnt)) 936 (incf cnt))
937 (setq cnt 1000)))) 937 (setq cnt 1000))))
938 938
939 (while (and (memq cnt opt-args) 939 (while (and (memq cnt opt-args)
940 (eq (following-char) ?\{)) 940 (eq (following-char) ?\{))
941 (incf cnt))) 941 (incf cnt)))
942 (if (and (= n cnt) 942 (if (and (= n cnt)
943 (> (skip-chars-forward "{\\[") 0)) 943 (> (skip-chars-forward "{\\[") 0))
944 (reftex-context-substring) 944 (reftex-context-substring)
945 nil)))) 945 nil))))
946 946
947(defun reftex-move-over-touching-args () 947(defun reftex-move-over-touching-args ()
948 (condition-case nil 948 (condition-case nil
949 (while (memq (following-char) '(?\[ ?\{)) 949 (while (memq (following-char) '(?\[ ?\{))
950 (forward-list 1)) 950 (forward-list 1))
951 (error nil))) 951 (error nil)))
952 952
953(defun reftex-context-substring (&optional to-end) 953(defun reftex-context-substring (&optional to-end)
954 ;; Return up to 150 chars from point 954 ;; Return up to 150 chars from point
@@ -959,11 +959,11 @@ of master file."
959 (buffer-substring-no-properties 959 (buffer-substring-no-properties
960 (point) 960 (point)
961 (min (+ (point) 150) 961 (min (+ (point) 150)
962 (save-match-data 962 (save-match-data
963 ;; FIXME: This is not perfect 963 ;; FIXME: THis is not perfect
964 (if (re-search-forward "\\\\end{" nil t) 964 (if (re-search-forward "\\\\end{" nil t)
965 (match-beginning 0) 965 (match-beginning 0)
966 (point-max)))))) 966 (point-max))))))
967 ((or (= (preceding-char) ?\{) 967 ((or (= (preceding-char) ?\{)
968 (= (preceding-char) ?\[)) 968 (= (preceding-char) ?\[))
969 ;; Inside a list - get only the list. 969 ;; Inside a list - get only the list.
@@ -978,8 +978,8 @@ of master file."
978 (error (point-max)))))) 978 (error (point-max))))))
979 (t 979 (t
980 ;; no list - just grab 150 characters 980 ;; no list - just grab 150 characters
981 (buffer-substring-no-properties (point) 981 (buffer-substring-no-properties (point)
982 (min (+ (point) 150) (point-max)))))) 982 (min (+ (point) 150) (point-max))))))
983 983
984;; Variable holding the vector with section numbers 984;; Variable holding the vector with section numbers
985(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0)) 985(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0))
@@ -994,11 +994,11 @@ of master file."
994 (while (>= i 0) 994 (while (>= i 0)
995 (if (> i level) 995 (if (> i level)
996 (aset reftex-section-numbers i 0) 996 (aset reftex-section-numbers i 0)
997 (setq number-string (or (car numbers) "0")) 997 (setq number-string (or (car numbers) "0"))
998 (if (string-match "\\`[A-Z]\\'" number-string) 998 (if (string-match "\\`[A-Z]\\'" number-string)
999 (aset reftex-section-numbers i 999 (aset reftex-section-numbers i
1000 (- (string-to-char number-string) ?A -1)) 1000 (- (string-to-char number-string) ?A -1))
1001 (aset reftex-section-numbers i (string-to-int number-string))) 1001 (aset reftex-section-numbers i (string-to-int number-string)))
1002 (pop numbers)) 1002 (pop numbers))
1003 (decf i))) 1003 (decf i)))
1004 (put 'reftex-section-numbers 'appendix appendix)) 1004 (put 'reftex-section-numbers 'appendix appendix))
@@ -1007,66 +1007,65 @@ of master file."
1007 ;; Return a string with the current section number. 1007 ;; Return a string with the current section number.
1008 ;; When LEVEL is non-nil, increase section numbers on that level. 1008 ;; When LEVEL is non-nil, increase section numbers on that level.
1009 (let* ((depth (1- (length reftex-section-numbers))) idx n (string "") 1009 (let* ((depth (1- (length reftex-section-numbers))) idx n (string "")
1010 (appendix (get 'reftex-section-numbers 'appendix)) 1010 (appendix (get 'reftex-section-numbers 'appendix))
1011 (partspecial (and (not reftex-part-resets-chapter) 1011 (partspecial (and (not reftex-part-resets-chapter)
1012 (equal level 0)))) 1012 (equal level 0))))
1013 ;; partspecial means, this is a part statement. 1013 ;; partspecial means, this is a part statement.
1014 ;; Parts do not reset the chapter counter, and the part number is 1014 ;; Parts do not reset the chapter counter, and the part number is
1015 ;; not included in the numbering of other sectioning levels. 1015 ;; not included in the numbering of other sectioning levels.
1016 (when level 1016 (when level
1017 (when (and (> level -1) (not star)) 1017 (when (and (> level -1) (not star))
1018 (aset reftex-section-numbers 1018 (aset reftex-section-numbers
1019 level (1+ (aref reftex-section-numbers level)))) 1019 level (1+ (aref reftex-section-numbers level))))
1020 (setq idx (1+ level)) 1020 (setq idx (1+ level))
1021 (when (not star) 1021 (when (not star)
1022 (while (<= idx depth) 1022 (while (<= idx depth)
1023 (if (or (not partspecial) 1023 (if (or (not partspecial)
1024 (not (= idx 1))) 1024 (not (= idx 1)))
1025 (aset reftex-section-numbers idx 0)) 1025 (aset reftex-section-numbers idx 0))
1026 (incf idx)))) 1026 (incf idx))))
1027 (if partspecial 1027 (if partspecial
1028 (setq string (concat "Part " (reftex-roman-number 1028 (setq string (concat "Part " (reftex-roman-number
1029 (aref reftex-section-numbers 0)))) 1029 (aref reftex-section-numbers 0))))
1030 (setq idx (if reftex-part-resets-chapter 0 1)) 1030 (setq idx (if reftex-part-resets-chapter 0 1))
1031 (while (<= idx depth) 1031 (while (<= idx depth)
1032 (setq n (aref reftex-section-numbers idx)) 1032 (setq n (aref reftex-section-numbers idx))
1033 (if (not (and partspecial (not (equal string "")))) 1033 (if (not (and partspecial (not (equal string ""))))
1034 (setq string (concat string (if (not (string= string "")) "." "") 1034 (setq string (concat string (if (not (string= string "")) "." "")
1035 (int-to-string n)))) 1035 (int-to-string n))))
1036 (incf idx)) 1036 (incf idx))
1037 (save-match-data 1037 (save-match-data
1038 (if (string-match "\\`\\([@0]\\.\\)+" string) 1038 (if (string-match "\\`\\([@0]\\.\\)+" string)
1039 (setq string (replace-match "" nil nil string))) 1039 (setq string (replace-match "" nil nil string)))
1040 (if (string-match "\\(\\.0\\)+\\'" string) 1040 (if (string-match "\\(\\.0\\)+\\'" string)
1041 (setq string (replace-match "" nil nil string))) 1041 (setq string (replace-match "" nil nil string)))
1042 (if (and appendix 1042 (if (and appendix
1043 (string-match "\\`[0-9]+" string)) 1043 (string-match "\\`[0-9]+" string))
1044 (setq string 1044 (setq string
1045 (concat 1045 (concat
1046 (char-to-string 1046 (char-to-string
1047 (1- (+ ?A (string-to-int (match-string 0 string))))) 1047 (1- (+ ?A (string-to-int (match-string 0 string)))))
1048 (substring string (match-end 0)))))) 1048 (substring string (match-end 0))))))
1049 (if star 1049 (if star
1050 (concat (make-string (1- (length string)) ?\ ) "*") 1050 (concat (make-string (1- (length string)) ?\ ) "*")
1051 string)))) 1051 string))))
1052 1052
1053(defun reftex-roman-number (n) 1053(defun reftex-roman-number (n)
1054 ;; Return as a string the roman number equal to N. 1054 ;; Return as a string the roman number equal to N.
1055 (let ((nrest n) 1055 (let ((nrest n)
1056 (string "") 1056 (string "")
1057 (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD") 1057 (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD")
1058 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL") 1058 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1059 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV") 1059 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1060 ( 1 . "I"))) 1060 ( 1 . "I")))
1061 listel i s) 1061 listel i s)
1062 (while (>= nrest 1) 1062 (while (>= nrest 1)
1063 (setq listel (pop list) 1063 (setq listel (pop list)
1064 i (car listel) 1064 i (car listel)
1065 s (cdr listel)) 1065 s (cdr listel))
1066 (while (>= nrest i) 1066 (while (>= nrest i)
1067 (setq string (concat string s) 1067 (setq string (concat string s)
1068 nrest (- nrest i)))) 1068 nrest (- nrest i))))
1069 string)) 1069 string))
1070 1070
1071;;; arch-tag: 6a8168f7-abb9-4576-99dc-fcbc7ba901a3
1072;;; reftex-parse.el ends here 1071;;; reftex-parse.el ends here