annotate lisp/textmodes/reftex-parse.el @ 112447:bcecab2ad22d

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