aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/textmodes
diff options
context:
space:
mode:
authorKenichi Handa2003-09-08 11:56:09 +0000
committerKenichi Handa2003-09-08 11:56:09 +0000
commit463f5630a5e7cbe7f042bc1175d1fa1c4e98860f (patch)
tree3287d0c628fea2249abf4635b3a4f45bedd6f8c4 /lisp/textmodes
parent4256310de631bd57c78b88b5131caa073315b3d7 (diff)
downloademacs-463f5630a5e7cbe7f042bc1175d1fa1c4e98860f.tar.gz
emacs-463f5630a5e7cbe7f042bc1175d1fa1c4e98860f.zip
New directory
Diffstat (limited to 'lisp/textmodes')
-rw-r--r--lisp/textmodes/artist.el1
-rw-r--r--lisp/textmodes/bib-mode.el2
-rw-r--r--lisp/textmodes/bibtex.el1
-rw-r--r--lisp/textmodes/enriched.el1
-rw-r--r--lisp/textmodes/fill.el1
-rw-r--r--lisp/textmodes/flyspell.el1
-rw-r--r--lisp/textmodes/ispell.el1
-rw-r--r--lisp/textmodes/makeinfo.el1
-rw-r--r--lisp/textmodes/nroff-mode.el1
-rw-r--r--lisp/textmodes/page-ext.el2
-rw-r--r--lisp/textmodes/page.el1
-rw-r--r--lisp/textmodes/paragraphs.el1
-rw-r--r--lisp/textmodes/picture.el1
-rw-r--r--lisp/textmodes/po.el1
-rw-r--r--lisp/textmodes/refbib.el1
-rw-r--r--lisp/textmodes/refer.el1
-rw-r--r--lisp/textmodes/refill.el2
-rw-r--r--lisp/textmodes/reftex-auc.el103
-rw-r--r--lisp/textmodes/reftex-cite.el821
-rw-r--r--lisp/textmodes/reftex-dcr.el415
-rw-r--r--lisp/textmodes/reftex-global.el251
-rw-r--r--lisp/textmodes/reftex-index.el1839
-rw-r--r--lisp/textmodes/reftex-parse.el869
-rw-r--r--lisp/textmodes/reftex-ref.el728
-rw-r--r--lisp/textmodes/reftex-sel.el485
-rw-r--r--lisp/textmodes/reftex-toc.el833
-rw-r--r--lisp/textmodes/reftex-vars.el356
-rw-r--r--lisp/textmodes/reftex.el1292
-rw-r--r--lisp/textmodes/sgml-mode.el1
-rw-r--r--lisp/textmodes/spell.el1
-rw-r--r--lisp/textmodes/table.el1
-rw-r--r--lisp/textmodes/tex-mode.el3
-rw-r--r--lisp/textmodes/texinfmt.el1
-rw-r--r--lisp/textmodes/texinfo.el1
-rw-r--r--lisp/textmodes/texnfo-upd.el1
-rw-r--r--lisp/textmodes/text-mode.el1
-rw-r--r--lisp/textmodes/tildify.el1
-rw-r--r--lisp/textmodes/two-column.el1
-rw-r--r--lisp/textmodes/underline.el1
39 files changed, 3764 insertions, 4261 deletions
diff --git a/lisp/textmodes/artist.el b/lisp/textmodes/artist.el
index e4f143c3b87..b973290725c 100644
--- a/lisp/textmodes/artist.el
+++ b/lisp/textmodes/artist.el
@@ -5515,5 +5515,4 @@ The event, EV, is the mouse event."
5515;; Don't hesitate to ask me any questions. 5515;; Don't hesitate to ask me any questions.
5516 5516
5517 5517
5518;;; arch-tag: 3e63b881-aaaa-4b83-a072-220d4661a8a3
5519;;; artist.el ends here 5518;;; artist.el ends here
diff --git a/lisp/textmodes/bib-mode.el b/lisp/textmodes/bib-mode.el
index 63714a3a096..82dd8cc785c 100644
--- a/lisp/textmodes/bib-mode.el
+++ b/lisp/textmodes/bib-mode.el
@@ -34,7 +34,6 @@
34(defgroup bib nil 34(defgroup bib nil
35 "Major mode for editing bib files." 35 "Major mode for editing bib files."
36 :prefix "bib-" 36 :prefix "bib-"
37 :group 'external
38 :group 'wp) 37 :group 'wp)
39 38
40(defcustom bib-file "~/my-bibliography.bib" 39(defcustom bib-file "~/my-bibliography.bib"
@@ -236,5 +235,4 @@ named by variable `unread-bib-file'."
236 235
237(provide 'bib-mode) 236(provide 'bib-mode)
238 237
239;;; arch-tag: e3a97958-3c2c-487f-9557-fafc3c98452d
240;;; bib-mode.el ends here 238;;; bib-mode.el ends here
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 480f304f175..141d1236417 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -3891,5 +3891,4 @@ is outside key or BibTeX field."
3891 3891
3892(provide 'bibtex) 3892(provide 'bibtex)
3893 3893
3894;;; arch-tag: ee2be3af-caad-427f-b42a-d20fad630d04
3895;;; bibtex.el ends here 3894;;; bibtex.el ends here
diff --git a/lisp/textmodes/enriched.el b/lisp/textmodes/enriched.el
index 05eaef06ce6..acbef7ae18e 100644
--- a/lisp/textmodes/enriched.el
+++ b/lisp/textmodes/enriched.el
@@ -471,5 +471,4 @@ the range of text to assign text property SYMBOL with value VALUE."
471 (message "Warning: invalid <x-display> parameter %s" param)) 471 (message "Warning: invalid <x-display> parameter %s" param))
472 (list start end 'display prop))) 472 (list start end 'display prop)))
473 473
474;;; arch-tag: 05cae488-3fea-45cd-ac29-5b02cb64e42b
475;;; enriched.el ends here 474;;; enriched.el ends here
diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el
index 69b17f677ff..c8e635268eb 100644
--- a/lisp/textmodes/fill.el
+++ b/lisp/textmodes/fill.el
@@ -1406,5 +1406,4 @@ Also, if CITATION-REGEXP is non-nil, don't fill header lines."
1406 "") 1406 "")
1407 string)) 1407 string))
1408 1408
1409;;; arch-tag: 727ad455-1161-4fa9-8df5-0f74b179216d
1410;;; fill.el ends here 1409;;; fill.el ends here
diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el
index dc4f521c018..9d553a68845 100644
--- a/lisp/textmodes/flyspell.el
+++ b/lisp/textmodes/flyspell.el
@@ -2123,5 +2123,4 @@ This function is meant to be added to 'flyspell-incorrect-hook'."
2123 2123
2124(provide 'flyspell) 2124(provide 'flyspell)
2125 2125
2126;;; arch-tag: 05d915b9-e9cf-44fb-9137-fc28f5eaab2a
2127;;; flyspell.el ends here 2126;;; flyspell.el ends here
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index e384c01b31b..5848956ac2a 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -3572,5 +3572,4 @@ Both should not be used to define a buffer-local dictionary."
3572; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict unsplitable 3572; LocalWords: uuencoded unidiff sc nn VM SGML eval IspellPersDict unsplitable
3573; LocalWords: lns XEmacs HTML casechars Multibyte 3573; LocalWords: lns XEmacs HTML casechars Multibyte
3574 3574
3575;;; arch-tag: 4941b9f9-3b7c-4a76-a4ed-5fa8b6010ef5
3576;;; ispell.el ends here 3575;;; ispell.el ends here
diff --git a/lisp/textmodes/makeinfo.el b/lisp/textmodes/makeinfo.el
index 9136cb52202..c7489216068 100644
--- a/lisp/textmodes/makeinfo.el
+++ b/lisp/textmodes/makeinfo.el
@@ -282,5 +282,4 @@ line LINE of the window, or centered if LINE is nil."
282;;; Place `provide' at end of file. 282;;; Place `provide' at end of file.
283(provide 'makeinfo) 283(provide 'makeinfo)
284 284
285;;; arch-tag: 5f810713-3de2-4e20-8030-4bc3dd0d9604
286;;; makeinfo.el ends here 285;;; makeinfo.el ends here
diff --git a/lisp/textmodes/nroff-mode.el b/lisp/textmodes/nroff-mode.el
index c0638804ffa..de122679f98 100644
--- a/lisp/textmodes/nroff-mode.el
+++ b/lisp/textmodes/nroff-mode.el
@@ -272,5 +272,4 @@ turns it on iff arg is positive, otherwise off."
272 272
273(provide 'nroff-mode) 273(provide 'nroff-mode)
274 274
275;;; arch-tag: 6e276340-6c65-4f65-b4e3-0ca431ddfb6c
276;;; nroff-mode.el ends here 275;;; nroff-mode.el ends here
diff --git a/lisp/textmodes/page-ext.el b/lisp/textmodes/page-ext.el
index 2afaafd6012..2c3fd38f340 100644
--- a/lisp/textmodes/page-ext.el
+++ b/lisp/textmodes/page-ext.el
@@ -800,6 +800,4 @@ to the same line in the pages buffer."
800 :syntax-table nil) 800 :syntax-table nil)
801 801
802(provide 'page-ext) 802(provide 'page-ext)
803
804;;; arch-tag: 2f311550-c6e0-4458-9c12-7f039c058bdb
805;;; page-ext.el ends here 803;;; page-ext.el ends here
diff --git a/lisp/textmodes/page.el b/lisp/textmodes/page.el
index f033a8504c8..ec09153d139 100644
--- a/lisp/textmodes/page.el
+++ b/lisp/textmodes/page.el
@@ -163,5 +163,4 @@ thus showing a page other than the one point was originally in."
163;;; Place `provide' at end of file. 163;;; Place `provide' at end of file.
164(provide 'page) 164(provide 'page)
165 165
166;;; arch-tag: e8d7a0bd-8655-4b6e-b852-f2ee25316a1d
167;;; page.el ends here 166;;; page.el ends here
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index 97abc2c1583..735eeca3e2a 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -469,5 +469,4 @@ ones already marked."
469;;; coding: iso-2022-7bit 469;;; coding: iso-2022-7bit
470;;; End: 470;;; End:
471 471
472;;; arch-tag: e727eb1a-527a-4464-b9d7-9d3ec0d1a575
473;;; paragraphs.el ends here 472;;; paragraphs.el ends here
diff --git a/lisp/textmodes/picture.el b/lisp/textmodes/picture.el
index 0497a823049..08357632177 100644
--- a/lisp/textmodes/picture.el
+++ b/lisp/textmodes/picture.el
@@ -755,5 +755,4 @@ With no argument strips whitespace from end of every line in Picture buffer
755 755
756(provide 'picture) 756(provide 'picture)
757 757
758;;; arch-tag: e452d08d-a470-4fbf-896e-ea276698d1ca
759;;; picture.el ends here 758;;; picture.el ends here
diff --git a/lisp/textmodes/po.el b/lisp/textmodes/po.el
index a4ec5d3ac8b..46e37311ab9 100644
--- a/lisp/textmodes/po.el
+++ b/lisp/textmodes/po.el
@@ -122,5 +122,4 @@ Called through `file-coding-system-alist', before the file is visited for real."
122 122
123(provide 'po) 123(provide 'po)
124 124
125;;; arch-tag: 56748a57-d64c-4200-8f6b-c3a70496eb8c
126;;; po.el ends here 125;;; po.el ends here
diff --git a/lisp/textmodes/refbib.el b/lisp/textmodes/refbib.el
index 5c9e6c1c6dc..4b3699409da 100644
--- a/lisp/textmodes/refbib.el
+++ b/lisp/textmodes/refbib.el
@@ -740,5 +740,4 @@ Please send bug reports and suggestions to
740(provide 'refbib) 740(provide 'refbib)
741(provide 'refer-to-bibtex) 741(provide 'refer-to-bibtex)
742 742
743;;; arch-tag: 664afee2-6e76-4408-ba56-981d8a179586
744;;; refbib.el ends here 743;;; refbib.el ends here
diff --git a/lisp/textmodes/refer.el b/lisp/textmodes/refer.el
index dd2006ad40d..9087f690a7c 100644
--- a/lisp/textmodes/refer.el
+++ b/lisp/textmodes/refer.el
@@ -395,5 +395,4 @@ found on the last refer-find-entry or refer-find-next-entry."
395 (setq refer-bib-files files)) 395 (setq refer-bib-files files))
396 files)) 396 files))
397 397
398;;; arch-tag: 151f641b-e79b-462b-9a29-a95c3793f300
399;;; refer.el ends here 398;;; refer.el ends here
diff --git a/lisp/textmodes/refill.el b/lisp/textmodes/refill.el
index 60b64e9a9f2..b5dd64a891a 100644
--- a/lisp/textmodes/refill.el
+++ b/lisp/textmodes/refill.el
@@ -3,7 +3,6 @@
3;; Copyright (C) 2000, 2003 Free Software Foundation, Inc. 3;; Copyright (C) 2000, 2003 Free Software Foundation, Inc.
4 4
5;; Author: Dave Love <fx@gnu.org> 5;; Author: Dave Love <fx@gnu.org>
6;; Maintainer: Miles Bader <miles@gnu.org>
7;; Keywords: wp 6;; Keywords: wp
8 7
9;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
@@ -257,5 +256,4 @@ refilling if they would cause auto-filling."
257 256
258(provide 'refill) 257(provide 'refill)
259 258
260;;; arch-tag: 2c4ce9e8-1daa-4a3b-b6f8-fd6ac5bf6138
261;;; refill.el ends here 259;;; refill.el ends here
diff --git a/lisp/textmodes/reftex-auc.el b/lisp/textmodes/reftex-auc.el
index 7b9ad8348ca..b71e325612e 100644
--- a/lisp/textmodes/reftex-auc.el
+++ b/lisp/textmodes/reftex-auc.el
@@ -1,8 +1,8 @@
1;;; reftex-auc.el --- RefTeX's interface to AUC TeX 1;;; reftex-auc.el --- RefTeX's interface to AUC TeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -34,7 +34,7 @@
34 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX 34 ;; Tell if a certain flag is set in reftex-plug-into-AUCTeX
35 (or (eq t reftex-plug-into-AUCTeX) 35 (or (eq t reftex-plug-into-AUCTeX)
36 (and (listp reftex-plug-into-AUCTeX) 36 (and (listp reftex-plug-into-AUCTeX)
37 (nth which reftex-plug-into-AUCTeX)))) 37 (nth which reftex-plug-into-AUCTeX))))
38 38
39(defun reftex-arg-label (optional &optional prompt definition) 39(defun reftex-arg-label (optional &optional prompt definition)
40 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg. 40 "Use `reftex-label', `reftex-reference' or AUCTeX's code to insert label arg.
@@ -44,17 +44,17 @@ What is being used depends upon `reftex-plug-into-AUCTeX'."
44 ((and definition (reftex-plug-flag 1)) 44 ((and definition (reftex-plug-flag 1))
45 ;; Create a new label, with a temporary brace for `reftex-what-macro' 45 ;; Create a new label, with a temporary brace for `reftex-what-macro'
46 (unwind-protect 46 (unwind-protect
47 (progn (insert "{") (setq label (or (reftex-label nil t) ""))) 47 (progn (insert "{") (setq label (or (reftex-label nil t) "")))
48 (delete-backward-char 1))) 48 (delete-backward-char 1)))
49 ((and (not definition) (reftex-plug-flag 2)) 49 ((and (not definition) (reftex-plug-flag 2))
50 ;; Reference a label with RefTeX 50 ;; Reference a label with RefTeX
51 (setq label (reftex-reference nil t))) 51 (setq label (reftex-reference nil t)))
52 (t 52 (t
53 ;; AUCTeX's default mechanism 53 ;; AUCTeX's default mechanism
54 (setq label (completing-read (TeX-argument-prompt optional prompt "Key") 54 (setq label (completing-read (TeX-argument-prompt optional prompt "Key")
55 (LaTeX-label-list))))) 55 (LaTeX-label-list)))))
56 (if (and definition (not (string-equal "" label))) 56 (if (and definition (not (string-equal "" label)))
57 (LaTeX-add-labels label)) 57 (LaTeX-add-labels label))
58 (TeX-argument-insert label optional))) 58 (TeX-argument-insert label optional)))
59 59
60(defun reftex-arg-cite (optional &optional prompt definition) 60(defun reftex-arg-cite (optional &optional prompt definition)
@@ -66,28 +66,28 @@ What is being used depends upon `reftex-plug-into-AUCTeX'."
66 (setq items (list (or (reftex-citation t) "")))) 66 (setq items (list (or (reftex-citation t) ""))))
67 (t 67 (t
68 (setq prompt (concat (if optional "(Optional) " "") 68 (setq prompt (concat (if optional "(Optional) " "")
69 (if prompt prompt "Add key") 69 (if prompt prompt "Add key")
70 ": (default none) ")) 70 ": (default none) "))
71 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list))))) 71 (setq items (multi-prompt "," t prompt (LaTeX-bibitem-list)))))
72 (apply 'LaTeX-add-bibitems items) 72 (apply 'LaTeX-add-bibitems items)
73 (TeX-argument-insert (mapconcat 'identity items ",") optional))) 73 (TeX-argument-insert (mapconcat 'identity items ",") optional)))
74 74
75 75
76(defun reftex-arg-index-tag (optional &optional prompt &rest args) 76(defun reftex-arg-index-tag (optional &optional prompt &rest args)
77 "Prompt for an index tag with completion. 77 "Prompt for an index tag with completion.
78This is the name of an index, not the entry." 78This is the name of an index, not the entry."
79 (let (tag taglist) 79 (let (tag taglist)
80 (setq prompt (concat (if optional "(Optional) " "") 80 (setq prompt (concat (if optional "(Optional) " "")
81 (if prompt prompt "Index tag") 81 (if prompt prompt "Index tag")
82 ": (default none) ")) 82 ": (default none) "))
83 (if (and reftex-support-index (reftex-plug-flag 4)) 83 (if (and reftex-support-index (reftex-plug-flag 4))
84 ;; Use RefTeX completion 84 ;; Use RefTeX completion
85 (progn 85 (progn
86 (reftex-access-scan-info nil) 86 (reftex-access-scan-info nil)
87 (setq taglist 87 (setq taglist
88 (cdr (assoc 'index-tags 88 (cdr (assoc 'index-tags
89 (symbol-value reftex-docstruct-symbol))) 89 (symbol-value reftex-docstruct-symbol)))
90 tag (completing-read prompt (mapcar 'list taglist)))) 90 tag (completing-read prompt (mapcar 'list taglist))))
91 ;; Just ask like AUCTeX does. 91 ;; Just ask like AUCTeX does.
92 (setq tag (read-string prompt))) 92 (setq tag (read-string prompt)))
93 (TeX-argument-insert tag optional))) 93 (TeX-argument-insert tag optional)))
@@ -98,12 +98,12 @@ Completion is specific for just one index, if the macro or a tag
98argument identify one of multiple indices." 98argument identify one of multiple indices."
99 (let* (tag key) 99 (let* (tag key)
100 (if (and reftex-support-index (reftex-plug-flag 4)) 100 (if (and reftex-support-index (reftex-plug-flag 4))
101 (progn 101 (progn
102 (reftex-access-scan-info nil) 102 (reftex-access-scan-info nil)
103 (setq tag (reftex-what-index-tag) 103 (setq tag (reftex-what-index-tag)
104 key (reftex-index-complete-key (or tag "idx")))) 104 key (reftex-index-complete-key (or tag "idx"))))
105 (setq key (completing-read (TeX-argument-prompt optional prompt "Key") 105 (setq key (completing-read (TeX-argument-prompt optional prompt "Key")
106 (LaTeX-index-entry-list)))) 106 (LaTeX-index-entry-list))))
107 (unless (string-equal "" key) 107 (unless (string-equal "" key)
108 (LaTeX-add-index-entries key)) 108 (LaTeX-add-index-entries key))
109 (TeX-argument-insert key optional))) 109 (TeX-argument-insert key optional)))
@@ -111,18 +111,18 @@ argument identify one of multiple indices."
111(defun reftex-what-index-tag () 111(defun reftex-what-index-tag ()
112 ;; Look backward to find out what index the macro at point belongs to 112 ;; Look backward to find out what index the macro at point belongs to
113 (let ((macro (save-excursion 113 (let ((macro (save-excursion
114 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t) 114 (and (re-search-backward "\\\\[a-zA-Z*]+" nil t)
115 (match-string 0)))) 115 (match-string 0))))
116 tag entry) 116 tag entry)
117 (when (and macro 117 (when (and macro
118 (setq entry (assoc macro reftex-index-macro-alist))) 118 (setq entry (assoc macro reftex-index-macro-alist)))
119 (setq tag (nth 1 entry)) 119 (setq tag (nth 1 entry))
120 (cond 120 (cond
121 ((stringp tag) tag) 121 ((stringp tag) tag)
122 ((integerp tag) 122 ((integerp tag)
123 (save-excursion 123 (save-excursion
124 (goto-char (match-end 1)) 124 (goto-char (match-end 1))
125 (or (reftex-nth-arg tag (nth 6 entry)) "idx"))) 125 (or (reftex-nth-arg tag (nth 6 entry)) "idx")))
126 (t "idx"))))) 126 (t "idx")))))
127 127
128(defvar LaTeX-label-function) 128(defvar LaTeX-label-function)
@@ -130,7 +130,7 @@ argument identify one of multiple indices."
130 ;; Replace AUCTeX functions with RefTeX functions. 130 ;; Replace AUCTeX functions with RefTeX functions.
131 ;; Which functions are replaced is controlled by the variable 131 ;; Which functions are replaced is controlled by the variable
132 ;; `reftex-plug-into-AUCTeX'. 132 ;; `reftex-plug-into-AUCTeX'.
133 133
134 (if (reftex-plug-flag 0) 134 (if (reftex-plug-flag 0)
135 (setq LaTeX-label-function 'reftex-label) 135 (setq LaTeX-label-function 'reftex-label)
136 (setq LaTeX-label-function nil)) 136 (setq LaTeX-label-function nil))
@@ -142,11 +142,11 @@ argument identify one of multiple indices."
142 (and (reftex-plug-flag 3) 142 (and (reftex-plug-flag 3)
143 (fboundp 'TeX-arg-cite) 143 (fboundp 'TeX-arg-cite)
144 (fset 'TeX-arg-cite 'reftex-arg-cite)) 144 (fset 'TeX-arg-cite 'reftex-arg-cite))
145 145
146 (and (reftex-plug-flag 4) 146 (and (reftex-plug-flag 4)
147 (fboundp 'TeX-arg-index-tag) 147 (fboundp 'TeX-arg-index-tag)
148 (fset 'TeX-arg-index-tag 'reftex-arg-index-tag)) 148 (fset 'TeX-arg-index-tag 'reftex-arg-index-tag))
149 (and (reftex-plug-flag 4) 149 (and (reftex-plug-flag 4)
150 (fboundp 'TeX-arg-index) 150 (fboundp 'TeX-arg-index)
151 (fset 'TeX-arg-index 'reftex-arg-index))) 151 (fset 'TeX-arg-index 'reftex-arg-index)))
152 152
@@ -174,17 +174,17 @@ the label information is recompiled on next use."
174 (unless reftex-docstruct-symbol 174 (unless reftex-docstruct-symbol
175 (reftex-tie-multifile-symbols)) 175 (reftex-tie-multifile-symbols))
176 (when (and reftex-docstruct-symbol 176 (when (and reftex-docstruct-symbol
177 (symbolp reftex-docstruct-symbol)) 177 (symbolp reftex-docstruct-symbol))
178 (let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style)) 178 (let ((list (get reftex-docstruct-symbol 'reftex-label-alist-style))
179 entry changed) 179 entry changed)
180 (while entry-list 180 (while entry-list
181 (setq entry (pop entry-list)) 181 (setq entry (pop entry-list))
182 (unless (member entry list) 182 (unless (member entry list)
183 (setq reftex-tables-dirty t 183 (setq reftex-tables-dirty t
184 changed t) 184 changed t)
185 (push entry list))) 185 (push entry list)))
186 (when changed 186 (when changed
187 (put reftex-docstruct-symbol 'reftex-label-alist-style list))))) 187 (put reftex-docstruct-symbol 'reftex-label-alist-style list)))))
188(defalias 'reftex-add-to-label-alist 'reftex-add-label-environments) 188(defalias 'reftex-add-to-label-alist 'reftex-add-label-environments)
189 189
190(defun reftex-add-section-levels (entry-list) 190(defun reftex-add-section-levels (entry-list)
@@ -195,20 +195,19 @@ of ENTRY-LIST is a list of cons cells (\"MACRONAME\" . LEVEL). See
195 (unless reftex-docstruct-symbol 195 (unless reftex-docstruct-symbol
196 (reftex-tie-multifile-symbols)) 196 (reftex-tie-multifile-symbols))
197 (when (and reftex-docstruct-symbol 197 (when (and reftex-docstruct-symbol
198 (symbolp reftex-docstruct-symbol)) 198 (symbolp reftex-docstruct-symbol))
199 (let ((list (get reftex-docstruct-symbol 'reftex-section-levels)) 199 (let ((list (get reftex-docstruct-symbol 'reftex-section-levels))
200 entry changed) 200 entry changed)
201 (while entry-list 201 (while entry-list
202 (setq entry (pop entry-list)) 202 (setq entry (pop entry-list))
203 (unless (member entry list) 203 (unless (member entry list)
204 (setq reftex-tables-dirty t 204 (setq reftex-tables-dirty t
205 changed t) 205 changed t)
206 (push entry list))) 206 (push entry list)))
207 (when changed 207 (when changed
208 (put reftex-docstruct-symbol 'reftex-section-levels list))))) 208 (put reftex-docstruct-symbol 'reftex-section-levels list)))))
209 209
210(defun reftex-notice-new-section () 210(defun reftex-notice-new-section ()
211 (reftex-notice-new 1 'force)) 211 (reftex-notice-new 1 'force))
212 212
213;;; arch-tag: 4a798e68-3405-421c-a09b-0269aac64ab4
214;;; reftex-auc.el ends here 213;;; reftex-auc.el ends here
diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el
index e25464c798d..acd33f3d62a 100644
--- a/lisp/textmodes/reftex-cite.el
+++ b/lisp/textmodes/reftex-cite.el
@@ -1,8 +1,8 @@
1;;; reftex-cite.el --- creating citations with RefTeX 1;;; reftex-cite.el --- creating citations with RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -57,21 +57,21 @@
57(defmacro reftex-with-special-syntax-for-bib (&rest body) 57(defmacro reftex-with-special-syntax-for-bib (&rest body)
58 `(let ((saved-syntax (syntax-table))) 58 `(let ((saved-syntax (syntax-table)))
59 (unwind-protect 59 (unwind-protect
60 (progn 60 (progn
61 (set-syntax-table reftex-syntax-table-for-bib) 61 (set-syntax-table reftex-syntax-table-for-bib)
62 ,@body) 62 ,@body)
63 (set-syntax-table saved-syntax)))) 63 (set-syntax-table saved-syntax))))
64 64
65(defun reftex-default-bibliography () 65(defun reftex-default-bibliography ()
66 ;; Return the expanded value of `reftex-default-bibliography'. 66 ;; Return the expanded value of `reftex-default-bibliography'.
67 ;; The expanded value is cached. 67 ;; The expanded value is cached.
68 (unless (eq (get 'reftex-default-bibliography :reftex-raw) 68 (unless (eq (get 'reftex-default-bibliography :reftex-raw)
69 reftex-default-bibliography) 69 reftex-default-bibliography)
70 (put 'reftex-default-bibliography :reftex-expanded 70 (put 'reftex-default-bibliography :reftex-expanded
71 (reftex-locate-bibliography-files 71 (reftex-locate-bibliography-files
72 default-directory reftex-default-bibliography)) 72 default-directory reftex-default-bibliography))
73 (put 'reftex-default-bibliography :reftex-raw 73 (put 'reftex-default-bibliography :reftex-raw
74 reftex-default-bibliography)) 74 reftex-default-bibliography))
75 (get 'reftex-default-bibliography :reftex-expanded)) 75 (get 'reftex-default-bibliography :reftex-expanded))
76 76
77(defun reftex-bib-or-thebib () 77(defun reftex-bib-or-thebib ()
@@ -79,19 +79,19 @@
79 ;; citation 79 ;; citation
80 ;; Find the bof of the current file 80 ;; Find the bof of the current file
81 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) 81 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
82 (rest (or (member (list 'bof (buffer-file-name)) docstruct) 82 (rest (or (member (list 'bof (buffer-file-name)) docstruct)
83 docstruct)) 83 docstruct))
84 (bib (assq 'bib rest)) 84 (bib (assq 'bib rest))
85 (thebib (assq 'thebib rest)) 85 (thebib (assq 'thebib rest))
86 (bibmem (memq bib rest)) 86 (bibmem (memq bib rest))
87 (thebibmem (memq thebib rest))) 87 (thebibmem (memq thebib rest)))
88 (when (not (or thebib bib)) 88 (when (not (or thebib bib))
89 (setq bib (assq 'bib docstruct) 89 (setq bib (assq 'bib docstruct)
90 thebib (assq 'thebib docstruct) 90 thebib (assq 'thebib docstruct)
91 bibmem (memq bib docstruct) 91 bibmem (memq bib docstruct)
92 thebibmem (memq thebib docstruct))) 92 thebibmem (memq thebib docstruct)))
93 (if (> (length bibmem) (length thebibmem)) 93 (if (> (length bibmem) (length thebibmem))
94 (if bib 'bib nil) 94 (if bib 'bib nil)
95 (if thebib 'thebib nil)))) 95 (if thebib 'thebib nil))))
96 96
97(defun reftex-get-bibfile-list () 97(defun reftex-get-bibfile-list ()
@@ -119,7 +119,7 @@
119;; Find a certain reference in any of the BibTeX files. 119;; Find a certain reference in any of the BibTeX files.
120 120
121(defun reftex-pop-to-bibtex-entry (key file-list &optional mark-to-kill 121(defun reftex-pop-to-bibtex-entry (key file-list &optional mark-to-kill
122 highlight item return) 122 highlight item return)
123 ;; Find BibTeX KEY in any file in FILE-LIST in another window. 123 ;; Find BibTeX KEY in any file in FILE-LIST in another window.
124 ;; If MARK-TO-KILL is non-nil, mark new buffer to kill. 124 ;; If MARK-TO-KILL is non-nil, mark new buffer to kill.
125 ;; If HIGHLIGHT is non-nil, highlight the match. 125 ;; If HIGHLIGHT is non-nil, highlight the match.
@@ -127,11 +127,11 @@
127 ;; If RETURN is non-nil, just return the entry. 127 ;; If RETURN is non-nil, just return the entry.
128 128
129 (let* ((re 129 (let* ((re
130 (if item 130 (if item
131 (concat "\\\\bibitem\\(\\[[^]]*\\]\\)?{" (regexp-quote key) "}") 131 (concat "\\\\bibitem\\(\\[[^]]*\\]\\)?{" (regexp-quote key) "}")
132 (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key) 132 (concat "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*" (regexp-quote key)
133 "[, \t\r\n}]"))) 133 "[, \t\r\n}]")))
134 (buffer-conf (current-buffer)) 134 (buffer-conf (current-buffer))
135 file buf pos) 135 file buf pos)
136 136
137 (catch 'exit 137 (catch 'exit
@@ -145,71 +145,47 @@
145 (goto-char (point-min)) 145 (goto-char (point-min))
146 (when (re-search-forward re nil t) 146 (when (re-search-forward re nil t)
147 (goto-char (match-beginning 0)) 147 (goto-char (match-beginning 0))
148 (setq pos (point)) 148 (setq pos (point))
149 (when return 149 (when return
150 ;; Just return the relevant entry 150 ;; Just return the relevant entry
151 (if item (goto-char (match-end 0))) 151 (if item (goto-char (match-end 0)))
152 (setq return (buffer-substring 152 (setq return (buffer-substring
153 (point) (reftex-end-of-bib-entry item))) 153 (point) (reftex-end-of-bib-entry item)))
154 (set-buffer buffer-conf) 154 (set-buffer buffer-conf)
155 (throw 'exit return)) 155 (throw 'exit return))
156 (switch-to-buffer-other-window buf) 156 (switch-to-buffer-other-window buf)
157 (goto-char pos) 157 (goto-char pos)
158 (recenter 0) 158 (recenter 0)
159 (if highlight 159 (if highlight
160 (reftex-highlight 0 (match-beginning 0) (match-end 0))) 160 (reftex-highlight 0 (match-beginning 0) (match-end 0)))
161 (throw 'exit (selected-window)))) 161 (throw 'exit (selected-window))))
162 (set-buffer buffer-conf) 162 (set-buffer buffer-conf)
163 (if item 163 (if item
164 (error "No \\bibitem with citation key %s" key) 164 (error "No \\bibitem with citation key %s" key)
165 (error "No BibTeX entry with citation key %s" key))))) 165 (error "No BibTeX entry with citation key %s" key)))))
166 166
167(defun reftex-end-of-bib-entry (item) 167(defun reftex-end-of-bib-entry (item)
168 (save-excursion 168 (save-excursion
169 (condition-case nil 169 (condition-case nil
170 (if item 170 (if item
171 (progn (end-of-line) 171 (progn (end-of-line)
172 (re-search-forward 172 (re-search-forward
173 "\\\\bibitem\\|\\end{thebibliography}") 173 "\\\\bibitem\\|\\end{thebibliography}")
174 (1- (match-beginning 0))) 174 (1- (match-beginning 0)))
175 (progn (forward-list 1) (point))) 175 (progn (forward-list 1) (point)))
176 (error (min (point-max) (+ 300 (point))))))) 176 (error (min (point-max) (+ 300 (point)))))))
177 177
178;; Parse bibtex buffers 178;; Parse bibtex buffers
179 179
180(defun reftex-extract-bib-entries (buffers) 180(defun reftex-extract-bib-entries (buffers re-list)
181 ;; Extract bib entries which match regexps from BUFFERS. 181 ;; Extract bib entries which match regexps from BUFFERS.
182 ;; BUFFERS is a list of buffers or file names. 182 ;; BUFFERS is a list of buffers or file names.
183 ;; Return list with entries." 183 ;; Return list with entries."
184 (let* (re-list first-re rest-re 184 (let* ((buffer-list (if (listp buffers) buffers (list buffers)))
185 (buffer-list (if (listp buffers) buffers (list buffers))) 185 (first-re (car re-list)) ; We'll use the first re to find things,
186 found-list entry buffer1 buffer alist 186 (rest-re (cdr re-list)) ; the others to narrow down.
187 key-point start-point end-point default) 187 found-list entry buffer1 buffer alist
188 188 key-point start-point end-point default)
189 ;; Read a regexp, completing on known citation keys.
190 (setq default (regexp-quote (reftex-get-bibkey-default)))
191 (setq re-list
192 (split-string
193 (completing-read
194 (concat
195 "Regex { && Regex...}: "
196 "[" default "]: ")
197 (if reftex-mode
198 (if (fboundp 'LaTeX-bibitem-list)
199 (LaTeX-bibitem-list)
200 (cdr (assoc 'bibview-cache
201 (symbol-value reftex-docstruct-symbol))))
202 nil)
203 nil nil nil 'reftex-cite-regexp-hist)
204 "[ \t]*&&[ \t]*"))
205
206 (if (or (null re-list ) (equal re-list '("")))
207 (setq re-list (list default)))
208
209 (setq first-re (car re-list) ; We'll use the first re to find things,
210 rest-re (cdr re-list)) ; the others to narrow down.
211 (if (string-match "\\`[ \t]*\\'" (or first-re ""))
212 (error "Empty regular expression"))
213 189
214 (save-excursion 190 (save-excursion
215 (save-window-excursion 191 (save-window-excursion
@@ -228,65 +204,62 @@
228 (message "Scanning bibliography database %s" buffer1)) 204 (message "Scanning bibliography database %s" buffer1))
229 205
230 (set-buffer buffer1) 206 (set-buffer buffer1)
231 (reftex-with-special-syntax-for-bib 207 (reftex-with-special-syntax-for-bib
232 (save-excursion 208 (save-excursion
233 (goto-char (point-min)) 209 (goto-char (point-min))
234 (while (re-search-forward first-re nil t) 210 (while (re-search-forward first-re nil t)
235 (catch 'search-again 211 (catch 'search-again
236 (setq key-point (point)) 212 (setq key-point (point))
237 (unless (re-search-backward 213 (unless (re-search-backward
238 "\\(\\`\\|[\n\r]\\)[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t) 214 "^[ \t]*@\\([a-zA-Z]+\\)[ \t\n\r]*[{(]" nil t)
239 (throw 'search-again nil)) 215 (throw 'search-again nil))
240 (setq start-point (point)) 216 (setq start-point (point))
241 (goto-char (match-end 0)) 217 (goto-char (match-end 0))
242 (condition-case nil 218 (condition-case nil
243 (up-list 1) 219 (up-list 1)
244 (error (goto-char key-point) 220 (error (goto-char key-point)
245 (throw 'search-again nil))) 221 (throw 'search-again nil)))
246 (setq end-point (point)) 222 (setq end-point (point))
247 223
248 ;; Ignore @string, @comment and @c entries or things 224 ;; Ignore @string, @comment and @c entries or things
249 ;; outside entries 225 ;; outside entries
250 (when (or (string= (downcase (match-string 2)) "string") 226 (when (or (member-ignore-case (match-string 1)
251 (string= (downcase (match-string 2)) "comment") 227 '("string" "comment" "c"))
252 (string= (downcase (match-string 2)) "c") 228 (< (point) key-point)) ; this means match not in {}
253 (< (point) key-point)) ; this means match not in {} 229 (goto-char key-point)
254 (goto-char key-point) 230 (throw 'search-again nil))
255 (throw 'search-again nil)) 231
256 232 ;; Well, we have got a match
257 ;; Well, we have got a match 233 (setq entry (buffer-substring start-point (point)))
258 ;;(setq entry (concat 234
259 ;; (buffer-substring start-point (point)) "\n")) 235 ;; Check if other regexp match as well
260 (setq entry (buffer-substring start-point (point))) 236 (setq re-list rest-re)
261 237 (while re-list
262 ;; Check if other regexp match as well 238 (unless (string-match (car re-list) entry)
263 (setq re-list rest-re) 239 ;; nope - move on
264 (while re-list 240 (throw 'search-again nil))
265 (unless (string-match (car re-list) entry) 241 (pop re-list))
266 ;; nope - move on 242
267 (throw 'search-again nil)) 243 (setq alist (reftex-parse-bibtex-entry
268 (pop re-list)) 244 nil start-point end-point))
269 245 (push (cons "&entry" entry) alist)
270 (setq alist (reftex-parse-bibtex-entry 246
271 nil start-point end-point)) 247 ;; check for crossref entries
272 (push (cons "&entry" entry) alist) 248 (if (assoc "crossref" alist)
273 249 (setq alist
274 ;; check for crossref entries 250 (append
275 (if (assoc "crossref" alist) 251 alist (reftex-get-crossref-alist alist))))
276 (setq alist 252
277 (append 253 ;; format the entry
278 alist (reftex-get-crossref-alist alist)))) 254 (push (cons "&formatted" (reftex-format-bib-entry alist))
279 255 alist)
280 ;; format the entry 256
281 (push (cons "&formatted" (reftex-format-bib-entry alist)) 257 ;; make key the first element
282 alist) 258 (push (reftex-get-bib-field "&key" alist) alist)
283 259
284 ;; make key the first element 260 ;; add it to the list
285 (push (reftex-get-bib-field "&key" alist) alist) 261 (push alist found-list)))))
286 262 (reftex-kill-temporary-buffers))))
287 ;; add it to the list
288 (push alist found-list)))))
289 (reftex-kill-temporary-buffers))))
290 (setq found-list (nreverse found-list)) 263 (setq found-list (nreverse found-list))
291 264
292 ;; Sorting 265 ;; Sorting
@@ -337,84 +310,61 @@
337 nil))))) 310 nil)))))
338 311
339;; Parse the bibliography environment 312;; Parse the bibliography environment
340(defun reftex-extract-bib-entries-from-thebibliography (files) 313(defun reftex-extract-bib-entries-from-thebibliography (files re-list)
341 ;; Extract bib-entries from the \begin{thebibliography} environment. 314 ;; Extract bib-entries from the \begin{thebibliography} environment.
342 ;; Parsing is not as good as for the BibTeX database stuff. 315 ;; Parsing is not as good as for the BibTeX database stuff.
343 ;; The environment should be located in file FILE. 316 ;; The environment should be located in file FILE.
344 317
345 (let* (start end buf entries re re-list file default) 318 (let* (start end buf entries re file default)
346 (unless files 319 (unless files
347 (error "Need file name to find thebibliography environment")) 320 (error "Need file name to find thebibliography environment"))
348 (while (setq file (pop files)) 321 (while (setq file (pop files))
349 (setq buf (reftex-get-file-buffer-force 322 (setq buf (reftex-get-file-buffer-force
350 file (not reftex-keep-temporary-buffers))) 323 file (not reftex-keep-temporary-buffers)))
351 (unless buf 324 (unless buf
352 (error "No such file %s" file)) 325 (error "No such file %s" file))
353 (message "Scanning thebibliography environment in %s" file) 326 (message "Scanning thebibliography environment in %s" file)
354 327
355 (save-excursion 328 (save-excursion
356 (set-buffer buf) 329 (set-buffer buf)
357 (save-restriction 330 (save-restriction
358 (widen) 331 (widen)
359 (goto-char (point-min)) 332 (goto-char (point-min))
360 (while (re-search-forward 333 (while (re-search-forward
361 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) 334 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t)
362 (beginning-of-line 2) 335 (beginning-of-line 2)
363 (setq start (point)) 336 (setq start (point))
364 (if (re-search-forward 337 (if (re-search-forward
365 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t) 338 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\end{thebibliography}" nil t)
366 (progn 339 (progn
367 (beginning-of-line 1) 340 (beginning-of-line 1)
368 (setq end (point)))) 341 (setq end (point))))
369 (when (and start end) 342 (when (and start end)
370 (setq entries 343 (setq entries
371 (append entries 344 (append entries
372 (mapcar 'reftex-parse-bibitem 345 (mapcar 'reftex-parse-bibitem
373 (delete "" 346 (delete ""
374 (split-string 347 (split-string
375 (buffer-substring-no-properties start end) 348 (buffer-substring-no-properties start end)
376 "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*")))))) 349 "[ \t\n\r]*\\\\bibitem\\(\\[[^]]*]\\)*"))))))
377 (goto-char end))))) 350 (goto-char end)))))
378 (unless entries 351 (unless entries
379 (error "No bibitems found")) 352 (error "No bibitems found"))
380 353
381 ;; Read a regexp, completing on known citation keys.
382 (setq default (regexp-quote (reftex-get-bibkey-default)))
383 (setq re-list
384 (split-string
385 (completing-read
386 (concat
387 "Regex { && Regex...}: "
388 "[" default "]: ")
389 (if reftex-mode
390 (if (fboundp 'LaTeX-bibitem-list)
391 (LaTeX-bibitem-list)
392 (cdr (assoc 'bibview-cache
393 (symbol-value reftex-docstruct-symbol))))
394 nil)
395 nil nil nil 'reftex-cite-regexp-hist)
396 "[ \t]*&&[ \t]*"))
397
398 (if (or (null re-list ) (equal re-list '("")))
399 (setq re-list (list default)))
400
401 (if (string-match "\\`[ \t]*\\'" (car re-list))
402 (error "Empty regular expression"))
403
404 (while (and (setq re (pop re-list)) entries) 354 (while (and (setq re (pop re-list)) entries)
405 (setq entries 355 (setq entries
406 (delq nil (mapcar 356 (delq nil (mapcar
407 (lambda (x) 357 (lambda (x)
408 (if (string-match re (cdr (assoc "&entry" x))) 358 (if (string-match re (cdr (assoc "&entry" x)))
409 x nil)) 359 x nil))
410 entries)))) 360 entries))))
411 (setq entries 361 (setq entries
412 (mapcar 362 (mapcar
413 (lambda (x) 363 (lambda (x)
414 (push (cons "&formatted" (reftex-format-bibitem x)) x) 364 (push (cons "&formatted" (reftex-format-bibitem x)) x)
415 (push (reftex-get-bib-field "&key" x) x) 365 (push (reftex-get-bib-field "&key" x) x)
416 x) 366 x)
417 entries)) 367 entries))
418 368
419 entries)) 369 entries))
420 370
@@ -424,7 +374,7 @@
424 (let* ((macro (reftex-what-macro 1))) 374 (let* ((macro (reftex-what-macro 1)))
425 (save-excursion 375 (save-excursion
426 (if (and macro (string-match "cite" (car macro))) 376 (if (and macro (string-match "cite" (car macro)))
427 (goto-char (cdr macro))) 377 (goto-char (cdr macro)))
428 (skip-chars-backward "^a-zA-Z0-9") 378 (skip-chars-backward "^a-zA-Z0-9")
429 (reftex-this-word)))) 379 (reftex-this-word))))
430 380
@@ -453,7 +403,7 @@
453 (progn 403 (progn
454 (set-buffer (get-buffer-create " *RefTeX-scratch*")) 404 (set-buffer (get-buffer-create " *RefTeX-scratch*"))
455 (fundamental-mode) 405 (fundamental-mode)
456 (set-syntax-table reftex-syntax-table-for-bib) 406 (set-syntax-table reftex-syntax-table-for-bib)
457 (erase-buffer) 407 (erase-buffer)
458 (insert entry)) 408 (insert entry))
459 (widen) 409 (widen)
@@ -500,9 +450,9 @@
500 ;; Extract the field FIELDNAME from an ENTRY 450 ;; Extract the field FIELDNAME from an ENTRY
501 (let ((cell (assoc fieldname entry))) 451 (let ((cell (assoc fieldname entry)))
502 (if cell 452 (if cell
503 (if format 453 (if format
504 (format format (cdr cell)) 454 (format format (cdr cell))
505 (cdr cell)) 455 (cdr cell))
506 ""))) 456 "")))
507 457
508(defun reftex-format-bib-entry (entry) 458(defun reftex-format-bib-entry (entry)
@@ -537,9 +487,9 @@
537 (setq authors (reftex-truncate authors 30 t t)) 487 (setq authors (reftex-truncate authors 30 t t))
538 (when (reftex-use-fonts) 488 (when (reftex-use-fonts)
539 (put-text-property 0 (length key) 'face 489 (put-text-property 0 (length key) 'face
540 (reftex-verified-face reftex-label-face 490 (reftex-verified-face reftex-label-face
541 'font-lock-constant-face 491 'font-lock-constant-face
542 'font-lock-reference-face) 492 'font-lock-reference-face)
543 key) 493 key)
544 (put-text-property 0 (length authors) 'face reftex-bib-author-face 494 (put-text-property 0 (length authors) 'face reftex-bib-author-face
545 authors) 495 authors)
@@ -556,12 +506,12 @@
556 (let ((key "") (text "")) 506 (let ((key "") (text ""))
557 (when (string-match "\\`{\\([^}]+\\)}\\([^\000]*\\)" item) 507 (when (string-match "\\`{\\([^}]+\\)}\\([^\000]*\\)" item)
558 (setq key (match-string 1 item) 508 (setq key (match-string 1 item)
559 text (match-string 2 item))) 509 text (match-string 2 item)))
560 ;; Clean up the text a little bit 510 ;; Clean up the text a little bit
561 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text) 511 (while (string-match "[\n\r\t]\\|[ \t][ \t]+" text)
562 (setq text (replace-match " " nil t text))) 512 (setq text (replace-match " " nil t text)))
563 (if (string-match "\\`[ \t]+" text) 513 (if (string-match "\\`[ \t]+" text)
564 (setq text (replace-match "" nil t text))) 514 (setq text (replace-match "" nil t text)))
565 (list 515 (list
566 (cons "&key" key) 516 (cons "&key" key)
567 (cons "&text" text) 517 (cons "&text" text)
@@ -570,14 +520,14 @@
570(defun reftex-format-bibitem (item) 520(defun reftex-format-bibitem (item)
571 ;; Format a \bibitem entry so that it is (relatively) nice to look at. 521 ;; Format a \bibitem entry so that it is (relatively) nice to look at.
572 (let ((text (reftex-get-bib-field "&text" item)) 522 (let ((text (reftex-get-bib-field "&text" item))
573 (key (reftex-get-bib-field "&key" item)) 523 (key (reftex-get-bib-field "&key" item))
574 (lines nil)) 524 (lines nil))
575 525
576 ;; Wrap the text into several lines. 526 ;; Wrap the text into several lines.
577 (while (and (> (length text) 70) 527 (while (and (> (length text) 70)
578 (string-match " " (substring text 60))) 528 (string-match " " (substring text 60)))
579 (push (substring text 0 (+ 60 (match-beginning 0))) lines) 529 (push (substring text 0 (+ 60 (match-beginning 0))) lines)
580 (setq text (substring text (+ 61 (match-beginning 0))))) 530 (setq text (substring text (+ 61 (match-beginning 0)))))
581 (push text lines) 531 (push text lines)
582 (setq text (mapconcat 'identity (nreverse lines) "\n ")) 532 (setq text (mapconcat 'identity (nreverse lines) "\n "))
583 533
@@ -629,18 +579,18 @@ While entering the regexp, completion on knows citation keys is possible.
629 ;; This really does the work of reftex-citation. 579 ;; This really does the work of reftex-citation.
630 580
631 (let* ((format (reftex-figure-out-cite-format arg no-insert format-key)) 581 (let* ((format (reftex-figure-out-cite-format arg no-insert format-key))
632 (docstruct-symbol reftex-docstruct-symbol) 582 (docstruct-symbol reftex-docstruct-symbol)
633 (selected-entries (reftex-offer-bib-menu)) 583 (selected-entries (reftex-offer-bib-menu))
634 (insert-entries selected-entries) 584 (insert-entries selected-entries)
635 entry string cite-view) 585 entry string cite-view)
636 586
637 (unless selected-entries (error "Quit")) 587 (unless selected-entries (error "Quit"))
638 588
639 (if (stringp selected-entries) 589 (if (stringp selected-entries)
640 ;; Nonexistent entry 590 ;; Nonexistent entry
641 (setq selected-entries nil 591 (setq selected-entries nil
642 insert-entries (list (list selected-entries 592 insert-entries (list (list selected-entries
643 (cons "&key" selected-entries)))) 593 (cons "&key" selected-entries))))
644 ;; It makes sense to compute the cite-view strings. 594 ;; It makes sense to compute the cite-view strings.
645 (setq cite-view t)) 595 (setq cite-view t))
646 596
@@ -648,54 +598,54 @@ While entering the regexp, completion on knows citation keys is possible.
648 ;; All keys go into a single command - we need to trick a little 598 ;; All keys go into a single command - we need to trick a little
649 (pop selected-entries) 599 (pop selected-entries)
650 (let ((concat-keys (mapconcat 'car selected-entries ","))) 600 (let ((concat-keys (mapconcat 'car selected-entries ",")))
651 (setq insert-entries 601 (setq insert-entries
652 (list (list concat-keys (cons "&key" concat-keys)))))) 602 (list (list concat-keys (cons "&key" concat-keys))))))
653 603
654 (unless no-insert 604 (unless no-insert
655 605
656 ;; We shall insert this into the buffer... 606 ;; We shall insert this into the buffer...
657 (message "Formatting...") 607 (message "Formatting...")
658 608
659 (while (setq entry (pop insert-entries)) 609 (while (setq entry (pop insert-entries))
660 ;; Format the citation and insert it 610 ;; Format the citation and insert it
661 (setq string (if reftex-format-cite-function 611 (setq string (if reftex-format-cite-function
662 (funcall reftex-format-cite-function 612 (funcall reftex-format-cite-function
663 (reftex-get-bib-field "&key" entry) 613 (reftex-get-bib-field "&key" entry)
664 format) 614 format)
665 (reftex-format-citation entry format))) 615 (reftex-format-citation entry format)))
666 (insert string)) 616 (insert string))
667 617
668 ;; Reposition cursor? 618 ;; Reposition cursor?
669 (when (string-match "\\?" string) 619 (when (string-match "\\?" string)
670 (search-backward "?") 620 (search-backward "?")
671 (delete-char 1)) 621 (delete-char 1))
672 622
673 ;; Tell AUCTeX 623 ;; Tell AUCTeX
674 (when (and reftex-mode 624 (when (and reftex-mode
675 (fboundp 'LaTeX-add-bibitems) 625 (fboundp 'LaTeX-add-bibitems)
676 reftex-plug-into-AUCTeX) 626 reftex-plug-into-AUCTeX)
677 (apply 'LaTeX-add-bibitems (mapcar 'car selected-entries))) 627 (apply 'LaTeX-add-bibitems (mapcar 'car selected-entries)))
678 628
679 ;; Produce the cite-view strings 629 ;; Produce the cite-view strings
680 (when (and reftex-mode reftex-cache-cite-echo cite-view) 630 (when (and reftex-mode reftex-cache-cite-echo cite-view)
681 (mapcar (lambda (entry) 631 (mapcar (lambda (entry)
682 (reftex-make-cite-echo-string entry docstruct-symbol)) 632 (reftex-make-cite-echo-string entry docstruct-symbol))
683 selected-entries)) 633 selected-entries))
684 634
685 (message "")) 635 (message ""))
686 636
687 (set-marker reftex-select-return-marker nil) 637 (set-marker reftex-select-return-marker nil)
688 (reftex-kill-buffer "*RefTeX Select*") 638 (reftex-kill-buffer "*RefTeX Select*")
689 639
690 ;; Check if the prefix arg was numeric, and call recursively 640 ;; Check if the prefix arg was numeric, and call recursively
691 (when (integerp arg) 641 (when (integerp arg)
692 (if (> arg 1) 642 (if (> arg 1)
693 (progn 643 (progn
694 (skip-chars-backward "}") 644 (skip-chars-backward "}")
695 (decf arg) 645 (decf arg)
696 (reftex-do-citation arg)) 646 (reftex-do-citation arg))
697 (forward-char 1))) 647 (forward-char 1)))
698 648
699 ;; Return the citation key 649 ;; Return the citation key
700 (car (car selected-entries)))) 650 (car (car selected-entries))))
701 651
@@ -703,44 +653,44 @@ While entering the regexp, completion on knows citation keys is possible.
703 ;; Check if there is already a cite command at point and change cite format 653 ;; Check if there is already a cite command at point and change cite format
704 ;; in order to only add another reference in the same cite command. 654 ;; in order to only add another reference in the same cite command.
705 (let ((macro (car (reftex-what-macro 1))) 655 (let ((macro (car (reftex-what-macro 1)))
706 (cite-format-value (reftex-get-cite-format)) 656 (cite-format-value (reftex-get-cite-format))
707 key format) 657 key format)
708 (cond 658 (cond
709 (no-insert 659 (no-insert
710 ;; Format does not really matter because nothing will be inserted. 660 ;; Format does not really matter because nothing will be inserted.
711 (setq format "%l")) 661 (setq format "%l"))
712 662
713 ((and (stringp macro) 663 ((and (stringp macro)
714 (string-match "\\`\\\\cite\\|cite\\'" macro)) 664 (string-match "\\`\\\\cite\\|cite\\'" macro))
715 ;; We are already inside a cite macro 665 ;; We are already inside a cite macro
716 (if (or (not arg) (not (listp arg))) 666 (if (or (not arg) (not (listp arg)))
717 (setq format 667 (setq format
718 (concat 668 (concat
719 (if (member (preceding-char) '(?\{ ?,)) "" ",") 669 (if (member (preceding-char) '(?\{ ?,)) "" ",")
720 "%l" 670 "%l"
721 (if (member (following-char) '(?\} ?,)) "" ","))) 671 (if (member (following-char) '(?\} ?,)) "" ",")))
722 (setq format "%l"))) 672 (setq format "%l")))
723 (t 673 (t
724 ;; Figure out the correct format 674 ;; Figure out the correct format
725 (setq format 675 (setq format
726 (if (and (symbolp cite-format-value) 676 (if (and (symbolp cite-format-value)
727 (assq cite-format-value reftex-cite-format-builtin)) 677 (assq cite-format-value reftex-cite-format-builtin))
728 (nth 2 (assq cite-format-value reftex-cite-format-builtin)) 678 (nth 2 (assq cite-format-value reftex-cite-format-builtin))
729 cite-format-value)) 679 cite-format-value))
730 (when (listp format) 680 (when (listp format)
731 (setq key 681 (setq key
732 (or format-key 682 (or format-key
733 (reftex-select-with-char 683 (reftex-select-with-char
734 "" (concat "SELECT A CITATION FORMAT\n\n" 684 "" (concat "SELECT A CITATION FORMAT\n\n"
735 (mapconcat 685 (mapconcat
736 (lambda (x) 686 (lambda (x)
737 (format "[%c] %s %s" (car x) 687 (format "[%c] %s %s" (car x)
738 (if (> (car x) 31) " " "") 688 (if (> (car x) 31) " " "")
739 (cdr x))) 689 (cdr x)))
740 format "\n"))))) 690 format "\n")))))
741 (if (assq key format) 691 (if (assq key format)
742 (setq format (cdr (assq key format))) 692 (setq format (cdr (assq key format)))
743 (error "No citation format associated with key `%c'" key))))) 693 (error "No citation format associated with key `%c'" key)))))
744 format)) 694 format))
745 695
746(defun reftex-citep () 696(defun reftex-citep ()
@@ -758,141 +708,163 @@ While entering the regexp, completion on knows citation keys is possible.
758 ;; Offer bib menu and return list of selected items 708 ;; Offer bib menu and return list of selected items
759 709
760 (let ((bibtype (reftex-bib-or-thebib)) 710 (let ((bibtype (reftex-bib-or-thebib))
761 found-list rtn key data selected-entries) 711 found-list rtn key data selected-entries re-list)
762 (while 712 (while
763 (not 713 (not
764 (catch 'done 714 (catch 'done
765 ;; Scan bibtex files 715 ;; Get the search regexps, completing on known citation keys.
766 (setq found-list 716 (setq re-list
767 (cond 717 (let ((default (regexp-quote (reftex-get-bibkey-default))))
768 ((eq bibtype 'bib) 718 (split-string
769; ((assq 'bib (symbol-value reftex-docstruct-symbol)) 719 (completing-read
770 ;; using BibTeX database files. 720 (concat
771 (reftex-extract-bib-entries (reftex-get-bibfile-list))) 721 "Regex { && Regex...}: "
772 ((eq bibtype 'thebib) 722 "[" default "]: ")
773; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) 723 (if reftex-mode
774 ;; using thebibliography environment. 724 (if (fboundp 'LaTeX-bibitem-list)
775 (reftex-extract-bib-entries-from-thebibliography 725 (LaTeX-bibitem-list)
776 (reftex-uniquify 726 (cdr (assoc 'bibview-cache
777 (mapcar 'cdr 727 (symbol-value reftex-docstruct-symbol))))
778 (reftex-all-assq 728 nil)
779 'thebib (symbol-value reftex-docstruct-symbol)))))) 729 nil nil nil 'reftex-cite-regexp-hist default)
780 (reftex-default-bibliography 730 "[ \t]*&&[ \t]*")))
781 (message "Using default bibliography") 731
782 (reftex-extract-bib-entries (reftex-default-bibliography))) 732 (if (string-match "\\`[ \t]*\\'" (car re-list))
783 (t (error "No valid bibliography in this document, and no default available")))) 733 (error "Empty regular expression"))
784 734
785 (unless found-list 735 ;; Scan bibtex files
786 (error "Sorry, no matches found")) 736 (setq found-list
787 737 (cond
788 ;; Remember where we came from 738 ((eq bibtype 'bib)
789 (setq reftex-call-back-to-this-buffer (current-buffer)) 739; ((assq 'bib (symbol-value reftex-docstruct-symbol))
790 (set-marker reftex-select-return-marker (point)) 740 ;; using BibTeX database files.
791 741 (reftex-extract-bib-entries (reftex-get-bibfile-list) re-list))
792 ;; Offer selection 742 ((eq bibtype 'thebib)
793 (save-window-excursion 743; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
794 (delete-other-windows) 744 ;; using thebibliography environment.
795 (let ((default-major-mode 'reftex-select-bib-mode)) 745 (reftex-extract-bib-entries-from-thebibliography
796 (reftex-kill-buffer "*RefTeX Select*") 746 (reftex-uniquify
797 (switch-to-buffer-other-window "*RefTeX Select*") 747 (mapcar 'cdr
798 (unless (eq major-mode 'reftex-select-bib-mode) 748 (reftex-all-assq
799 (reftex-select-bib-mode)) 749 'thebib (symbol-value reftex-docstruct-symbol))))
800 (let ((buffer-read-only nil)) 750 re-list))
801 (erase-buffer) 751 (reftex-default-bibliography
802 (reftex-insert-bib-matches found-list))) 752 (message "Using default bibliography")
803 (setq buffer-read-only t) 753 (reftex-extract-bib-entries (reftex-default-bibliography)
804 (if (= 0 (buffer-size)) 754 re-list))
805 (error "No matches found")) 755 (t (error "No valid bibliography in this document, and no default available"))))
806 (setq truncate-lines t) 756
807 (goto-char 1) 757 (unless found-list
808 (while t 758 (error "Sorry, no matches found"))
809 (setq rtn 759
810 (reftex-select-item 760 ;; Remember where we came from
811 reftex-citation-prompt 761 (setq reftex-call-back-to-this-buffer (current-buffer))
812 reftex-citation-help 762 (set-marker reftex-select-return-marker (point))
813 reftex-select-bib-map 763
814 nil 764 ;; Offer selection
815 'reftex-bibtex-selection-callback nil)) 765 (save-window-excursion
816 (setq key (car rtn) 766 (delete-other-windows)
817 data (nth 1 rtn)) 767 (let ((default-major-mode 'reftex-select-bib-mode))
818 (unless key (throw 'done t)) 768 (reftex-kill-buffer "*RefTeX Select*")
819 (cond 769 (switch-to-buffer-other-window "*RefTeX Select*")
820 ((eq key ?g) 770 (unless (eq major-mode 'reftex-select-bib-mode)
821 ;; Start over 771 (reftex-select-bib-mode))
822 (throw 'done nil)) 772 (let ((buffer-read-only nil))
823 ((eq key ?r) 773 (erase-buffer)
824 ;; Restrict with new regular expression 774 (reftex-insert-bib-matches found-list)))
825 (setq found-list (reftex-restrict-bib-matches found-list)) 775 (setq buffer-read-only t)
826 (let ((buffer-read-only nil)) 776 (if (= 0 (buffer-size))
827 (erase-buffer) 777 (error "No matches found"))
828 (reftex-insert-bib-matches found-list)) 778 (setq truncate-lines t)
829 (goto-char 1)) 779 (goto-char 1)
830 ((eq key ?A) 780 (while t
831 ;; Take all (marked) 781 (setq rtn
832 (setq selected-entries 782 (reftex-select-item
833 (if reftex-select-marked 783 reftex-citation-prompt
834 (mapcar 'car (nreverse reftex-select-marked)) 784 reftex-citation-help
835 found-list)) 785 reftex-select-bib-map
836 (throw 'done t)) 786 nil
837 ((eq key ?a) 787 'reftex-bibtex-selection-callback nil))
838 ;; Take all (marked), and push the symbol 'concat 788 (setq key (car rtn)
839 (setq selected-entries 789 data (nth 1 rtn))
840 (cons 'concat 790 (unless key (throw 'done t))
841 (if reftex-select-marked 791 (cond
842 (mapcar 'car (nreverse reftex-select-marked)) 792 ((eq key ?g)
843 found-list))) 793 ;; Start over
844 (throw 'done t)) 794 (throw 'done nil))
845 ((or (eq key ?\C-m) 795 ((eq key ?r)
846 (eq key 'return)) 796 ;; Restrict with new regular expression
847 ;; Take selected 797 (setq found-list (reftex-restrict-bib-matches found-list))
848 (setq selected-entries 798 (let ((buffer-read-only nil))
849 (if reftex-select-marked 799 (erase-buffer)
850 (cons 'concat 800 (reftex-insert-bib-matches found-list))
851 (mapcar 'car (nreverse reftex-select-marked))) 801 (goto-char 1))
852 (if data (list data) nil))) 802 ((eq key ?A)
853 (throw 'done t)) 803 ;; Take all (marked)
854 ((stringp key) 804 (setq selected-entries
855 ;; Got this one with completion 805 (if reftex-select-marked
856 (setq selected-entries key) 806 (mapcar 'car (nreverse reftex-select-marked))
857 (throw 'done t)) 807 found-list))
858 (t 808 (throw 'done t))
859 (ding)))))))) 809 ((eq key ?a)
810 ;; Take all (marked), and push the symbol 'concat
811 (setq selected-entries
812 (cons 'concat
813 (if reftex-select-marked
814 (mapcar 'car (nreverse reftex-select-marked))
815 found-list)))
816 (throw 'done t))
817 ((or (eq key ?\C-m)
818 (eq key 'return))
819 ;; Take selected
820 (setq selected-entries
821 (if reftex-select-marked
822 (cons 'concat
823 (mapcar 'car (nreverse reftex-select-marked)))
824 (if data (list data) nil)))
825 (throw 'done t))
826 ((stringp key)
827 ;; Got this one with completion
828 (setq selected-entries key)
829 (throw 'done t))
830 (t
831 (ding))))))))
860 selected-entries)) 832 selected-entries))
861 833
862(defun reftex-restrict-bib-matches (found-list) 834(defun reftex-restrict-bib-matches (found-list)
863 ;; Limit FOUND-LIST with more regular expressions 835 ;; Limit FOUND-LIST with more regular expressions
864 (let ((re-list (split-string (read-string 836 (let ((re-list (split-string (read-string
865 "RegExp [ && RegExp...]: " 837 "RegExp [ && RegExp...]: "
866 nil 'reftex-cite-regexp-hist) 838 nil 'reftex-cite-regexp-hist)
867 "[ \t]*&&[ \t]*")) 839 "[ \t]*&&[ \t]*"))
868 (found-list-r found-list) 840 (found-list-r found-list)
869 re) 841 re)
870 (while (setq re (pop re-list)) 842 (while (setq re (pop re-list))
871 (setq found-list-r 843 (setq found-list-r
872 (delq nil 844 (delq nil
873 (mapcar 845 (mapcar
874 (lambda (x) 846 (lambda (x)
875 (if (string-match 847 (if (string-match
876 re (cdr (assoc "&entry" x))) 848 re (cdr (assoc "&entry" x)))
877 x 849 x
878 nil)) 850 nil))
879 found-list-r)))) 851 found-list-r))))
880 (if found-list-r 852 (if found-list-r
881 found-list-r 853 found-list-r
882 (ding) 854 (ding)
883 found-list))) 855 found-list)))
884 856
885(defun reftex-insert-bib-matches (list) 857(defun reftex-insert-bib-matches (list)
886 ;; Insert the bib matches and number them correctly 858 ;; Insert the bib matches and number them correctly
887 (let ((mouse-face 859 (let ((mouse-face
888 (if (memq reftex-highlight-selection '(mouse both)) 860 (if (memq reftex-highlight-selection '(mouse both))
889 reftex-mouse-selected-face 861 reftex-mouse-selected-face
890 nil)) 862 nil))
891 tmp len) 863 tmp len)
892 (mapcar 864 (mapcar
893 (lambda (x) 865 (lambda (x)
894 (setq tmp (cdr (assoc "&formatted" x)) 866 (setq tmp (cdr (assoc "&formatted" x))
895 len (length tmp)) 867 len (length tmp))
896 (put-text-property 0 len :data x tmp) 868 (put-text-property 0 len :data x tmp)
897 (put-text-property 0 (1- len) 'mouse-face mouse-face tmp) 869 (put-text-property 0 (1- len) 'mouse-face mouse-face tmp)
898 (insert tmp)) 870 (insert tmp))
@@ -944,7 +916,7 @@ While entering the regexp, completion on knows citation keys is possible.
944 ((= l ?A) (car (reftex-get-bib-names "author" entry))) 916 ((= l ?A) (car (reftex-get-bib-names "author" entry)))
945 ((= l ?b) (reftex-get-bib-field "booktitle" entry "in: %s")) 917 ((= l ?b) (reftex-get-bib-field "booktitle" entry "in: %s"))
946 ((= l ?B) (reftex-abbreviate-title 918 ((= l ?B) (reftex-abbreviate-title
947 (reftex-get-bib-field "booktitle" entry "in: %s"))) 919 (reftex-get-bib-field "booktitle" entry "in: %s")))
948 ((= l ?c) (reftex-get-bib-field "chapter" entry)) 920 ((= l ?c) (reftex-get-bib-field "chapter" entry))
949 ((= l ?d) (reftex-get-bib-field "edition" entry)) 921 ((= l ?d) (reftex-get-bib-field "edition" entry))
950 ((= l ?e) (reftex-format-names 922 ((= l ?e) (reftex-format-names
@@ -967,7 +939,7 @@ While entering the regexp, completion on knows citation keys is possible.
967 ((= l ?r) (reftex-get-bib-field "address" entry)) 939 ((= l ?r) (reftex-get-bib-field "address" entry))
968 ((= l ?t) (reftex-get-bib-field "title" entry)) 940 ((= l ?t) (reftex-get-bib-field "title" entry))
969 ((= l ?T) (reftex-abbreviate-title 941 ((= l ?T) (reftex-abbreviate-title
970 (reftex-get-bib-field "title" entry))) 942 (reftex-get-bib-field "title" entry)))
971 ((= l ?v) (reftex-get-bib-field "volume" entry)) 943 ((= l ?v) (reftex-get-bib-field "volume" entry))
972 ((= l ?y) (reftex-get-bib-field "year" entry))))) 944 ((= l ?y) (reftex-get-bib-field "year" entry)))))
973 945
@@ -984,25 +956,25 @@ While entering the regexp, completion on knows citation keys is possible.
984(defun reftex-make-cite-echo-string (entry docstruct-symbol) 956(defun reftex-make-cite-echo-string (entry docstruct-symbol)
985 ;; Format a bibtex entry for the echo area and cache the result. 957 ;; Format a bibtex entry for the echo area and cache the result.
986 (let* ((key (reftex-get-bib-field "&key" entry)) 958 (let* ((key (reftex-get-bib-field "&key" entry))
987 (string 959 (string
988 (let* ((reftex-cite-punctuation '(" " " & " " etal."))) 960 (let* ((reftex-cite-punctuation '(" " " & " " etal.")))
989 (reftex-format-citation entry reftex-cite-view-format))) 961 (reftex-format-citation entry reftex-cite-view-format)))
990 (cache (assq 'bibview-cache (symbol-value docstruct-symbol))) 962 (cache (assq 'bibview-cache (symbol-value docstruct-symbol)))
991 (cache-entry (assoc key (cdr cache)))) 963 (cache-entry (assoc key (cdr cache))))
992 (unless cache 964 (unless cache
993 ;; This docstruct has no cache - make one. 965 ;; This docstruct has no cache - make one.
994 (set docstruct-symbol (cons (cons 'bibview-cache nil) 966 (set docstruct-symbol (cons (cons 'bibview-cache nil)
995 (symbol-value docstruct-symbol)))) 967 (symbol-value docstruct-symbol))))
996 (when reftex-cache-cite-echo 968 (when reftex-cache-cite-echo
997 (setq key (copy-sequence key)) 969 (setq key (copy-sequence key))
998 (set-text-properties 0 (length key) nil key) 970 (set-text-properties 0 (length key) nil key)
999 (set-text-properties 0 (length string) nil string) 971 (set-text-properties 0 (length string) nil string)
1000 (if cache-entry 972 (if cache-entry
1001 (unless (string= (cdr cache-entry) string) 973 (unless (string= (cdr cache-entry) string)
1002 (setcdr cache-entry string) 974 (setcdr cache-entry string)
1003 (put reftex-docstruct-symbol 'modified t)) 975 (put reftex-docstruct-symbol 'modified t))
1004 (push (cons key string) (cdr cache)) 976 (push (cons key string) (cdr cache))
1005 (put reftex-docstruct-symbol 'modified t))) 977 (put reftex-docstruct-symbol 'modified t)))
1006 string)) 978 string))
1007 979
1008(defun reftex-bibtex-selection-callback (data ignore no-revisit) 980(defun reftex-bibtex-selection-callback (data ignore no-revisit)
@@ -1015,33 +987,32 @@ While entering the regexp, completion on knows citation keys is possible.
1015 987
1016 (catch 'exit 988 (catch 'exit
1017 (save-excursion 989 (save-excursion
1018 (set-buffer reftex-call-back-to-this-buffer) 990 (set-buffer reftex-call-back-to-this-buffer)
1019 (setq bibtype (reftex-bib-or-thebib)) 991 (setq bibtype (reftex-bib-or-thebib))
1020 (cond 992 (cond
1021 ((eq bibtype 'bib) 993 ((eq bibtype 'bib)
1022; ((assq 'bib (symbol-value reftex-docstruct-symbol)) 994; ((assq 'bib (symbol-value reftex-docstruct-symbol))
1023 (setq bibfile-list (reftex-get-bibfile-list))) 995 (setq bibfile-list (reftex-get-bibfile-list)))
1024 ((eq bibtype 'thebib) 996 ((eq bibtype 'thebib)
1025; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) 997; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
1026 (setq bibfile-list 998 (setq bibfile-list
1027 (reftex-uniquify 999 (reftex-uniquify
1028 (mapcar 'cdr 1000 (mapcar 'cdr
1029 (reftex-all-assq 1001 (reftex-all-assq
1030 'thebib (symbol-value reftex-docstruct-symbol)))) 1002 'thebib (symbol-value reftex-docstruct-symbol))))
1031 item t)) 1003 item t))
1032 (reftex-default-bibliography 1004 (reftex-default-bibliography
1033 (setq bibfile-list (reftex-default-bibliography))) 1005 (setq bibfile-list (reftex-default-bibliography)))
1034 (t (ding) (throw 'exit nil)))) 1006 (t (ding) (throw 'exit nil))))
1035 1007
1036 (when no-revisit 1008 (when no-revisit
1037 (setq bibfile-list (reftex-visited-files bibfile-list))) 1009 (setq bibfile-list (reftex-visited-files bibfile-list)))
1038 1010
1039 (condition-case nil 1011 (condition-case nil
1040 (reftex-pop-to-bibtex-entry 1012 (reftex-pop-to-bibtex-entry
1041 key bibfile-list (not reftex-keep-temporary-buffers) t item) 1013 key bibfile-list (not reftex-keep-temporary-buffers) t item)
1042 (error (ding)))) 1014 (error (ding))))
1043 1015
1044 (select-window win))) 1016 (select-window win)))
1045 1017
1046;;; arch-tag: d53d0a5a-ab32-4b52-a846-2a7c3527cd89
1047;;; reftex-cite.el ends here 1018;;; reftex-cite.el ends here
diff --git a/lisp/textmodes/reftex-dcr.el b/lisp/textmodes/reftex-dcr.el
index dc47a5e7564..34fd334987c 100644
--- a/lisp/textmodes/reftex-dcr.el
+++ b/lisp/textmodes/reftex-dcr.el
@@ -1,8 +1,8 @@
1;;; reftex-dcr.el --- viewing cross references and citations with RefTeX 1;;; reftex-dcr.el --- viewing cross references and citations with RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6;; 6;;
7 7
8;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
@@ -52,10 +52,10 @@ to the functions `reftex-view-cr-cite' and `reftex-view-cr-ref'."
52 ;; See where we are. 52 ;; See where we are.
53 (let* ((macro (car (reftex-what-macro-safe 1))) 53 (let* ((macro (car (reftex-what-macro-safe 1)))
54 (key (reftex-this-word "^{}%\n\r, \t")) 54 (key (reftex-this-word "^{}%\n\r, \t"))
55 dw) 55 dw)
56 56
57 (if (or (null macro) (reftex-in-comment)) 57 (if (or (null macro) (reftex-in-comment))
58 (error "Not on a crossref macro argument")) 58 (error "Not on a crossref macro argument"))
59 59
60 (setq reftex-call-back-to-this-buffer (current-buffer)) 60 (setq reftex-call-back-to-this-buffer (current-buffer))
61 61
@@ -68,42 +68,42 @@ to the functions `reftex-view-cr-cite' and `reftex-view-cr-ref'."
68 (setq dw (reftex-view-cr-ref arg key auto-how))) 68 (setq dw (reftex-view-cr-ref arg key auto-how)))
69 (auto-how nil) ;; No further action for automatic display (speed) 69 (auto-how nil) ;; No further action for automatic display (speed)
70 ((or (equal macro "\\label") 70 ((or (equal macro "\\label")
71 (member macro reftex-macros-with-labels)) 71 (member macro reftex-macros-with-labels))
72 ;; A label macro: search for reference macros 72 ;; A label macro: search for reference macros
73 (reftex-access-scan-info arg) 73 (reftex-access-scan-info arg)
74 (setq dw (reftex-view-regexp-match 74 (setq dw (reftex-view-regexp-match
75 (format reftex-find-reference-format (regexp-quote key)) 75 (format reftex-find-reference-format (regexp-quote key))
76 4 nil nil))) 76 4 nil nil)))
77 ((equal macro "\\bibitem") 77 ((equal macro "\\bibitem")
78 ;; A bibitem macro: search for citations 78 ;; A bibitem macro: search for citations
79 (reftex-access-scan-info arg) 79 (reftex-access-scan-info arg)
80 (setq dw (reftex-view-regexp-match 80 (setq dw (reftex-view-regexp-match
81 (format reftex-find-citation-regexp-format (regexp-quote key)) 81 (format reftex-find-citation-regexp-format (regexp-quote key))
82 4 nil nil))) 82 4 nil nil)))
83 ((member macro reftex-macros-with-index) 83 ((member macro reftex-macros-with-index)
84 (reftex-access-scan-info arg) 84 (reftex-access-scan-info arg)
85 (setq dw (reftex-view-regexp-match 85 (setq dw (reftex-view-regexp-match
86 (format reftex-find-index-entry-regexp-format 86 (format reftex-find-index-entry-regexp-format
87 (regexp-quote key)) 87 (regexp-quote key))
88 3 nil nil))) 88 3 nil nil)))
89 (t 89 (t
90 (reftex-access-scan-info arg) 90 (reftex-access-scan-info arg)
91 (catch 'exit 91 (catch 'exit
92 (let ((list reftex-view-crossref-extra) 92 (let ((list reftex-view-crossref-extra)
93 entry mre action group) 93 entry mre action group)
94 (while (setq entry (pop list)) 94 (while (setq entry (pop list))
95 (setq mre (car entry) 95 (setq mre (car entry)
96 action (nth 1 entry) 96 action (nth 1 entry)
97 group (nth 2 entry)) 97 group (nth 2 entry))
98 (when (string-match mre macro) 98 (when (string-match mre macro)
99 (setq dw (reftex-view-regexp-match 99 (setq dw (reftex-view-regexp-match
100 (format action key) group nil nil)) 100 (format action key) group nil nil))
101 (throw 'exit t)))) 101 (throw 'exit t))))
102 (error "Not on a crossref macro argument")))) 102 (error "Not on a crossref macro argument"))))
103 (if (and (eq arg 2) (windowp dw)) (select-window dw)))) 103 (if (and (eq arg 2) (windowp dw)) (select-window dw))))
104 104
105(defun reftex-view-cr-cite (arg key how) 105(defun reftex-view-cr-cite (arg key how)
106 ;; View crossreference of a ref cite. HOW can have the values 106 ;; View crossreference of a ref cite. HOW can have the values
107 ;; nil: Show in another window. 107 ;; nil: Show in another window.
108 ;; echo: Show one-line info in echo area. 108 ;; echo: Show one-line info in echo area.
109 ;; tmp-window: Show in small window and arrange for window to disappear. 109 ;; tmp-window: Show in small window and arrange for window to disappear.
@@ -113,113 +113,113 @@ to the functions `reftex-view-cr-cite' and `reftex-view-cr-ref'."
113 113
114 (if (eq how 'tmp-window) 114 (if (eq how 'tmp-window)
115 ;; Remember the window configuration 115 ;; Remember the window configuration
116 (put 'reftex-auto-view-crossref 'last-window-conf 116 (put 'reftex-auto-view-crossref 'last-window-conf
117 (current-window-configuration))) 117 (current-window-configuration)))
118 118
119 (let (files size item (pos (point)) (win (selected-window)) pop-win 119 (let (files size item (pos (point)) (win (selected-window)) pop-win
120 (bibtype (reftex-bib-or-thebib))) 120 (bibtype (reftex-bib-or-thebib)))
121 ;; Find the citation mode and the file list 121 ;; Find the citation mode and the file list
122 (cond 122 (cond
123; ((assq 'bib (symbol-value reftex-docstruct-symbol)) 123; ((assq 'bib (symbol-value reftex-docstruct-symbol))
124 ((eq bibtype 'bib) 124 ((eq bibtype 'bib)
125 (setq item nil 125 (setq item nil
126 files (reftex-get-bibfile-list))) 126 files (reftex-get-bibfile-list)))
127; ((assq 'thebib (symbol-value reftex-docstruct-symbol)) 127; ((assq 'thebib (symbol-value reftex-docstruct-symbol))
128 ((eq bibtype 'thebib) 128 ((eq bibtype 'thebib)
129 (setq item t 129 (setq item t
130 files (reftex-uniquify 130 files (reftex-uniquify
131 (mapcar 'cdr 131 (mapcar 'cdr
132 (reftex-all-assq 132 (reftex-all-assq
133 'thebib (symbol-value reftex-docstruct-symbol)))))) 133 'thebib (symbol-value reftex-docstruct-symbol))))))
134 (reftex-default-bibliography 134 (reftex-default-bibliography
135 (setq item nil 135 (setq item nil
136 files (reftex-default-bibliography))) 136 files (reftex-default-bibliography)))
137 (how) ;; don't throw for special display 137 (how) ;; don't throw for special display
138 (t (error "Cannot display crossref"))) 138 (t (error "Cannot display crossref")))
139 139
140 (if (eq how 'echo) 140 (if (eq how 'echo)
141 ;; Display in Echo area 141 ;; Display in Echo area
142 (reftex-echo-cite key files item) 142 (reftex-echo-cite key files item)
143 ;; Display in a window 143 ;; Display in a window
144 (if (not (eq how 'tmp-window)) 144 (if (not (eq how 'tmp-window))
145 ;; Normal display 145 ;; Normal display
146 (reftex-pop-to-bibtex-entry key files nil t item) 146 (reftex-pop-to-bibtex-entry key files nil t item)
147 ;; A temporary window 147 ;; A temporary window
148 (condition-case nil 148 (condition-case nil
149 (reftex-pop-to-bibtex-entry key files nil t item) 149 (reftex-pop-to-bibtex-entry key files nil t item)
150 (error (goto-char pos) 150 (error (goto-char pos)
151 (message "cite: no such citation key %s" key) 151 (message "cite: no such citation key %s" key)
152 (error ""))) 152 (error "")))
153 ;; Resize the window 153 ;; Resize the window
154 (setq size (max 1 (count-lines (point) 154 (setq size (max 1 (count-lines (point)
155 (reftex-end-of-bib-entry item)))) 155 (reftex-end-of-bib-entry item))))
156 (let ((window-min-height 2)) 156 (let ((window-min-height 2))
157 (shrink-window (1- (- (window-height) size))) 157 (shrink-window (1- (- (window-height) size)))
158 (recenter 0)) 158 (recenter 0))
159 ;; Arrange restoration 159 ;; Arrange restoration
160 (add-hook 'pre-command-hook 'reftex-restore-window-conf)) 160 (add-hook 'pre-command-hook 'reftex-restore-window-conf))
161 161
162 ;; Normal display in other window 162 ;; Normal display in other window
163 (add-hook 'pre-command-hook 'reftex-highlight-shall-die) 163 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)
164 (setq pop-win (selected-window)) 164 (setq pop-win (selected-window))
165 (select-window win) 165 (select-window win)
166 (goto-char pos) 166 (goto-char pos)
167 (when (equal arg 2) 167 (when (equal arg 2)
168 (select-window pop-win))))) 168 (select-window pop-win)))))
169 169
170(defun reftex-view-cr-ref (arg label how) 170(defun reftex-view-cr-ref (arg label how)
171 ;; View crossreference of a ref macro. HOW can have the values 171 ;; View crossreference of a ref macro. HOW can have the values
172 ;; nil: Show in another window. 172 ;; nil: Show in another window.
173 ;; echo: Show one-line info in echo area. 173 ;; echo: Show one-line info in echo area.
174 ;; tmp-window: Show in small window and arrange for window to disappear. 174 ;; tmp-window: Show in small window and arrange for window to disappear.
175 175
176 ;; Ensure access to scanning info 176 ;; Ensure access to scanning info
177 (reftex-access-scan-info (or arg current-prefix-arg)) 177 (reftex-access-scan-info (or arg current-prefix-arg))
178 178
179 (if (eq how 'tmp-window) 179 (if (eq how 'tmp-window)
180 ;; Remember the window configuration 180 ;; Remember the window configuration
181 (put 'reftex-auto-view-crossref 'last-window-conf 181 (put 'reftex-auto-view-crossref 'last-window-conf
182 (current-window-configuration))) 182 (current-window-configuration)))
183 183
184 (let* ((xr-data (assoc 'xr (symbol-value reftex-docstruct-symbol))) 184 (let* ((xr-data (assoc 'xr (symbol-value reftex-docstruct-symbol)))
185 (xr-re (nth 2 xr-data)) 185 (xr-re (nth 2 xr-data))
186 (entry (assoc label (symbol-value reftex-docstruct-symbol))) 186 (entry (assoc label (symbol-value reftex-docstruct-symbol)))
187 (win (selected-window)) pop-win (pos (point))) 187 (win (selected-window)) pop-win (pos (point)))
188 188
189 (if (and (not entry) (stringp label) xr-re (string-match xr-re label)) 189 (if (and (not entry) (stringp label) xr-re (string-match xr-re label))
190 ;; Label is defined in external document 190 ;; Label is defined in external document
191 (save-excursion 191 (save-excursion
192 (save-match-data 192 (save-match-data
193 (set-buffer 193 (set-buffer
194 (or (reftex-get-file-buffer-force 194 (or (reftex-get-file-buffer-force
195 (cdr (assoc (match-string 1 label) (nth 1 195 (cdr (assoc (match-string 1 label) (nth 1
196 xr-data)))) 196 xr-data))))
197 (error "Problem with external label %s" label)))) 197 (error "Problem with external label %s" label))))
198 (setq label (substring label (match-end 1))) 198 (setq label (substring label (match-end 1)))
199 (reftex-access-scan-info) 199 (reftex-access-scan-info)
200 (setq entry 200 (setq entry
201 (assoc label (symbol-value reftex-docstruct-symbol))))) 201 (assoc label (symbol-value reftex-docstruct-symbol)))))
202 (if (eq how 'echo) 202 (if (eq how 'echo)
203 ;; Display in echo area 203 ;; Display in echo area
204 (reftex-echo-ref label entry (symbol-value reftex-docstruct-symbol)) 204 (reftex-echo-ref label entry (symbol-value reftex-docstruct-symbol))
205 (let ((window-conf (current-window-configuration))) 205 (let ((window-conf (current-window-configuration)))
206 (condition-case nil 206 (condition-case nil
207 (reftex-show-label-location entry t nil t t) 207 (reftex-show-label-location entry t nil t t)
208 (error (set-window-configuration window-conf) 208 (error (set-window-configuration window-conf)
209 (message "ref: Label %s not found" label) 209 (message "ref: Label %s not found" label)
210 (error "ref: Label %s not found" label)))) ;; 2nd is line OK 210 (error "ref: Label %s not found" label)))) ;; 2nd is line OK
211 (add-hook 'pre-command-hook 'reftex-highlight-shall-die) 211 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)
212 212
213 (when (eq how 'tmp-window) 213 (when (eq how 'tmp-window)
214 ;; Resize window and arrange restauration 214 ;; Resize window and arrange restauration
215 (shrink-window (1- (- (window-height) 9))) 215 (shrink-window (1- (- (window-height) 9)))
216 (recenter '(4)) 216 (recenter '(4))
217 (add-hook 'pre-command-hook 'reftex-restore-window-conf)) 217 (add-hook 'pre-command-hook 'reftex-restore-window-conf))
218 (setq pop-win (selected-window)) 218 (setq pop-win (selected-window))
219 (select-window win) 219 (select-window win)
220 (goto-char pos) 220 (goto-char pos)
221 (when (equal arg 2) 221 (when (equal arg 2)
222 (select-window pop-win))))) 222 (select-window pop-win)))))
223 223
224(defun reftex-mouse-view-crossref (ev) 224(defun reftex-mouse-view-crossref (ev)
225 "View cross reference of \\ref or \\cite macro where you click. 225 "View cross reference of \\ref or \\cite macro where you click.
@@ -240,28 +240,28 @@ With argument, actually select the window showing the cross reference."
240 (or (eq reftex-auto-view-crossref 'window) (not (current-message))) 240 (or (eq reftex-auto-view-crossref 'window) (not (current-message)))
241 ;; Make sure we are not already displaying this one 241 ;; Make sure we are not already displaying this one
242 (not (memq last-command '(reftex-view-crossref 242 (not (memq last-command '(reftex-view-crossref
243 reftex-mouse-view-crossref))) 243 reftex-mouse-view-crossref)))
244 ;; Quick precheck if this might be a relevant spot 244 ;; Quick precheck if this might be a relevant spot
245 ;; FIXME: Can fail with backslash in comment 245 ;; FIXME: Can fail with backslash in comment
246 (save-excursion 246 (save-excursion
247 (search-backward "\\" nil t) 247 (search-backward "\\" nil t)
248 (looking-at "\\\\[a-zA-Z]*\\(cite\\|ref\\|bibentry\\)")) 248 (looking-at "\\\\[a-zA-Z]*\\(cite\\|ref\\|bibentry\\)"))
249 249
250 (condition-case nil 250 (condition-case nil
251 (let ((current-prefix-arg nil)) 251 (let ((current-prefix-arg nil))
252 (cond 252 (cond
253 ((eq reftex-auto-view-crossref t) 253 ((eq reftex-auto-view-crossref t)
254 (reftex-view-crossref -1 'echo)) 254 (reftex-view-crossref -1 'echo))
255 ((eq reftex-auto-view-crossref 'window) 255 ((eq reftex-auto-view-crossref 'window)
256 (reftex-view-crossref -1 'tmp-window)) 256 (reftex-view-crossref -1 'tmp-window))
257 (t nil))) 257 (t nil)))
258 (error nil)))) 258 (error nil))))
259 259
260(defun reftex-restore-window-conf () 260(defun reftex-restore-window-conf ()
261 (set-window-configuration (get 'reftex-auto-view-crossref 'last-window-conf)) 261 (set-window-configuration (get 'reftex-auto-view-crossref 'last-window-conf))
262 (put 'reftex-auto-view-crossref 'last-window-conf nil) 262 (put 'reftex-auto-view-crossref 'last-window-conf nil)
263 (remove-hook 'pre-command-hook 'reftex-restore-window-conf)) 263 (remove-hook 'pre-command-hook 'reftex-restore-window-conf))
264 264
265(defun reftex-echo-ref (label entry docstruct) 265(defun reftex-echo-ref (label entry docstruct)
266 ;; Display crossref info in echo area. 266 ;; Display crossref info in echo area.
267 (cond 267 (cond
@@ -274,46 +274,46 @@ With argument, actually select the window showing the cross reference."
274 (message "ref(%s): %s" (nth 1 entry) (nth 2 entry))) 274 (message "ref(%s): %s" (nth 1 entry) (nth 2 entry)))
275 (let ((buf (get-buffer " *Echo Area*"))) 275 (let ((buf (get-buffer " *Echo Area*")))
276 (when buf 276 (when buf
277 (save-excursion 277 (save-excursion
278 (set-buffer buf) 278 (set-buffer buf)
279 (run-hooks 'reftex-display-copied-context-hook))))))) 279 (run-hooks 'reftex-display-copied-context-hook)))))))
280 280
281(defun reftex-echo-cite (key files item) 281(defun reftex-echo-cite (key files item)
282 ;; Display citation info in echo area. 282 ;; Display citation info in echo area.
283 (let* ((cache (assq 'bibview-cache (symbol-value reftex-docstruct-symbol))) 283 (let* ((cache (assq 'bibview-cache (symbol-value reftex-docstruct-symbol)))
284 (cache-entry (assoc key (cdr cache))) 284 (cache-entry (assoc key (cdr cache)))
285 entry string buf (all-files files)) 285 entry string buf (all-files files))
286 286
287 (if (and reftex-cache-cite-echo cache-entry) 287 (if (and reftex-cache-cite-echo cache-entry)
288 ;; We can just use the cache 288 ;; We can just use the cache
289 (setq string (cdr cache-entry)) 289 (setq string (cdr cache-entry))
290 290
291 ;; Need to look in the database 291 ;; Need to look in the database
292 (unless reftex-revisit-to-echo 292 (unless reftex-revisit-to-echo
293 (setq files (reftex-visited-files files))) 293 (setq files (reftex-visited-files files)))
294 294
295 (setq entry 295 (setq entry
296 (condition-case nil 296 (condition-case nil
297 (save-excursion 297 (save-excursion
298 (reftex-pop-to-bibtex-entry key files nil nil item t)) 298 (reftex-pop-to-bibtex-entry key files nil nil item t))
299 (error 299 (error
300 (if (and files (= (length all-files) (length files))) 300 (if (and files (= (length all-files) (length files)))
301 (message "cite: no such database entry: %s" key) 301 (message "cite: no such database entry: %s" key)
302 (message (substitute-command-keys 302 (message (substitute-command-keys
303 (format reftex-no-info-message "cite")))) 303 (format reftex-no-info-message "cite"))))
304 nil))) 304 nil)))
305 (when entry 305 (when entry
306 (if item 306 (if item
307 (setq string (reftex-nicify-text entry)) 307 (setq string (reftex-nicify-text entry))
308 (setq string (reftex-make-cite-echo-string 308 (setq string (reftex-make-cite-echo-string
309 (reftex-parse-bibtex-entry entry) 309 (reftex-parse-bibtex-entry entry)
310 reftex-docstruct-symbol))))) 310 reftex-docstruct-symbol)))))
311 (unless (or (null string) (equal string "")) 311 (unless (or (null string) (equal string ""))
312 (message "cite: %s" string)) 312 (message "cite: %s" string))
313 (when (setq buf (get-buffer " *Echo Area*")) 313 (when (setq buf (get-buffer " *Echo Area*"))
314 (save-excursion 314 (save-excursion
315 (set-buffer buf) 315 (set-buffer buf)
316 (run-hooks 'reftex-display-copied-context-hook))))) 316 (run-hooks 'reftex-display-copied-context-hook)))))
317 317
318(defvar reftex-use-itimer-in-xemacs nil 318(defvar reftex-use-itimer-in-xemacs nil
319 "*Non-nil means use the idle timers in XEmacs for crossref display. 319 "*Non-nil means use the idle timers in XEmacs for crossref display.
@@ -326,34 +326,34 @@ will display info in the echo area."
326 (interactive) 326 (interactive)
327 (if reftex-auto-view-crossref-timer 327 (if reftex-auto-view-crossref-timer
328 (progn 328 (progn
329 (if (featurep 'xemacs) 329 (if (featurep 'xemacs)
330 (if reftex-use-itimer-in-xemacs 330 (if reftex-use-itimer-in-xemacs
331 (delete-itimer reftex-auto-view-crossref-timer) 331 (delete-itimer reftex-auto-view-crossref-timer)
332 (remove-hook 'post-command-hook 'reftex-start-itimer-once)) 332 (remove-hook 'post-command-hook 'reftex-start-itimer-once))
333 (cancel-timer reftex-auto-view-crossref-timer)) 333 (cancel-timer reftex-auto-view-crossref-timer))
334 (setq reftex-auto-view-crossref-timer nil) 334 (setq reftex-auto-view-crossref-timer nil)
335 (message "Automatic display of crossref information was turned off")) 335 (message "Automatic display of crossref information was turned off"))
336 (setq reftex-auto-view-crossref-timer 336 (setq reftex-auto-view-crossref-timer
337 (if (featurep 'xemacs) 337 (if (featurep 'xemacs)
338 (if reftex-use-itimer-in-xemacs 338 (if reftex-use-itimer-in-xemacs
339 (start-itimer "RefTeX Idle Timer" 339 (start-itimer "RefTeX Idle Timer"
340 'reftex-view-crossref-when-idle 340 'reftex-view-crossref-when-idle
341 reftex-idle-time reftex-idle-time t) 341 reftex-idle-time reftex-idle-time t)
342 (add-hook 'post-command-hook 'reftex-start-itimer-once) 342 (add-hook 'post-command-hook 'reftex-start-itimer-once)
343 t) 343 t)
344 (run-with-idle-timer 344 (run-with-idle-timer
345 reftex-idle-time t 'reftex-view-crossref-when-idle))) 345 reftex-idle-time t 'reftex-view-crossref-when-idle)))
346 (unless reftex-auto-view-crossref 346 (unless reftex-auto-view-crossref
347 (setq reftex-auto-view-crossref t)) 347 (setq reftex-auto-view-crossref t))
348 (message "Automatic display of crossref information was turned on"))) 348 (message "Automatic display of crossref information was turned on")))
349 349
350(defun reftex-start-itimer-once () 350(defun reftex-start-itimer-once ()
351 (and reftex-mode 351 (and reftex-mode
352 (not (itimer-live-p reftex-auto-view-crossref-timer)) 352 (not (itimer-live-p reftex-auto-view-crossref-timer))
353 (setq reftex-auto-view-crossref-timer 353 (setq reftex-auto-view-crossref-timer
354 (start-itimer "RefTeX Idle Timer" 354 (start-itimer "RefTeX Idle Timer"
355 'reftex-view-crossref-when-idle 355 'reftex-view-crossref-when-idle
356 reftex-idle-time nil t)))) 356 reftex-idle-time nil t))))
357 357
358(defun reftex-view-crossref-from-bibtex (&optional arg) 358(defun reftex-view-crossref-from-bibtex (&optional arg)
359 "View location in a LaTeX document which cites the BibTeX entry at point. 359 "View location in a LaTeX document which cites the BibTeX entry at point.
@@ -362,34 +362,34 @@ prompts upon first use for a buffer in RefTeX mode. To reset this
362link to a document, call the function with with a prefix arg. 362link to a document, call the function with with a prefix arg.
363Calling this function several times find successive citation locations." 363Calling this function several times find successive citation locations."
364 (interactive "P") 364 (interactive "P")
365 (when arg 365 (when arg
366 ;; Break connection to reference buffer 366 ;; Break connection to reference buffer
367 (put 'reftex-bibtex-view-cite-locations :ref-buffer nil)) 367 (put 'reftex-bibtex-view-cite-locations :ref-buffer nil))
368 (let ((ref-buffer (get 'reftex-bibtex-view-cite-locations :ref-buffer))) 368 (let ((ref-buffer (get 'reftex-bibtex-view-cite-locations :ref-buffer)))
369 ;; Establish connection to reference buffer 369 ;; Establish connection to reference buffer
370 (unless ref-buffer 370 (unless ref-buffer
371 (setq ref-buffer 371 (setq ref-buffer
372 (save-excursion 372 (save-excursion
373 (completing-read 373 (completing-read
374 "Reference buffer: " 374 "Reference buffer: "
375 (delq nil 375 (delq nil
376 (mapcar 376 (mapcar
377 (lambda (b) 377 (lambda (b)
378 (set-buffer b) 378 (set-buffer b)
379 (if reftex-mode (list (buffer-name b)) nil)) 379 (if reftex-mode (list (buffer-name b)) nil))
380 (buffer-list))) 380 (buffer-list)))
381 nil t))) 381 nil t)))
382 (put 'reftex-bibtex-view-cite-locations :ref-buffer ref-buffer)) 382 (put 'reftex-bibtex-view-cite-locations :ref-buffer ref-buffer))
383 ;; Search for citations 383 ;; Search for citations
384 (bibtex-beginning-of-entry) 384 (bibtex-beginning-of-entry)
385 (if (looking-at 385 (if (looking-at
386 "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*\\([^, \t\r\n}]+\\)") 386 "@[a-zA-Z]+[ \t\n\r]*[{(][ \t\n\r]*\\([^, \t\r\n}]+\\)")
387 (progn 387 (progn
388 (goto-char (match-beginning 1)) 388 (goto-char (match-beginning 1))
389 (reftex-view-regexp-match 389 (reftex-view-regexp-match
390 (format reftex-find-citation-regexp-format 390 (format reftex-find-citation-regexp-format
391 (regexp-quote (match-string 1))) 391 (regexp-quote (match-string 1)))
392 4 arg ref-buffer)) 392 4 arg ref-buffer))
393 (error "Cannot find citation key in BibTeX entry")))) 393 (error "Cannot find citation key in BibTeX entry"))))
394 394
395(defun reftex-view-regexp-match (re &optional highlight-group new ref-buffer) 395(defun reftex-view-regexp-match (re &optional highlight-group new ref-buffer)
@@ -402,39 +402,39 @@ Calling this function several times find successive citation locations."
402 402
403 ;;; Decide if new search or continued search 403 ;;; Decide if new search or continued search
404 (let* ((oldprop (get 'reftex-view-regexp-match :props)) 404 (let* ((oldprop (get 'reftex-view-regexp-match :props))
405 (newprop (list (current-buffer) re)) 405 (newprop (list (current-buffer) re))
406 (cont (and (not new) (equal oldprop newprop))) 406 (cont (and (not new) (equal oldprop newprop)))
407 (cnt (if cont (get 'reftex-view-regexp-match :cnt) 0)) 407 (cnt (if cont (get 'reftex-view-regexp-match :cnt) 0))
408 (current-window (selected-window)) 408 (current-window (selected-window))
409 (window-conf (current-window-configuration)) 409 (window-conf (current-window-configuration))
410 match pop-window) 410 match pop-window)
411 (switch-to-buffer-other-window (or ref-buffer (current-buffer))) 411 (switch-to-buffer-other-window (or ref-buffer (current-buffer)))
412 ;; Search 412 ;; Search
413 (condition-case nil 413 (condition-case nil
414 (if cont 414 (if cont
415 (setq match (reftex-global-search-continue)) 415 (setq match (reftex-global-search-continue))
416 (reftex-access-scan-info) 416 (reftex-access-scan-info)
417 (setq match (reftex-global-search re (reftex-all-document-files)))) 417 (setq match (reftex-global-search re (reftex-all-document-files))))
418 (error nil)) 418 (error nil))
419 ;; Evaluate the match. 419 ;; Evaluate the match.
420 (if match 420 (if match
421 (progn 421 (progn
422 (put 'reftex-view-regexp-match :props newprop) 422 (put 'reftex-view-regexp-match :props newprop)
423 (put 'reftex-view-regexp-match :cnt (incf cnt)) 423 (put 'reftex-view-regexp-match :cnt (incf cnt))
424 (reftex-highlight 0 (match-beginning highlight-group) 424 (reftex-highlight 0 (match-beginning highlight-group)
425 (match-end highlight-group)) 425 (match-end highlight-group))
426 (add-hook 'pre-command-hook 'reftex-highlight-shall-die) 426 (add-hook 'pre-command-hook 'reftex-highlight-shall-die)
427 (setq pop-window (selected-window))) 427 (setq pop-window (selected-window)))
428 (put 'reftex-view-regexp-match :props nil) 428 (put 'reftex-view-regexp-match :props nil)
429 (or cont (set-window-configuration window-conf))) 429 (or cont (set-window-configuration window-conf)))
430 (select-window current-window) 430 (select-window current-window)
431 (if match 431 (if match
432 (progn 432 (progn
433 (message "Match Nr. %s" cnt) 433 (message "Match Nr. %s" cnt)
434 pop-window) 434 pop-window)
435 (if cont 435 (if cont
436 (error "No further matches (total number of matches: %d)" cnt) 436 (error "No further matches (total number of matches: %d)" cnt)
437 (error "No matches"))))) 437 (error "No matches")))))
438 438
439(defvar reftex-global-search-marker (make-marker)) 439(defvar reftex-global-search-marker (make-marker))
440(defun reftex-global-search (regexp file-list) 440(defun reftex-global-search (regexp file-list)
@@ -449,11 +449,11 @@ Calling this function several times find successive citation locations."
449 (unless (get 'reftex-global-search :file-list) 449 (unless (get 'reftex-global-search :file-list)
450 (error "No global search to continue")) 450 (error "No global search to continue"))
451 (let* ((file-list (get 'reftex-global-search :file-list)) 451 (let* ((file-list (get 'reftex-global-search :file-list))
452 (regexp (get 'reftex-global-search :regexp)) 452 (regexp (get 'reftex-global-search :regexp))
453 (buf (or (marker-buffer reftex-global-search-marker) 453 (buf (or (marker-buffer reftex-global-search-marker)
454 (reftex-get-file-buffer-force (car file-list)))) 454 (reftex-get-file-buffer-force (car file-list))))
455 (pos (or (marker-position reftex-global-search-marker) 1)) 455 (pos (or (marker-position reftex-global-search-marker) 1))
456 file) 456 file)
457 ;; Take up starting position 457 ;; Take up starting position
458 (unless buf (error "No such buffer %s" buf)) 458 (unless buf (error "No such buffer %s" buf))
459 (switch-to-buffer buf) 459 (switch-to-buffer buf)
@@ -461,23 +461,22 @@ Calling this function several times find successive citation locations."
461 (goto-char pos) 461 (goto-char pos)
462 ;; Search and switch file if necessary 462 ;; Search and switch file if necessary
463 (if (catch 'exit 463 (if (catch 'exit
464 (while t 464 (while t
465 (when (re-search-forward regexp nil t) 465 (when (re-search-forward regexp nil t)
466 (move-marker reftex-global-search-marker (point)) 466 (move-marker reftex-global-search-marker (point))
467 (throw 'exit t)) 467 (throw 'exit t))
468 ;; No match - goto next file 468 ;; No match - goto next file
469 (pop file-list) 469 (pop file-list)
470 (or file-list (throw 'exit nil)) 470 (or file-list (throw 'exit nil))
471 (setq file (car file-list) 471 (setq file (car file-list)
472 buf (reftex-get-file-buffer-force file)) 472 buf (reftex-get-file-buffer-force file))
473 (unless buf (error "Cannot access file %s" file)) 473 (unless buf (error "Cannot access file %s" file))
474 (put 'reftex-global-search :file-list file-list) 474 (put 'reftex-global-search :file-list file-list)
475 (switch-to-buffer buf) 475 (switch-to-buffer buf)
476 (widen) 476 (widen)
477 (goto-char 1))) 477 (goto-char 1)))
478 t 478 t
479 (move-marker reftex-global-search-marker nil) 479 (move-marker reftex-global-search-marker nil)
480 (error "All files processed")))) 480 (error "All files processed"))))
481 481
482;;; arch-tag: d2f52b56-744e-44ad-830d-1fc193b90eda
483;;; reftex-dcr.el ends here 482;;; reftex-dcr.el ends here
diff --git a/lisp/textmodes/reftex-global.el b/lisp/textmodes/reftex-global.el
index 84b4c7c67f5..36cecd12c1a 100644
--- a/lisp/textmodes/reftex-global.el
+++ b/lisp/textmodes/reftex-global.el
@@ -1,8 +1,8 @@
1;;; reftex-global.el --- operations on entire documents with RefTeX 1;;; reftex-global.el --- operations on entire documents with RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -107,26 +107,26 @@ No active TAGS table is required."
107 (reftex-access-scan-info t) 107 (reftex-access-scan-info t)
108 108
109 (let ((master (reftex-TeX-master-file)) 109 (let ((master (reftex-TeX-master-file))
110 (cnt 0) 110 (cnt 0)
111 (dlist 111 (dlist
112 (mapcar 112 (mapcar
113 (lambda (x) 113 (lambda (x)
114 (let (x1) 114 (let (x1)
115 (cond 115 (cond
116 ((memq (car x) 116 ((memq (car x)
117 '(toc bof eof bib thebib label-numbers xr xr-doc 117 '(toc bof eof bib thebib label-numbers xr xr-doc
118 master-dir file-error bibview-cache appendix 118 master-dir file-error bibview-cache appendix
119 is-multi index)) 119 is-multi index))
120 nil) 120 nil)
121 (t 121 (t
122 (setq x1 (reftex-all-assoc-string 122 (setq x1 (reftex-all-assoc-string
123 (car x) (symbol-value reftex-docstruct-symbol))) 123 (car x) (symbol-value reftex-docstruct-symbol)))
124 (if (< 1 (length x1)) 124 (if (< 1 (length x1))
125 (append (list (car x)) 125 (append (list (car x))
126 (mapcar (lambda(x) 126 (mapcar (lambda(x)
127 (abbreviate-file-name (nth 3 x))) 127 (abbreviate-file-name (nth 3 x)))
128 x1)) 128 x1))
129 (list nil)))))) 129 (list nil))))))
130 (reftex-uniquify-by-car (symbol-value reftex-docstruct-symbol))))) 130 (reftex-uniquify-by-car (symbol-value reftex-docstruct-symbol)))))
131 131
132 (setq dlist (reftex-uniquify-by-car dlist)) 132 (setq dlist (reftex-uniquify-by-car dlist))
@@ -135,19 +135,19 @@ No active TAGS table is required."
135 (set (make-local-variable 'TeX-master) master) 135 (set (make-local-variable 'TeX-master) master)
136 (erase-buffer) 136 (erase-buffer)
137 (insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n") 137 (insert " MULTIPLE LABELS IN CURRENT DOCUMENT:\n")
138 (insert 138 (insert
139 " Move point to label and type `r' to run a query-replace on the label\n" 139 " Move point to label and type `r' to run a query-replace on the label\n"
140 " and its references. Type `q' to exit this buffer.\n\n") 140 " and its references. Type `q' to exit this buffer.\n\n")
141 (insert " LABEL FILE\n") 141 (insert " LABEL FILE\n")
142 (insert " -------------------------------------------------------------\n") 142 (insert " -------------------------------------------------------------\n")
143 (use-local-map (make-sparse-keymap)) 143 (use-local-map (make-sparse-keymap))
144 (local-set-key [?q] (lambda () "Kill this buffer." (interactive) 144 (local-set-key [?q] (lambda () "Kill this buffer." (interactive)
145 (kill-buffer (current-buffer)) (delete-window))) 145 (kill-buffer (current-buffer)) (delete-window)))
146 (local-set-key [?r] 'reftex-change-label) 146 (local-set-key [?r] 'reftex-change-label)
147 (while dlist 147 (while dlist
148 (when (and (car (car dlist)) 148 (when (and (car (car dlist))
149 (cdr (car dlist))) 149 (cdr (car dlist)))
150 (incf cnt) 150 (incf cnt)
151 (insert (mapconcat 'identity (car dlist) "\n ") "\n")) 151 (insert (mapconcat 'identity (car dlist) "\n ") "\n"))
152 (pop dlist)) 152 (pop dlist))
153 (goto-char (point-min)) 153 (goto-char (point-min))
@@ -157,7 +157,7 @@ No active TAGS table is required."
157 (message "Document does not contain duplicate labels.")))) 157 (message "Document does not contain duplicate labels."))))
158 158
159(defun reftex-change-label (&optional from to) 159(defun reftex-change-label (&optional from to)
160 "Run `query-replace-regexp' of FROM with TO in all macro arguments. 160 "Run `query-replace-regexp' of FROM with TO in all \\label and \\ref commands.
161Works on the entire multifile document. 161Works on the entire multifile document.
162If you exit (\\[keyboard-quit], RET or q), you can resume the query replace 162If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
163with the command \\[tags-loop-continue]. 163with the command \\[tags-loop-continue].
@@ -172,8 +172,8 @@ No active TAGS table is required."
172 (setq to (read-string (format "Replace label %s with: " 172 (setq to (read-string (format "Replace label %s with: "
173 from)))) 173 from))))
174 (reftex-query-replace-document 174 (reftex-query-replace-document
175 (concat "{" (regexp-quote from) "}") 175 (concat "\\\\\\(label\\|[a-zA-Z]*ref\\){" (regexp-quote from) "}")
176 (format "{%s}" to)))) 176 (format "\\\\\\1{%s}" to))))
177 177
178(defun reftex-renumber-simple-labels () 178(defun reftex-renumber-simple-labels ()
179 "Renumber all simple labels in the document to make them sequentially. 179 "Renumber all simple labels in the document to make them sequentially.
@@ -190,33 +190,33 @@ one with the `xr' package."
190 (reftex-access-scan-info 1) 190 (reftex-access-scan-info 1)
191 ;; Get some insurance 191 ;; Get some insurance
192 (if (and (reftex-is-multi) 192 (if (and (reftex-is-multi)
193 (not (yes-or-no-p "Replacing all simple labels in multiple files is risky. Continue? "))) 193 (not (yes-or-no-p "Replacing all simple labels in multiple files is risky. Continue? ")))
194 (error "Abort")) 194 (error "Abort"))
195 ;; Make the translation list 195 ;; Make the translation list
196 (let* ((re-core (concat "\\(" 196 (let* ((re-core (concat "\\("
197 (mapconcat 'cdr reftex-typekey-to-prefix-alist "\\|") 197 (mapconcat 'cdr reftex-typekey-to-prefix-alist "\\|")
198 "\\)")) 198 "\\)"))
199 (label-re (concat "\\`" re-core "\\([0-9]+\\)\\'")) 199 (label-re (concat "\\`" re-core "\\([0-9]+\\)\\'"))
200 (search-re (concat "[{,]\\(" re-core "\\([0-9]+\\)\\)[,}]")) 200 (search-re (concat "[{,]\\(" re-core "\\([0-9]+\\)\\)[,}]"))
201 (error-fmt "Undefined label or reference %s. Ignore and continue? ") 201 (error-fmt "Undefined label or reference %s. Ignore and continue? ")
202 (label-numbers-alist (mapcar (lambda (x) (cons (cdr x) 0)) 202 (label-numbers-alist (mapcar (lambda (x) (cons (cdr x) 0))
203 reftex-typekey-to-prefix-alist)) 203 reftex-typekey-to-prefix-alist))
204 (files (reftex-all-document-files)) 204 (files (reftex-all-document-files))
205 (list (symbol-value reftex-docstruct-symbol)) 205 (list (symbol-value reftex-docstruct-symbol))
206 translate-alist n entry label new-label nr-cell changed-sequence) 206 translate-alist n entry label new-label nr-cell changed-sequence)
207 207
208 (while (setq entry (pop list)) 208 (while (setq entry (pop list))
209 (when (and (stringp (car entry)) 209 (when (and (stringp (car entry))
210 (string-match label-re (car entry))) 210 (string-match label-re (car entry)))
211 (setq label (car entry) 211 (setq label (car entry)
212 nr-cell (assoc (match-string 1 (car entry)) 212 nr-cell (assoc (match-string 1 (car entry))
213 label-numbers-alist)) 213 label-numbers-alist))
214 (if (assoc label translate-alist) 214 (if (assoc label translate-alist)
215 (error "Duplicate label %s" label)) 215 (error "Duplicate label %s" label))
216 (setq new-label (concat (match-string 1 (car entry)) 216 (setq new-label (concat (match-string 1 (car entry))
217 (int-to-string (incf (cdr nr-cell))))) 217 (int-to-string (incf (cdr nr-cell)))))
218 (push (cons label new-label) translate-alist) 218 (push (cons label new-label) translate-alist)
219 (or (string= label new-label) (setq changed-sequence t)))) 219 (or (string= label new-label) (setq changed-sequence t))))
220 220
221 (unless changed-sequence 221 (unless changed-sequence
222 (error "Simple labels are already in correct sequence")) 222 (error "Simple labels are already in correct sequence"))
@@ -227,79 +227,79 @@ one with the `xr' package."
227 (reftex-save-all-document-buffers) 227 (reftex-save-all-document-buffers)
228 228
229 ;; First test to check for erros 229 ;; First test to check for erros
230 (setq n (reftex-translate 230 (setq n (reftex-translate
231 files search-re translate-alist error-fmt 'test)) 231 files search-re translate-alist error-fmt 'test))
232 232
233 ;; Now the real thing. 233 ;; Now the real thing.
234 (if (yes-or-no-p 234 (if (yes-or-no-p
235 (format "Replace %d items at %d places in %d files? " 235 (format "Replace %d items at %d places in %d files? "
236 (length translate-alist) n (length files))) 236 (length translate-alist) n (length files)))
237 (progn 237 (progn
238 (let ((inhibit-quit t)) ;; Do not disturb... 238 (let ((inhibit-quit t)) ;; Do not disturb...
239 (reftex-translate 239 (reftex-translate
240 files search-re translate-alist error-fmt nil) 240 files search-re translate-alist error-fmt nil)
241 (setq quit-flag nil)) 241 (setq quit-flag nil))
242 (if (and (reftex-is-multi) 242 (if (and (reftex-is-multi)
243 (yes-or-no-p "Save entire document? ")) 243 (yes-or-no-p "Save entire document? "))
244 (reftex-save-all-document-buffers)) 244 (reftex-save-all-document-buffers))
245 ;; Rescan again... 245 ;; Rescan again...
246 (reftex-access-scan-info 1) 246 (reftex-access-scan-info 1)
247 (message "Done replacing simple labels.")) 247 (message "Done replacing simple labels."))
248 (message "No replacements done")))) 248 (message "No replacements done"))))
249 249
250(defun reftex-translate (files search-re translate-alist error-fmt test) 250(defun reftex-translate (files search-re translate-alist error-fmt test)
251 ;; In FILES, look for SEARCH-RE and replace match 1 of it with 251 ;; In FILES, look for SEARCH-RE and replace match 1 of it with
252 ;; its association in TRANSLATE-ALSIT. 252 ;; its association in TRANSLATE-ALSIT.
253 ;; If we do not find an association and TEST is non-nil, query 253 ;; If we do not find an association and TEST is non-nil, query
254 ;; to ignore the problematic string. 254 ;; to ignore the problematic string.
255 ;; If TEST is nil, it is ignored without query. 255 ;; If TEST is nil, it is ignored without query.
256 ;; Return the number of replacements. 256 ;; Return the number of replacements.
257 (let ((n 0) file label match-data buf macro pos cell) 257 (let ((n 0) file label match-data buf macro pos cell)
258 (while (setq file (pop files)) 258 (while (setq file (pop files))
259 (setq buf (reftex-get-file-buffer-force file)) 259 (setq buf (reftex-get-file-buffer-force file))
260 (unless buf 260 (unless buf
261 (error "No such file %s" file)) 261 (error "No such file %s" file))
262 (set-buffer buf) 262 (set-buffer buf)
263 (save-excursion 263 (save-excursion
264 (save-restriction 264 (save-restriction
265 (widen) 265 (widen)
266 (goto-char (point-min)) 266 (goto-char (point-min))
267 (while (re-search-forward search-re nil t) 267 (while (re-search-forward search-re nil t)
268 (backward-char) 268 (backward-char)
269 (save-excursion 269 (save-excursion
270 (setq label (reftex-match-string 1) 270 (setq label (reftex-match-string 1)
271 cell (assoc label translate-alist) 271 cell (assoc label translate-alist)
272 match-data (match-data) 272 match-data (match-data)
273 macro (reftex-what-macro 1) 273 macro (reftex-what-macro 1)
274 pos (cdr macro)) 274 pos (cdr macro))
275 (goto-char (or pos (point))) 275 (goto-char (or pos (point)))
276 (when (and macro 276 (when (and macro
277 (or (looking-at "\\\\ref") 277 (or (looking-at "\\\\ref")
278 (looking-at "\\\\[a-zA-Z]*ref\\(range\\)?[^a-zA-Z]") 278 (looking-at "\\\\[a-zA-Z]*ref\\(range\\)?[^a-zA-Z]")
279 (looking-at "\\\\ref[a-zA-Z]*[^a-zA-Z]") 279 (looking-at "\\\\ref[a-zA-Z]*[^a-zA-Z]")
280 (looking-at (format 280 (looking-at (format
281 reftex-find-label-regexp-format 281 reftex-find-label-regexp-format
282 (regexp-quote label))))) 282 (regexp-quote label)))))
283 ;; OK, we should replace it. 283 ;; OK, we should replace it.
284 (set-match-data match-data) 284 (set-match-data match-data)
285 (cond 285 (cond
286 ((and test (not cell)) 286 ((and test (not cell))
287 ;; We've got a problem 287 ;; We've got a problem
288 (unwind-protect 288 (unwind-protect
289 (progn 289 (progn
290 (reftex-highlight 1 (match-beginning 0) (match-end 0)) 290 (reftex-highlight 1 (match-beginning 0) (match-end 0))
291 (ding) 291 (ding)
292 (or (y-or-n-p (format error-fmt label)) 292 (or (y-or-n-p (format error-fmt label))
293 (error "Abort"))) 293 (error "Abort")))
294 (reftex-unhighlight 1))) 294 (reftex-unhighlight 1)))
295 ((and test cell) 295 ((and test cell)
296 (incf n)) 296 (incf n))
297 ((and (not test) cell) 297 ((and (not test) cell)
298 ;; Replace 298 ;; Replace
299 (goto-char (match-beginning 1)) 299 (goto-char (match-beginning 1))
300 (delete-region (match-beginning 1) (match-end 1)) 300 (delete-region (match-beginning 1) (match-end 1))
301 (insert (cdr cell))) 301 (insert (cdr cell)))
302 (t nil)))))))) 302 (t nil))))))))
303 n)) 303 n))
304 304
305(defun reftex-save-all-document-buffers () 305(defun reftex-save-all-document-buffers ()
@@ -308,13 +308,13 @@ The function is useful after a global action like replacing or renumbering
308labels." 308labels."
309 (interactive) 309 (interactive)
310 (let ((files (reftex-all-document-files)) 310 (let ((files (reftex-all-document-files))
311 file buffer) 311 file buffer)
312 (save-excursion 312 (save-excursion
313 (while (setq file (pop files)) 313 (while (setq file (pop files))
314 (setq buffer (reftex-get-buffer-visiting file)) 314 (setq buffer (reftex-get-buffer-visiting file))
315 (when buffer 315 (when buffer
316 (set-buffer buffer) 316 (set-buffer buffer)
317 (save-buffer)))))) 317 (save-buffer))))))
318 318
319(defun reftex-ensure-write-access (files) 319(defun reftex-ensure-write-access (files)
320 "Make sure we have write access to all files in FILES. 320 "Make sure we have write access to all files in FILES.
@@ -322,21 +322,20 @@ Also checks if buffers visiting the files are in read-only mode."
322 (let (file buf) 322 (let (file buf)
323 (while (setq file (pop files)) 323 (while (setq file (pop files))
324 (unless (file-exists-p file) 324 (unless (file-exists-p file)
325 (ding) 325 (ding)
326 (or (y-or-n-p (format "No such file %s. Continue? " file)) 326 (or (y-or-n-p (format "No such file %s. Continue? " file))
327 (error "Abort"))) 327 (error "Abort")))
328 (unless (file-writable-p file) 328 (unless (file-writable-p file)
329 (ding) 329 (ding)
330 (or (y-or-n-p (format "No write access to %s. Continue? " file)) 330 (or (y-or-n-p (format "No write access to %s. Continue? " file))
331 (error "Abort"))) 331 (error "Abort")))
332 (when (and (setq buf (reftex-get-buffer-visiting file)) 332 (when (and (setq buf (reftex-get-buffer-visiting file))
333 (save-excursion 333 (save-excursion
334 (set-buffer buf) 334 (set-buffer buf)
335 buffer-read-only)) 335 buffer-read-only))
336 (ding) 336 (ding)
337 (or (y-or-n-p (format "Buffer %s is read-only. Continue? " 337 (or (y-or-n-p (format "Buffer %s is read-only. Continue? "
338 (buffer-name buf))) 338 (buffer-name buf)))
339 (error "Abort")))))) 339 (error "Abort"))))))
340 340
341;;; arch-tag: 2dbf7633-92c8-4340-8656-7aa019d0f80d
342;;; reftex-global.el ends here 341;;; reftex-global.el ends here
diff --git a/lisp/textmodes/reftex-index.el b/lisp/textmodes/reftex-index.el
index 71b3b624770..a1dd6054648 100644
--- a/lisp/textmodes/reftex-index.el
+++ b/lisp/textmodes/reftex-index.el
@@ -1,8 +1,8 @@
1;;; reftex-index.el --- index support with RefTeX 1;;; reftex-index.el --- index support with RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -47,48 +47,48 @@ which is part of AUCTeX, the string is first processed with the
47`reftex-index-math-format', which see." 47`reftex-index-math-format', which see."
48 (interactive "P") 48 (interactive "P")
49 (let* ((use-default (not (equal arg '(16)))) ; check for double prefix 49 (let* ((use-default (not (equal arg '(16)))) ; check for double prefix
50 ;; check if we have an active selection 50 ;; check if we have an active selection
51 (active (if (boundp 'zmacs-regions) 51 (active (if (boundp 'zmacs-regions)
52 (and zmacs-regions (region-exists-p)) ; XEmacs 52 (and zmacs-regions (region-exists-p)) ; XEmacs
53 (and transient-mark-mode mark-active))) ; Emacs 53 (and transient-mark-mode mark-active))) ; Emacs
54 (beg (if active 54 (beg (if active
55 (region-beginning) 55 (region-beginning)
56 (save-excursion 56 (save-excursion
57 (skip-syntax-backward "w\\") (point)))) 57 (skip-syntax-backward "w\\") (point))))
58 (end (if active 58 (end (if active
59 (region-end) 59 (region-end)
60 (save-excursion 60 (save-excursion
61 (skip-syntax-forward "w\\") (point)))) 61 (skip-syntax-forward "w\\") (point))))
62 (sel (buffer-substring beg end)) 62 (sel (buffer-substring beg end))
63 (mathp (condition-case nil (texmathp) (error nil))) 63 (mathp (condition-case nil (texmathp) (error nil)))
64 (current-prefix-arg nil) ; we want to call reftex-index without prefix. 64 (current-prefix-arg nil) ; we want to call reftex-index without prefix.
65 key def-char def-tag full-entry) 65 key def-char def-tag full-entry)
66 66
67 (if phrase 67 (if phrase
68 (progn 68 (progn
69 (reftex-index-visit-phrases-buffer) 69 (reftex-index-visit-phrases-buffer)
70 (reftex-index-new-phrase sel)) 70 (reftex-index-new-phrase sel))
71 71
72 (if (equal sel "") 72 (if (equal sel "")
73 ;; Nothing selected, no word, so use full reftex-index command 73 ;; Nothing selected, no word, so use full reftex-index command
74 (reftex-index) 74 (reftex-index)
75 ;; OK, we have something to index here. 75 ;; OK, we have something to index here.
76 ;; Add the dollars when necessary 76 ;; Add the dollars when necessary
77 (setq key (if mathp 77 (setq key (if mathp
78 (format reftex-index-math-format sel) 78 (format reftex-index-math-format sel)
79 sel)) 79 sel))
80 ;; Get info from `reftex-index-default-macro' 80 ;; Get info from `reftex-index-default-macro'
81 (setq def-char (if use-default (car reftex-index-default-macro))) 81 (setq def-char (if use-default (car reftex-index-default-macro)))
82 (setq def-tag (if use-default (nth 1 reftex-index-default-macro))) 82 (setq def-tag (if use-default (nth 1 reftex-index-default-macro)))
83 ;; Does the user want to edit the entry? 83 ;; Does the user want to edit the entry?
84 (setq full-entry (if arg 84 (setq full-entry (if arg
85 (reftex-index-complete-key 85 (reftex-index-complete-key
86 def-tag nil (cons key 0)) 86 def-tag nil (cons key 0))
87 key)) 87 key))
88 ;; Delete what is in the buffer and make the index entry 88 ;; Delete what is in the buffer and make the index entry
89 (delete-region beg end) 89 (delete-region beg end)
90 (reftex-index def-char full-entry def-tag sel))))) 90 (reftex-index def-char full-entry def-tag sel)))))
91 91
92(defun reftex-index (&optional char key tag sel no-insert) 92(defun reftex-index (&optional char key tag sel no-insert)
93 "Query for an index macro and insert it along with its argments. 93 "Query for an index macro and insert it along with its argments.
94The index macros available are those defined in `reftex-index-macro' or 94The index macros available are those defined in `reftex-index-macro' or
@@ -104,58 +104,58 @@ will prompt for other arguments."
104 104
105 ;; Find out which macro we are going to use 105 ;; Find out which macro we are going to use
106 (let* ((char (or char 106 (let* ((char (or char
107 (reftex-select-with-char reftex-query-index-macro-prompt 107 (reftex-select-with-char reftex-query-index-macro-prompt
108 reftex-query-index-macro-help))) 108 reftex-query-index-macro-help)))
109 (macro (nth 1 (assoc char reftex-key-to-index-macro-alist))) 109 (macro (nth 1 (assoc char reftex-key-to-index-macro-alist)))
110 (entry (or (assoc macro reftex-index-macro-alist) 110 (entry (or (assoc macro reftex-index-macro-alist)
111 (error "No index macro associated with %c" char))) 111 (error "No index macro associated with %c" char)))
112 (ntag (nth 1 entry)) 112 (ntag (nth 1 entry))
113 (tag (or tag (nth 1 entry))) 113 (tag (or tag (nth 1 entry)))
114 (nargs (nth 4 entry)) 114 (nargs (nth 4 entry))
115 (nindex (nth 5 entry)) 115 (nindex (nth 5 entry))
116 (opt-args (nth 6 entry)) 116 (opt-args (nth 6 entry))
117 (repeat (nth 7 entry)) 117 (repeat (nth 7 entry))
118 opt tag1 value) 118 opt tag1 value)
119 119
120 ;; Get the supported arguments 120 ;; Get the supported arguments
121 (if (stringp tag) 121 (if (stringp tag)
122 (setq tag1 tag) 122 (setq tag1 tag)
123 (setq tag1 (or (reftex-index-complete-tag tag opt-args) ""))) 123 (setq tag1 (or (reftex-index-complete-tag tag opt-args) "")))
124 (setq key (or key 124 (setq key (or key
125 (reftex-index-complete-key 125 (reftex-index-complete-key
126 (if (string= tag1 "") "idx" tag1) 126 (if (string= tag1 "") "idx" tag1)
127 (member nindex opt-args)))) 127 (member nindex opt-args))))
128 128
129 ;; Insert the macro and ask for any additional args 129 ;; Insert the macro and ask for any additional args
130 (insert macro) 130 (insert macro)
131 (loop for i from 1 to nargs do 131 (loop for i from 1 to nargs do
132 (setq opt (member i opt-args) 132 (setq opt (member i opt-args)
133 value (cond ((= nindex i) key) 133 value (cond ((= nindex i) key)
134 ((equal ntag i) tag1) 134 ((equal ntag i) tag1)
135 (t (read-string (concat "Macro arg nr. " 135 (t (read-string (concat "Macro arg nr. "
136 (int-to-string i) 136 (int-to-string i)
137 (if opt " (optional)" "") 137 (if opt " (optional)" "")
138 ": "))))) 138 ": ")))))
139 (unless (and opt (string= value "")) 139 (unless (and opt (string= value ""))
140 (insert (if opt "[" "{") value (if opt "]" "}")))) 140 (insert (if opt "[" "{") value (if opt "]" "}"))))
141 (and repeat (stringp sel) (insert sel)) 141 (and repeat (stringp sel) (insert sel))
142 (and key reftex-plug-into-AUCTeX (fboundp 'LaTeX-add-index-entries) 142 (and key reftex-plug-into-AUCTeX (fboundp 'LaTeX-add-index-entries)
143 (LaTeX-add-index-entries key)) 143 (LaTeX-add-index-entries key))
144 (reftex-index-update-taglist tag1) 144 (reftex-index-update-taglist tag1)
145 (reftex-notice-new))) 145 (reftex-notice-new)))
146 146
147(defun reftex-default-index () 147(defun reftex-default-index ()
148 (cond ((null reftex-index-default-tag) nil) 148 (cond ((null reftex-index-default-tag) nil)
149 ((stringp reftex-index-default-tag) reftex-index-default-tag) 149 ((stringp reftex-index-default-tag) reftex-index-default-tag)
150 (t (or (get reftex-docstruct-symbol 'default-index-tag) 150 (t (or (get reftex-docstruct-symbol 'default-index-tag)
151 "idx")))) 151 "idx"))))
152 152
153(defun reftex-update-default-index (tag &optional tag-list) 153(defun reftex-update-default-index (tag &optional tag-list)
154 (if (and (not (equal tag "")) 154 (if (and (not (equal tag ""))
155 (stringp tag) 155 (stringp tag)
156 (eq reftex-index-default-tag 'last) 156 (eq reftex-index-default-tag 'last)
157 (or (null tag-list) 157 (or (null tag-list)
158 (member tag tag-list))) 158 (member tag tag-list)))
159 (put reftex-docstruct-symbol 'default-index-tag tag))) 159 (put reftex-docstruct-symbol 'default-index-tag tag)))
160 160
161(defun reftex-index-complete-tag (&optional itag opt-args) 161(defun reftex-index-complete-tag (&optional itag opt-args)
@@ -164,13 +164,13 @@ will prompt for other arguments."
164 ;; OPT-ARGS is a list of optional argument indices, as given by 164 ;; OPT-ARGS is a list of optional argument indices, as given by
165 ;; `reftex-parse-args'. 165 ;; `reftex-parse-args'.
166 (let* ((opt (and (integerp itag) (member itag opt-args))) 166 (let* ((opt (and (integerp itag) (member itag opt-args)))
167 (index-tags (cdr (assq 'index-tags 167 (index-tags (cdr (assq 'index-tags
168 (symbol-value reftex-docstruct-symbol)))) 168 (symbol-value reftex-docstruct-symbol))))
169 (default (reftex-default-index)) 169 (default (reftex-default-index))
170 (prompt (concat "Index tag" 170 (prompt (concat "Index tag"
171 (if default (format " (default: %s)" default) "") 171 (if default (format " (default: %s)" default) "")
172 (if opt " (optional)" "") ": ")) 172 (if opt " (optional)" "") ": "))
173 (tag (completing-read prompt (mapcar 'list index-tags)))) 173 (tag (completing-read prompt (mapcar 'list index-tags))))
174 (if (and default (equal tag "")) (setq tag default)) 174 (if (and default (equal tag "")) (setq tag default))
175 (reftex-update-default-index tag) 175 (reftex-update-default-index tag)
176 tag)) 176 tag))
@@ -178,70 +178,70 @@ will prompt for other arguments."
178(defun reftex-index-select-tag () 178(defun reftex-index-select-tag ()
179 ;; Have the user select an index tag. 179 ;; Have the user select an index tag.
180 ;; FIXME: should we cache tag-alist, prompt and help? 180 ;; FIXME: should we cache tag-alist, prompt and help?
181 (let* ((index-tags (cdr (assoc 'index-tags 181 (let* ((index-tags (cdr (assoc 'index-tags
182 (symbol-value reftex-docstruct-symbol)))) 182 (symbol-value reftex-docstruct-symbol))))
183 (default (reftex-default-index))) 183 (default (reftex-default-index)))
184 (cond 184 (cond
185 ((null index-tags) 185 ((null index-tags)
186 (error "No index tags available")) 186 (error "No index tags available"))
187 187
188 ((= (length index-tags) 1) 188 ((= (length index-tags) 1)
189 ;; Just one index, use it 189 ;; Just one index, use it
190 (car index-tags)) 190 (car index-tags))
191 191
192 ((> (length index-tags) 1) 192 ((> (length index-tags) 1)
193 ;; Several indices, ask. 193 ;; Several indices, ask.
194 (let* ((tags (copy-sequence index-tags)) 194 (let* ((tags (copy-sequence index-tags))
195 (cnt 0) 195 (cnt 0)
196 tag-alist i val len tag prompt help rpl) 196 tag-alist i val len tag prompt help rpl)
197 ;; Move idx and glo up in the list to ensure ?i and ?g shortcuts 197 ;; Move idx and glo up in the list to ensure ?i and ?g shortcuts
198 (if (member "glo" tags) 198 (if (member "glo" tags)
199 (setq tags (cons "glo" (delete "glo" tags)))) 199 (setq tags (cons "glo" (delete "glo" tags))))
200 (if (member "idx" tags) 200 (if (member "idx" tags)
201 (setq tags (cons "idx" (delete "idx" tags)))) 201 (setq tags (cons "idx" (delete "idx" tags))))
202 ;; Find unique shortcuts for each index. 202 ;; Find unique shortcuts for each index.
203 (while (setq tag (pop tags)) 203 (while (setq tag (pop tags))
204 (setq len (length tag) 204 (setq len (length tag)
205 i -1 205 i -1
206 val nil) 206 val nil)
207 (catch 'exit 207 (catch 'exit
208 (while (and (< (incf i) len) (null val)) 208 (while (and (< (incf i) len) (null val))
209 (unless (assq (aref tag i) tag-alist) 209 (unless (assq (aref tag i) tag-alist)
210 (push (list (aref tag i) 210 (push (list (aref tag i)
211 tag 211 tag
212 (concat (substring tag 0 i) 212 (concat (substring tag 0 i)
213 "[" (substring tag i (incf i)) "]" 213 "[" (substring tag i (incf i)) "]"
214 (substring tag i))) 214 (substring tag i)))
215 tag-alist) 215 tag-alist)
216 (throw 'exit t))) 216 (throw 'exit t)))
217 (push (list (+ ?0 (incf cnt)) tag 217 (push (list (+ ?0 (incf cnt)) tag
218 (concat "[" (int-to-string cnt) "]:" tag)) 218 (concat "[" (int-to-string cnt) "]:" tag))
219 tag-alist))) 219 tag-alist)))
220 (setq tag-alist (nreverse tag-alist)) 220 (setq tag-alist (nreverse tag-alist))
221 ;; Compute Prompt and Help strings 221 ;; Compute Prompt and Help strings
222 (setq prompt 222 (setq prompt
223 (concat 223 (concat
224 (format "Select Index%s: " 224 (format "Select Index%s: "
225 (if default (format " (Default <%s>)" default) "")) 225 (if default (format " (Default <%s>)" default) ""))
226 (mapconcat (lambda(x) (nth 2 x)) tag-alist " "))) 226 (mapconcat (lambda(x) (nth 2 x)) tag-alist " ")))
227 (setq help 227 (setq help
228 (concat "Select an Index\n===============\n" 228 (concat "Select an Index\n===============\n"
229 (if default 229 (if default
230 (format "[^M] %s (the default)\n" default) 230 (format "[^M] %s (the default)\n" default)
231 "") 231 "")
232 (mapconcat (lambda(x) 232 (mapconcat (lambda(x)
233 (apply 'format "[%c] %s" x)) 233 (apply 'format "[%c] %s" x))
234 tag-alist "\n"))) 234 tag-alist "\n")))
235 ;; Query the user for an index-tag 235 ;; Query the user for an index-tag
236 (setq rpl (reftex-select-with-char prompt help 3 t)) 236 (setq rpl (reftex-select-with-char prompt help 3 t))
237 (message "") 237 (message "")
238 (if (and default (equal rpl ?\C-m)) 238 (if (and default (equal rpl ?\C-m))
239 default 239 default
240 (if (assq rpl tag-alist) 240 (if (assq rpl tag-alist)
241 (progn 241 (progn
242 (reftex-update-default-index (nth 1 (assq rpl tag-alist))) 242 (reftex-update-default-index (nth 1 (assq rpl tag-alist)))
243 (nth 1 (assq rpl tag-alist))) 243 (nth 1 (assq rpl tag-alist)))
244 (error "No index tag associated with %c" rpl))))) 244 (error "No index tag associated with %c" rpl)))))
245 (t (error "This should not happen (reftex-index-select-tag)"))))) 245 (t (error "This should not happen (reftex-index-select-tag)")))))
246 246
247(defun reftex-index-complete-key (&optional tag optional initial) 247(defun reftex-index-complete-key (&optional tag optional initial)
@@ -249,19 +249,19 @@ will prompt for other arguments."
249 ;; Restrict completion table on index tag TAG. 249 ;; Restrict completion table on index tag TAG.
250 ;; OPTIONAL indicates if the arg is optional. 250 ;; OPTIONAL indicates if the arg is optional.
251 (let* ((table (reftex-sublist-nth 251 (let* ((table (reftex-sublist-nth
252 (symbol-value reftex-docstruct-symbol) 6 252 (symbol-value reftex-docstruct-symbol) 6
253 (lambda(x) (and (eq (car x) 'index) 253 (lambda(x) (and (eq (car x) 'index)
254 (string= (nth 1 x) (or tag "")))) 254 (string= (nth 1 x) (or tag ""))))
255 t)) 255 t))
256 (prompt (concat "Index key" (if optional " (optional)" "") ": ")) 256 (prompt (concat "Index key" (if optional " (optional)" "") ": "))
257 (key (completing-read prompt table nil nil initial))) 257 (key (completing-read prompt table nil nil initial)))
258 key)) 258 key))
259 259
260(defun reftex-index-update-taglist (newtag) 260(defun reftex-index-update-taglist (newtag)
261 ;; add NEWTAG to the list of available index tags. 261 ;; add NEWTAG to the list of available index tags.
262 (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))) 262 (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))
263 (and newtag (cdr cell) (not (member newtag (cdr cell))) 263 (and newtag (cdr cell) (not (member newtag (cdr cell)))
264 (push newtag (cdr cell))))) 264 (push newtag (cdr cell)))))
265 265
266(defvar reftex-index-map (make-sparse-keymap) 266(defvar reftex-index-map (make-sparse-keymap)
267 "Keymap used for *Index* buffers.") 267 "Keymap used for *Index* buffers.")
@@ -290,16 +290,16 @@ Here are all local bindings.
290 (interactive) 290 (interactive)
291 (kill-all-local-variables) 291 (kill-all-local-variables)
292 (setq major-mode 'reftex-index-mode 292 (setq major-mode 'reftex-index-mode
293 mode-name "RefTeX Index") 293 mode-name "RefTeX Index")
294 (use-local-map reftex-index-map) 294 (use-local-map reftex-index-map)
295 (set (make-local-variable 'revert-buffer-function) 'reftex-index-revert) 295 (set (make-local-variable 'revert-buffer-function) 'reftex-index-revert)
296 (set (make-local-variable 'reftex-index-restriction-data) nil) 296 (set (make-local-variable 'reftex-index-restriction-data) nil)
297 (set (make-local-variable 'reftex-index-restriction-indicator) nil) 297 (set (make-local-variable 'reftex-index-restriction-indicator) nil)
298 (setq mode-line-format 298 (setq mode-line-format
299 (list "---- " 'mode-line-buffer-identification 299 (list "---- " 'mode-line-buffer-identification
300 " " 'global-mode-string 300 " " 'global-mode-string
301 " R<" 'reftex-index-restriction-indicator ">" 301 " R<" 'reftex-index-restriction-indicator ">"
302 " -%-")) 302 " -%-"))
303 (setq truncate-lines t) 303 (setq truncate-lines t)
304 (when (featurep 'xemacs) 304 (when (featurep 'xemacs)
305 ;; XEmacs needs the call to make-local-hook 305 ;; XEmacs needs the call to make-local-hook
@@ -339,21 +339,21 @@ _ ^ Add/Remove parent key (to make this item a subitem).
339 ;; Note: This function just looks for the nearest match of the 339 ;; Note: This function just looks for the nearest match of the
340 ;; context string and may fail if the entry moved and an identical 340 ;; context string and may fail if the entry moved and an identical
341 ;; entry is close to the old position. Frequent rescans make this 341 ;; entry is close to the old position. Frequent rescans make this
342 ;; safer. 342 ;; safer.
343 (let* ((file (nth 3 data)) 343 (let* ((file (nth 3 data))
344 (literal (nth 2 data)) 344 (literal (nth 2 data))
345 (pos (nth 4 data)) 345 (pos (nth 4 data))
346 (re (regexp-quote literal)) 346 (re (regexp-quote literal))
347 (match 347 (match
348 (cond 348 (cond
349 ((or (not no-revisit) 349 ((or (not no-revisit)
350 (reftex-get-buffer-visiting file)) 350 (reftex-get-buffer-visiting file))
351 (switch-to-buffer-other-window 351 (switch-to-buffer-other-window
352 (reftex-get-file-buffer-force file nil)) 352 (reftex-get-file-buffer-force file nil))
353 (goto-char (or pos (point-min))) 353 (goto-char (or pos (point-min)))
354 (or (looking-at re) 354 (or (looking-at re)
355 (reftex-nearest-match re (length literal)))) 355 (reftex-nearest-match re (length literal))))
356 (t (message reftex-no-follow-message) nil)))) 356 (t (message reftex-no-follow-message) nil))))
357 (when match 357 (when match
358 (goto-char (match-beginning 0)) 358 (goto-char (match-beginning 0))
359 (recenter '(4)) 359 (recenter '(4))
@@ -361,7 +361,7 @@ _ ^ Add/Remove parent key (to make this item a subitem).
361 match)) 361 match))
362 362
363(defun reftex-display-index (&optional tag overriding-restriction 363(defun reftex-display-index (&optional tag overriding-restriction
364 &rest locations) 364 &rest locations)
365 "Display a buffer with an index compiled from the current document. 365 "Display a buffer with an index compiled from the current document.
366When the document has multiple indices, first prompts for the correct one. 366When the document has multiple indices, first prompts for the correct one.
367When index support is turned off, offer to turn it on. 367When index support is turned off, offer to turn it on.
@@ -381,40 +381,40 @@ With prefix 3, restrict index to region."
381 381
382 ;; Determine the correct index to process 382 ;; Determine the correct index to process
383 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) 383 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
384 (docstruct-symbol reftex-docstruct-symbol) 384 (docstruct-symbol reftex-docstruct-symbol)
385 (index-tag (or tag (reftex-index-select-tag))) 385 (index-tag (or tag (reftex-index-select-tag)))
386 (master (reftex-TeX-master-file)) 386 (master (reftex-TeX-master-file))
387 (calling-file (buffer-file-name)) 387 (calling-file (buffer-file-name))
388 (restriction 388 (restriction
389 (or overriding-restriction 389 (or overriding-restriction
390 (and (interactive-p) 390 (and (interactive-p)
391 (reftex-get-restriction current-prefix-arg docstruct)))) 391 (reftex-get-restriction current-prefix-arg docstruct))))
392 (locations 392 (locations
393 ;; See if we are on an index macro as initial position 393 ;; See if we are on an index macro as initial position
394 (or locations 394 (or locations
395 (let* ((what-macro (reftex-what-macro-safe 1)) 395 (let* ((what-macro (reftex-what-macro-safe 1))
396 (macro (car what-macro)) 396 (macro (car what-macro))
397 (here-I-am (when (member macro reftex-macros-with-index) 397 (here-I-am (when (member macro reftex-macros-with-index)
398 (save-excursion 398 (save-excursion
399 (goto-char (+ (cdr what-macro) 399 (goto-char (+ (cdr what-macro)
400 (length macro))) 400 (length macro)))
401 (reftex-move-over-touching-args) 401 (reftex-move-over-touching-args)
402 (reftex-where-am-I))))) 402 (reftex-where-am-I)))))
403 (if (eq (car (car here-I-am)) 'index) 403 (if (eq (car (car here-I-am)) 'index)
404 (list (car here-I-am)))))) 404 (list (car here-I-am))))))
405 buffer-name) 405 buffer-name)
406 406
407 (setq buffer-name (reftex-make-index-buffer-name index-tag)) 407 (setq buffer-name (reftex-make-index-buffer-name index-tag))
408 408
409 ;; Goto the buffer and put it into the correct mode 409 ;; Goto the buffer and put it into the correct mode
410 410
411 (when (or restriction current-prefix-arg) 411 (when (or restriction current-prefix-arg)
412 (reftex-kill-buffer buffer-name)) 412 (reftex-kill-buffer buffer-name))
413 413
414 (if (get-buffer-window buffer-name) 414 (if (get-buffer-window buffer-name)
415 (select-window (get-buffer-window buffer-name)) 415 (select-window (get-buffer-window buffer-name))
416 (let ((default-major-mode 'reftex-index-mode)) 416 (let ((default-major-mode 'reftex-index-mode))
417 (switch-to-buffer buffer-name))) 417 (switch-to-buffer buffer-name)))
418 418
419 (or (eq major-mode 'reftex-index-mode) (reftex-index-mode)) 419 (or (eq major-mode 'reftex-index-mode) (reftex-index-mode))
420 420
@@ -425,11 +425,11 @@ With prefix 3, restrict index to region."
425 (set (make-local-variable 'reftex-index-tag) index-tag) 425 (set (make-local-variable 'reftex-index-tag) index-tag)
426 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol) 426 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
427 (if restriction 427 (if restriction
428 (setq reftex-index-restriction-indicator (car restriction) 428 (setq reftex-index-restriction-indicator (car restriction)
429 reftex-index-restriction-data (cdr restriction)) 429 reftex-index-restriction-data (cdr restriction))
430 (if (interactive-p) 430 (if (interactive-p)
431 (setq reftex-index-restriction-indicator nil 431 (setq reftex-index-restriction-indicator nil
432 reftex-index-restriction-data nil))) 432 reftex-index-restriction-data nil)))
433 (when (= (buffer-size) 0) 433 (when (= (buffer-size) 0)
434 ;; buffer is empty - fill it 434 ;; buffer is empty - fill it
435 (message "Building %s buffer..." buffer-name) 435 (message "Building %s buffer..." buffer-name)
@@ -466,22 +466,22 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
466 ;; it with whatever the DOCSTRUCT contains. 466 ;; it with whatever the DOCSTRUCT contains.
467 ;; REMARK can be a note to add to the entry. 467 ;; REMARK can be a note to add to the entry.
468 (let* ((all docstruct) 468 (let* ((all docstruct)
469 (indent " ") 469 (indent " ")
470 (context reftex-index-include-context) 470 (context reftex-index-include-context)
471 (context-indent (concat indent " ")) 471 (context-indent (concat indent " "))
472 (section-chars (mapcar 'identity reftex-index-section-letters)) 472 (section-chars (mapcar 'identity reftex-index-section-letters))
473 (this-section-char 0) 473 (this-section-char 0)
474 (font (reftex-use-fonts)) 474 (font (reftex-use-fonts))
475 (bor (car reftex-index-restriction-data)) 475 (bor (car reftex-index-restriction-data))
476 (eor (nth 1 reftex-index-restriction-data)) 476 (eor (nth 1 reftex-index-restriction-data))
477 (mouse-face 477 (mouse-face
478 (if (memq reftex-highlight-selection '(mouse both)) 478 (if (memq reftex-highlight-selection '(mouse both))
479 reftex-mouse-selected-face 479 reftex-mouse-selected-face
480 nil)) 480 nil))
481 (index-face (reftex-verified-face reftex-label-face 481 (index-face (reftex-verified-face reftex-label-face
482 'font-lock-constant-face 482 'font-lock-constant-face
483 'font-lock-reference-face)) 483 'font-lock-reference-face))
484 sublist cell from to first-char) 484 sublist cell from to first-char)
485 485
486 ;; Make the sublist and sort it 486 ;; Make the sublist and sort it
487 (when bor 487 (when bor
@@ -489,68 +489,68 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
489 489
490 (while (setq cell (pop all)) 490 (while (setq cell (pop all))
491 (if (eq cell eor) 491 (if (eq cell eor)
492 (setq all nil) 492 (setq all nil)
493 (and (eq (car cell) 'index) 493 (and (eq (car cell) 'index)
494 (equal (nth 1 cell) tag) 494 (equal (nth 1 cell) tag)
495 (push cell sublist)))) 495 (push cell sublist))))
496 (setq sublist (sort (nreverse sublist) 496 (setq sublist (sort (nreverse sublist)
497 (lambda (a b) (string< (nth 8 a) (nth 8 b))))) 497 (lambda (a b) (string< (nth 8 a) (nth 8 b)))))
498 498
499 (when update-one 499 (when update-one
500 ;; Delete the entry at place 500 ;; Delete the entry at place
501 (and (bolp) (forward-char 1)) 501 (and (bolp) (forward-char 1))
502 (delete-region (previous-single-property-change (1+ (point)) :data) 502 (delete-region (previous-single-property-change (1+ (point)) :data)
503 (or (next-single-property-change (point) :data) 503 (or (next-single-property-change (point) :data)
504 (point-max)))) 504 (point-max))))
505 505
506 ;; Walk through the list and insert all entries 506 ;; Walk through the list and insert all entries
507 (while (setq cell (pop sublist)) 507 (while (setq cell (pop sublist))
508 (unless update-one 508 (unless update-one
509 (setq first-char (upcase (string-to-char (nth 6 cell)))) 509 (setq first-char (upcase (string-to-char (nth 6 cell))))
510 (when (and (not (equal first-char this-section-char)) 510 (when (and (not (equal first-char this-section-char))
511 (member first-char section-chars)) 511 (member first-char section-chars))
512 ;; There is a new initial letter, so start a new section 512 ;; There is a new initial letter, so start a new section
513 (reftex-index-insert-new-letter first-char font) 513 (reftex-index-insert-new-letter first-char font)
514 (setq section-chars (delete first-char section-chars) 514 (setq section-chars (delete first-char section-chars)
515 this-section-char first-char)) 515 this-section-char first-char))
516 (when (= this-section-char 0) 516 (when (= this-section-char 0)
517 (setq this-section-char ?!) 517 (setq this-section-char ?!)
518 (reftex-index-insert-new-letter this-section-char font))) 518 (reftex-index-insert-new-letter this-section-char font)))
519 519
520 (setq from (point)) 520 (setq from (point))
521 (insert indent (nth 7 cell)) 521 (insert indent (nth 7 cell))
522 (when font 522 (when font
523 (setq to (point)) 523 (setq to (point))
524 (put-text-property 524 (put-text-property
525 (- (point) (length (nth 7 cell))) to 525 (- (point) (length (nth 7 cell))) to
526 'face index-face) 526 'face index-face)
527 (goto-char to)) 527 (goto-char to))
528 528
529 (when (or remark (nth 9 cell)) 529 (when (or remark (nth 9 cell))
530 (and (< (current-column) 40) 530 (and (< (current-column) 40)
531 ;; FIXME: maybe this is too slow? 531 ;; FIXME: maybe this is too slow?
532 (insert (make-string (max (- 40 (current-column)) 0) ?\ ))) 532 (insert (make-string (max (- 40 (current-column)) 0) ?\ )))
533 (and (nth 9 cell) (insert " " (substring (nth 5 cell) (nth 9 cell)))) 533 (and (nth 9 cell) (insert " " (substring (nth 5 cell) (nth 9 cell))))
534 (and remark (insert " " remark))) 534 (and remark (insert " " remark)))
535 535
536 (insert "\n") 536 (insert "\n")
537 (setq to (point)) 537 (setq to (point))
538 538
539 (when context 539 (when context
540 (insert context-indent (nth 2 cell) "\n") 540 (insert context-indent (nth 2 cell) "\n")
541 (setq to (point))) 541 (setq to (point)))
542 (put-text-property from to :data cell) 542 (put-text-property from to :data cell)
543 (when mouse-face 543 (when mouse-face
544 (put-text-property from (1- to) 544 (put-text-property from (1- to)
545 'mouse-face mouse-face)) 545 'mouse-face mouse-face))
546 (goto-char to)))) 546 (goto-char to))))
547 547
548 548
549(defun reftex-index-insert-new-letter (letter &optional font) 549(defun reftex-index-insert-new-letter (letter &optional font)
550 ;; Start a new section in the index 550 ;; Start a new section in the index
551 (let ((from (point))) 551 (let ((from (point)))
552 (insert "\n" letter letter letter 552 (insert "\n" letter letter letter
553 "-----------------------------------------------------------------") 553 "-----------------------------------------------------------------")
554 (when font 554 (when font
555 (put-text-property from (point) 'face reftex-index-section-face)) 555 (put-text-property from (point) 'face reftex-index-section-face))
556 (insert "\n"))) 556 (insert "\n")))
@@ -558,30 +558,30 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
558(defun reftex-get-restriction (arg docstruct) 558(defun reftex-get-restriction (arg docstruct)
559 ;; Interprete the prefix ARG and derive index restriction specs. 559 ;; Interprete the prefix ARG and derive index restriction specs.
560 (let* ((beg (min (point) (or (condition-case nil (mark) (error nil)) 560 (let* ((beg (min (point) (or (condition-case nil (mark) (error nil))
561 (point-max)))) 561 (point-max))))
562 (end (max (point) (or (condition-case nil (mark) (error nil)) 562 (end (max (point) (or (condition-case nil (mark) (error nil))
563 (point-min)))) 563 (point-min))))
564 bor eor label here-I-am) 564 bor eor label here-I-am)
565 (cond 565 (cond
566 ((eq arg 2) 566 ((eq arg 2)
567 (setq here-I-am (car (reftex-where-am-I)) 567 (setq here-I-am (car (reftex-where-am-I))
568 bor (if (eq (car here-I-am) 'toc) 568 bor (if (eq (car here-I-am) 'toc)
569 here-I-am 569 here-I-am
570 (reftex-last-assoc-before-elt 570 (reftex-last-assoc-before-elt
571 'toc here-I-am docstruct)) 571 'toc here-I-am docstruct))
572 eor (car (memq (assq 'toc (cdr (memq bor docstruct))) docstruct)) 572 eor (car (memq (assq 'toc (cdr (memq bor docstruct))) docstruct))
573 label (nth 6 bor))) 573 label (nth 6 bor)))
574 ((eq arg 3) 574 ((eq arg 3)
575 (save-excursion 575 (save-excursion
576 (setq label "region") 576 (setq label "region")
577 (goto-char beg) 577 (goto-char beg)
578 (setq bor (car (reftex-where-am-I))) 578 (setq bor (car (reftex-where-am-I)))
579 (setq bor (nth 1 (memq bor docstruct))) 579 (setq bor (nth 1 (memq bor docstruct)))
580 (goto-char end) 580 (goto-char end)
581 (setq eor (nth 1 (memq (car (reftex-where-am-I)) docstruct))))) 581 (setq eor (nth 1 (memq (car (reftex-where-am-I)) docstruct)))))
582 (t nil)) 582 (t nil))
583 (if (and label (or bor eor)) 583 (if (and label (or bor eor))
584 (list label bor eor) 584 (list label bor eor)
585 nil))) 585 nil)))
586 586
587(defun reftex-index-pre-command-hook () 587(defun reftex-index-pre-command-hook ()
@@ -593,23 +593,23 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
593 ;; Used in the post-command-hook for the *Index* buffer 593 ;; Used in the post-command-hook for the *Index* buffer
594 (when (get-text-property (point) :data) 594 (when (get-text-property (point) :data)
595 (and (> (point) 1) 595 (and (> (point) 1)
596 (not (get-text-property (point) 'intangible)) 596 (not (get-text-property (point) 'intangible))
597 (memq reftex-highlight-selection '(cursor both)) 597 (memq reftex-highlight-selection '(cursor both))
598 (reftex-highlight 1 598 (reftex-highlight 1
599 (or (previous-single-property-change (1+ (point)) :data) 599 (or (previous-single-property-change (1+ (point)) :data)
600 (point-min)) 600 (point-min))
601 (or (next-single-property-change (point) :data) 601 (or (next-single-property-change (point) :data)
602 (point-max))))) 602 (point-max)))))
603 (if (integerp reftex-index-follow-mode) 603 (if (integerp reftex-index-follow-mode)
604 ;; Remove delayed action 604 ;; Remove delayed action
605 (setq reftex-index-follow-mode t) 605 (setq reftex-index-follow-mode t)
606 (and reftex-index-follow-mode 606 (and reftex-index-follow-mode
607 (not (equal reftex-last-follow-point (point))) 607 (not (equal reftex-last-follow-point (point)))
608 ;; Show context in other window 608 ;; Show context in other window
609 (setq reftex-last-follow-point (point)) 609 (setq reftex-last-follow-point (point))
610 (condition-case nil 610 (condition-case nil
611 (reftex-index-visit-location nil (not reftex-revisit-to-follow)) 611 (reftex-index-visit-location nil (not reftex-revisit-to-follow))
612 (error t))))) 612 (error t)))))
613 613
614(defun reftex-index-show-help () 614(defun reftex-index-show-help ()
615 "Show a summary of special key bindings." 615 "Show a summary of special key bindings."
@@ -626,20 +626,20 @@ SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
626 (interactive "p") 626 (interactive "p")
627 (setq reftex-callback-fwd t) 627 (setq reftex-callback-fwd t)
628 (or (eobp) (forward-char 1)) 628 (or (eobp) (forward-char 1))
629 (goto-char (or (next-single-property-change (point) :data) 629 (goto-char (or (next-single-property-change (point) :data)
630 (point))) 630 (point)))
631 (unless (get-text-property (point) :data) 631 (unless (get-text-property (point) :data)
632 (goto-char (or (next-single-property-change (point) :data) 632 (goto-char (or (next-single-property-change (point) :data)
633 (point))))) 633 (point)))))
634(defun reftex-index-previous (&optional arg) 634(defun reftex-index-previous (&optional arg)
635 "Move to previous selectable item." 635 "Move to previous selectable item."
636 (interactive "p") 636 (interactive "p")
637 (setq reftex-callback-fwd nil) 637 (setq reftex-callback-fwd nil)
638 (goto-char (or (previous-single-property-change (point) :data) 638 (goto-char (or (previous-single-property-change (point) :data)
639 (point))) 639 (point)))
640 (unless (get-text-property (point) :data) 640 (unless (get-text-property (point) :data)
641 (goto-char (or (previous-single-property-change (point) :data) 641 (goto-char (or (previous-single-property-change (point) :data)
642 (point))))) 642 (point)))))
643(defun reftex-index-toggle-follow () 643(defun reftex-index-toggle-follow ()
644 "Toggle follow (other window follows with context)." 644 "Toggle follow (other window follows with context)."
645 (interactive) 645 (interactive)
@@ -695,22 +695,22 @@ The function will go to the section where the entry at point was defined."
695 (interactive) 695 (interactive)
696 (let ((index-tag reftex-index-tag)) 696 (let ((index-tag reftex-index-tag))
697 (if (and reftex-enable-partial-scans 697 (if (and reftex-enable-partial-scans
698 (null current-prefix-arg)) 698 (null current-prefix-arg))
699 (let* ((data (get-text-property (point) :data)) 699 (let* ((data (get-text-property (point) :data))
700 (file (nth 3 data)) 700 (file (nth 3 data))
701 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) 701 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
702 (if (not file) 702 (if (not file)
703 (error "Don't know which file to rescan. Try `C-u r'") 703 (error "Don't know which file to rescan. Try `C-u r'")
704 (switch-to-buffer (reftex-get-file-buffer-force file)) 704 (switch-to-buffer (reftex-get-file-buffer-force file))
705 (setq current-prefix-arg '(4)) 705 (setq current-prefix-arg '(4))
706 (reftex-display-index index-tag nil line))) 706 (reftex-display-index index-tag nil line)))
707 (reftex-index-Rescan)) 707 (reftex-index-Rescan))
708 (reftex-kill-temporary-buffers))) 708 (reftex-kill-temporary-buffers)))
709(defun reftex-index-Rescan (&rest ignore) 709(defun reftex-index-Rescan (&rest ignore)
710 "Regenerate the *Index* buffer after reparsing the entire document." 710 "Regenerate the *Index* buffer after reparsing the entire document."
711 (interactive) 711 (interactive)
712 (let ((index-tag reftex-index-tag) 712 (let ((index-tag reftex-index-tag)
713 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) 713 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
714 (switch-to-buffer 714 (switch-to-buffer
715 (reftex-get-file-buffer-force reftex-last-index-file)) 715 (reftex-get-file-buffer-force reftex-last-index-file))
716 (setq current-prefix-arg '(16)) 716 (setq current-prefix-arg '(16))
@@ -719,14 +719,14 @@ The function will go to the section where the entry at point was defined."
719 "Regenerate the *Index* from the internal lists. No reparsing os done." 719 "Regenerate the *Index* from the internal lists. No reparsing os done."
720 (interactive) 720 (interactive)
721 (let ((buf (current-buffer)) 721 (let ((buf (current-buffer))
722 (index-tag reftex-index-tag) 722 (index-tag reftex-index-tag)
723 (data (get-text-property (point) :data)) 723 (data (get-text-property (point) :data))
724 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) 724 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
725 (switch-to-buffer 725 (switch-to-buffer
726 (reftex-get-file-buffer-force reftex-last-index-file)) 726 (reftex-get-file-buffer-force reftex-last-index-file))
727 (reftex-erase-buffer buf) 727 (reftex-erase-buffer buf)
728 (setq current-prefix-arg nil 728 (setq current-prefix-arg nil
729 reftex-last-follow-point 1) 729 reftex-last-follow-point 1)
730 (reftex-display-index index-tag nil data line))) 730 (reftex-display-index index-tag nil data line)))
731(defun reftex-index-switch-index-tag (&rest ignore) 731(defun reftex-index-switch-index-tag (&rest ignore)
732 "Switch to a different index of the same document." 732 "Switch to a different index of the same document."
@@ -741,23 +741,23 @@ The function will go to the section where the entry at point was defined."
741 ;; Optional FORCE means, even if point is not on an index entry. 741 ;; Optional FORCE means, even if point is not on an index entry.
742 (interactive) 742 (interactive)
743 (let* ((data (get-text-property (point) :data)) 743 (let* ((data (get-text-property (point) :data))
744 (docstruct (symbol-value reftex-docstruct-symbol)) 744 (docstruct (symbol-value reftex-docstruct-symbol))
745 bor eor) 745 bor eor)
746 (if (and (not data) force) 746 (if (and (not data) force)
747 (setq data (assq 'toc docstruct))) 747 (setq data (assq 'toc docstruct)))
748 (when data 748 (when data
749 (setq bor (reftex-last-assoc-before-elt 'toc data docstruct) 749 (setq bor (reftex-last-assoc-before-elt 'toc data docstruct)
750 eor (car (memq (assq 'toc (cdr (memq bor docstruct))) 750 eor (car (memq (assq 'toc (cdr (memq bor docstruct)))
751 docstruct)) 751 docstruct))
752 reftex-index-restriction-data (list bor eor) 752 reftex-index-restriction-data (list bor eor)
753 reftex-index-restriction-indicator (nth 6 bor) ))) 753 reftex-index-restriction-indicator (nth 6 bor) )))
754 (reftex-index-revert)) 754 (reftex-index-revert))
755 755
756(defun reftex-index-widen (&rest ignore) 756(defun reftex-index-widen (&rest ignore)
757 "Show the unrestricted index (all entries)." 757 "Show the unrestricted index (all entries)."
758 (interactive) 758 (interactive)
759 (setq reftex-index-restriction-indicator nil 759 (setq reftex-index-restriction-indicator nil
760 reftex-index-restriction-data nil) 760 reftex-index-restriction-data nil)
761 (reftex-index-revert) 761 (reftex-index-revert)
762 (message "Index widened")) 762 (message "Index widened"))
763(defun reftex-index-restriction-forward (&rest ignore) 763(defun reftex-index-restriction-forward (&rest ignore)
@@ -766,15 +766,15 @@ When index is currently unrestricted, restrict it to a section.
766When index is restricted, select the next section as restriction criterion." 766When index is restricted, select the next section as restriction criterion."
767 (interactive) 767 (interactive)
768 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) 768 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
769 (bor (nth 1 reftex-index-restriction-data))) 769 (bor (nth 1 reftex-index-restriction-data)))
770 (if (or (not bor) 770 (if (or (not bor)
771 (not (eq (car bor) 'toc))) 771 (not (eq (car bor) 'toc)))
772 (reftex-index-restrict-to-section t) 772 (reftex-index-restrict-to-section t)
773 (setq reftex-index-restriction-indicator (nth 6 bor) 773 (setq reftex-index-restriction-indicator (nth 6 bor)
774 reftex-index-restriction-data 774 reftex-index-restriction-data
775 (list bor 775 (list bor
776 (car (memq (assq 'toc (cdr (memq bor docstruct))) 776 (car (memq (assq 'toc (cdr (memq bor docstruct)))
777 docstruct)))) 777 docstruct))))
778 (reftex-index-revert)))) 778 (reftex-index-revert))))
779(defun reftex-index-restriction-backward (&rest ignore) 779(defun reftex-index-restriction-backward (&rest ignore)
780 "Restrict to next section. 780 "Restrict to next section.
@@ -782,14 +782,14 @@ When index is currently unrestricted, restrict it to a section.
782When index is restricted, select the previous section as restriction criterion." 782When index is restricted, select the previous section as restriction criterion."
783 (interactive) 783 (interactive)
784 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) 784 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
785 (eor (car reftex-index-restriction-data)) 785 (eor (car reftex-index-restriction-data))
786 (bor (reftex-last-assoc-before-elt 'toc eor docstruct t))) 786 (bor (reftex-last-assoc-before-elt 'toc eor docstruct t)))
787 (if (or (not bor) 787 (if (or (not bor)
788 (not (eq (car bor) 'toc))) 788 (not (eq (car bor) 'toc)))
789 (reftex-index-restrict-to-section t) 789 (reftex-index-restrict-to-section t)
790 (setq reftex-index-restriction-indicator (nth 6 bor) 790 (setq reftex-index-restriction-indicator (nth 6 bor)
791 reftex-index-restriction-data 791 reftex-index-restriction-data
792 (list bor eor)) 792 (list bor eor))
793 (reftex-index-revert)))) 793 (reftex-index-revert))))
794 794
795(defun reftex-index-visit-location (&optional final no-revisit) 795(defun reftex-index-visit-location (&optional final no-revisit)
@@ -804,9 +804,9 @@ When index is restricted, select the previous section as restriction criterion."
804 show-window show-buffer match) 804 show-window show-buffer match)
805 805
806 (unless data (error "Don't know which index entry to visit")) 806 (unless data (error "Don't know which index entry to visit"))
807 807
808 (if (eq (car data) 'index) 808 (if (eq (car data) 'index)
809 (setq match (reftex-index-show-entry data no-revisit))) 809 (setq match (reftex-index-show-entry data no-revisit)))
810 810
811 (setq show-window (selected-window) 811 (setq show-window (selected-window)
812 show-buffer (current-buffer)) 812 show-buffer (current-buffer))
@@ -833,32 +833,32 @@ When index is restricted, select the previous section as restriction criterion."
833 ;; values are accessible individually. 833 ;; values are accessible individually.
834 (interactive) 834 (interactive)
835 (let* ((arg (nth 5 data)) 835 (let* ((arg (nth 5 data))
836 (context (nth 2 data)) 836 (context (nth 2 data))
837 (sc reftex-index-special-chars) 837 (sc reftex-index-special-chars)
838 (boa (if (string-match (regexp-quote (concat "{" arg "}")) context) 838 (boa (if (string-match (regexp-quote (concat "{" arg "}")) context)
839 (1+ (match-beginning 0)) 839 (1+ (match-beginning 0))
840 (error "Something is wrong here"))) 840 (error "Something is wrong here")))
841 (eoa (1- (match-end 0))) 841 (eoa (1- (match-end 0)))
842 (boactual (if (string-match (concat "[^" (nth 3 sc) "]" (nth 2 sc)) 842 (boactual (if (string-match (concat "[^" (nth 3 sc) "]" (nth 2 sc))
843 context boa) 843 context boa)
844 (1+ (match-beginning 0)) 844 (1+ (match-beginning 0))
845 eoa)) 845 eoa))
846 (boattr (if (string-match (concat "[^" (nth 3 sc) "]" (nth 1 sc)) 846 (boattr (if (string-match (concat "[^" (nth 3 sc) "]" (nth 1 sc))
847 context boa) 847 context boa)
848 (1+ (match-beginning 0)) 848 (1+ (match-beginning 0))
849 boactual)) 849 boactual))
850 (pre (substring context 0 boa)) 850 (pre (substring context 0 boa))
851 (key (substring context boa boattr)) 851 (key (substring context boa boattr))
852 (attr (substring context boattr boactual)) 852 (attr (substring context boattr boactual))
853 (actual (substring context boactual eoa)) 853 (actual (substring context boactual eoa))
854 (post (substring context eoa))) 854 (post (substring context eoa)))
855 (list pre key attr actual post))) 855 (list pre key attr actual post)))
856 856
857(defun reftex-index-edit () 857(defun reftex-index-edit ()
858 "Edit the index entry at point." 858 "Edit the index entry at point."
859 (interactive) 859 (interactive)
860 (let* ((data (get-text-property (point) :data)) 860 (let* ((data (get-text-property (point) :data))
861 old new) 861 old new)
862 (unless data (error "Don't know which index entry to edit")) 862 (unless data (error "Don't know which index entry to edit"))
863 (reftex-index-view-entry) 863 (reftex-index-view-entry)
864 (setq old (nth 2 data) new (read-string "Edit: " old)) 864 (setq old (nth 2 data) new (read-string "Edit: " old))
@@ -868,33 +868,33 @@ When index is restricted, select the previous section as restriction criterion."
868 "Toggle the page range start attribute `|('." 868 "Toggle the page range start attribute `|('."
869 (interactive) 869 (interactive)
870 (let* ((data (get-text-property (point) :data)) 870 (let* ((data (get-text-property (point) :data))
871 (bor (concat (nth 1 reftex-index-special-chars) "(")) 871 (bor (concat (nth 1 reftex-index-special-chars) "("))
872 new analyze attr) 872 new analyze attr)
873 (unless data (error "Don't know which index entry to edit")) 873 (unless data (error "Don't know which index entry to edit"))
874 (setq analyze (reftex-index-analyze-entry data) 874 (setq analyze (reftex-index-analyze-entry data)
875 attr (nth 2 analyze)) 875 attr (nth 2 analyze))
876 (setf (nth 2 analyze) (if (string= attr bor) "" bor)) 876 (setf (nth 2 analyze) (if (string= attr bor) "" bor))
877 (setq new (apply 'concat analyze)) 877 (setq new (apply 'concat analyze))
878 (reftex-index-change-entry 878 (reftex-index-change-entry
879 new (if (string= (nth 2 analyze) bor) 879 new (if (string= (nth 2 analyze) bor)
880 "Entry is now START-OF-PAGE-RANGE" 880 "Entry is now START-OF-PAGE-RANGE"
881 "START-OF-PAGE-RANGE canceled")))) 881 "START-OF-PAGE-RANGE canceled"))))
882 882
883(defun reftex-index-toggle-range-end () 883(defun reftex-index-toggle-range-end ()
884 "Toggle the page-range-end attribute `|)'." 884 "Toggle the page-range-end attribute `|)'."
885 (interactive) 885 (interactive)
886 (let* ((data (get-text-property (point) :data)) 886 (let* ((data (get-text-property (point) :data))
887 (eor (concat (nth 1 reftex-index-special-chars) ")")) 887 (eor (concat (nth 1 reftex-index-special-chars) ")"))
888 new analyze attr) 888 new analyze attr)
889 (unless data (error "Don't know which index entry to edit")) 889 (unless data (error "Don't know which index entry to edit"))
890 (setq analyze (reftex-index-analyze-entry data) 890 (setq analyze (reftex-index-analyze-entry data)
891 attr (nth 2 analyze)) 891 attr (nth 2 analyze))
892 (setf (nth 2 analyze) (if (string= attr eor) "" eor)) 892 (setf (nth 2 analyze) (if (string= attr eor) "" eor))
893 (setq new (apply 'concat analyze)) 893 (setq new (apply 'concat analyze))
894 (reftex-index-change-entry 894 (reftex-index-change-entry
895 new (if (string= (nth 2 analyze) eor) 895 new (if (string= (nth 2 analyze) eor)
896 "Entry is now END-OF-PAGE-RANGE" 896 "Entry is now END-OF-PAGE-RANGE"
897 "END-OF-PAGE-RANGE canceled")))) 897 "END-OF-PAGE-RANGE canceled"))))
898 898
899(defun reftex-index-edit-key () 899(defun reftex-index-edit-key ()
900 "Edit the KEY part of the index entry." 900 "Edit the KEY part of the index entry."
@@ -905,7 +905,7 @@ When index is restricted, select the previous section as restriction criterion."
905 "EDIT the ATTRIBUTE part of the entry. With arg: remove entire ATTRIBUTE." 905 "EDIT the ATTRIBUTE part of the entry. With arg: remove entire ATTRIBUTE."
906 (interactive "P") 906 (interactive "P")
907 (reftex-index-edit-part arg 2 (nth 1 reftex-index-special-chars) 907 (reftex-index-edit-part arg 2 (nth 1 reftex-index-special-chars)
908 "Attribute: ")) 908 "Attribute: "))
909 909
910(defun reftex-index-edit-visual (&optional arg) 910(defun reftex-index-edit-visual (&optional arg)
911 "EDIT the VISUAL part of the entry. With arg: remove entire VISUAL string." 911 "EDIT the VISUAL part of the entry. With arg: remove entire VISUAL string."
@@ -915,51 +915,51 @@ When index is restricted, select the previous section as restriction criterion."
915(defun reftex-index-edit-part (arg n initial prompt &optional dont-allow-empty) 915(defun reftex-index-edit-part (arg n initial prompt &optional dont-allow-empty)
916 ;; This function does the work for all partial editing commands 916 ;; This function does the work for all partial editing commands
917 (let* ((data (get-text-property (point) :data)) 917 (let* ((data (get-text-property (point) :data))
918 new analyze opart npart) 918 new analyze opart npart)
919 (unless data (error "Don't know which index entry to edit")) 919 (unless data (error "Don't know which index entry to edit"))
920 ;; Analyze the whole context string 920 ;; Analyze the whole context string
921 (setq analyze (reftex-index-analyze-entry data) 921 (setq analyze (reftex-index-analyze-entry data)
922 opart (nth n analyze)) 922 opart (nth n analyze))
923 (and (> (length opart) 0) (setq opart (substring opart 1))) 923 (and (> (length opart) 0) (setq opart (substring opart 1)))
924 ;; Have the user editing the part 924 ;; Have the user editing the part
925 (setq npart (if arg "" (read-string (concat prompt initial) opart))) 925 (setq npart (if arg "" (read-string (concat prompt initial) opart)))
926 ;; Tests: 926 ;; Tests:
927 (cond ((string= npart opart) 927 (cond ((string= npart opart)
928 (error "Not changed")) 928 (error "Not changed"))
929 ((string= npart "") 929 ((string= npart "")
930 (if dont-allow-empty 930 (if dont-allow-empty
931 (error "Illegal value") 931 (error "Illegal value")
932 (setf (nth n analyze) npart))) 932 (setf (nth n analyze) npart)))
933 (t (setf (nth n analyze) (concat initial npart)))) 933 (t (setf (nth n analyze) (concat initial npart))))
934 (setq new (apply 'concat analyze)) 934 (setq new (apply 'concat analyze))
935 ;; Change the entry and insert the changed version into the index. 935 ;; Change the entry and insert the changed version into the index.
936 (reftex-index-change-entry 936 (reftex-index-change-entry
937 new (if (string= npart "") 937 new (if (string= npart "")
938 (format "Deleted: %s" opart) 938 (format "Deleted: %s" opart)
939 (format "New value is: %s" npart))))) 939 (format "New value is: %s" npart)))))
940 940
941(defun reftex-index-level-down () 941(defun reftex-index-level-down ()
942 "Make index entry a subitem of another entry." 942 "Make index entry a subitem of another entry."
943 (interactive) 943 (interactive)
944 (let* ((data (get-text-property (point) :data)) 944 (let* ((data (get-text-property (point) :data))
945 (docstruct (symbol-value reftex-docstruct-symbol)) 945 (docstruct (symbol-value reftex-docstruct-symbol))
946 old new prefix key) 946 old new prefix key)
947 (unless data (error "Don't know which index entry to change")) 947 (unless data (error "Don't know which index entry to change"))
948 (setq old (nth 2 data) 948 (setq old (nth 2 data)
949 key (nth 6 data) 949 key (nth 6 data)
950 prefix (completing-read 950 prefix (completing-read
951 "Prefix: " 951 "Prefix: "
952 (reftex-sublist-nth 952 (reftex-sublist-nth
953 docstruct 6 953 docstruct 6
954 (lambda (x) 954 (lambda (x)
955 (and (eq (car x) 'index) 955 (and (eq (car x) 'index)
956 (string= (nth 1 x) reftex-index-tag))) t))) 956 (string= (nth 1 x) reftex-index-tag))) t)))
957 (unless (string-match 957 (unless (string-match
958 (concat (regexp-quote (car reftex-index-special-chars)) "\\'") 958 (concat (regexp-quote (car reftex-index-special-chars)) "\\'")
959 prefix) 959 prefix)
960 (setq prefix (concat prefix (car reftex-index-special-chars)))) 960 (setq prefix (concat prefix (car reftex-index-special-chars))))
961 (if (string-match (regexp-quote key) old) 961 (if (string-match (regexp-quote key) old)
962 (setq new (replace-match (concat prefix key) t t old)) 962 (setq new (replace-match (concat prefix key) t t old))
963 (error "Cannot construct new index key")) 963 (error "Cannot construct new index key"))
964 (reftex-index-change-entry new (format "Added prefix: %s" prefix)))) 964 (reftex-index-change-entry new (format "Added prefix: %s" prefix))))
965 965
@@ -967,17 +967,17 @@ When index is restricted, select the previous section as restriction criterion."
967 "Remove the highest level of a hierarchical index entry." 967 "Remove the highest level of a hierarchical index entry."
968 (interactive) 968 (interactive)
969 (let* ((data (get-text-property (point) :data)) 969 (let* ((data (get-text-property (point) :data))
970 old new prefix) 970 old new prefix)
971 (unless data (error "Don't know which entry to change")) 971 (unless data (error "Don't know which entry to change"))
972 (setq old (nth 2 data)) 972 (setq old (nth 2 data))
973 (if (string-match (concat "{\\([^" (nth 0 reftex-index-special-chars) "]*" 973 (if (string-match (concat "{\\([^" (nth 0 reftex-index-special-chars) "]*"
974 "[^" (nth 3 reftex-index-special-chars) "]" 974 "[^" (nth 3 reftex-index-special-chars) "]"
975 (regexp-quote (nth 0 reftex-index-special-chars)) 975 (regexp-quote (nth 0 reftex-index-special-chars))
976 "\\)") 976 "\\)")
977 old) 977 old)
978 (setq prefix (substring old (match-beginning 1) (match-end 1)) 978 (setq prefix (substring old (match-beginning 1) (match-end 1))
979 new (concat (substring old 0 (match-beginning 1)) 979 new (concat (substring old 0 (match-beginning 1))
980 (substring old (match-end 1)))) 980 (substring old (match-end 1))))
981 (error "Entry is not a subitem")) 981 (error "Entry is not a subitem"))
982 (reftex-index-change-entry new (format "Removed prefix: %s" prefix)))) 982 (reftex-index-change-entry new (format "Removed prefix: %s" prefix))))
983 983
@@ -994,9 +994,9 @@ When index is restricted, select the previous section as restriction criterion."
994(defun reftex-index-change-entry (new &optional message) 994(defun reftex-index-change-entry (new &optional message)
995 ;; Change the full context string of the index entry at point to 995 ;; Change the full context string of the index entry at point to
996 ;; NEW. This actually edits the buffer where the entry is defined. 996 ;; NEW. This actually edits the buffer where the entry is defined.
997 997
998 (let* ((data (get-text-property (point) :data)) 998 (let* ((data (get-text-property (point) :data))
999 old beg end info) 999 old beg end info)
1000 (unless data (error "Cannot change entry")) 1000 (unless data (error "Cannot change entry"))
1001 (reftex-index-view-entry) 1001 (reftex-index-view-entry)
1002 (setq beg (match-beginning 0) end (match-end 0)) 1002 (setq beg (match-beginning 0) end (match-end 0))
@@ -1006,19 +1006,19 @@ When index is restricted, select the previous section as restriction criterion."
1006 (set-buffer (get-file-buffer (nth 3 data))) 1006 (set-buffer (get-file-buffer (nth 3 data)))
1007 (goto-char beg) 1007 (goto-char beg)
1008 (unless (looking-at (regexp-quote old)) 1008 (unless (looking-at (regexp-quote old))
1009 (error "This should not happen (reftex-index-change-entry)")) 1009 (error "This should not happen (reftex-index-change-entry)"))
1010 (delete-region beg end) 1010 (delete-region beg end)
1011 (insert new) 1011 (insert new)
1012 (goto-char (1- beg)) 1012 (goto-char (1- beg))
1013 (when (and (re-search-forward (reftex-everything-regexp) nil t) 1013 (when (and (re-search-forward (reftex-everything-regexp) nil t)
1014 (match-end 10) 1014 (match-end 10)
1015 (< (abs (- (match-beginning 10) beg)) (length new)) 1015 (< (abs (- (match-beginning 10) beg)) (length new))
1016 (setq info (reftex-index-info-safe buffer-file-name))) 1016 (setq info (reftex-index-info-safe buffer-file-name)))
1017 (setcdr data (cdr info)))) 1017 (setcdr data (cdr info))))
1018 (let ((buffer-read-only nil)) 1018 (let ((buffer-read-only nil))
1019 (save-excursion 1019 (save-excursion
1020 (reftex-insert-index (list data) reftex-index-tag t 1020 (reftex-insert-index (list data) reftex-index-tag t
1021 "EDITED"))) 1021 "EDITED")))
1022 (setq reftex-last-follow-point 1) 1022 (setq reftex-last-follow-point 1)
1023 (and message (message message)))) 1023 (and message (message message))))
1024 1024
@@ -1033,33 +1033,33 @@ When index is restricted, select the previous section as restriction criterion."
1033 1033
1034(loop for x in 1034(loop for x in
1035 '(("n" . reftex-index-next) 1035 '(("n" . reftex-index-next)
1036 ("p" . reftex-index-previous) 1036 ("p" . reftex-index-previous)
1037 ("?" . reftex-index-show-help) 1037 ("?" . reftex-index-show-help)
1038 (" " . reftex-index-view-entry) 1038 (" " . reftex-index-view-entry)
1039 ("\C-m" . reftex-index-goto-entry-and-hide) 1039 ("\C-m" . reftex-index-goto-entry-and-hide)
1040 ("\C-i" . reftex-index-goto-entry) 1040 ("\C-i" . reftex-index-goto-entry)
1041 ("\C-k" . reftex-index-kill) 1041 ("\C-k" . reftex-index-kill)
1042 ("r" . reftex-index-rescan) 1042 ("r" . reftex-index-rescan)
1043 ("R" . reftex-index-Rescan) 1043 ("R" . reftex-index-Rescan)
1044 ("g" . revert-buffer) 1044 ("g" . revert-buffer)
1045 ("q" . reftex-index-quit) 1045 ("q" . reftex-index-quit)
1046 ("k" . reftex-index-quit-and-kill) 1046 ("k" . reftex-index-quit-and-kill)
1047 ("f" . reftex-index-toggle-follow) 1047 ("f" . reftex-index-toggle-follow)
1048 ("s" . reftex-index-switch-index-tag) 1048 ("s" . reftex-index-switch-index-tag)
1049 ("e" . reftex-index-edit) 1049 ("e" . reftex-index-edit)
1050 ("^" . reftex-index-level-up) 1050 ("^" . reftex-index-level-up)
1051 ("_" . reftex-index-level-down) 1051 ("_" . reftex-index-level-down)
1052 ("}" . reftex-index-restrict-to-section) 1052 ("}" . reftex-index-restrict-to-section)
1053 ("{" . reftex-index-widen) 1053 ("{" . reftex-index-widen)
1054 (">" . reftex-index-restriction-forward) 1054 (">" . reftex-index-restriction-forward)
1055 ("<" . reftex-index-restriction-backward) 1055 ("<" . reftex-index-restriction-backward)
1056 ("(" . reftex-index-toggle-range-beginning) 1056 ("(" . reftex-index-toggle-range-beginning)
1057 (")" . reftex-index-toggle-range-end) 1057 (")" . reftex-index-toggle-range-end)
1058 ("|" . reftex-index-edit-attribute) 1058 ("|" . reftex-index-edit-attribute)
1059 ("@" . reftex-index-edit-visual) 1059 ("@" . reftex-index-edit-visual)
1060 ("*" . reftex-index-edit-key) 1060 ("*" . reftex-index-edit-key)
1061 ("\C-c=". reftex-index-goto-toc) 1061 ("\C-c=". reftex-index-goto-toc)
1062 ("c" . reftex-index-toggle-context)) 1062 ("c" . reftex-index-toggle-context))
1063 do (define-key reftex-index-map (car x) (cdr x))) 1063 do (define-key reftex-index-map (car x) (cdr x)))
1064 1064
1065(loop for key across "0123456789" do 1065(loop for key across "0123456789" do
@@ -1069,33 +1069,33 @@ When index is restricted, select the previous section as restriction criterion."
1069;; The capital letters and the exclamation mark 1069;; The capital letters and the exclamation mark
1070(loop for key across (concat "!" reftex-index-section-letters) do 1070(loop for key across (concat "!" reftex-index-section-letters) do
1071 (define-key reftex-index-map (vector (list key)) 1071 (define-key reftex-index-map (vector (list key))
1072 (list 'lambda '() '(interactive) 1072 (list 'lambda '() '(interactive)
1073 (list 'reftex-index-goto-letter key)))) 1073 (list 'reftex-index-goto-letter key))))
1074 1074
1075(defun reftex-index-goto-letter (char) 1075(defun reftex-index-goto-letter (char)
1076 "Go to the CHAR section in the index." 1076 "Go to the CHAR section in the index."
1077 (let ((pos (point)) 1077 (let ((pos (point))
1078 (case-fold-search nil)) 1078 (case-fold-search nil))
1079 (goto-line 3) 1079 (goto-line 3)
1080 (if (re-search-forward (concat "^" (char-to-string char)) nil t) 1080 (if (re-search-forward (concat "^" (char-to-string char)) nil t)
1081 (progn 1081 (progn
1082 (beginning-of-line) 1082 (beginning-of-line)
1083 (recenter 0) 1083 (recenter 0)
1084 (reftex-index-next)) 1084 (reftex-index-next))
1085 (goto-char pos) 1085 (goto-char pos)
1086 (if (eq char ?!) 1086 (if (eq char ?!)
1087 (error "This <%s> index does not contain entries sorted before the letters" 1087 (error "This <%s> index does not contain entries sorted before the letters"
1088 reftex-index-tag) 1088 reftex-index-tag)
1089 (error "This <%s> index does not contain entries starting with `%c'" 1089 (error "This <%s> index does not contain entries starting with `%c'"
1090 reftex-index-tag char))))) 1090 reftex-index-tag char)))))
1091 1091
1092(easy-menu-define 1092(easy-menu-define
1093 reftex-index-menu reftex-index-map 1093 reftex-index-menu reftex-index-map
1094 "Menu for Index buffer" 1094 "Menu for Index buffer"
1095 `("Index" 1095 `("Index"
1096 ["Goto section A-Z" 1096 ["Goto section A-Z"
1097 (message "To go to a section, just press any of: !%s" 1097 (message "To go to a section, just press any of: !%s"
1098 reftex-index-section-letters) t] 1098 reftex-index-section-letters) t]
1099 ["Show Entry" reftex-index-view-entry t] 1099 ["Show Entry" reftex-index-view-entry t]
1100 ["Go To Entry" reftex-index-goto-entry t] 1100 ["Go To Entry" reftex-index-goto-entry t]
1101 ["Exit & Go To Entry" reftex-index-goto-entry-and-hide t] 1101 ["Exit & Go To Entry" reftex-index-goto-entry-and-hide t]
@@ -1133,7 +1133,7 @@ When index is restricted, select the previous section as restriction criterion."
1133 ["Context" reftex-index-toggle-context :style toggle 1133 ["Context" reftex-index-toggle-context :style toggle
1134 :selected reftex-index-include-context] 1134 :selected reftex-index-include-context]
1135 "--" 1135 "--"
1136 ["Follow Mode" reftex-index-toggle-follow :style toggle 1136 ["Follow Mode" reftex-index-toggle-follow :style toggle
1137 :selected reftex-index-follow-mode]) 1137 :selected reftex-index-follow-mode])
1138 "--" 1138 "--"
1139 ["Help" reftex-index-show-help t])) 1139 ["Help" reftex-index-show-help t]))
@@ -1185,79 +1185,79 @@ You get a chance to edit the entry in the phrases buffer - finish with
1185 (set-marker reftex-index-return-marker (point)) 1185 (set-marker reftex-index-return-marker (point))
1186 (reftex-index-selection-or-word arg 'phrase) 1186 (reftex-index-selection-or-word arg 'phrase)
1187 (if (eq major-mode 'reftex-index-phrases-mode) 1187 (if (eq major-mode 'reftex-index-phrases-mode)
1188 (message 1188 (message
1189 (substitute-command-keys 1189 (substitute-command-keys
1190 "Return to LaTeX with \\[reftex-index-phrases-save-and-return]")))) 1190 "Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))
1191 1191
1192(defun reftex-index-visit-phrases-buffer () 1192(defun reftex-index-visit-phrases-buffer ()
1193 "Switch to the phrases buffer, initialize if empty." 1193 "Switch to the phrases buffer, initialize if empty."
1194 (interactive) 1194 (interactive)
1195 (reftex-access-scan-info) 1195 (reftex-access-scan-info)
1196 (let* ((master (reftex-TeX-master-file)) 1196 (let* ((master (reftex-TeX-master-file))
1197 (name (concat (file-name-sans-extension master) 1197 (name (concat (file-name-sans-extension master)
1198 reftex-index-phrase-file-extension))) 1198 reftex-index-phrase-file-extension)))
1199 (find-file name) 1199 (find-file name)
1200 (unless (eq major-mode 'reftex-index-phrases-mode) 1200 (unless (eq major-mode 'reftex-index-phrases-mode)
1201 (reftex-index-phrases-mode)) 1201 (reftex-index-phrases-mode))
1202 (if (= (buffer-size) 0) 1202 (if (= (buffer-size) 0)
1203 (reftex-index-initialize-phrases-buffer master)))) 1203 (reftex-index-initialize-phrases-buffer master))))
1204 1204
1205(defun reftex-index-initialize-phrases-buffer (&optional master) 1205(defun reftex-index-initialize-phrases-buffer (&optional master)
1206 "Initialize the phrases buffer by creating the header. 1206 "Initialize the phrases buffer by creating the header.
1207If the buffer is non-empty, delete the old header first." 1207If the buffer is non-empty, delete the old header first."
1208 (interactive) 1208 (interactive)
1209 (let* ((case-fold-search t) 1209 (let* ((case-fold-search t)
1210 (default-key (car reftex-index-default-macro)) 1210 (default-key (car reftex-index-default-macro))
1211 (default-macro (nth 1 (assoc default-key 1211 (default-macro (nth 1 (assoc default-key
1212 reftex-key-to-index-macro-alist))) 1212 reftex-key-to-index-macro-alist)))
1213 (macro-alist 1213 (macro-alist
1214 (sort (copy-sequence reftex-index-macro-alist) 1214 (sort (copy-sequence reftex-index-macro-alist)
1215 (lambda (a b) (equal (car a) default-macro)))) 1215 (lambda (a b) (equal (car a) default-macro))))
1216 macro entry key repeat) 1216 macro entry key repeat)
1217 1217
1218 (if master (set (make-local-variable 'TeX-master) 1218 (if master (set (make-local-variable 'TeX-master)
1219 (file-name-nondirectory master))) 1219 (file-name-nondirectory master)))
1220 1220
1221 (when (> (buffer-size) 0) 1221 (when (> (buffer-size) 0)
1222 (goto-char 1) 1222 (goto-char 1)
1223 (set-mark (point)) 1223 (set-mark (point))
1224 (while (re-search-forward reftex-index-phrases-macrodef-regexp nil t) 1224 (while (re-search-forward reftex-index-phrases-macrodef-regexp nil t)
1225 (end-of-line)) 1225 (end-of-line))
1226 (beginning-of-line 2) 1226 (beginning-of-line 2)
1227 (if (looking-at reftex-index-phrases-comment-regexp) 1227 (if (looking-at reftex-index-phrases-comment-regexp)
1228 (beginning-of-line 2)) 1228 (beginning-of-line 2))
1229 (while (looking-at "^[ \t]*$") 1229 (while (looking-at "^[ \t]*$")
1230 (beginning-of-line 2)) 1230 (beginning-of-line 2))
1231 (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region)) 1231 (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region))
1232 ((boundp 'make-active) (setq mark-active t))) 1232 ((boundp 'make-active) (setq mark-active t)))
1233 (if (yes-or-no-p "Delete and rebuilt header ") 1233 (if (yes-or-no-p "Delete and rebuilt header ")
1234 (delete-region (point-min) (point)))) 1234 (delete-region (point-min) (point))))
1235 1235
1236 ;; Insert the mode line 1236 ;; Insert the mode line
1237 (insert 1237 (insert
1238 (format "%% -*- mode: reftex-index-phrases; TeX-master: \"%s\" -*-\n" 1238 (format "%% -*- mode: reftex-index-phrases; TeX-master: \"%s\" -*-\n"
1239 (file-name-nondirectory (reftex-index-phrase-tex-master)))) 1239 (file-name-nondirectory (reftex-index-phrase-tex-master))))
1240 ;; Insert the macro definitions 1240 ;; Insert the macro definitions
1241 (insert "% Key Macro Format Repeat\n") 1241 (insert "% Key Macro Format Repeat\n")
1242 (insert "%---------------------------------------------------------------------\n") 1242 (insert "%---------------------------------------------------------------------\n")
1243 (while (setq entry (pop macro-alist)) 1243 (while (setq entry (pop macro-alist))
1244 (setq macro (car entry) 1244 (setq macro (car entry)
1245 repeat (nth 7 entry) 1245 repeat (nth 7 entry)
1246 key (car (delq nil (mapcar (lambda (x) (if (equal (nth 1 x) macro) 1246 key (car (delq nil (mapcar (lambda (x) (if (equal (nth 1 x) macro)
1247 (car x) 1247 (car x)
1248 nil)) 1248 nil))
1249 reftex-key-to-index-macro-alist)))) 1249 reftex-key-to-index-macro-alist))))
1250 (insert (format ">>>INDEX_MACRO_DEFINITION:\t%s\t%-20s\t%s\n" 1250 (insert (format ">>>INDEX_MACRO_DEFINITION:\t%s\t%-20s\t%s\n"
1251 (char-to-string key) (concat macro "{%s}") 1251 (char-to-string key) (concat macro "{%s}")
1252 (if repeat "t" "nil")))) 1252 (if repeat "t" "nil"))))
1253 (insert "%---------------------------------------------------------------------\n\n\n"))) 1253 (insert "%---------------------------------------------------------------------\n\n\n")))
1254 1254
1255(defvar TeX-master) 1255(defvar TeX-master)
1256(defun reftex-index-phrase-tex-master (&optional dir) 1256(defun reftex-index-phrase-tex-master (&optional dir)
1257 "Return the name of the master file associated with a phrase buffer." 1257 "Return the name of the master file associated with a phrase buffer."
1258 (if (and (boundp 'TeX-master) 1258 (if (and (boundp 'TeX-master)
1259 (local-variable-p 'TeX-master (current-buffer)) 1259 (local-variable-p 'TeX-master (current-buffer))
1260 (stringp TeX-master)) 1260 (stringp TeX-master))
1261 ;; We have a local variable which tells us which file to use 1261 ;; We have a local variable which tells us which file to use
1262 (expand-file-name TeX-master dir) 1262 (expand-file-name TeX-master dir)
1263 ;; have to guess 1263 ;; have to guess
@@ -1301,9 +1301,9 @@ Here are all local bindings.
1301 (interactive) 1301 (interactive)
1302 (kill-all-local-variables) 1302 (kill-all-local-variables)
1303 (setq major-mode 'reftex-index-phrases-mode 1303 (setq major-mode 'reftex-index-phrases-mode
1304 mode-name "Phrases") 1304 mode-name "Phrases")
1305 (use-local-map reftex-index-phrases-map) 1305 (use-local-map reftex-index-phrases-map)
1306 (set (make-local-variable 'font-lock-defaults) 1306 (set (make-local-variable 'font-lock-defaults)
1307 reftex-index-phrases-font-lock-defaults) 1307 reftex-index-phrases-font-lock-defaults)
1308 (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map) 1308 (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map)
1309 (set (make-local-variable 'reftex-index-phrases-marker) (make-marker)) 1309 (set (make-local-variable 'reftex-index-phrases-marker) (make-marker))
@@ -1313,31 +1313,31 @@ Here are all local bindings.
1313;; Font Locking stuff 1313;; Font Locking stuff
1314(let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection))) 1314(let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection)))
1315 (setq reftex-index-phrases-font-lock-keywords 1315 (setq reftex-index-phrases-font-lock-keywords
1316 (list 1316 (list
1317 (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face) 1317 (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face)
1318 (list reftex-index-phrases-macrodef-regexp 1318 (list reftex-index-phrases-macrodef-regexp
1319 '(1 font-lock-type-face) 1319 '(1 font-lock-type-face)
1320 '(2 font-lock-keyword-face) 1320 '(2 font-lock-keyword-face)
1321 (list 3 ss) 1321 (list 3 ss)
1322 '(4 font-lock-function-name-face) 1322 '(4 font-lock-function-name-face)
1323 (list 5 ss) 1323 (list 5 ss)
1324 '(6 font-lock-string-face)) 1324 '(6 font-lock-string-face))
1325 (list reftex-index-phrases-phrase-regexp1 1325 (list reftex-index-phrases-phrase-regexp1
1326 '(1 font-lock-keyword-face) 1326 '(1 font-lock-keyword-face)
1327 (list 2 ss) 1327 (list 2 ss)
1328 '(3 font-lock-string-face) 1328 '(3 font-lock-string-face)
1329 (list 4 ss)) 1329 (list 4 ss))
1330 (list reftex-index-phrases-phrase-regexp2 1330 (list reftex-index-phrases-phrase-regexp2
1331 '(1 font-lock-keyword-face) 1331 '(1 font-lock-keyword-face)
1332 (list 2 ss) 1332 (list 2 ss)
1333 '(3 font-lock-string-face) 1333 '(3 font-lock-string-face)
1334 (list 4 ss) 1334 (list 4 ss)
1335 '(5 font-lock-function-name-face)) 1335 '(5 font-lock-function-name-face))
1336 (cons "^\t$" ss))) 1336 (cons "^\t$" ss)))
1337 (setq reftex-index-phrases-font-lock-defaults 1337 (setq reftex-index-phrases-font-lock-defaults
1338 '((reftex-index-phrases-font-lock-keywords) 1338 '((reftex-index-phrases-font-lock-keywords)
1339 nil t nil beginning-of-line)) 1339 nil t nil beginning-of-line))
1340 (put 'reftex-index-phrases-mode 'font-lock-defaults 1340 (put 'reftex-index-phrases-mode 'font-lock-defaults
1341 reftex-index-phrases-font-lock-defaults) ; XEmacs 1341 reftex-index-phrases-font-lock-defaults) ; XEmacs
1342 ) 1342 )
1343 1343
@@ -1350,9 +1350,9 @@ Here are all local bindings.
1350 (decf arg) 1350 (decf arg)
1351 (end-of-line) 1351 (end-of-line)
1352 (if (re-search-forward reftex-index-phrases-phrase-regexp12 nil t) 1352 (if (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
1353 (progn 1353 (progn
1354 (goto-char (match-beginning 0)) 1354 (goto-char (match-beginning 0))
1355 (reftex-index-this-phrase)) 1355 (reftex-index-this-phrase))
1356 (error "No more phrase lines after point")))) 1356 (error "No more phrase lines after point"))))
1357 1357
1358(defun reftex-index-this-phrase () 1358(defun reftex-index-this-phrase ()
@@ -1364,48 +1364,48 @@ match, the user will be asked to confirm the replacement."
1364 (save-excursion 1364 (save-excursion
1365 (beginning-of-line) 1365 (beginning-of-line)
1366 (cond ((looking-at reftex-index-phrases-comment-regexp) 1366 (cond ((looking-at reftex-index-phrases-comment-regexp)
1367 (if (interactive-p) (error "Comment line"))) 1367 (if (interactive-p) (error "Comment line")))
1368 ((looking-at "^[ \t]*$") 1368 ((looking-at "^[ \t]*$")
1369 (if (interactive-p) (error "Empty line"))) 1369 (if (interactive-p) (error "Empty line")))
1370 ((looking-at reftex-index-phrases-macrodef-regexp) 1370 ((looking-at reftex-index-phrases-macrodef-regexp)
1371 (if (interactive-p) (error "Macro definition line"))) 1371 (if (interactive-p) (error "Macro definition line")))
1372 ((looking-at reftex-index-phrases-phrase-regexp12) 1372 ((looking-at reftex-index-phrases-phrase-regexp12)
1373 ;; This is a phrase 1373 ;; This is a phrase
1374 (let* ((char (if (not (equal (match-string 1) "")) 1374 (let* ((char (if (not (equal (match-string 1) ""))
1375 (string-to-char (match-string 1)))) 1375 (string-to-char (match-string 1))))
1376 (phrase (match-string 3)) 1376 (phrase (match-string 3))
1377 (index-key (match-string 6)) 1377 (index-key (match-string 6))
1378 (macro-data (cdr (if (null char) 1378 (macro-data (cdr (if (null char)
1379 (car reftex-index-phrases-macro-data) 1379 (car reftex-index-phrases-macro-data)
1380 (assoc char reftex-index-phrases-macro-data)))) 1380 (assoc char reftex-index-phrases-macro-data))))
1381 (macro-fmt (car macro-data)) 1381 (macro-fmt (car macro-data))
1382 (repeat (nth 1 macro-data)) 1382 (repeat (nth 1 macro-data))
1383 (files 1383 (files
1384 (cond ((and (stringp reftex-index-phrases-restrict-file) 1384 (cond ((and (stringp reftex-index-phrases-restrict-file)
1385 (file-regular-p reftex-index-phrases-restrict-file)) 1385 (file-regular-p reftex-index-phrases-restrict-file))
1386 (list reftex-index-phrases-restrict-file)) 1386 (list reftex-index-phrases-restrict-file))
1387 ((stringp reftex-index-phrases-restrict-file) 1387 ((stringp reftex-index-phrases-restrict-file)
1388 (error "Illegal restriction file %s" 1388 (error "Illegal restriction file %s"
1389 reftex-index-phrases-restrict-file)) 1389 reftex-index-phrases-restrict-file))
1390 (t reftex-index-phrases-files))) 1390 (t reftex-index-phrases-files)))
1391 (as-words reftex-index-phrases-search-whole-words)) 1391 (as-words reftex-index-phrases-search-whole-words))
1392 (unless macro-data 1392 (unless macro-data
1393 (error "No macro associated with key %c" char)) 1393 (error "No macro associated with key %c" char))
1394 (unwind-protect 1394 (unwind-protect
1395 (let ((overlay-arrow-string "=>") 1395 (let ((overlay-arrow-string "=>")
1396 (overlay-arrow-position 1396 (overlay-arrow-position
1397 reftex-index-phrases-marker) 1397 reftex-index-phrases-marker)
1398 (replace-count 0)) 1398 (replace-count 0))
1399 ;; Show the overlay arrow 1399 ;; Show the overlay arrow
1400 (move-marker reftex-index-phrases-marker 1400 (move-marker reftex-index-phrases-marker
1401 (match-beginning 0) (current-buffer)) 1401 (match-beginning 0) (current-buffer))
1402 ;; Start the query-replace 1402 ;; Start the query-replace
1403 (reftex-query-index-phrase-globally 1403 (reftex-query-index-phrase-globally
1404 files phrase macro-fmt 1404 files phrase macro-fmt
1405 index-key repeat as-words) 1405 index-key repeat as-words)
1406 (message "%s replaced" 1406 (message "%s replaced"
1407 (reftex-number replace-count "occurrence")))))) 1407 (reftex-number replace-count "occurrence"))))))
1408 (t (error "Cannot parse this line"))))) 1408 (t (error "Cannot parse this line")))))
1409 1409
1410(defun reftex-index-all-phrases () 1410(defun reftex-index-all-phrases ()
1411 "Index all phrases in the phrases buffer. 1411 "Index all phrases in the phrases buffer.
@@ -1428,7 +1428,7 @@ Calls `reftex-index-this-phrase' on each line in the region."
1428 (reftex-index-phrases-parse-header t) 1428 (reftex-index-phrases-parse-header t)
1429 (goto-char beg) 1429 (goto-char beg)
1430 (while (not (or (eobp) 1430 (while (not (or (eobp)
1431 (>= (point) end))) 1431 (>= (point) end)))
1432 (save-excursion (reftex-index-this-phrase)) 1432 (save-excursion (reftex-index-this-phrase))
1433 (beginning-of-line 2))) 1433 (beginning-of-line 2)))
1434 1434
@@ -1438,31 +1438,31 @@ The definitions get stored in `reftex-index-phrases-macro-data'.
1438Also switches to the LaTeX document to find out which files belong to 1438Also switches to the LaTeX document to find out which files belong to
1439the document and stores the list in `reftex-index-phrases-files'." 1439the document and stores the list in `reftex-index-phrases-files'."
1440 (let* ((master (reftex-index-phrase-tex-master)) 1440 (let* ((master (reftex-index-phrase-tex-master))
1441 buf) 1441 buf)
1442 (if get-files 1442 (if get-files
1443 ;; Get the file list 1443 ;; Get the file list
1444 (save-excursion 1444 (save-excursion
1445 (setq buf (reftex-get-file-buffer-force master)) 1445 (setq buf (reftex-get-file-buffer-force master))
1446 (unless buf (error "Master file %s not found" master)) 1446 (unless buf (error "Master file %s not found" master))
1447 (set-buffer buf) 1447 (set-buffer buf)
1448 (reftex-access-scan-info) 1448 (reftex-access-scan-info)
1449 (setq reftex-index-phrases-files 1449 (setq reftex-index-phrases-files
1450 (reftex-all-document-files)))) 1450 (reftex-all-document-files))))
1451 ;; Parse the files header for macro definitions 1451 ;; Parse the files header for macro definitions
1452 (setq reftex-index-phrases-macro-data nil) 1452 (setq reftex-index-phrases-macro-data nil)
1453 (save-excursion 1453 (save-excursion
1454 (goto-char (point-min)) 1454 (goto-char (point-min))
1455 (while (re-search-forward reftex-index-phrases-macrodef-regexp nil t) 1455 (while (re-search-forward reftex-index-phrases-macrodef-regexp nil t)
1456 (push (list 1456 (push (list
1457 (string-to-char (match-string 2)) 1457 (string-to-char (match-string 2))
1458 (match-string 4) 1458 (match-string 4)
1459 (equal (match-string 6) "t")) 1459 (equal (match-string 6) "t"))
1460 reftex-index-phrases-macro-data)) 1460 reftex-index-phrases-macro-data))
1461 ;; Reverse the list, so that the first macro is first 1461 ;; Reverse the list, so that the first macro is first
1462 (if (null reftex-index-phrases-macro-data) 1462 (if (null reftex-index-phrases-macro-data)
1463 (error "No valid MACRO DEFINITION line in %s file (make sure to use TAB separators)" reftex-index-phrase-file-extension)) 1463 (error "No valid MACRO DEFINITION line in %s file (make sure to use TAB separators)" reftex-index-phrase-file-extension))
1464 (setq reftex-index-phrases-macro-data 1464 (setq reftex-index-phrases-macro-data
1465 (nreverse reftex-index-phrases-macro-data)) 1465 (nreverse reftex-index-phrases-macro-data))
1466 (goto-char (point-min))))) 1466 (goto-char (point-min)))))
1467 1467
1468(defun reftex-index-phrases-apply-to-region (beg end) 1468(defun reftex-index-phrases-apply-to-region (beg end)
@@ -1473,34 +1473,34 @@ you need to add/change text in an already indexed document and want to
1473index the new part without having to go over the unchanged parts again." 1473index the new part without having to go over the unchanged parts again."
1474 (interactive "r") 1474 (interactive "r")
1475 (let ((win-conf (current-window-configuration)) 1475 (let ((win-conf (current-window-configuration))
1476 (reftex-index-phrases-restrict-file (buffer-file-name))) 1476 (reftex-index-phrases-restrict-file (buffer-file-name)))
1477 (save-excursion 1477 (save-excursion
1478 (save-restriction 1478 (save-restriction
1479 (narrow-to-region beg end) 1479 (narrow-to-region beg end)
1480 (unwind-protect 1480 (unwind-protect
1481 (progn 1481 (progn
1482 ;; Hide the region highlighting 1482 ;; Hide the region highlighting
1483 (cond ((fboundp 'zmacs-deactivate-region) (zmacs-deactivate-region)) 1483 (cond ((fboundp 'zmacs-deactivate-region) (zmacs-deactivate-region))
1484 ((fboundp 'deactivate-mark) (deactivate-mark))) 1484 ((fboundp 'deactivate-mark) (deactivate-mark)))
1485 (delete-other-windows) 1485 (delete-other-windows)
1486 (reftex-index-visit-phrases-buffer) 1486 (reftex-index-visit-phrases-buffer)
1487 (reftex-index-all-phrases)) 1487 (reftex-index-all-phrases))
1488 (set-window-configuration win-conf)))))) 1488 (set-window-configuration win-conf))))))
1489 1489
1490(defun reftex-index-new-phrase (&optional text) 1490(defun reftex-index-new-phrase (&optional text)
1491 "Open a new line in the phrases buffer, insert TEXT." 1491 "Open a new line in the phrases buffer, insert TEXT."
1492 (interactive) 1492 (interactive)
1493 (if (and text (stringp text)) 1493 (if (and text (stringp text))
1494 (progn 1494 (progn
1495 ;; Check if the phrase is already in the buffer 1495 ;; Check if the phrase is already in the buffer
1496 (setq text (reftex-index-simplify-phrase text)) 1496 (setq text (reftex-index-simplify-phrase text))
1497 (goto-char (point-min)) 1497 (goto-char (point-min))
1498 (if (re-search-forward 1498 (if (re-search-forward
1499 (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text) 1499 (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text)
1500 "\\) *[\t\n]") nil t) 1500 "\\) *[\t\n]") nil t)
1501 (progn 1501 (progn
1502 (goto-char (match-end 2)) 1502 (goto-char (match-end 2))
1503 (error "Phrase is already in phrases buffer"))))) 1503 (error "Phrase is already in phrases buffer")))))
1504 ;; Add the new phrase line after the last in the buffer 1504 ;; Add the new phrase line after the last in the buffer
1505 (goto-char (point-max)) 1505 (goto-char (point-max))
1506 (if (re-search-backward reftex-index-phrases-phrase-regexp12 nil t) 1506 (if (re-search-backward reftex-index-phrases-phrase-regexp12 nil t)
@@ -1521,19 +1521,19 @@ To check the whole buffer, start at the beginning and continue by calling
1521this function repeatedly." 1521this function repeatedly."
1522 (interactive "P") 1522 (interactive "P")
1523 (if (catch 'exit 1523 (if (catch 'exit
1524 (while (re-search-forward reftex-index-phrases-phrase-regexp12 nil t) 1524 (while (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
1525 (goto-char (match-beginning 3)) 1525 (goto-char (match-beginning 3))
1526 (let* ((phrase (match-string 3)) 1526 (let* ((phrase (match-string 3))
1527 (case-fold-search reftex-index-phrases-case-fold-search) 1527 (case-fold-search reftex-index-phrases-case-fold-search)
1528 (re (reftex-index-phrases-find-dup-re phrase t))) 1528 (re (reftex-index-phrases-find-dup-re phrase t)))
1529 (if (save-excursion 1529 (if (save-excursion
1530 (goto-char (point-min)) 1530 (goto-char (point-min))
1531 (and (re-search-forward re nil t) 1531 (and (re-search-forward re nil t)
1532 (re-search-forward re nil t))) 1532 (re-search-forward re nil t)))
1533 (throw 'exit t))))) 1533 (throw 'exit t)))))
1534 (progn 1534 (progn
1535 (reftex-index-phrases-info) 1535 (reftex-index-phrases-info)
1536 (message "Phrase with match conflict discovered")) 1536 (message "Phrase with match conflict discovered"))
1537 (goto-char (point-max)) 1537 (goto-char (point-max))
1538 (error "No further problematic phrases found"))) 1538 (error "No further problematic phrases found")))
1539 1539
@@ -1546,82 +1546,82 @@ this function repeatedly."
1546 (error "Not a phrase line")) 1546 (error "Not a phrase line"))
1547 (save-match-data (reftex-index-phrases-parse-header t)) 1547 (save-match-data (reftex-index-phrases-parse-header t))
1548 (let* ((char (if (not (equal (match-string 1) "")) 1548 (let* ((char (if (not (equal (match-string 1) ""))
1549 (string-to-char (match-string 1)))) 1549 (string-to-char (match-string 1))))
1550 (phrase (match-string 3)) 1550 (phrase (match-string 3))
1551 (index-key (match-string 6)) 1551 (index-key (match-string 6))
1552 (index-keys (split-string 1552 (index-keys (split-string
1553 (or index-key phrase) 1553 (or index-key phrase)
1554 reftex-index-phrases-logical-or-regexp)) 1554 reftex-index-phrases-logical-or-regexp))
1555 (macro-data (cdr (if (null char) 1555 (macro-data (cdr (if (null char)
1556 (car reftex-index-phrases-macro-data) 1556 (car reftex-index-phrases-macro-data)
1557 (assoc char reftex-index-phrases-macro-data)))) 1557 (assoc char reftex-index-phrases-macro-data))))
1558 (macro-fmt (car macro-data)) 1558 (macro-fmt (car macro-data))
1559 (repeat (nth 1 macro-data)) 1559 (repeat (nth 1 macro-data))
1560 (as-words reftex-index-phrases-search-whole-words) 1560 (as-words reftex-index-phrases-search-whole-words)
1561 (example (reftex-index-make-replace-string 1561 (example (reftex-index-make-replace-string
1562 macro-fmt (downcase phrase) (car index-keys) repeat)) 1562 macro-fmt (downcase phrase) (car index-keys) repeat))
1563 (re (reftex-index-make-phrase-regexp phrase as-words t)) 1563 (re (reftex-index-make-phrase-regexp phrase as-words t))
1564 (re1 (reftex-index-phrases-find-dup-re phrase)) 1564 (re1 (reftex-index-phrases-find-dup-re phrase))
1565 (re2 (reftex-index-phrases-find-dup-re phrase 'sub)) 1565 (re2 (reftex-index-phrases-find-dup-re phrase 'sub))
1566 superphrases 1566 superphrases
1567 (nmatches 0) 1567 (nmatches 0)
1568 (ntimes1 0) 1568 (ntimes1 0)
1569 (ntimes2 0) 1569 (ntimes2 0)
1570 (case-fold-search reftex-index-phrases-case-fold-search) 1570 (case-fold-search reftex-index-phrases-case-fold-search)
1571 file files buf) 1571 file files buf)
1572 (setq files reftex-index-phrases-files) 1572 (setq files reftex-index-phrases-files)
1573 (save-excursion 1573 (save-excursion
1574 (save-restriction 1574 (save-restriction
1575 (widen) 1575 (widen)
1576 (goto-char (point-min)) 1576 (goto-char (point-min))
1577 (while (re-search-forward re1 nil t) 1577 (while (re-search-forward re1 nil t)
1578 (incf ntimes1)) 1578 (incf ntimes1))
1579 (goto-char (point-min)) 1579 (goto-char (point-min))
1580 (while (re-search-forward re2 nil t) 1580 (while (re-search-forward re2 nil t)
1581 (push (cons (count-lines 1 (point)) (match-string 1)) superphrases) 1581 (push (cons (count-lines 1 (point)) (match-string 1)) superphrases)
1582 (incf ntimes2)))) 1582 (incf ntimes2))))
1583 (save-excursion 1583 (save-excursion
1584 (while (setq file (pop files)) 1584 (while (setq file (pop files))
1585 (setq buf (reftex-get-file-buffer-force file)) 1585 (setq buf (reftex-get-file-buffer-force file))
1586 (when buf 1586 (when buf
1587 (set-buffer buf) 1587 (set-buffer buf)
1588 (save-excursion 1588 (save-excursion
1589 (save-restriction 1589 (save-restriction
1590 (widen) 1590 (widen)
1591 (goto-char (point-min)) 1591 (goto-char (point-min))
1592 (let ((case-fold-search reftex-index-phrases-case-fold-search)) 1592 (let ((case-fold-search reftex-index-phrases-case-fold-search))
1593 (while (re-search-forward re nil t) 1593 (while (re-search-forward re nil t)
1594 (or (reftex-in-comment) 1594 (or (reftex-in-comment)
1595 (incf nmatches))))))))) 1595 (incf nmatches)))))))))
1596 (with-output-to-temp-buffer "*Help*" 1596 (with-output-to-temp-buffer "*Help*"
1597 (princ (format " Phrase: %s\n" phrase)) 1597 (princ (format " Phrase: %s\n" phrase))
1598 (princ (format " Macro key: %s\n" char)) 1598 (princ (format " Macro key: %s\n" char))
1599 (princ (format " Macro format: %s\n" macro-fmt)) 1599 (princ (format " Macro format: %s\n" macro-fmt))
1600 (princ (format " Repeat: %s\n" repeat)) 1600 (princ (format " Repeat: %s\n" repeat))
1601 (cond 1601 (cond
1602 (index-key 1602 (index-key
1603 (let ((iks index-keys) (cnt 0) ik) 1603 (let ((iks index-keys) (cnt 0) ik)
1604 (while (setq ik (pop iks)) 1604 (while (setq ik (pop iks))
1605 (princ (format "Index entry %d: %s\n" (incf cnt) ik))))) 1605 (princ (format "Index entry %d: %s\n" (incf cnt) ik)))))
1606 (repeat 1606 (repeat
1607 (princ (format " Index entry: %s\n" phrase))) 1607 (princ (format " Index entry: %s\n" phrase)))
1608 (t 1608 (t
1609 (princ (format " Index key: <<Given by the match>>\n")))) 1609 (princ (format " Index key: <<Given by the match>>\n"))))
1610 (princ (format " Example: %s\n" example)) 1610 (princ (format " Example: %s\n" example))
1611 (terpri) 1611 (terpri)
1612 (princ (format "Total matches: %s in %s\n" 1612 (princ (format "Total matches: %s in %s\n"
1613 (reftex-number nmatches "match" "es") 1613 (reftex-number nmatches "match" "es")
1614 (reftex-number (length reftex-index-phrases-files) 1614 (reftex-number (length reftex-index-phrases-files)
1615 "LaTeX file"))) 1615 "LaTeX file")))
1616 (princ (format " Uniqueness: Phrase occurs %s in phrase buffer\n" 1616 (princ (format " Uniqueness: Phrase occurs %s in phrase buffer\n"
1617 (reftex-number ntimes1 "time"))) 1617 (reftex-number ntimes1 "time")))
1618 (if (> ntimes2 1) 1618 (if (> ntimes2 1)
1619 (progn 1619 (progn
1620 (princ (format " Superphrases: Phrase matches the following %s in the phrase buffer:\n" 1620 (princ (format " Superphrases: Phrase matches the following %s in the phrase buffer:\n"
1621 (reftex-number ntimes2 "line"))) 1621 (reftex-number ntimes2 "line")))
1622 (mapcar (lambda(x) 1622 (mapcar (lambda(x)
1623 (princ (format " Line %4d: %s\n" (car x) (cdr x)))) 1623 (princ (format " Line %4d: %s\n" (car x) (cdr x))))
1624 (nreverse superphrases)))))))) 1624 (nreverse superphrases))))))))
1625 1625
1626(defun reftex-index-phrases-set-macro-key () 1626(defun reftex-index-phrases-set-macro-key ()
1627 "Change the macro key for the current line. 1627 "Change the macro key for the current line.
@@ -1634,32 +1634,32 @@ information about the currently selected macro."
1634 (save-excursion 1634 (save-excursion
1635 (beginning-of-line) 1635 (beginning-of-line)
1636 (unless (or (looking-at reftex-index-phrases-phrase-regexp12) 1636 (unless (or (looking-at reftex-index-phrases-phrase-regexp12)
1637 (looking-at "\t")) 1637 (looking-at "\t"))
1638 (error "This is not a phrase line")) 1638 (error "This is not a phrase line"))
1639 (let* ((nc (reftex-index-select-phrases-macro 0)) 1639 (let* ((nc (reftex-index-select-phrases-macro 0))
1640 (macro-data (assoc nc reftex-index-phrases-macro-data)) 1640 (macro-data (assoc nc reftex-index-phrases-macro-data))
1641 macro-fmt repeat) 1641 macro-fmt repeat)
1642 (cond (macro-data) 1642 (cond (macro-data)
1643 ((equal nc ?\ ) 1643 ((equal nc ?\ )
1644 (setq nc "" 1644 (setq nc ""
1645 macro-data (car reftex-index-phrases-macro-data))) 1645 macro-data (car reftex-index-phrases-macro-data)))
1646 ((equal nc ?\C-m) 1646 ((equal nc ?\C-m)
1647 (setq nc (char-after (point))) 1647 (setq nc (char-after (point)))
1648 (if (equal nc ?\t) 1648 (if (equal nc ?\t)
1649 (setq nc "" 1649 (setq nc ""
1650 macro-data (car reftex-index-phrases-macro-data)) 1650 macro-data (car reftex-index-phrases-macro-data))
1651 (setq macro-data (assoc nc reftex-index-phrases-macro-data)))) 1651 (setq macro-data (assoc nc reftex-index-phrases-macro-data))))
1652 (t (error "No macro associated with %c" nc))) 1652 (t (error "No macro associated with %c" nc)))
1653 1653
1654 (setq macro-fmt (nth 1 macro-data) 1654 (setq macro-fmt (nth 1 macro-data)
1655 repeat (nth 2 macro-data)) 1655 repeat (nth 2 macro-data))
1656 (if macro-data 1656 (if macro-data
1657 (progn 1657 (progn
1658 (if (looking-at "[^\t]") (delete-char 1)) 1658 (if (looking-at "[^\t]") (delete-char 1))
1659 (insert nc) 1659 (insert nc)
1660 (message "Line will use %s %s repeat" macro-fmt 1660 (message "Line will use %s %s repeat" macro-fmt
1661 (if repeat "with" "without"))) 1661 (if repeat "with" "without")))
1662 (error "Abort"))))) 1662 (error "Abort")))))
1663 1663
1664(defun reftex-index-sort-phrases (&optional chars-first) 1664(defun reftex-index-sort-phrases (&optional chars-first)
1665 "Sort the phrases lines in the buffer alphabetically. 1665 "Sort the phrases lines in the buffer alphabetically.
@@ -1668,28 +1668,28 @@ it first compares the macro identifying chars and then the phrases."
1668 (interactive "P") 1668 (interactive "P")
1669 ;; Remember the current line, so that we can return 1669 ;; Remember the current line, so that we can return
1670 (let ((line (buffer-substring (progn (beginning-of-line) (point)) 1670 (let ((line (buffer-substring (progn (beginning-of-line) (point))
1671 (progn (end-of-line) (point)))) 1671 (progn (end-of-line) (point))))
1672 beg end) 1672 beg end)
1673 (goto-char (point-min)) 1673 (goto-char (point-min))
1674 ;; Find first and last phrase line in buffer 1674 ;; Find first and last phrase line in buffer
1675 (setq beg 1675 (setq beg
1676 (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t) 1676 (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
1677 (match-beginning 0))) 1677 (match-beginning 0)))
1678 (goto-char (point-max)) 1678 (goto-char (point-max))
1679 (setq end (re-search-backward reftex-index-phrases-phrase-regexp12 nil t)) 1679 (setq end (re-search-backward reftex-index-phrases-phrase-regexp12 nil t))
1680 (if end (setq end (progn (goto-char end) (end-of-line) (point)))) 1680 (if end (setq end (progn (goto-char end) (end-of-line) (point))))
1681 ;; Take the lines, sort them and re-insert. 1681 ;; Take the lines, sort them and re-insert.
1682 (if (and beg end) 1682 (if (and beg end)
1683 (progn 1683 (progn
1684 (message "Sorting lines...") 1684 (message "Sorting lines...")
1685 (let* ((lines (split-string (buffer-substring beg end) "\n")) 1685 (let* ((lines (split-string (buffer-substring beg end) "\n"))
1686 (lines1 (sort lines 'reftex-compare-phrase-lines))) 1686 (lines1 (sort lines 'reftex-compare-phrase-lines)))
1687 (message "Sorting lines...done") 1687 (message "Sorting lines...done")
1688 (let ((inhibit-quit t)) ;; make sure we do not loose lines 1688 (let ((inhibit-quit t)) ;; make sure we do not loose lines
1689 (delete-region beg end) 1689 (delete-region beg end)
1690 (insert (mapconcat 'identity lines1 "\n")))) 1690 (insert (mapconcat 'identity lines1 "\n"))))
1691 (goto-char (point-max)) 1691 (goto-char (point-max))
1692 (re-search-backward (concat "^" (regexp-quote line) "$") nil t)) 1692 (re-search-backward (concat "^" (regexp-quote line) "$") nil t))
1693 (error "Cannot find phrases lines to sort")))) 1693 (error "Cannot find phrases lines to sort"))))
1694 1694
1695(defvar chars-first) 1695(defvar chars-first)
@@ -1697,28 +1697,28 @@ it first compares the macro identifying chars and then the phrases."
1697 "The comparison function used for sorting." 1697 "The comparison function used for sorting."
1698 (let (ca cb pa pb c-p p-p) 1698 (let (ca cb pa pb c-p p-p)
1699 (if (string-match reftex-index-phrases-phrase-regexp12 a) 1699 (if (string-match reftex-index-phrases-phrase-regexp12 a)
1700 (progn 1700 (progn
1701 ;; Extract macro char and phrase-or-key for a 1701 ;; Extract macro char and phrase-or-key for a
1702 (setq ca (match-string 1 a) 1702 (setq ca (match-string 1 a)
1703 pa (downcase 1703 pa (downcase
1704 (or (and reftex-index-phrases-sort-prefers-entry 1704 (or (and reftex-index-phrases-sort-prefers-entry
1705 (match-string 6 a)) 1705 (match-string 6 a))
1706 (match-string 3 a)))) 1706 (match-string 3 a))))
1707 (if (string-match reftex-index-phrases-phrase-regexp12 b) 1707 (if (string-match reftex-index-phrases-phrase-regexp12 b)
1708 (progn 1708 (progn
1709 ;; Extract macro char and phrase-or-key for b 1709 ;; Extract macro char and phrase-or-key for b
1710 (setq cb (match-string 1 b) 1710 (setq cb (match-string 1 b)
1711 pb (downcase 1711 pb (downcase
1712 (or (and reftex-index-phrases-sort-prefers-entry 1712 (or (and reftex-index-phrases-sort-prefers-entry
1713 (match-string 6 b)) 1713 (match-string 6 b))
1714 (match-string 3 b)))) 1714 (match-string 3 b))))
1715 (setq c-p (string< ca cb) 1715 (setq c-p (string< ca cb)
1716 p-p (string< pa pb)) 1716 p-p (string< pa pb))
1717 ;; Do the right comparison, based on the value of `chars-first' 1717 ;; Do the right comparison, based on the value of `chars-first'
1718 ;; `chars-first' is bound locally in the calling function 1718 ;; `chars-first' is bound locally in the calling function
1719 (if chars-first 1719 (if chars-first
1720 (if (string= ca cb) p-p c-p) 1720 (if (string= ca cb) p-p c-p)
1721 (if (string= pa pb) c-p p-p))))) 1721 (if (string= pa pb) c-p p-p)))))
1722 ;; If line a does not match, the answer we return determines 1722 ;; If line a does not match, the answer we return determines
1723 ;; if non-matching lines are collected at the beginning. 1723 ;; if non-matching lines are collected at the beginning.
1724 ;; When we return t here, non-matching lines form 1724 ;; When we return t here, non-matching lines form
@@ -1726,22 +1726,22 @@ it first compares the macro identifying chars and then the phrases."
1726 (not reftex-index-phrases-sort-in-blocks)))) 1726 (not reftex-index-phrases-sort-in-blocks))))
1727 1727
1728(defvar reftex-index-phrases-menu) 1728(defvar reftex-index-phrases-menu)
1729(defun reftex-index-make-phrase-regexp (phrase &optional 1729(defun reftex-index-make-phrase-regexp (phrase &optional
1730 as-words allow-newline) 1730 as-words allow-newline)
1731 "Return a regexp matching PHRASE, even if distributed over lines. 1731 "Return a regexp matching PHRASE, even if distributed over lines.
1732With optional arg AS-WORDS, require word boundary at beginning and end. 1732With optional arg AS-WORDS, require word boundary at beginning and end.
1733With optional arg ALLOW-NEWLINE, allow single newline between words." 1733With optional arg ALLOW-NEWLINE, allow single newline between words."
1734 (let* ((words (split-string phrase)) 1734 (let* ((words (split-string phrase))
1735 (space-re (if allow-newline 1735 (space-re (if allow-newline
1736 "\\([ \t]*\\(\n[ \t]*\\)?\\|[ \t]\\)" 1736 "\\([ \t]*\\(\n[ \t]*\\)?\\|[ \t]\\)"
1737 "\\([ \t]+\\)"))) 1737 "\\([ \t]+\\)")))
1738 (concat (if (and as-words (string-match "\\`\\w" (car words))) 1738 (concat (if (and as-words (string-match "\\`\\w" (car words)))
1739 "\\<" "") 1739 "\\<" "")
1740 (mapconcat (lambda (w) (regexp-quote (downcase w))) 1740 (mapconcat (lambda (w) (regexp-quote (downcase w)))
1741 words space-re) 1741 words space-re)
1742 (if (and as-words 1742 (if (and as-words
1743 (string-match "\\w\\'" (nth (1- (length words)) words))) 1743 (string-match "\\w\\'" (nth (1- (length words)) words)))
1744 "\\>" "")))) 1744 "\\>" ""))))
1745 1745
1746(defun reftex-index-simplify-phrase (phrase) 1746(defun reftex-index-simplify-phrase (phrase)
1747 "Make phrase single spaces and single line." 1747 "Make phrase single spaces and single line."
@@ -1752,40 +1752,40 @@ With optional arg ALLOW-NEWLINE, allow single newline between words."
1752When SUB ins non-nil, the regexp will also match when PHRASE is a subphrase 1752When SUB ins non-nil, the regexp will also match when PHRASE is a subphrase
1753of another phrase. The regexp works lonly in the phrase buffer." 1753of another phrase. The regexp works lonly in the phrase buffer."
1754 (concat (if sub "^\\S-?\t\\([^\t\n]*" "^\\S-?\t") 1754 (concat (if sub "^\\S-?\t\\([^\t\n]*" "^\\S-?\t")
1755 (mapconcat 'regexp-quote (split-string phrase) " +") 1755 (mapconcat 'regexp-quote (split-string phrase) " +")
1756 (if sub "[^\t\n]*\\)\\([\t\n]\\|$\\)" " *\\([\t\n]\\|$\\)"))) 1756 (if sub "[^\t\n]*\\)\\([\t\n]\\|$\\)" " *\\([\t\n]\\|$\\)")))
1757 1757
1758(defun reftex-index-make-replace-string (macro-fmt match index-key 1758(defun reftex-index-make-replace-string (macro-fmt match index-key
1759 &optional repeat mathp) 1759 &optional repeat mathp)
1760 "Return the string which can be used as replacement. 1760 "Return the string which can be used as replacement.
1761Treats the logical `and' for index phrases." 1761Treats the logical `and' for index phrases."
1762 (let ((index-keys (split-string (or index-key match) 1762 (let ((index-keys (split-string (or index-key match)
1763 reftex-index-phrases-logical-and-regexp))) 1763 reftex-index-phrases-logical-and-regexp)))
1764 (concat 1764 (concat
1765 (mapconcat (lambda (x) 1765 (mapconcat (lambda (x)
1766 (format macro-fmt 1766 (format macro-fmt
1767 (format (if mathp reftex-index-math-format "%s") x))) 1767 (format (if mathp reftex-index-math-format "%s") x)))
1768 index-keys "") 1768 index-keys "")
1769 (if repeat (reftex-index-simplify-phrase match) "")))) 1769 (if repeat (reftex-index-simplify-phrase match) ""))))
1770 1770
1771(defun reftex-query-index-phrase-globally (files &rest args) 1771(defun reftex-query-index-phrase-globally (files &rest args)
1772 "Call `reftex-query-index-phrase' for all files in FILES." 1772 "Call `reftex-query-index-phrase' for all files in FILES."
1773 (let ((win-conf (current-window-configuration)) 1773 (let ((win-conf (current-window-configuration))
1774 (file)) 1774 (file))
1775 (unless files (error "No files")) 1775 (unless files (error "No files"))
1776 (unwind-protect 1776 (unwind-protect
1777 (progn 1777 (progn
1778 (switch-to-buffer-other-window (reftex-get-file-buffer-force 1778 (switch-to-buffer-other-window (reftex-get-file-buffer-force
1779 (car files))) 1779 (car files)))
1780 (catch 'no-more-files 1780 (catch 'no-more-files
1781 (while (setq file (pop files)) 1781 (while (setq file (pop files))
1782 (switch-to-buffer (reftex-get-file-buffer-force file)) 1782 (switch-to-buffer (reftex-get-file-buffer-force file))
1783 (save-excursion 1783 (save-excursion
1784 (save-restriction 1784 (save-restriction
1785 (unless (stringp reftex-index-phrases-restrict-file) 1785 (unless (stringp reftex-index-phrases-restrict-file)
1786 (widen)) 1786 (widen))
1787 (goto-char (point-min)) 1787 (goto-char (point-min))
1788 (apply 'reftex-query-index-phrase args)))))) 1788 (apply 'reftex-query-index-phrase args))))))
1789 (reftex-unhighlight 0) 1789 (reftex-unhighlight 0)
1790 (set-window-configuration win-conf)))) 1790 (set-window-configuration win-conf))))
1791 1791
@@ -1806,7 +1806,7 @@ C-g Abort"
1806 1806
1807(defvar replace-count) 1807(defvar replace-count)
1808(defun reftex-query-index-phrase (phrase macro-fmt &optional 1808(defun reftex-query-index-phrase (phrase macro-fmt &optional
1809 index-key repeat as-words) 1809 index-key repeat as-words)
1810 "Search through buffer for PHRASE, and offer to replace it with an indexed 1810 "Search through buffer for PHRASE, and offer to replace it with an indexed
1811version. The index version is derived by applying `format' with MACRO-FMT 1811version. The index version is derived by applying `format' with MACRO-FMT
1812to INDEX-KEY or PHRASE. When REPEAT is non-nil, the PHRASE is inserted 1812to INDEX-KEY or PHRASE. When REPEAT is non-nil, the PHRASE is inserted
@@ -1814,142 +1814,140 @@ again after the macro.
1814AS-WORDS means, the search for PHRASE should require word boundaries at 1814AS-WORDS means, the search for PHRASE should require word boundaries at
1815both ends." 1815both ends."
1816 (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline)) 1816 (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline))
1817 (case-fold-search reftex-index-phrases-case-fold-search) 1817 (case-fold-search reftex-index-phrases-case-fold-search)
1818 (index-keys (split-string 1818 (index-keys (split-string
1819 (or index-key phrase) 1819 (or index-key phrase)
1820 reftex-index-phrases-logical-or-regexp)) 1820 reftex-index-phrases-logical-or-regexp))
1821 (nkeys (length index-keys)) 1821 (nkeys (length index-keys))
1822 (ckey (nth 0 index-keys)) 1822 (ckey (nth 0 index-keys))
1823 (all-yes nil) 1823 (all-yes nil)
1824 match rpl char beg end mathp) 1824 match rpl char beg end mathp)
1825 (unwind-protect 1825 (unwind-protect
1826 (while (re-search-forward re nil t) 1826 (while (re-search-forward re nil t)
1827 (catch 'next-match 1827 (catch 'next-match
1828 (if (and (fboundp reftex-index-verify-function) 1828 (if (and (fboundp reftex-index-verify-function)
1829 (not (funcall reftex-index-verify-function))) 1829 (not (funcall reftex-index-verify-function)))
1830 (throw 'next-match nil)) 1830 (throw 'next-match nil))
1831 (setq match (match-string 0)) 1831 (setq match (match-string 0))
1832 (setq mathp 1832 (setq mathp
1833 (save-match-data 1833 (save-match-data
1834 (condition-case nil (texmathp) (error nil)))) 1834 (condition-case nil (texmathp) (error nil))))
1835 (setq beg (car (match-data)) 1835 (setq beg (car (match-data))
1836 end (nth 1 (match-data))) 1836 end (nth 1 (match-data)))
1837 (if (and reftex-index-phrases-skip-indexed-matches 1837 (if (and reftex-index-phrases-skip-indexed-matches
1838 (save-match-data 1838 (save-match-data
1839 (reftex-index-phrase-match-is-indexed beg 1839 (reftex-index-phrase-match-is-indexed beg
1840 end))) 1840 end)))
1841 (throw 'next-match nil)) 1841 (throw 'next-match nil))
1842 (reftex-highlight 0 (match-beginning 0) (match-end 0)) 1842 (reftex-highlight 0 (match-beginning 0) (match-end 0))
1843 (setq rpl 1843 (setq rpl
1844 (save-match-data 1844 (save-match-data
1845 (reftex-index-make-replace-string 1845 (reftex-index-make-replace-string
1846 macro-fmt (match-string 0) ckey repeat mathp))) 1846 macro-fmt (match-string 0) ckey repeat mathp)))
1847 (while 1847 (while
1848 (not 1848 (not
1849 (catch 'loop 1849 (catch 'loop
1850 (message "REPLACE: %s? (yn!qoe%s?)" 1850 (message "REPLACE: %s? (yn!qoe%s?)"
1851 rpl 1851 rpl
1852 (if (> nkeys 1) 1852 (if (> nkeys 1)
1853 (concat "1-" (int-to-string nkeys)) 1853 (concat "1-" (int-to-string nkeys))
1854 "")) 1854 ""))
1855 (setq char (if all-yes ?y (read-char-exclusive))) 1855 (setq char (if all-yes ?y (read-char-exclusive)))
1856 (cond ((member char '(?y ?Y ?\ )) 1856 (cond ((member char '(?y ?Y ?\ ))
1857 ;; Yes! 1857 ;; Yes!
1858 (replace-match rpl t t) 1858 (replace-match rpl t t)
1859 (incf replace-count) 1859 (incf replace-count)
1860 ;; See if we should insert newlines to shorten lines 1860 ;; See if we should insert newlines to shorten lines
1861 (and reftex-index-phrases-wrap-long-lines 1861 (and reftex-index-phrases-wrap-long-lines
1862 (reftex-index-phrases-fixup-line beg end)) 1862 (reftex-index-phrases-fixup-line beg end))
1863 (throw 'loop t)) 1863 (throw 'loop t))
1864 ((member char '(?n ?N ?\C-h ?\C-?));; FIXME: DEL 1864 ((member char '(?n ?N ?\C-h ?\C-?));; FIXME: DEL
1865 ;; No 1865 ;; No
1866 (throw 'loop t)) 1866 (throw 'loop t))
1867 ((equal char ?!) 1867 ((equal char ?!)
1868 ;; Yes for all in this buffer 1868 ;; Yes for all in this buffer
1869 (setq all-yes t)) 1869 (setq all-yes t))
1870 ((equal char ?q) 1870 ((equal char ?q)
1871 ;; Stop this one in this file 1871 ;; Stop this one in this file
1872 (goto-char (point-max)) 1872 (goto-char (point-max))
1873 (throw 'loop t)) 1873 (throw 'loop t))
1874 ((equal char ?Q) 1874 ((equal char ?Q)
1875 ;; Stop this one 1875 ;; Stop this one
1876 (throw 'no-more-files t)) 1876 (throw 'no-more-files t))
1877 ((equal char ?s) 1877 ((equal char ?s)
1878 (save-buffer)) 1878 (save-buffer))
1879 ((equal char ?S) 1879 ((equal char ?S)
1880 (reftex-save-all-document-buffers)) 1880 (reftex-save-all-document-buffers))
1881 ((equal char ?\C-g) 1881 ((equal char ?\C-g)
1882 (keyboard-quit)) 1882 (keyboard-quit))
1883 ((member char '(?o ?O)) 1883 ((member char '(?o ?O))
1884 ;; Select a differnt macro 1884 ;; Select a differnt macro
1885 (let* ((nc (reftex-index-select-phrases-macro 2)) 1885 (let* ((nc (reftex-index-select-phrases-macro 2))
1886 (macro-data 1886 (macro-data
1887 (cdr (assoc nc reftex-index-phrases-macro-data))) 1887 (cdr (assoc nc reftex-index-phrases-macro-data)))
1888 (macro-fmt (car macro-data)) 1888 (macro-fmt (car macro-data))
1889 (repeat (nth 1 macro-data))) 1889 (repeat (nth 1 macro-data)))
1890 (if macro-data 1890 (if macro-data
1891 (setq rpl (save-match-data 1891 (setq rpl (save-match-data
1892 (reftex-index-make-replace-string 1892 (reftex-index-make-replace-string
1893 macro-fmt match 1893 macro-fmt match
1894 ckey repeat mathp))) 1894 ckey repeat mathp)))
1895 (ding)))) 1895 (ding))))
1896 ((equal char ?\?) 1896 ((equal char ?\?)
1897 ;; Help 1897 ;; Help
1898 (with-output-to-temp-buffer "*Help*" 1898 (with-output-to-temp-buffer "*Help*"
1899 (princ reftex-index-phrases-help))) 1899 (princ reftex-index-phrases-help)))
1900 ((equal char ?\C-r) 1900 ((equal char ?\C-r)
1901 ;; Recursive edit 1901 ;; Recursive edit
1902 (save-match-data 1902 (save-match-data
1903 (save-excursion 1903 (save-excursion
1904 (message 1904 (message
1905 (substitute-command-keys 1905 (substitute-command-keys
1906 "Recursive edit. Resume with \\[exit-recursive-edit]")) 1906 "Recursive edit. Resume with \\[exit-recursive-edit]"))
1907 (recursive-edit)))) 1907 (recursive-edit))))
1908 ((equal char ?e) 1908 ((equal char ?e)
1909 (setq rpl (read-string "Edit: " rpl))) 1909 (setq rpl (read-string "Edit: " rpl)))
1910 ((equal char ?0) 1910 ((equal char ?0)
1911 (setq ckey (or index-key phrase) 1911 (setq ckey (or index-key phrase)
1912 rpl (save-match-data 1912 rpl (save-match-data
1913 (reftex-index-make-replace-string 1913 (reftex-index-make-replace-string
1914 macro-fmt match ckey repeat mathp)))) 1914 macro-fmt match ckey repeat mathp))))
1915 ((and (> char ?0) 1915 ((and (> char ?0)
1916 (<= char (+ ?0 nkeys))) 1916 (<= char (+ ?0 nkeys)))
1917 (setq ckey (nth (1- (- char ?0)) index-keys) 1917 (setq ckey (nth (1- (- char ?0)) index-keys)
1918 rpl (save-match-data 1918 rpl (save-match-data
1919 (reftex-index-make-replace-string 1919 (reftex-index-make-replace-string
1920 macro-fmt match ckey repeat mathp)))) 1920 macro-fmt match ckey repeat mathp))))
1921 (t (ding))) 1921 (t (ding)))
1922 nil))))) 1922 nil)))))
1923 (message "") 1923 (message "")
1924 (setq all-yes nil) 1924 (setq all-yes nil)
1925 (reftex-unhighlight 0)))) 1925 (reftex-unhighlight 0))))
1926 1926
1927(defun reftex-index-phrase-match-is-indexed (beg end) 1927(defun reftex-index-phrase-match-is-indexed (beg end)
1928 ;; CHeck if match is in an argument of an index macro, or if an
1929 ;; index macro is directly attached to the match.
1930 (save-excursion 1928 (save-excursion
1931 (goto-char end) 1929 (goto-char end)
1932 (let* ((all-macros (reftex-what-macro t)) 1930 (let* ((this-macro (car (reftex-what-macro 1)))
1933 (this-macro (car (car all-macros))) 1931 (before-char (char-before beg))
1934 (before-macro 1932 (after-char (char-after end))
1935 (and (> beg 2) 1933 (before-macro
1936 (goto-char (1- beg)) 1934 (and (> beg 2)
1937 (memq (char-after (point)) '(?\] ?\})) 1935 (goto-char (1- beg))
1938 (car (reftex-what-macro 1)))) 1936 (memq (char-after (point)) '(?\] ?\}))
1939 (after-macro 1937 (car (reftex-what-macro 1))))
1940 (and (goto-char end) 1938 (after-macro
1941 (looking-at "\\(\\\\[a-zA-Z]+\\*?\\)[[{]") 1939 (and (goto-char end)
1942 (match-string 1))) 1940 (looking-at "\\(\\\\[a-zA-Z]+\\*?\\)[[{]")
1943 macro) 1941 (match-string 1))))
1944 (or (catch 'matched 1942 (or (and this-macro
1945 (while (setq macro (pop all-macros)) 1943 (member before-char '(?\{ ?\[))
1946 (if (member (car macro) reftex-macros-with-index) 1944 (member after-char '(?\} ?\]))
1947 (throw 'matched t))) 1945 (member this-macro reftex-macros-with-index))
1948 nil) 1946 (and before-macro
1949 (and before-macro 1947 (member before-macro reftex-macros-with-index))
1950 (member before-macro reftex-macros-with-index)) 1948 (and after-macro
1951 (and after-macro 1949 (member after-macro reftex-macros-with-index))))))
1952 (member after-macro reftex-macros-with-index)))))) 1950
1953 1951
1954(defun reftex-index-phrases-fixup-line (beg end) 1952(defun reftex-index-phrases-fixup-line (beg end)
1955 "Insert newlines before BEG and/or after END to shorten line." 1953 "Insert newlines before BEG and/or after END to shorten line."
@@ -1963,38 +1961,38 @@ both ends."
1963 (goto-char beg) 1961 (goto-char beg)
1964 (skip-chars-backward "^ \n") 1962 (skip-chars-backward "^ \n")
1965 (if (and (equal (preceding-char) ?\ ) 1963 (if (and (equal (preceding-char) ?\ )
1966 (string-match "\\S-" (buffer-substring bol (point)))) 1964 (string-match "\\S-" (buffer-substring bol (point))))
1967 (setq space1 (1- (point)))) 1965 (setq space1 (1- (point))))
1968 (goto-char end) 1966 (goto-char end)
1969 (skip-chars-forward "^ \n") 1967 (skip-chars-forward "^ \n")
1970 (if (and (equal (following-char) ?\ ) 1968 (if (and (equal (following-char) ?\ )
1971 (string-match "\\S-" (buffer-substring (point) eol))) 1969 (string-match "\\S-" (buffer-substring (point) eol)))
1972 (setq space2 (point))) 1970 (setq space2 (point)))
1973 ;; Now check what we have and insert the newlines 1971 ;; Now check what we have and insert the newlines
1974 (if (<= (- eol bol) fill-column) 1972 (if (<= (- eol bol) fill-column)
1975 ;; Line is already short 1973 ;; Line is already short
1976 nil 1974 nil
1977 (cond 1975 (cond
1978 ((and (not space1) (not space2))) ; No spaces available 1976 ((and (not space1) (not space2))) ; No spaces available
1979 ((not space2) ; Do space1 1977 ((not space2) ; Do space1
1980 (reftex-index-phrases-replace-space space1)) 1978 (reftex-index-phrases-replace-space space1))
1981 ((not space1) ; Do space2 1979 ((not space1) ; Do space2
1982 (reftex-index-phrases-replace-space space2)) 1980 (reftex-index-phrases-replace-space space2))
1983 (t ; We have both spaces 1981 (t ; We have both spaces
1984 (let ((l1 (- space1 bol)) 1982 (let ((l1 (- space1 bol))
1985 (l2 (- space2 space1)) 1983 (l2 (- space2 space1))
1986 (l3 (- eol space2))) 1984 (l3 (- eol space2)))
1987 (if (> l2 fill-column) 1985 (if (> l2 fill-column)
1988 ;; The central part alone is more than one line 1986 ;; The central part alone is more than one line
1989 (progn 1987 (progn
1990 (reftex-index-phrases-replace-space space1) 1988 (reftex-index-phrases-replace-space space1)
1991 (reftex-index-phrases-replace-space space2)) 1989 (reftex-index-phrases-replace-space space2))
1992 (if (> (+ l1 l2) fill-column) 1990 (if (> (+ l1 l2) fill-column)
1993 ;; Need to split beginning 1991 ;; Need to split beginning
1994 (reftex-index-phrases-replace-space space1)) 1992 (reftex-index-phrases-replace-space space1))
1995 (if (> (+ l2 l3) fill-column) 1993 (if (> (+ l2 l3) fill-column)
1996 ;; Need to split end 1994 ;; Need to split end
1997 (reftex-index-phrases-replace-space space2)))))))))) 1995 (reftex-index-phrases-replace-space space2))))))))))
1998 1996
1999(defun reftex-index-phrases-replace-space (pos) 1997(defun reftex-index-phrases-replace-space (pos)
2000 "If there is a space at POS, replace it with a newline char. 1998 "If there is a space at POS, replace it with a newline char.
@@ -2007,34 +2005,34 @@ Does not do a save-excursion."
2007(defun reftex-index-select-phrases-macro (&optional delay) 2005(defun reftex-index-select-phrases-macro (&optional delay)
2008 "Offer a list of possible index macros and have the user select one." 2006 "Offer a list of possible index macros and have the user select one."
2009 (let* ((prompt (concat "Select macro: [" 2007 (let* ((prompt (concat "Select macro: ["
2010 (mapconcat (lambda (x) (char-to-string (car x))) 2008 (mapconcat (lambda (x) (char-to-string (car x)))
2011 reftex-index-phrases-macro-data "") 2009 reftex-index-phrases-macro-data "")
2012 "] ")) 2010 "] "))
2013 (help (concat "Select an indexing macro\n========================\n" 2011 (help (concat "Select an indexing macro\n========================\n"
2014 (mapconcat (lambda (x) 2012 (mapconcat (lambda (x)
2015 (format " [%c] %s" 2013 (format " [%c] %s"
2016 (car x) (nth 1 x))) 2014 (car x) (nth 1 x)))
2017 reftex-index-phrases-macro-data "\n")))) 2015 reftex-index-phrases-macro-data "\n"))))
2018 (reftex-select-with-char prompt help delay))) 2016 (reftex-select-with-char prompt help delay)))
2019 2017
2020;; Keybindings and Menu for phrases buffer 2018;; Keybindings and Menu for phrases buffer
2021 2019
2022(loop for x in 2020(loop for x in
2023 '(("\C-c\C-c" . reftex-index-phrases-save-and-return) 2021 '(("\C-c\C-c" . reftex-index-phrases-save-and-return)
2024 ("\C-c\C-x" . reftex-index-this-phrase) 2022 ("\C-c\C-x" . reftex-index-this-phrase)
2025 ("\C-c\C-f" . reftex-index-next-phrase) 2023 ("\C-c\C-f" . reftex-index-next-phrase)
2026 ("\C-c\C-r" . reftex-index-region-phrases) 2024 ("\C-c\C-r" . reftex-index-region-phrases)
2027 ("\C-c\C-a" . reftex-index-all-phrases) 2025 ("\C-c\C-a" . reftex-index-all-phrases)
2028 ("\C-c\C-d" . reftex-index-remaining-phrases) 2026 ("\C-c\C-d" . reftex-index-remaining-phrases)
2029 ("\C-c\C-s" . reftex-index-sort-phrases) 2027 ("\C-c\C-s" . reftex-index-sort-phrases)
2030 ("\C-c\C-n" . reftex-index-new-phrase) 2028 ("\C-c\C-n" . reftex-index-new-phrase)
2031 ("\C-c\C-m" . reftex-index-phrases-set-macro-key) 2029 ("\C-c\C-m" . reftex-index-phrases-set-macro-key)
2032 ("\C-c\C-i" . reftex-index-phrases-info) 2030 ("\C-c\C-i" . reftex-index-phrases-info)
2033 ("\C-c\C-t" . reftex-index-find-next-conflict-phrase) 2031 ("\C-c\C-t" . reftex-index-find-next-conflict-phrase)
2034 ("\C-i" . self-insert-command)) 2032 ("\C-i" . self-insert-command))
2035 do (define-key reftex-index-phrases-map (car x) (cdr x))) 2033 do (define-key reftex-index-phrases-map (car x) (cdr x)))
2036 2034
2037(easy-menu-define 2035(easy-menu-define
2038 reftex-index-phrases-menu reftex-index-phrases-map 2036 reftex-index-phrases-menu reftex-index-phrases-map
2039 "Menu for Phrases buffer" 2037 "Menu for Phrases buffer"
2040 '("Phrases" 2038 '("Phrases"
@@ -2051,7 +2049,7 @@ Does not do a save-excursion."
2051 ["by Index Entry" (setq reftex-index-phrases-sort-prefers-entry t) 2049 ["by Index Entry" (setq reftex-index-phrases-sort-prefers-entry t)
2052 :style radio :selected reftex-index-phrases-sort-prefers-entry] 2050 :style radio :selected reftex-index-phrases-sort-prefers-entry]
2053 ["in Blocks" (setq reftex-index-phrases-sort-in-blocks 2051 ["in Blocks" (setq reftex-index-phrases-sort-in-blocks
2054 (not reftex-index-phrases-sort-in-blocks)) 2052 (not reftex-index-phrases-sort-in-blocks))
2055 :style toggle :selected reftex-index-phrases-sort-in-blocks]) 2053 :style toggle :selected reftex-index-phrases-sort-in-blocks])
2056 ["Describe Phrase" reftex-index-phrases-info t] 2054 ["Describe Phrase" reftex-index-phrases-info t]
2057 ["Next Phrase Conflict" reftex-index-find-next-conflict-phrase t] 2055 ["Next Phrase Conflict" reftex-index-find-next-conflict-phrase t]
@@ -2065,21 +2063,20 @@ Does not do a save-excursion."
2065 "--" 2063 "--"
2066 "Options" 2064 "Options"
2067 ["Match Whole Words" (setq reftex-index-phrases-search-whole-words 2065 ["Match Whole Words" (setq reftex-index-phrases-search-whole-words
2068 (not reftex-index-phrases-search-whole-words)) 2066 (not reftex-index-phrases-search-whole-words))
2069 :style toggle :selected reftex-index-phrases-search-whole-words] 2067 :style toggle :selected reftex-index-phrases-search-whole-words]
2070 ["Case Sensitive Search" (setq reftex-index-phrases-case-fold-search 2068 ["Case Sensitive Search" (setq reftex-index-phrases-case-fold-search
2071 (not reftex-index-phrases-case-fold-search)) 2069 (not reftex-index-phrases-case-fold-search))
2072 :style toggle :selected (not 2070 :style toggle :selected (not
2073 reftex-index-phrases-case-fold-search)] 2071 reftex-index-phrases-case-fold-search)]
2074 ["Wrap Long Lines" (setq reftex-index-phrases-wrap-long-lines 2072 ["Wrap Long Lines" (setq reftex-index-phrases-wrap-long-lines
2075 (not reftex-index-phrases-wrap-long-lines)) 2073 (not reftex-index-phrases-wrap-long-lines))
2076 :style toggle :selected reftex-index-phrases-wrap-long-lines] 2074 :style toggle :selected reftex-index-phrases-wrap-long-lines]
2077 ["Skip Indexed Matches" (setq reftex-index-phrases-skip-indexed-matches 2075 ["Skip Indexed Matches" (setq reftex-index-phrases-skip-indexed-matches
2078 (not reftex-index-phrases-skip-indexed-matches)) 2076 (not reftex-index-phrases-skip-indexed-matches))
2079 :style toggle :selected reftex-index-phrases-skip-indexed-matches]) 2077 :style toggle :selected reftex-index-phrases-skip-indexed-matches])
2080 "--" 2078 "--"
2081 ["Save and Return" reftex-index-phrases-save-and-return t])) 2079 ["Save and Return" reftex-index-phrases-save-and-return t]))
2082 2080
2083 2081
2084;;; arch-tag: 4b2362af-c156-42c1-8932-ea2823e205c1
2085;;; reftex-index.el ends here 2082;;; reftex-index.el ends here
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 534775bf5a5..a03c5b6646b 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -1,8 +1,8 @@
1;;; reftex-parse.el --- parser functions for RefTeX 1;;; reftex-parse.el --- parser functions for RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6;; 6;;
7 7
8;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
@@ -33,10 +33,10 @@
33(defmacro reftex-with-special-syntax (&rest body) 33(defmacro reftex-with-special-syntax (&rest body)
34 `(let ((saved-syntax (syntax-table))) 34 `(let ((saved-syntax (syntax-table)))
35 (unwind-protect 35 (unwind-protect
36 (progn 36 (progn
37 (set-syntax-table reftex-syntax-table) 37 (set-syntax-table reftex-syntax-table)
38 (let ((case-fold-search nil)) 38 (let ((case-fold-search nil))
39 ,@body)) 39 ,@body))
40 (set-syntax-table saved-syntax)))) 40 (set-syntax-table saved-syntax))))
41 41
42(defun reftex-parse-one () 42(defun reftex-parse-one ()
@@ -68,12 +68,12 @@
68 68
69 (let* ((old-list (symbol-value reftex-docstruct-symbol)) 69 (let* ((old-list (symbol-value reftex-docstruct-symbol))
70 (master (reftex-TeX-master-file)) 70 (master (reftex-TeX-master-file))
71 (true-master (file-truename master)) 71 (true-master (file-truename master))
72 (master-dir (file-name-as-directory (file-name-directory master))) 72 (master-dir (file-name-as-directory (file-name-directory master)))
73 (file (or file (buffer-file-name))) 73 (file (or file (buffer-file-name)))
74 (true-file (file-truename file)) 74 (true-file (file-truename file))
75 (bibview-cache (assq 'bibview-cache old-list)) 75 (bibview-cache (assq 'bibview-cache old-list))
76 (index-tags (cdr (assq 'index-tags old-list))) 76 (index-tags (cdr (assq 'index-tags old-list)))
77 from-file appendix docstruct tmp) 77 from-file appendix docstruct tmp)
78 78
79 ;; Make sure replacement is really an option here 79 ;; Make sure replacement is really an option here
@@ -97,9 +97,9 @@
97 97
98 ;; Find active toc entry and initialize section-numbers 98 ;; Find active toc entry and initialize section-numbers
99 (setq reftex-active-toc (reftex-last-assoc-before-elt 99 (setq reftex-active-toc (reftex-last-assoc-before-elt
100 'toc (list 'bof from-file) old-list) 100 'toc (list 'bof from-file) old-list)
101 appendix (reftex-last-assoc-before-elt 101 appendix (reftex-last-assoc-before-elt
102 'appendix (list 'bof from-file) old-list)) 102 'appendix (list 'bof from-file) old-list))
103 103
104 (reftex-init-section-numbers reftex-active-toc appendix) 104 (reftex-init-section-numbers reftex-active-toc appendix)
105 105
@@ -110,11 +110,11 @@
110 (reftex-with-special-syntax 110 (reftex-with-special-syntax
111 (save-window-excursion 111 (save-window-excursion
112 (save-excursion 112 (save-excursion
113 (unwind-protect 113 (unwind-protect
114 (setq docstruct 114 (setq docstruct
115 (reftex-parse-from-file 115 (reftex-parse-from-file
116 from-file docstruct master-dir)) 116 from-file docstruct master-dir))
117 (reftex-kill-temporary-buffers))))) 117 (reftex-kill-temporary-buffers)))))
118 118
119 (message "Scanning document... done") 119 (message "Scanning document... done")
120 120
@@ -141,27 +141,27 @@
141 (and index-tags (setq index-tags (sort index-tags 'string<))) 141 (and index-tags (setq index-tags (sort index-tags 'string<)))
142 (let ((index-tag-cell (assq 'index-tags docstruct))) 142 (let ((index-tag-cell (assq 'index-tags docstruct)))
143 (if index-tag-cell 143 (if index-tag-cell
144 (setcdr index-tag-cell index-tags) 144 (setcdr index-tag-cell index-tags)
145 (push (cons 'index-tags index-tags) docstruct))) 145 (push (cons 'index-tags index-tags) docstruct)))
146 (unless (assq 'xr docstruct) 146 (unless (assq 'xr docstruct)
147 (let* ((allxr (reftex-all-assq 'xr-doc docstruct)) 147 (let* ((allxr (reftex-all-assq 'xr-doc docstruct))
148 (alist (mapcar 148 (alist (mapcar
149 (lambda (x) 149 (lambda (x)
150 (if (setq tmp (reftex-locate-file (nth 2 x) "tex" 150 (if (setq tmp (reftex-locate-file (nth 2 x) "tex"
151 master-dir)) 151 master-dir))
152 (cons (nth 1 x) tmp) 152 (cons (nth 1 x) tmp)
153 (message "Can't find external document %s" 153 (message "Can't find external document %s"
154 (nth 2 x)) 154 (nth 2 x))
155 nil)) 155 nil))
156 allxr)) 156 allxr))
157 (alist (delq nil alist)) 157 (alist (delq nil alist))
158 (allprefix (delq nil (mapcar 'car alist))) 158 (allprefix (delq nil (mapcar 'car alist)))
159 (regexp (if allprefix 159 (regexp (if allprefix
160 (concat "\\`\\(" 160 (concat "\\`\\("
161 (mapconcat 'identity allprefix "\\|") 161 (mapconcat 'identity allprefix "\\|")
162 "\\)") 162 "\\)")
163 "\\\\\\\\\\\\"))) ; this will never match 163 "\\\\\\\\\\\\"))) ; this will never match
164 (push (list 'xr alist regexp) docstruct))) 164 (push (list 'xr alist regexp) docstruct)))
165 165
166 (set reftex-docstruct-symbol docstruct) 166 (set reftex-docstruct-symbol docstruct)
167 (put reftex-docstruct-symbol 'modified t))) 167 (put reftex-docstruct-symbol 'modified t)))
@@ -201,8 +201,8 @@ of master file."
201 (catch 'exit 201 (catch 'exit
202 (setq file-found (reftex-locate-file file "tex" master-dir)) 202 (setq file-found (reftex-locate-file file "tex" master-dir))
203 (if (and (not file-found) 203 (if (and (not file-found)
204 (setq buf (reftex-get-buffer-visiting file))) 204 (setq buf (reftex-get-buffer-visiting file)))
205 (setq file-found (buffer-file-name buf))) 205 (setq file-found (buffer-file-name buf)))
206 206
207 (unless file-found 207 (unless file-found
208 (push (list 'file-error file) docstruct) 208 (push (list 'file-error file) docstruct)
@@ -221,106 +221,106 @@ of master file."
221 (setq file (buffer-file-name)) 221 (setq file (buffer-file-name))
222 (push (list 'bof file) docstruct) 222 (push (list 'bof file) docstruct)
223 223
224 (reftex-with-special-syntax 224 (reftex-with-special-syntax
225 (save-excursion 225 (save-excursion
226 (save-restriction 226 (save-restriction
227 (widen) 227 (widen)
228 (goto-char 1) 228 (goto-char 1)
229 229
230 (while (re-search-forward regexp nil t) 230 (while (re-search-forward regexp nil t)
231 231
232 (cond 232 (cond
233 233
234 ((match-end 1) 234 ((match-end 1)
235 ;; It is a label 235 ;; It is a label
236 (push (reftex-label-info (reftex-match-string 1) file bound) 236 (push (reftex-label-info (reftex-match-string 1) file bound)
237 docstruct)) 237 docstruct))
238 238
239 ((match-end 3) 239 ((match-end 3)
240 ;; It is a section 240 ;; It is a section
241 (setq bound (point)) 241 (setq bound (point))
242 242
243 ;; Insert in List 243 ;; Insert in List
244 (setq toc-entry (reftex-section-info file)) 244 (setq toc-entry (reftex-section-info file))
245 (when toc-entry 245 (when toc-entry
246 ;; It can happen that section info returns nil 246 ;; It can happen that section info returns nil
247 (setq level (nth 5 toc-entry)) 247 (setq level (nth 5 toc-entry))
248 (setq highest-level (min highest-level level)) 248 (setq highest-level (min highest-level level))
249 (if (= level highest-level) 249 (if (= level highest-level)
250 (message 250 (message
251 "Scanning %s %s ..." 251 "Scanning %s %s ..."
252 (car (rassoc level reftex-section-levels-all)) 252 (car (rassoc level reftex-section-levels-all))
253 (nth 6 toc-entry))) 253 (nth 6 toc-entry)))
254 254
255 (push toc-entry docstruct) 255 (push toc-entry docstruct)
256 (setq reftex-active-toc toc-entry))) 256 (setq reftex-active-toc toc-entry)))
257 257
258 ((match-end 7) 258 ((match-end 7)
259 ;; It's an include or input 259 ;; It's an include or input
260 (setq include-file (reftex-match-string 7)) 260 (setq include-file (reftex-match-string 7))
261 ;; Test if this file should be ignored 261 ;; Test if this file should be ignored
262 (unless (delq nil (mapcar 262 (unless (delq nil (mapcar
263 (lambda (x) (string-match x include-file)) 263 (lambda (x) (string-match x include-file))
264 reftex-no-include-regexps)) 264 reftex-no-include-regexps))
265 ;; Parse it 265 ;; Parse it
266 (setq docstruct 266 (setq docstruct
267 (reftex-parse-from-file 267 (reftex-parse-from-file
268 include-file 268 include-file
269 docstruct master-dir)))) 269 docstruct master-dir))))
270 270
271 ((match-end 9) 271 ((match-end 9)
272 ;; Appendix starts here 272 ;; Appendix starts here
273 (reftex-init-section-numbers nil t) 273 (reftex-init-section-numbers nil t)
274 (push (cons 'appendix t) docstruct)) 274 (push (cons 'appendix t) docstruct))
275 275
276 ((match-end 10) 276 ((match-end 10)
277 ;; Index entry 277 ;; Index entry
278 (when reftex-support-index 278 (when reftex-support-index
279 (setq index-entry (reftex-index-info file)) 279 (setq index-entry (reftex-index-info file))
280 (when index-entry 280 (when index-entry
281 (add-to-list 'index-tags (nth 1 index-entry)) 281 (add-to-list 'index-tags (nth 1 index-entry))
282 (push index-entry docstruct)))) 282 (push index-entry docstruct))))
283 283
284 ((match-end 11) 284 ((match-end 11)
285 ;; A macro with label 285 ;; A macro with label
286 (save-excursion 286 (save-excursion
287 (let* ((mac (reftex-match-string 11)) 287 (let* ((mac (reftex-match-string 11))
288 (label (progn (goto-char (match-end 11)) 288 (label (progn (goto-char (match-end 11))
289 (save-match-data 289 (save-match-data
290 (reftex-no-props 290 (reftex-no-props
291 (reftex-nth-arg-wrapper 291 (reftex-nth-arg-wrapper
292 mac))))) 292 mac)))))
293 (typekey (nth 1 (assoc mac reftex-env-or-mac-alist))) 293 (typekey (nth 1 (assoc mac reftex-env-or-mac-alist)))
294 (entry (progn (if typekey 294 (entry (progn (if typekey
295 ;; A typing macro 295 ;; A typing macro
296 (goto-char (match-end 0)) 296 (goto-char (match-end 0))
297 ;; A neutral macro 297 ;; A neutral macro
298 (goto-char (match-end 11)) 298 (goto-char (match-end 11))
299 (reftex-move-over-touching-args)) 299 (reftex-move-over-touching-args))
300 (reftex-label-info 300 (reftex-label-info
301 label file bound nil nil)))) 301 label file bound nil nil))))
302 (push entry docstruct)))) 302 (push entry docstruct))))
303 (t (error "This should not happen (reftex-parse-from-file)"))) 303 (t (error "This should not happen (reftex-parse-from-file)")))
304 ) 304 )
305 305
306 ;; Find bibliography statement 306 ;; Find bibliography statement
307 (when (setq tmp (reftex-locate-bibliography-files master-dir)) 307 (when (setq tmp (reftex-locate-bibliography-files master-dir))
308 (push (cons 'bib tmp) docstruct)) 308 (push (cons 'bib tmp) docstruct))
309 309
310 (goto-char 1) 310 (goto-char 1)
311 (when (re-search-forward 311 (when (re-search-forward
312 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t) 312 "\\(\\`\\|[\n\r]\\)[ \t]*\\\\begin{thebibliography}" nil t)
313 (push (cons 'thebib file) docstruct)) 313 (push (cons 'thebib file) docstruct))
314 314
315 ;; Find external document specifications 315 ;; Find external document specifications
316 (goto-char 1) 316 (goto-char 1)
317 (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t) 317 (while (re-search-forward "[\n\r][ \t]*\\\\externaldocument\\(\\[\\([^]]*\\)\\]\\)?{\\([^}]+\\)}" nil t)
318 (push (list 'xr-doc (reftex-match-string 2) 318 (push (list 'xr-doc (reftex-match-string 2)
319 (reftex-match-string 3)) 319 (reftex-match-string 3))
320 docstruct)) 320 docstruct))
321 321
322 ;; End of file mark 322 ;; End of file mark
323 (push (list 'eof file) docstruct))))) 323 (push (list 'eof file) docstruct)))))
324 324
325 ;; Kill the scanned buffer 325 ;; Kill the scanned buffer
326 (reftex-kill-temporary-buffers next-buf)) 326 (reftex-kill-temporary-buffers next-buf))
@@ -330,31 +330,31 @@ of master file."
330 330
331(defun reftex-locate-bibliography-files (master-dir &optional files) 331(defun reftex-locate-bibliography-files (master-dir &optional files)
332 ;; Scan buffer for bibliography macro and return file list. 332 ;; Scan buffer for bibliography macro and return file list.
333 333
334 (unless files 334 (unless files
335 (save-excursion 335 (save-excursion
336 (goto-char (point-min)) 336 (goto-char (point-min))
337 (if (re-search-forward 337 (if (re-search-forward
338 (concat 338 (concat
339; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\(" 339; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
340 "\\(^\\)[^%\n\r]*\\\\\\(" 340 "\\(^\\)[^%]*\\\\\\("
341 (mapconcat 'identity reftex-bibliography-commands "\\|") 341 (mapconcat 'identity reftex-bibliography-commands "\\|")
342 "\\){[ \t]*\\([^}]+\\)") nil t) 342 "\\){[ \t]*\\([^}]+\\)") nil t)
343 (setq files 343 (setq files
344 (split-string (reftex-match-string 3) 344 (split-string (reftex-match-string 3)
345 "[ \t\n\r]*,[ \t\n\r]*"))))) 345 "[ \t\n\r]*,[ \t\n\r]*")))))
346 (when files 346 (when files
347 (setq files 347 (setq files
348 (mapcar 348 (mapcar
349 (lambda (x) 349 (lambda (x)
350 (if (or (member x reftex-bibfile-ignore-list) 350 (if (or (member x reftex-bibfile-ignore-list)
351 (delq nil (mapcar (lambda (re) (string-match re x)) 351 (delq nil (mapcar (lambda (re) (string-match re x))
352 reftex-bibfile-ignore-regexps))) 352 reftex-bibfile-ignore-regexps)))
353 ;; excluded file 353 ;; excluded file
354 nil 354 nil
355 ;; find the file 355 ;; find the file
356 (reftex-locate-file x "bib" master-dir))) 356 (reftex-locate-file x "bib" master-dir)))
357 files)) 357 files))
358 (delq nil files))) 358 (delq nil files)))
359 359
360(defun reftex-replace-label-list-segment (old insert &optional entirely) 360(defun reftex-replace-label-list-segment (old insert &optional entirely)
@@ -387,24 +387,24 @@ of master file."
387 ;; Carefull: This function expects the match-data to be still in place! 387 ;; Carefull: This function expects the match-data to be still in place!
388 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3)))) 388 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3))))
389 (macro (reftex-match-string 3)) 389 (macro (reftex-match-string 3))
390 (prefix (save-match-data 390 (prefix (save-match-data
391 (if (string-match "begin{\\([^}]+\\)}" macro) 391 (if (string-match "begin{\\([^}]+\\)}" macro)
392 (match-string 1 macro)))) 392 (match-string 1 macro))))
393 (level-exp (cdr (assoc macro reftex-section-levels-all))) 393 (level-exp (cdr (assoc macro reftex-section-levels-all)))
394 (level (if (symbolp level-exp) 394 (level (if (symbolp level-exp)
395 (save-match-data (funcall level-exp)) 395 (save-match-data (funcall level-exp))
396 level-exp)) 396 level-exp))
397 (star (= ?* (char-after (match-end 3)))) 397 (star (= ?* (char-after (match-end 3))))
398 (unnumbered (or star (< level 0))) 398 (unnumbered (or star (< level 0)))
399 (level (abs level)) 399 (level (abs level))
400 (section-number (reftex-section-number level unnumbered)) 400 (section-number (reftex-section-number level unnumbered))
401 (text1 (save-match-data 401 (text1 (save-match-data
402 (save-excursion 402 (save-excursion
403 (reftex-context-substring prefix)))) 403 (reftex-context-substring prefix))))
404 (literal (buffer-substring-no-properties 404 (literal (buffer-substring-no-properties
405 (1- (match-beginning 3)) 405 (1- (match-beginning 3))
406 (min (point-max) (+ (match-end 0) (length text1) 1)))) 406 (min (point-max) (+ (match-end 0) (length text1) 1))))
407 ;; Literal can be too short since text1 too short. No big problem. 407 ;; Literal can be too short since text1 too short. No big problem.
408 (text (reftex-nicify-text text1))) 408 (text (reftex-nicify-text text1)))
409 409
410 ;; Add section number and indentation 410 ;; Add section number and indentation
@@ -413,7 +413,7 @@ of master file."
413 (make-string (* reftex-level-indent level) ?\ ) 413 (make-string (* reftex-level-indent level) ?\ )
414 (if (nth 1 reftex-label-menu-flags) ; section number flag 414 (if (nth 1 reftex-label-menu-flags) ; section number flag
415 (concat section-number " ")) 415 (concat section-number " "))
416 (if prefix (concat (capitalize prefix) ": ") "") 416 (if prefix (concat (capitalize prefix) ": ") "")
417 text)) 417 text))
418 (list 'toc "toc" text file marker level section-number 418 (list 'toc "toc" text file marker level section-number
419 literal (marker-position marker)))) 419 literal (marker-position marker))))
@@ -426,12 +426,12 @@ of master file."
426 (reftex-support-index t) 426 (reftex-support-index t)
427 ((y-or-n-p "Turn on index support and rescan entire document? ") 427 ((y-or-n-p "Turn on index support and rescan entire document? ")
428 (setq reftex-support-index 'demanded 428 (setq reftex-support-index 'demanded
429 current-prefix-arg '(16))) 429 current-prefix-arg '(16)))
430 (t (if abort 430 (t (if abort
431 (error "No index support") 431 (error "No index support")
432 (message "No index support") 432 (message "No index support")
433 (ding) 433 (ding)
434 (sit-for 1))))) 434 (sit-for 1)))))
435 435
436(defun reftex-index-info-safe (file) 436(defun reftex-index-info-safe (file)
437 (reftex-with-special-syntax 437 (reftex-with-special-syntax
@@ -443,49 +443,49 @@ of master file."
443 ;; Carefull: This function expects the match-data to be still in place! 443 ;; Carefull: This function expects the match-data to be still in place!
444 (catch 'exit 444 (catch 'exit
445 (let* ((macro (reftex-match-string 10)) 445 (let* ((macro (reftex-match-string 10))
446 (bom (match-beginning 10)) 446 (bom (match-beginning 10))
447 (boa (match-end 10)) 447 (boa (match-end 10))
448 (entry (or (assoc macro reftex-index-macro-alist) 448 (entry (or (assoc macro reftex-index-macro-alist)
449 (throw 'exit nil))) 449 (throw 'exit nil)))
450 (exclude (nth 3 entry)) 450 (exclude (nth 3 entry))
451 ;; The following is a test if this match should be excluded 451 ;; The following is a test if this match should be excluded
452 (test-dummy (and (fboundp exclude) 452 (test-dummy (and (fboundp exclude)
453 (funcall exclude) 453 (funcall exclude)
454 (throw 'exit nil))) 454 (throw 'exit nil)))
455 (itag (nth 1 entry)) 455 (itag (nth 1 entry))
456 (prefix (nth 2 entry)) 456 (prefix (nth 2 entry))
457 (index-tag 457 (index-tag
458 (cond ((stringp itag) itag) 458 (cond ((stringp itag) itag)
459 ((integerp itag) 459 ((integerp itag)
460 (progn (goto-char boa) 460 (progn (goto-char boa)
461 (or (reftex-nth-arg itag (nth 6 entry)) "idx"))) 461 (or (reftex-nth-arg itag (nth 6 entry)) "idx")))
462 (t "idx"))) 462 (t "idx")))
463 (arg (or (progn (goto-char boa) 463 (arg (or (progn (goto-char boa)
464 (reftex-nth-arg (nth 5 entry) (nth 6 entry))) 464 (reftex-nth-arg (nth 5 entry) (nth 6 entry)))
465 "")) 465 ""))
466 (end-of-args (progn (goto-char boa) 466 (end-of-args (progn (goto-char boa)
467 (reftex-move-over-touching-args) 467 (reftex-move-over-touching-args)
468 (point))) 468 (point)))
469 (end-of-context (progn (skip-chars-forward "^ \t\n\r") (point))) 469 (end-of-context (progn (skip-chars-forward "^ \t\n\r") (point)))
470 (begin-of-context 470 (begin-of-context
471 (progn (goto-char bom) 471 (progn (goto-char bom)
472 (skip-chars-backward "^ \t\r\n") 472 (skip-chars-backward "^ \t\r\n")
473 (point))) 473 (point)))
474 (context (buffer-substring-no-properties 474 (context (buffer-substring-no-properties
475 begin-of-context end-of-context)) 475 begin-of-context end-of-context))
476 (key-end (if (string-match reftex-index-key-end-re arg) 476 (key-end (if (string-match reftex-index-key-end-re arg)
477 (1+ (match-beginning 0)))) 477 (1+ (match-beginning 0))))
478 (rawkey (substring arg 0 key-end)) 478 (rawkey (substring arg 0 key-end))
479 479
480 (key (if prefix (concat prefix rawkey) rawkey)) 480 (key (if prefix (concat prefix rawkey) rawkey))
481 (sortkey (downcase key)) 481 (sortkey (downcase key))
482 (showkey (mapconcat 'identity 482 (showkey (mapconcat 'identity
483 (split-string key reftex-index-level-re) 483 (split-string key reftex-index-level-re)
484 " ! "))) 484 " ! ")))
485 (goto-char end-of-args) 485 (goto-char end-of-args)
486 ;; 0 1 2 3 4 5 6 7 8 9 486 ;; 0 1 2 3 4 5 6 7 8 9
487 (list 'index index-tag context file bom arg key showkey sortkey key-end)))) 487 (list 'index index-tag context file bom arg key showkey sortkey key-end))))
488 488
489(defun reftex-short-context (env parse &optional bound derive) 489(defun reftex-short-context (env parse &optional bound derive)
490 ;; Get about one line of useful context for the label definition at point. 490 ;; Get about one line of useful context for the label definition at point.
491 491
@@ -516,9 +516,9 @@ of master file."
516 (match-string 1 (nth 7 reftex-active-toc))) 516 (match-string 1 (nth 7 reftex-active-toc)))
517 "SECTION HEADING NOT FOUND"))) 517 "SECTION HEADING NOT FOUND")))
518 (save-excursion 518 (save-excursion
519 (goto-char reftex-default-context-position) 519 (goto-char reftex-default-context-position)
520 (unless (eq (string-to-char env) ?\\) 520 (unless (eq (string-to-char env) ?\\)
521 (reftex-move-over-touching-args)) 521 (reftex-move-over-touching-args))
522 (reftex-context-substring)))) 522 (reftex-context-substring))))
523 523
524 ((stringp parse) 524 ((stringp parse)
@@ -593,7 +593,7 @@ of master file."
593 ((looking-at (reftex-make-regexp-allow-for-ctrl-m 593 ((looking-at (reftex-make-regexp-allow-for-ctrl-m
594 (nth 7 (car list)))) 594 (nth 7 (car list))))
595 ;; Same title: remember, but keep looking 595 ;; Same title: remember, but keep looking
596 (setq rtn-if-no-other (car list))))) 596 (setq rtn-if-no-other (car list)))))
597 (pop list)) 597 (pop list))
598 rtn1)) 598 rtn1))
599 ((match-end 7) 599 ((match-end 7)
@@ -601,35 +601,35 @@ of master file."
601 (car 601 (car
602 (member (list 'eof (reftex-locate-file 602 (member (list 'eof (reftex-locate-file
603 (reftex-match-string 7) "tex" 603 (reftex-match-string 7) "tex"
604 (cdr (assq 'master-dir docstruct)))) 604 (cdr (assq 'master-dir docstruct))))
605 docstruct))) 605 docstruct)))
606 ((match-end 9) 606 ((match-end 9)
607 (assq 'appendix (symbol-value reftex-docstruct-symbol))) 607 (assq 'appendix (symbol-value reftex-docstruct-symbol)))
608 ((match-end 10) 608 ((match-end 10)
609 ;; Index entry 609 ;; Index entry
610 (when reftex-support-index 610 (when reftex-support-index
611 (let* ((index-info (save-excursion 611 (let* ((index-info (save-excursion
612 (reftex-index-info-safe nil))) 612 (reftex-index-info-safe nil)))
613 (list (member (list 'bof (buffer-file-name)) 613 (list (member (list 'bof (buffer-file-name))
614 docstruct)) 614 docstruct))
615 (endelt (car (member (list 'eof (buffer-file-name)) 615 (endelt (car (member (list 'eof (buffer-file-name))
616 list))) 616 list)))
617 dist last-dist last (n 0)) 617 dist last-dist last (n 0))
618 ;; Check all index entries with equal text 618 ;; Check all index entries with equal text
619 (while (and list (not (eq endelt (car list)))) 619 (while (and list (not (eq endelt (car list))))
620 (when (and (eq (car (car list)) 'index) 620 (when (and (eq (car (car list)) 'index)
621 (string= (nth 2 index-info) 621 (string= (nth 2 index-info)
622 (nth 2 (car list)))) 622 (nth 2 (car list))))
623 (incf n) 623 (incf n)
624 (setq dist (abs (- (point) (nth 4 (car list))))) 624 (setq dist (abs (- (point) (nth 4 (car list)))))
625 (if (or (not last-dist) (< dist last-dist)) 625 (if (or (not last-dist) (< dist last-dist))
626 (setq last-dist dist last (car list)))) 626 (setq last-dist dist last (car list))))
627 (setq list (cdr list))) 627 (setq list (cdr list)))
628 ;; We are sure if we have only one, or a zero distance 628 ;; We are sure if we have only one, or a zero distance
629 (cond ((or (= n 1) (equal dist 0)) last) 629 (cond ((or (= n 1) (= dist 0)) last)
630 ((> n 1) (setq cnt 2) last) 630 ((> n 1) (setq cnt 2) last)
631 (t nil))))) 631 (t nil)))))
632 ((match-end 11) 632 ((match-end 11)
633 (save-excursion 633 (save-excursion
634 (goto-char (match-end 11)) 634 (goto-char (match-end 11))
635 (assoc (reftex-no-props 635 (assoc (reftex-no-props
@@ -641,88 +641,88 @@ of master file."
641 ;; Check if there was only a by-name match for the section. 641 ;; Check if there was only a by-name match for the section.
642 (when (and (not rtn) rtn-if-no-other) 642 (when (and (not rtn) rtn-if-no-other)
643 (setq rtn rtn-if-no-other 643 (setq rtn rtn-if-no-other
644 cnt 2)) 644 cnt 2))
645 (cons rtn (eq cnt 1)))) 645 (cons rtn (eq cnt 1))))
646 646
647(defun reftex-notice-new (&optional n force) 647(defun reftex-notice-new (&optional n force)
648 "Hook to handshake with RefTeX after something new has been inserted." 648 "Hook to handshake with RefTeX after something new has been inserted."
649 ;; Add a new entry to the docstruct list. If it is a section, renumber 649 ;; Add a new entry to the docstruct list. If it is a section, renumber
650 ;; the following sections. 650 ;; the following sections.
651 ;; FIXME: Put in a WHAT parameter and search backward until one is found. 651 ;; FIXME: Put in a WHAT parameter
652 ;; When N is given, go back that many matches of reftex-everything-regexp 652 ;; When N is given, go back that many matches of reftex-everything-regexp
653 ;; When FORCE is non-nil, also insert if `reftex-where-am-I' was uncertain. 653 ;; When FORCE is non-nil, also insert if `reftex-where-am-I' was uncertain.
654 (condition-case nil 654 (condition-case nil
655 (catch 'exit 655 (catch 'exit
656 (unless reftex-mode (throw 'exit nil)) 656 (unless reftex-mode (throw 'exit nil))
657 (reftex-access-scan-info) 657 (reftex-access-scan-info)
658 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) 658 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
659 here-I-am appendix tail entry star level 659 here-I-am appendix tail entry star level
660 section-number context) 660 section-number context)
661 661
662 (save-excursion 662 (save-excursion
663 (when (re-search-backward (reftex-everything-regexp) nil t (or n 1)) 663 (when (re-search-backward (reftex-everything-regexp) nil t (or n 1))
664 664
665 ;; Find where we are 665 ;; Find where we are
666 (setq here-I-am (reftex-where-am-I)) 666 (setq here-I-am (reftex-where-am-I))
667 (or here-I-am (throw 'exit nil)) 667 (or here-I-am (throw 'exit nil))
668 (unless (or force (cdr here-I-am)) (throw 'exit nil)) 668 (unless (or force (cdr here-I-am)) (throw 'exit nil))
669 (setq tail (memq (car here-I-am) docstruct)) 669 (setq tail (memq (car here-I-am) docstruct))
670 (or tail (throw 'exit nil)) 670 (or tail (throw 'exit nil))
671 (setq reftex-active-toc (reftex-last-assoc-before-elt 671 (setq reftex-active-toc (reftex-last-assoc-before-elt
672 'toc (car here-I-am) docstruct) 672 'toc (car here-I-am) docstruct)
673 appendix (reftex-last-assoc-before-elt 673 appendix (reftex-last-assoc-before-elt
674 'appendix (car here-I-am) docstruct)) 674 'appendix (car here-I-am) docstruct))
675 675
676 ;; Initialize section numbers 676 ;; Initialize section numbers
677 (if (eq (car (car here-I-am)) 'appendix) 677 (if (eq (car (car here-I-am)) 'appendix)
678 (reftex-init-section-numbers nil t) 678 (reftex-init-section-numbers nil t)
679 (reftex-init-section-numbers reftex-active-toc appendix)) 679 (reftex-init-section-numbers reftex-active-toc appendix))
680 680
681 ;; Match the section command 681 ;; Match the section command
682 (when (re-search-forward (reftex-everything-regexp) nil t) 682 (when (re-search-forward (reftex-everything-regexp) nil t)
683 (cond 683 (cond
684 ((match-end 1) 684 ((match-end 1)
685 (push (reftex-label-info (reftex-match-string 1) buffer-file-name) 685 (push (reftex-label-info (reftex-match-string 1) buffer-file-name)
686 (cdr tail))) 686 (cdr tail)))
687 687
688 ((match-end 3) 688 ((match-end 3)
689 (setq star (= ?* (char-after (match-end 3))) 689 (setq star (= ?* (char-after (match-end 3)))
690 entry (reftex-section-info (buffer-file-name)) 690 entry (reftex-section-info (buffer-file-name))
691 level (nth 5 entry)) 691 level (nth 5 entry))
692 ;; Insert the section info 692 ;; Insert the section info
693 (push entry (cdr tail)) 693 (push entry (cdr tail))
694 694
695 ;; We are done unless we use section numbers 695 ;; We are done unless we use section numbers
696 (unless (nth 1 reftex-label-menu-flags) (throw 'exit nil)) 696 (unless (nth 1 reftex-label-menu-flags) (throw 'exit nil))
697 697
698 ;; Update the remaining toc items 698 ;; Update the remaining toc items
699 (setq tail (cdr tail)) 699 (setq tail (cdr tail))
700 (while (and (setq tail (memq (assq 'toc (cdr tail)) tail)) 700 (while (and (setq tail (memq (assq 'toc (cdr tail)) tail))
701 (setq entry (car tail)) 701 (setq entry (car tail))
702 (>= (nth 5 entry) level)) 702 (>= (nth 5 entry) level))
703 (setq star (string-match "\\*" (nth 6 entry)) 703 (setq star (string-match "\\*" (nth 6 entry))
704 context (nth 2 entry) 704 context (nth 2 entry)
705 section-number 705 section-number
706 (reftex-section-number (nth 5 entry) star)) 706 (reftex-section-number (nth 5 entry) star))
707 (when (string-match "\\`\\([ \t]*\\)\\([.0-9A-Z]+\\)\\(.*\\)" 707 (when (string-match "\\`\\([ \t]*\\)\\([.0-9A-Z]+\\)\\(.*\\)"
708 context) 708 context)
709 (when (and (not appendix) 709 (when (and (not appendix)
710 (>= (string-to-char (match-string 2)) ?A)) 710 (>= (string-to-char (match-string 2)) ?A))
711 ;; Just entered the appendex. Get out. 711 ;; Just entered the appendex. Get out.
712 (throw 'exit nil)) 712 (throw 'exit nil))
713 713
714 ;; Change the section number. 714 ;; Change the section number.
715 (setf (nth 2 entry) 715 (setf (nth 2 entry)
716 (concat (match-string 1 context) 716 (concat (match-string 1 context)
717 section-number 717 section-number
718 (match-string 3 context)))))) 718 (match-string 3 context))))))
719 ((match-end 10) 719 ((match-end 10)
720 ;; Index entry 720 ;; Index entry
721 (and reftex-support-index 721 (and reftex-support-index
722 (setq entry (reftex-index-info-safe buffer-file-name)) 722 (setq entry (reftex-index-info-safe buffer-file-name))
723 ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry)) 723 ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry))
724 (push entry (cdr tail)))))))))) 724 (push entry (cdr tail))))))))))
725 725
726 (error nil)) 726 (error nil))
727 ) 727 )
728 728
@@ -736,8 +736,8 @@ of master file."
736 ((memq (preceding-char) '(?\] ?\}))) 736 ((memq (preceding-char) '(?\] ?\})))
737 ;; Do a search 737 ;; Do a search
738 ((and reftex-allow-detached-macro-args 738 ((and reftex-allow-detached-macro-args
739 (re-search-backward 739 (re-search-backward
740 "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t)) 740 "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t))
741 (goto-char (1+ (match-beginning 0))) 741 (goto-char (1+ (match-beginning 0)))
742 t) 742 t)
743 (t nil))) 743 (t nil)))
@@ -774,7 +774,7 @@ of master file."
774 pos cmd-list cmd cnt cnt-opt entry) 774 pos cmd-list cmd cnt cnt-opt entry)
775 (save-restriction 775 (save-restriction
776 (save-excursion 776 (save-excursion
777 (narrow-to-region (max 1 bound) (point-max)) 777 (narrow-to-region (max (point-min) bound) (point-max))
778 ;; move back out of the current parenthesis 778 ;; move back out of the current parenthesis
779 (while (condition-case nil 779 (while (condition-case nil
780 (progn (up-list -1) t) 780 (progn (up-list -1) t)
@@ -782,29 +782,29 @@ of master file."
782 (setq cnt 1 cnt-opt 0) 782 (setq cnt 1 cnt-opt 0)
783 ;; move back over any touching sexps 783 ;; move back over any touching sexps
784 (while (and (reftex-move-to-previous-arg bound) 784 (while (and (reftex-move-to-previous-arg bound)
785 (condition-case nil 785 (condition-case nil
786 (progn (backward-sexp) t) 786 (progn (backward-sexp) t)
787 (error nil))) 787 (error nil)))
788 (if (eq (following-char) ?\[) (incf cnt-opt)) 788 (if (eq (following-char) ?\[) (incf cnt-opt))
789 (incf cnt)) 789 (incf cnt))
790 (setq pos (point)) 790 (setq pos (point))
791 (when (and (or (= (following-char) ?\[) 791 (when (and (or (= (following-char) ?\[)
792 (= (following-char) ?\{)) 792 (= (following-char) ?\{))
793 (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t)) 793 (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
794 (setq cmd (reftex-match-string 0)) 794 (setq cmd (reftex-match-string 0))
795 (when (looking-at "\\\\begin{[^}]*}") 795 (when (looking-at "\\\\begin{[^}]*}")
796 (setq cmd (reftex-match-string 0) 796 (setq cmd (reftex-match-string 0)
797 cnt (1- cnt))) 797 cnt (1- cnt)))
798 ;; This does ignore optional arguments. Very hard to fix. 798 ;; This does ignore optional arguments. Very hard to fix.
799 (when (setq entry (assoc cmd reftex-env-or-mac-alist)) 799 (when (setq entry (assoc cmd reftex-env-or-mac-alist))
800 (if (> cnt (or (nth 4 entry) 100)) 800 (if (> cnt (or (nth 4 entry) 100))
801 (setq cmd nil))) 801 (setq cmd nil)))
802 (cond 802 (cond
803 ((null cmd)) 803 ((null cmd))
804 ((eq t which) 804 ((eq t which)
805 (push (cons cmd (point)) cmd-list)) 805 (push (cons cmd (point)) cmd-list))
806 ((or (eq 1 which) (member cmd which)) 806 ((or (eq 1 which) (member cmd which))
807 (throw 'exit (cons cmd (point)))))) 807 (throw 'exit (cons cmd (point))))))
808 (goto-char pos))) 808 (goto-char pos)))
809 (nreverse cmd-list))))) 809 (nreverse cmd-list)))))
810 810
@@ -837,7 +837,7 @@ of master file."
837 (match-beginning 2) (match-end 2))) 837 (match-beginning 2) (match-end 2)))
838 (cond 838 (cond
839 ((string= (match-string 1) "end") 839 ((string= (match-string 1) "end")
840 (push env end-list)) 840 (push env end-list))
841 ((equal env (car end-list)) 841 ((equal env (car end-list))
842 (setq end-list (cdr end-list))) 842 (setq end-list (cdr end-list)))
843 ((eq t which) 843 ((eq t which)
@@ -867,25 +867,25 @@ of master file."
867 (let ((bound (or bound (save-excursion (re-search-backward 867 (let ((bound (or bound (save-excursion (re-search-backward
868 reftex-section-regexp nil 1) 868 reftex-section-regexp nil 1)
869 (point)))) 869 (point))))
870 (fun-list (if (listp which) 870 (fun-list (if (listp which)
871 (mapcar (lambda (x) (if (memq x which) x nil)) 871 (mapcar (lambda (x) (if (memq x which) x nil))
872 reftex-special-env-parsers) 872 reftex-special-env-parsers)
873 reftex-special-env-parsers)) 873 reftex-special-env-parsers))
874 specials rtn) 874 specials rtn)
875 ;; Call all functions 875 ;; Call all functions
876 (setq specials (mapcar 876 (setq specials (mapcar
877 (lambda (fun) 877 (lambda (fun)
878 (save-excursion 878 (save-excursion
879 (setq rtn (and fun (funcall fun bound))) 879 (setq rtn (and fun (funcall fun bound)))
880 (if rtn (cons (symbol-name fun) rtn) nil))) 880 (if rtn (cons (symbol-name fun) rtn) nil)))
881 fun-list)) 881 fun-list))
882 ;; Delete the non-matches 882 ;; Delete the non-matches
883 (setq specials (delq nil specials)) 883 (setq specials (delq nil specials))
884 ;; Sort 884 ;; Sort
885 (setq specials (sort specials (lambda (a b) (> (cdr a) (cdr b))))) 885 (setq specials (sort specials (lambda (a b) (> (cdr a) (cdr b)))))
886 (if (eq which t) 886 (if (eq which t)
887 specials 887 specials
888 (car specials)))))) 888 (car specials))))))
889 889
890(defsubst reftex-move-to-next-arg (&optional ignore) 890(defsubst reftex-move-to-next-arg (&optional ignore)
891 ;; Assuming that we are at the end of a macro name or a macro argument, 891 ;; Assuming that we are at the end of a macro name or a macro argument,
@@ -897,7 +897,7 @@ of master file."
897 ((memq (following-char) '(?\[ ?\{))) 897 ((memq (following-char) '(?\[ ?\{)))
898 ;; Do a search 898 ;; Do a search
899 ((and reftex-allow-detached-macro-args 899 ((and reftex-allow-detached-macro-args
900 (looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]")) 900 (looking-at "[ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*[[{]"))
901 (goto-char (1- (match-end 0))) 901 (goto-char (1- (match-end 0)))
902 t) 902 t)
903 (t nil))) 903 (t nil)))
@@ -916,39 +916,39 @@ of master file."
916 (if (= n 1000) 916 (if (= n 1000)
917 ;; Special case: Skip all touching arguments 917 ;; Special case: Skip all touching arguments
918 (progn 918 (progn
919 (reftex-move-over-touching-args) 919 (reftex-move-over-touching-args)
920 (reftex-context-substring)) 920 (reftex-context-substring))
921 921
922 ;; Do the real thing. 922 ;; Do the real thing.
923 (let ((cnt 1)) 923 (let ((cnt 1))
924 924
925 (when (reftex-move-to-next-arg) 925 (when (reftex-move-to-next-arg)
926 926
927 (while (< cnt n) 927 (while (< cnt n)
928 (while (and (member cnt opt-args) 928 (while (and (member cnt opt-args)
929 (eq (following-char) ?\{)) 929 (eq (following-char) ?\{))
930 (incf cnt)) 930 (incf cnt))
931 (when (< cnt n) 931 (when (< cnt n)
932 (unless (and (condition-case nil 932 (unless (and (condition-case nil
933 (or (forward-list 1) t) 933 (or (forward-list 1) t)
934 (error nil)) 934 (error nil))
935 (reftex-move-to-next-arg) 935 (reftex-move-to-next-arg)
936 (incf cnt)) 936 (incf cnt))
937 (setq cnt 1000)))) 937 (setq cnt 1000))))
938 938
939 (while (and (memq cnt opt-args) 939 (while (and (memq cnt opt-args)
940 (eq (following-char) ?\{)) 940 (eq (following-char) ?\{))
941 (incf cnt))) 941 (incf cnt)))
942 (if (and (= n cnt) 942 (if (and (= n cnt)
943 (> (skip-chars-forward "{\\[") 0)) 943 (> (skip-chars-forward "{\\[") 0))
944 (reftex-context-substring) 944 (reftex-context-substring)
945 nil)))) 945 nil))))
946 946
947(defun reftex-move-over-touching-args () 947(defun reftex-move-over-touching-args ()
948 (condition-case nil 948 (condition-case nil
949 (while (memq (following-char) '(?\[ ?\{)) 949 (while (memq (following-char) '(?\[ ?\{))
950 (forward-list 1)) 950 (forward-list 1))
951 (error nil))) 951 (error nil)))
952 952
953(defun reftex-context-substring (&optional to-end) 953(defun reftex-context-substring (&optional to-end)
954 ;; Return up to 150 chars from point 954 ;; Return up to 150 chars from point
@@ -959,11 +959,11 @@ of master file."
959 (buffer-substring-no-properties 959 (buffer-substring-no-properties
960 (point) 960 (point)
961 (min (+ (point) 150) 961 (min (+ (point) 150)
962 (save-match-data 962 (save-match-data
963 ;; FIXME: This is not perfect 963 ;; FIXME: THis is not perfect
964 (if (re-search-forward "\\\\end{" nil t) 964 (if (re-search-forward "\\\\end{" nil t)
965 (match-beginning 0) 965 (match-beginning 0)
966 (point-max)))))) 966 (point-max))))))
967 ((or (= (preceding-char) ?\{) 967 ((or (= (preceding-char) ?\{)
968 (= (preceding-char) ?\[)) 968 (= (preceding-char) ?\[))
969 ;; Inside a list - get only the list. 969 ;; Inside a list - get only the list.
@@ -978,8 +978,8 @@ of master file."
978 (error (point-max)))))) 978 (error (point-max))))))
979 (t 979 (t
980 ;; no list - just grab 150 characters 980 ;; no list - just grab 150 characters
981 (buffer-substring-no-properties (point) 981 (buffer-substring-no-properties (point)
982 (min (+ (point) 150) (point-max)))))) 982 (min (+ (point) 150) (point-max))))))
983 983
984;; Variable holding the vector with section numbers 984;; Variable holding the vector with section numbers
985(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0)) 985(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0))
@@ -994,11 +994,11 @@ of master file."
994 (while (>= i 0) 994 (while (>= i 0)
995 (if (> i level) 995 (if (> i level)
996 (aset reftex-section-numbers i 0) 996 (aset reftex-section-numbers i 0)
997 (setq number-string (or (car numbers) "0")) 997 (setq number-string (or (car numbers) "0"))
998 (if (string-match "\\`[A-Z]\\'" number-string) 998 (if (string-match "\\`[A-Z]\\'" number-string)
999 (aset reftex-section-numbers i 999 (aset reftex-section-numbers i
1000 (- (string-to-char number-string) ?A -1)) 1000 (- (string-to-char number-string) ?A -1))
1001 (aset reftex-section-numbers i (string-to-int number-string))) 1001 (aset reftex-section-numbers i (string-to-int number-string)))
1002 (pop numbers)) 1002 (pop numbers))
1003 (decf i))) 1003 (decf i)))
1004 (put 'reftex-section-numbers 'appendix appendix)) 1004 (put 'reftex-section-numbers 'appendix appendix))
@@ -1007,66 +1007,65 @@ of master file."
1007 ;; Return a string with the current section number. 1007 ;; Return a string with the current section number.
1008 ;; When LEVEL is non-nil, increase section numbers on that level. 1008 ;; When LEVEL is non-nil, increase section numbers on that level.
1009 (let* ((depth (1- (length reftex-section-numbers))) idx n (string "") 1009 (let* ((depth (1- (length reftex-section-numbers))) idx n (string "")
1010 (appendix (get 'reftex-section-numbers 'appendix)) 1010 (appendix (get 'reftex-section-numbers 'appendix))
1011 (partspecial (and (not reftex-part-resets-chapter) 1011 (partspecial (and (not reftex-part-resets-chapter)
1012 (equal level 0)))) 1012 (equal level 0))))
1013 ;; partspecial means, this is a part statement. 1013 ;; partspecial means, this is a part statement.
1014 ;; Parts do not reset the chapter counter, and the part number is 1014 ;; Parts do not reset the chapter counter, and the part number is
1015 ;; not included in the numbering of other sectioning levels. 1015 ;; not included in the numbering of other sectioning levels.
1016 (when level 1016 (when level
1017 (when (and (> level -1) (not star)) 1017 (when (and (> level -1) (not star))
1018 (aset reftex-section-numbers 1018 (aset reftex-section-numbers
1019 level (1+ (aref reftex-section-numbers level)))) 1019 level (1+ (aref reftex-section-numbers level))))
1020 (setq idx (1+ level)) 1020 (setq idx (1+ level))
1021 (when (not star) 1021 (when (not star)
1022 (while (<= idx depth) 1022 (while (<= idx depth)
1023 (if (or (not partspecial) 1023 (if (or (not partspecial)
1024 (not (= idx 1))) 1024 (not (= idx 1)))
1025 (aset reftex-section-numbers idx 0)) 1025 (aset reftex-section-numbers idx 0))
1026 (incf idx)))) 1026 (incf idx))))
1027 (if partspecial 1027 (if partspecial
1028 (setq string (concat "Part " (reftex-roman-number 1028 (setq string (concat "Part " (reftex-roman-number
1029 (aref reftex-section-numbers 0)))) 1029 (aref reftex-section-numbers 0))))
1030 (setq idx (if reftex-part-resets-chapter 0 1)) 1030 (setq idx (if reftex-part-resets-chapter 0 1))
1031 (while (<= idx depth) 1031 (while (<= idx depth)
1032 (setq n (aref reftex-section-numbers idx)) 1032 (setq n (aref reftex-section-numbers idx))
1033 (if (not (and partspecial (not (equal string "")))) 1033 (if (not (and partspecial (not (equal string ""))))
1034 (setq string (concat string (if (not (string= string "")) "." "") 1034 (setq string (concat string (if (not (string= string "")) "." "")
1035 (int-to-string n)))) 1035 (int-to-string n))))
1036 (incf idx)) 1036 (incf idx))
1037 (save-match-data 1037 (save-match-data
1038 (if (string-match "\\`\\([@0]\\.\\)+" string) 1038 (if (string-match "\\`\\([@0]\\.\\)+" string)
1039 (setq string (replace-match "" nil nil string))) 1039 (setq string (replace-match "" nil nil string)))
1040 (if (string-match "\\(\\.0\\)+\\'" string) 1040 (if (string-match "\\(\\.0\\)+\\'" string)
1041 (setq string (replace-match "" nil nil string))) 1041 (setq string (replace-match "" nil nil string)))
1042 (if (and appendix 1042 (if (and appendix
1043 (string-match "\\`[0-9]+" string)) 1043 (string-match "\\`[0-9]+" string))
1044 (setq string 1044 (setq string
1045 (concat 1045 (concat
1046 (char-to-string 1046 (char-to-string
1047 (1- (+ ?A (string-to-int (match-string 0 string))))) 1047 (1- (+ ?A (string-to-int (match-string 0 string)))))
1048 (substring string (match-end 0)))))) 1048 (substring string (match-end 0))))))
1049 (if star 1049 (if star
1050 (concat (make-string (1- (length string)) ?\ ) "*") 1050 (concat (make-string (1- (length string)) ?\ ) "*")
1051 string)))) 1051 string))))
1052 1052
1053(defun reftex-roman-number (n) 1053(defun reftex-roman-number (n)
1054 ;; Return as a string the roman number equal to N. 1054 ;; Return as a string the roman number equal to N.
1055 (let ((nrest n) 1055 (let ((nrest n)
1056 (string "") 1056 (string "")
1057 (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD") 1057 (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD")
1058 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL") 1058 ( 100 . "C") ( 90 . "XC") ( 50 . "L") ( 40 . "XL")
1059 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV") 1059 ( 10 . "X") ( 9 . "IX") ( 5 . "V") ( 4 . "IV")
1060 ( 1 . "I"))) 1060 ( 1 . "I")))
1061 listel i s) 1061 listel i s)
1062 (while (>= nrest 1) 1062 (while (>= nrest 1)
1063 (setq listel (pop list) 1063 (setq listel (pop list)
1064 i (car listel) 1064 i (car listel)
1065 s (cdr listel)) 1065 s (cdr listel))
1066 (while (>= nrest i) 1066 (while (>= nrest i)
1067 (setq string (concat string s) 1067 (setq string (concat string s)
1068 nrest (- nrest i)))) 1068 nrest (- nrest i))))
1069 string)) 1069 string))
1070 1070
1071;;; arch-tag: 6a8168f7-abb9-4576-99dc-fcbc7ba901a3
1072;;; reftex-parse.el ends here 1071;;; reftex-parse.el ends here
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 2d4935aedde..9991c0b2f77 100644
--- a/lisp/textmodes/reftex-ref.el
+++ b/lisp/textmodes/reftex-ref.el
@@ -1,8 +1,8 @@
1;;; reftex-ref.el --- code to create labels and references with RefTeX 1;;; reftex-ref.el --- code to create labels and references with RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -36,11 +36,11 @@ If optional BOUND is an integer, limit backward searches to that point."
36 36
37 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound)) 37 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
38 (loc2 (reftex-what-environment reftex-label-env-list bound)) 38 (loc2 (reftex-what-environment reftex-label-env-list bound))
39 (loc3 (reftex-what-special-env 1 bound)) 39 (loc3 (reftex-what-special-env 1 bound))
40 (p1 (or (cdr loc1) 0)) 40 (p1 (or (cdr loc1) 0))
41 (p2 (or (cdr loc2) 0)) 41 (p2 (or (cdr loc2) 0))
42 (p3 (or (cdr loc3) 0)) 42 (p3 (or (cdr loc3) 0))
43 (pmax (max p1 p2 p3))) 43 (pmax (max p1 p2 p3)))
44 44
45 (setq reftex-location-start pmax) 45 (setq reftex-location-start pmax)
46 (cond 46 (cond
@@ -57,9 +57,9 @@ If optional BOUND is an integer, limit backward searches to that point."
57 (setq reftex-default-context-position p3) 57 (setq reftex-default-context-position p3)
58 (setq loc3 (car loc3)) 58 (setq loc3 (car loc3))
59 (cond ((null loc3) "section") 59 (cond ((null loc3) "section")
60 ((symbolp loc3) (symbol-name loc3)) 60 ((symbolp loc3) (symbol-name loc3))
61 ((stringp loc3) loc3) 61 ((stringp loc3) loc3)
62 (t "section"))) 62 (t "section")))
63 (t ;; This should not happen, I think? 63 (t ;; This should not happen, I think?
64 "section")))) 64 "section"))))
65 65
@@ -83,11 +83,11 @@ If optional BOUND is an integer, limit backward searches to that point."
83 (goto-char 1) 83 (goto-char 1)
84 84
85 (if (or (re-search-forward 85 (if (or (re-search-forward
86 (format reftex-find-label-regexp-format 86 (format reftex-find-label-regexp-format
87 (regexp-quote label)) nil t) 87 (regexp-quote label)) nil t)
88 (re-search-forward 88 (re-search-forward
89 (format reftex-find-label-regexp-format2 89 (format reftex-find-label-regexp-format2
90 (regexp-quote label)) nil t)) 90 (regexp-quote label)) nil t))
91 91
92 (progn 92 (progn
93 (backward-char 1) 93 (backward-char 1)
@@ -102,7 +102,7 @@ If optional BOUND is an integer, limit backward searches to that point."
102 (parse (nth 2 (assoc env-or-mac reftex-env-or-mac-alist))) 102 (parse (nth 2 (assoc env-or-mac reftex-env-or-mac-alist)))
103 (text (reftex-short-context env-or-mac parse reftex-location-start 103 (text (reftex-short-context env-or-mac parse reftex-location-start
104 derive)) 104 derive))
105 (in-comment (reftex-in-comment))) 105 (in-comment (reftex-in-comment)))
106 (list label typekey text file in-comment))) 106 (list label typekey text file in-comment)))
107 107
108;;; Creating labels --------------------------------------------------------- 108;;; Creating labels ---------------------------------------------------------
@@ -132,18 +132,18 @@ This function is controlled by the settings of reftex-insert-label-flags."
132 ;; Ok, go ahead. 132 ;; Ok, go ahead.
133 (catch 'exit 133 (catch 'exit
134 (let* ((entry (assoc environment reftex-env-or-mac-alist)) 134 (let* ((entry (assoc environment reftex-env-or-mac-alist))
135 (typekey (nth 1 entry)) 135 (typekey (nth 1 entry))
136 (format (nth 3 entry)) 136 (format (nth 3 entry))
137 (macro-cell (reftex-what-macro 1)) 137 (macro-cell (reftex-what-macro 1))
138 (entry1 (assoc (car macro-cell) reftex-env-or-mac-alist)) 138 (entry1 (assoc (car macro-cell) reftex-env-or-mac-alist))
139 label naked prefix valid default force-prompt rescan-is-useful) 139 label naked prefix valid default force-prompt rescan-is-useful)
140 (when (and (or (nth 5 entry) (nth 5 entry1)) 140 (when (and (or (nth 5 entry) (nth 5 entry1))
141 (memq (preceding-char) '(?\[ ?\{))) 141 (memq (preceding-char) '(?\[ ?\{)))
142 ;; This is an argument of a label macro. Insert naked label. 142 ;; This is an argument of a label macro. Insert naked label.
143 (setq naked t format "%s")) 143 (setq naked t format "%s"))
144 144
145 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist)) 145 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
146 (concat typekey "-"))) 146 (concat typekey "-")))
147 ;; Replace any escapes in the prefix 147 ;; Replace any escapes in the prefix
148 (setq prefix (reftex-replace-prefix-escapes prefix)) 148 (setq prefix (reftex-replace-prefix-escapes prefix))
149 149
@@ -151,115 +151,115 @@ This function is controlled by the settings of reftex-insert-label-flags."
151 (cond 151 (cond
152 152
153 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags)) 153 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
154 ;; Derive a label from context. 154 ;; Derive a label from context.
155 (setq reftex-active-toc (reftex-last-assoc-before-elt 155 (setq reftex-active-toc (reftex-last-assoc-before-elt
156 'toc (car (reftex-where-am-I)) 156 'toc (car (reftex-where-am-I))
157 (symbol-value reftex-docstruct-symbol))) 157 (symbol-value reftex-docstruct-symbol)))
158 (setq default (reftex-no-props 158 (setq default (reftex-no-props
159 (nth 2 (reftex-label-info " " nil nil t)))) 159 (nth 2 (reftex-label-info " " nil nil t))))
160 ;; Catch the cases where the is actually no context available. 160 ;; Catch the cases where the is actually no context available.
161 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default) 161 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
162 (string-match "ILLEGAL VALUE OF PARSE" default) 162 (string-match "ILLEGAL VALUE OF PARSE" default)
163 (string-match "SECTION HEADING NOT FOUND" default) 163 (string-match "SECTION HEADING NOT FOUND" default)
164 (string-match "HOOK ERROR" default) 164 (string-match "HOOK ERROR" default)
165 (string-match "^[ \t]*$" default)) 165 (string-match "^[ \t]*$" default))
166 (setq default prefix 166 (setq default prefix
167 force-prompt t) ; need to prompt 167 force-prompt t) ; need to prompt
168 (setq default 168 (setq default
169 (concat prefix 169 (concat prefix
170 (funcall reftex-string-to-label-function default))) 170 (funcall reftex-string-to-label-function default)))
171 171
172 ;; Make it unique. 172 ;; Make it unique.
173 (setq default (reftex-uniquify-label default nil "-")))) 173 (setq default (reftex-uniquify-label default nil "-"))))
174 174
175 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) 175 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags))
176 ;; Minimal default: the user will be prompted. 176 ;; Minimal default: the user will be prompted.
177 (setq default prefix)) 177 (setq default prefix))
178 178
179 (t 179 (t
180 ;; Make an automatic label. 180 ;; Make an automatic label.
181 (setq default (reftex-uniquify-label prefix t)))) 181 (setq default (reftex-uniquify-label prefix t))))
182 182
183 ;; Should we ask the user? 183 ;; Should we ask the user?
184 (if (or (reftex-typekey-check typekey 184 (if (or (reftex-typekey-check typekey
185 (nth 1 reftex-insert-label-flags)) ; prompt 185 (nth 1 reftex-insert-label-flags)) ; prompt
186 force-prompt) 186 force-prompt)
187 187
188 (while (not valid) 188 (while (not valid)
189 ;; iterate until we get a legal label 189 ;; iterate until we get a legal label
190 190
191 (setq label (read-string 191 (setq label (read-string
192 (if naked "Naked Label: " "Label: ") 192 (if naked "Naked Label: " "Label: ")
193 default)) 193 default))
194 194
195 ;; Lets make sure that this is a legal label 195 ;; Lets make sure that this is a legal label
196 (cond 196 (cond
197 197
198 ((string-match (concat "\\`\\(" (regexp-quote prefix) 198 ((string-match (concat "\\`\\(" (regexp-quote prefix)
199 "\\)?[ \t]*\\'") 199 "\\)?[ \t]*\\'")
200 label) 200 label)
201 ;; No label at all, please 201 ;; No label at all, please
202 (message "No label inserted.") 202 (message "No label inserted.")
203 (throw 'exit nil)) 203 (throw 'exit nil))
204 204
205 ;; Test if label contains strange characters 205 ;; Test if label contains strange characters
206 ((string-match reftex-label-illegal-re label) 206 ((string-match reftex-label-illegal-re label)
207 (message "Label \"%s\" contains illegal characters" label) 207 (message "Label \"%s\" contains illegal characters" label)
208 (ding) 208 (ding)
209 (sit-for 2)) 209 (sit-for 2))
210 210
211 ;; Look it up in the label list 211 ;; Look it up in the label list
212 ((setq entry (assoc label 212 ((setq entry (assoc label
213 (symbol-value reftex-docstruct-symbol))) 213 (symbol-value reftex-docstruct-symbol)))
214 (ding) 214 (ding)
215 (if (y-or-n-p 215 (if (y-or-n-p
216 (format "Label '%s' exists. Use anyway? " label)) 216 (format "Label '%s' exists. Use anyway? " label))
217 (setq valid t))) 217 (setq valid t)))
218 218
219 ;; Label is ok 219 ;; Label is ok
220 (t 220 (t
221 (setq valid t)))) 221 (setq valid t))))
222 (setq label default)) 222 (setq label default))
223 223
224 ;; Insert the label into the label list 224 ;; Insert the label into the label list
225 (let* ((here-I-am-info 225 (let* ((here-I-am-info
226 (save-excursion 226 (save-excursion
227 (if (and (or naked no-insert) 227 (if (and (or naked no-insert)
228 (integerp (cdr macro-cell))) 228 (integerp (cdr macro-cell)))
229 (goto-char (cdr macro-cell))) 229 (goto-char (cdr macro-cell)))
230 (reftex-where-am-I))) 230 (reftex-where-am-I)))
231 (here-I-am (car here-I-am-info)) 231 (here-I-am (car here-I-am-info))
232 (note (if (cdr here-I-am-info) 232 (note (if (cdr here-I-am-info)
233 "" 233 ""
234 "POSITION UNCERTAIN. RESCAN TO FIX.")) 234 "POSITION UNCERTAIN. RESCAN TO FIX."))
235 (file (buffer-file-name)) 235 (file (buffer-file-name))
236 (text nil) 236 (text nil)
237 (tail (memq here-I-am (symbol-value reftex-docstruct-symbol)))) 237 (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
238 238
239 (or (cdr here-I-am-info) (setq rescan-is-useful t)) 239 (or (cdr here-I-am-info) (setq rescan-is-useful t))
240 240
241 (when tail 241 (when tail
242 (push (list label typekey text file nil note) (cdr tail)) 242 (push (list label typekey text file nil note) (cdr tail))
243 (put reftex-docstruct-symbol 'modified t))) 243 (put reftex-docstruct-symbol 'modified t)))
244 244
245 ;; Insert the label into the buffer 245 ;; Insert the label into the buffer
246 (unless no-insert 246 (unless no-insert
247 (insert 247 (insert
248 (if reftex-format-label-function 248 (if reftex-format-label-function
249 (funcall reftex-format-label-function label format) 249 (funcall reftex-format-label-function label format)
250 (format format label))) 250 (format format label)))
251 (if (and reftex-plug-into-AUCTeX 251 (if (and reftex-plug-into-AUCTeX
252 (fboundp 'LaTeX-add-labels)) 252 (fboundp 'LaTeX-add-labels))
253 ;; Tell AUCTeX about this 253 ;; Tell AUCTeX about this
254 (LaTeX-add-labels label))) 254 (LaTeX-add-labels label)))
255 255
256 ;; Delete the corresponding selection buffers to force update on next use. 256 ;; Delete the corresponding selection buffers to force update on next use.
257 (when reftex-auto-update-selection-buffers 257 (when reftex-auto-update-selection-buffers
258 (reftex-erase-buffer (reftex-make-selection-buffer-name typekey)) 258 (reftex-erase-buffer (reftex-make-selection-buffer-name typekey))
259 (reftex-erase-buffer (reftex-make-selection-buffer-name " "))) 259 (reftex-erase-buffer (reftex-make-selection-buffer-name " ")))
260 260
261 (when (and rescan-is-useful reftex-allow-automatic-rescan) 261 (when (and rescan-is-useful reftex-allow-automatic-rescan)
262 (reftex-parse-one)) 262 (reftex-parse-one))
263 263
264 ;; return value of the function is the label 264 ;; return value of the function is the label
265 label))) 265 label)))
@@ -269,24 +269,24 @@ This function is controlled by the settings of reftex-insert-label-flags."
269Uses `reftex-derive-label-parameters' and `reftex-label-illegal-re'. It 269Uses `reftex-derive-label-parameters' and `reftex-label-illegal-re'. It
270also applies `reftex-translate-to-ascii-function' to the string." 270also applies `reftex-translate-to-ascii-function' to the string."
271 (when (and reftex-translate-to-ascii-function 271 (when (and reftex-translate-to-ascii-function
272 (fboundp reftex-translate-to-ascii-function)) 272 (fboundp reftex-translate-to-ascii-function))
273 (setq string (funcall reftex-translate-to-ascii-function string))) 273 (setq string (funcall reftex-translate-to-ascii-function string)))
274 (apply 'reftex-convert-string string 274 (apply 'reftex-convert-string string
275 "[-~ \t\n\r,;]+" reftex-label-illegal-re nil nil 275 "[-~ \t\n\r,;]+" reftex-label-illegal-re nil nil
276 reftex-derive-label-parameters)) 276 reftex-derive-label-parameters))
277 277
278(defun reftex-latin1-to-ascii (string) 278(defun reftex-latin1-to-ascii (string)
279 ;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents 279 ;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents
280 (let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy") 280 (let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy")
281 (emacsp (not (featurep 'xemacs)))) 281 (emacsp (not (featurep 'xemacs))))
282 (mapconcat 282 (mapconcat
283 (lambda (c) 283 (lambda (c)
284 (cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1 284 (cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1
285 (char-to-string (aref tab (- c 128)))) 285 (char-to-string (aref tab (- c 128))))
286 ((and emacsp ; Not for XEmacs 286 ((and emacsp ; Not for XEmacs
287 (> c 2175) (< c 2304)) ; Mule Latin-1 287 (> c 2175) (< c 2304)) ; Mule Latin-1
288 (char-to-string (aref tab (- c 2176)))) 288 (char-to-string (aref tab (- c 2176))))
289 (t (char-to-string c)))) 289 (t (char-to-string c))))
290 string ""))) 290 string "")))
291 291
292(defun reftex-replace-prefix-escapes (prefix) 292(defun reftex-replace-prefix-escapes (prefix)
@@ -309,21 +309,21 @@ also applies `reftex-translate-to-ascii-function' to the string."
309 file))) 309 file)))
310 ((equal letter "u") 310 ((equal letter "u")
311 (or (user-login-name) "")) 311 (or (user-login-name) ""))
312 ((equal letter "S") 312 ((equal letter "S")
313 (let* (macro level-exp level) 313 (let* (macro level-exp level)
314 (save-excursion 314 (save-excursion
315 (save-match-data 315 (save-match-data
316 (when (re-search-backward reftex-section-regexp nil t) 316 (when (re-search-backward reftex-section-regexp nil t)
317 (setq macro (reftex-match-string 2) 317 (setq macro (reftex-match-string 2)
318 level-exp (cdr (assoc macro reftex-section-levels-all)) 318 level-exp (cdr (assoc macro reftex-section-levels-all))
319 level (if (symbolp level-exp) 319 level (if (symbolp level-exp)
320 (abs (save-match-data 320 (abs (save-match-data
321 (funcall level-exp))) 321 (funcall level-exp)))
322 (abs level-exp)))) 322 (abs level-exp))))
323 (cdr (or (assoc macro reftex-section-prefixes) 323 (cdr (or (assoc macro reftex-section-prefixes)
324 (assoc level reftex-section-prefixes) 324 (assoc level reftex-section-prefixes)
325 (assq t reftex-section-prefixes) 325 (assq t reftex-section-prefixes)
326 (list t "sec:"))))))) 326 (list t "sec:")))))))
327 (t ""))) 327 (t "")))
328 (setq num (1- (+ (match-beginning 1) (length replace))) 328 (setq num (1- (+ (match-beginning 1) (length replace)))
329 prefix (replace-match replace nil nil prefix))) 329 prefix (replace-match replace nil nil prefix)))
@@ -396,40 +396,40 @@ When called with 2 C-u prefix args, disable magic word recognition."
396 ;; check for active recursive edits 396 ;; check for active recursive edits
397 (reftex-check-recursive-edit) 397 (reftex-check-recursive-edit)
398 398
399 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4) 399 ;; Ensure access to scanning info and rescan buffer if prefix arg is '(4)
400 (reftex-access-scan-info current-prefix-arg) 400 (reftex-access-scan-info current-prefix-arg)
401 401
402 (unless type 402 (unless type
403 ;; guess type from context 403 ;; guess type from context
404 (if (and reftex-guess-label-type 404 (if (and reftex-guess-label-type
405 (setq type (reftex-guess-label-type))) 405 (setq type (reftex-guess-label-type)))
406 (setq cut (cdr type) 406 (setq cut (cdr type)
407 type (car type)) 407 type (car type))
408 (setq type (reftex-query-label-type)))) 408 (setq type (reftex-query-label-type))))
409 409
410 (let* ((refstyle 410 (let* ((refstyle
411 (cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref") 411 (cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref")
412 ((reftex-typekey-check type reftex-fref-is-default) "\\fref") 412 ((reftex-typekey-check type reftex-fref-is-default) "\\fref")
413 (t "\\ref"))) 413 (t "\\ref")))
414 (reftex-format-ref-function reftex-format-ref-function) 414 (reftex-format-ref-function reftex-format-ref-function)
415 (form "\\ref{%s}") 415 (form "\\ref{%s}")
416 label labels sep sep1) 416 label labels sep sep1)
417 417
418 ;; Have the user select a label 418 ;; Have the user select a label
419 (set-marker reftex-select-return-marker (point)) 419 (set-marker reftex-select-return-marker (point))
420 (setq labels (save-excursion 420 (setq labels (save-excursion
421 (reftex-offer-label-menu type))) 421 (reftex-offer-label-menu type)))
422 (reftex-ensure-compiled-variables) 422 (reftex-ensure-compiled-variables)
423 (set-marker reftex-select-return-marker nil) 423 (set-marker reftex-select-return-marker nil)
424 ;; If the first entry is the symbol 'concat, concat all labels. 424 ;; If the first entry is the symbol 'concat, concat all labels.
425 ;; We keep the cdr of the first label for typekey etc information. 425 ;; We keep the cdr of the first label for typekey etc information.
426 (if (eq (car labels) 'concat) 426 (if (eq (car labels) 'concat)
427 (setq labels (list (list (mapconcat 'car (cdr labels) ",") 427 (setq labels (list (list (mapconcat 'car (cdr labels) ",")
428 (cdr (nth 1 labels)))))) 428 (cdr (nth 1 labels))))))
429 (setq type (nth 1 (car labels)) 429 (setq type (nth 1 (car labels))
430 form (or (cdr (assoc type reftex-typekey-to-format-alist)) 430 form (or (cdr (assoc type reftex-typekey-to-format-alist))
431 form)) 431 form))
432 432
433 (cond 433 (cond
434 (no-insert 434 (no-insert
435 ;; Just return the first label 435 ;; Just return the first label
@@ -439,60 +439,60 @@ When called with 2 C-u prefix args, disable magic word recognition."
439 nil) 439 nil)
440 (t 440 (t
441 (while labels 441 (while labels
442 (setq label (car (car labels)) 442 (setq label (car (car labels))
443 sep (nth 2 (car labels)) 443 sep (nth 2 (car labels))
444 sep1 (cdr (assoc sep reftex-multiref-punctuation)) 444 sep1 (cdr (assoc sep reftex-multiref-punctuation))
445 labels (cdr labels)) 445 labels (cdr labels))
446 (when cut 446 (when cut
447 (backward-delete-char cut) 447 (backward-delete-char cut)
448 (setq cut nil)) 448 (setq cut nil))
449 449
450 ;; remove ~ if we do already have a space 450 ;; remove ~ if we do already have a space
451 (when (and (= ?~ (string-to-char form)) 451 (when (and (= ?~ (string-to-char form))
452 (member (preceding-char) '(?\ ?\t ?\n ?. ?~))) 452 (member (preceding-char) '(?\ ?\t ?\n)))
453 (setq form (substring form 1))) 453 (setq form (substring form 1)))
454 ;; do we have a special format? 454 ;; do we have a special format?
455 (setq reftex-format-ref-function 455 (setq reftex-format-ref-function
456 (cond 456 (cond
457 ((string= refstyle "\\vref") 'reftex-format-vref) 457 ((string= refstyle "\\vref") 'reftex-format-vref)
458 ((string= refstyle "\\fref") 'reftex-format-fref) 458 ((string= refstyle "\\fref") 'reftex-format-fref)
459 ((string= refstyle "\\Fref") 'reftex-format-Fref) 459 ((string= refstyle "\\Fref") 'reftex-format-Fref)
460 (t reftex-format-ref-function))) 460 (t reftex-format-ref-function)))
461 ;; ok, insert the reference 461 ;; ok, insert the reference
462 (if sep1 (insert sep1)) 462 (if sep1 (insert sep1))
463 (insert 463 (insert
464 (if reftex-format-ref-function 464 (if reftex-format-ref-function
465 (funcall reftex-format-ref-function label form) 465 (funcall reftex-format-ref-function label form)
466 (format form label label))) 466 (format form label label)))
467 ;; take out the initial ~ for good 467 ;; take out the initial ~ for good
468 (and (= ?~ (string-to-char form)) 468 (and (= ?~ (string-to-char form))
469 (setq form (substring form 1)))) 469 (setq form (substring form 1))))
470 (message "") 470 (message "")
471 label)))) 471 label))))
472 472
473(defun reftex-guess-label-type () 473(defun reftex-guess-label-type ()
474 ;; Examine context to guess what a \ref might want to reference. 474 ;; Examine context to guess what a \ref might want to reference.
475 (let ((words reftex-words-to-typekey-alist) 475 (let ((words reftex-words-to-typekey-alist)
476 (case-fold-search t) 476 (case-fold-search t)
477 (bound (max (point-min) (- (point) 35))) 477 (bound (max (point-min) (- (point) 35)))
478 matched cell) 478 matched cell)
479 (save-excursion 479 (save-excursion
480 (while (and (setq cell (pop words)) 480 (while (and (setq cell (pop words))
481 (not (setq matched 481 (not (setq matched
482 (re-search-backward (car cell) bound t)))))) 482 (re-search-backward (car cell) bound t))))))
483 (if matched 483 (if matched
484 (cons (cdr cell) (- (match-end 0) (match-end 1))) 484 (cons (cdr cell) (- (match-end 0) (match-end 1)))
485 nil))) 485 nil)))
486 486
487(defvar reftex-select-label-map) 487(defvar reftex-select-label-map)
488(defun reftex-offer-label-menu (typekey) 488(defun reftex-offer-label-menu (typekey)
489 ;; Offer a menu with the appropriate labels. 489 ;; Offer a menu with the appropriate labels.
490 (let* ((buf (current-buffer)) 490 (let* ((buf (current-buffer))
491 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) 491 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
492 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) 492 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
493 (xr-index 0) 493 (xr-index 0)
494 (here-I-am (car (reftex-where-am-I))) 494 (here-I-am (car (reftex-where-am-I)))
495 (here-I-am1 here-I-am) 495 (here-I-am1 here-I-am)
496 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0)) 496 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
497 (files (reftex-typekey-check typekey reftex-label-menu-flags 7)) 497 (files (reftex-typekey-check typekey reftex-label-menu-flags 7))
498 (context (not (reftex-typekey-check 498 (context (not (reftex-typekey-check
@@ -502,158 +502,158 @@ When called with 2 C-u prefix args, disable magic word recognition."
502 (follow (reftex-typekey-check 502 (follow (reftex-typekey-check
503 typekey reftex-label-menu-flags 4)) 503 typekey reftex-label-menu-flags 4))
504 (commented (nth 5 reftex-label-menu-flags)) 504 (commented (nth 5 reftex-label-menu-flags))
505 (prefix "") 505 (prefix "")
506 selection-buffers 506 selection-buffers
507 offset rtn key data last-data entries) 507 offset rtn key data last-data entries)
508 508
509 (unwind-protect 509 (unwind-protect
510 (catch 'exit 510 (catch 'exit
511 (while t 511 (while t
512 (save-window-excursion 512 (save-window-excursion
513 (delete-other-windows) 513 (delete-other-windows)
514 (setq reftex-call-back-to-this-buffer buf 514 (setq reftex-call-back-to-this-buffer buf
515 reftex-latex-syntax-table (syntax-table)) 515 reftex-latex-syntax-table (syntax-table))
516 (let ((default-major-mode 'reftex-select-label-mode)) 516 (let ((default-major-mode 'reftex-select-label-mode))
517 (if reftex-use-multiple-selection-buffers 517 (if reftex-use-multiple-selection-buffers
518 (switch-to-buffer-other-window 518 (switch-to-buffer-other-window
519 (save-excursion 519 (save-excursion
520 (set-buffer buf) 520 (set-buffer buf)
521 (reftex-make-selection-buffer-name typekey))) 521 (reftex-make-selection-buffer-name typekey)))
522 (switch-to-buffer-other-window "*RefTeX Select*") 522 (switch-to-buffer-other-window "*RefTeX Select*")
523 (reftex-erase-buffer))) 523 (reftex-erase-buffer)))
524 (unless (eq major-mode 'reftex-select-label-mode) 524 (unless (eq major-mode 'reftex-select-label-mode)
525 (reftex-select-label-mode)) 525 (reftex-select-label-mode))
526 (add-to-list 'selection-buffers (current-buffer)) 526 (add-to-list 'selection-buffers (current-buffer))
527 (setq truncate-lines t) 527 (setq truncate-lines t)
528 (setq mode-line-format 528 (setq mode-line-format
529 (list "---- " 'mode-line-buffer-identification 529 (list "---- " 'mode-line-buffer-identification
530 " " 'global-mode-string " (" mode-name ")" 530 " " 'global-mode-string " (" mode-name ")"
531 " S<" 'refstyle ">" 531 " S<" 'refstyle ">"
532 " -%-")) 532 " -%-"))
533 (cond 533 (cond
534 ((= 0 (buffer-size)) 534 ((= 0 (buffer-size))
535 (let ((buffer-read-only nil)) 535 (let ((buffer-read-only nil))
536 (message "Creating Selection Buffer...") 536 (message "Creating Selection Buffer...")
537 (setq offset (reftex-insert-docstruct 537 (setq offset (reftex-insert-docstruct
538 buf 538 buf
539 toc 539 toc
540 typekey 540 typekey
541 nil ; index 541 nil ; index
542 files 542 files
543 context 543 context
544 counter 544 counter
545 commented 545 commented
546 (or here-I-am offset) 546 (or here-I-am offset)
547 prefix 547 prefix
548 nil ; no a toc buffer 548 nil ; no a toc buffer
549 )))) 549 ))))
550 (here-I-am 550 (here-I-am
551 (setq offset (reftex-get-offset buf here-I-am typekey))) 551 (setq offset (reftex-get-offset buf here-I-am typekey)))
552 (t (setq offset t))) 552 (t (setq offset t)))
553 (setq buffer-read-only t) 553 (setq buffer-read-only t)
554 (setq offset (or offset t)) 554 (setq offset (or offset t))
555 555
556 (setq here-I-am nil) ; turn off determination of offset 556 (setq here-I-am nil) ; turn off determination of offset
557 (setq rtn 557 (setq rtn
558 (reftex-select-item 558 (reftex-select-item
559 reftex-select-label-prompt 559 reftex-select-label-prompt
560 reftex-select-label-help 560 reftex-select-label-help
561 reftex-select-label-map 561 reftex-select-label-map
562 offset 562 offset
563 'reftex-show-label-location follow)) 563 'reftex-show-label-location follow))
564 (setq key (car rtn) 564 (setq key (car rtn)
565 data (nth 1 rtn) 565 data (nth 1 rtn)
566 last-data (nth 2 rtn) 566 last-data (nth 2 rtn)
567 offset t) 567 offset t)
568 (unless key (throw 'exit nil)) 568 (unless key (throw 'exit nil))
569 (cond 569 (cond
570 ((eq key ?g) 570 ((eq key ?g)
571 ;; update buffer 571 ;; update buffer
572 (reftex-erase-buffer)) 572 (reftex-erase-buffer))
573 ((or (eq key ?r) 573 ((or (eq key ?r)
574 (eq key ?R)) 574 (eq key ?R))
575 ;; rescan buffer 575 ;; rescan buffer
576 (and current-prefix-arg (setq key ?R)) 576 (and current-prefix-arg (setq key ?R))
577 (reftex-erase-buffer) 577 (reftex-erase-buffer)
578 (reftex-reparse-document buf last-data key)) 578 (reftex-reparse-document buf last-data key))
579 ((eq key ?c) 579 ((eq key ?c)
580 ;; toggle context mode 580 ;; toggle context mode
581 (reftex-erase-buffer) 581 (reftex-erase-buffer)
582 (setq context (not context))) 582 (setq context (not context)))
583 ((eq key ?s) 583 ((eq key ?s)
584 ;; switch type 584 ;; switch type
585 (setq here-I-am here-I-am1) 585 (setq here-I-am here-I-am1)
586 (setq typekey (reftex-query-label-type))) 586 (setq typekey (reftex-query-label-type)))
587 ((eq key ?t) 587 ((eq key ?t)
588 ;; toggle table of contents display, or change depth 588 ;; toggle table of contents display, or change depth
589 (reftex-erase-buffer) 589 (reftex-erase-buffer)
590 (if current-prefix-arg 590 (if current-prefix-arg
591 (setq reftex-toc-max-level (prefix-numeric-value 591 (setq reftex-toc-max-level (prefix-numeric-value
592 current-prefix-arg)) 592 current-prefix-arg))
593 (setq toc (not toc)))) 593 (setq toc (not toc))))
594 ((eq key ?F) 594 ((eq key ?F)
595 ;; toggle display of included file borders 595 ;; toggle display of included file borders
596 (reftex-erase-buffer) 596 (reftex-erase-buffer)
597 (setq files (not files))) 597 (setq files (not files)))
598 ((eq key ?#) 598 ((eq key ?#)
599 ;; toggle counter display 599 ;; toggle counter display
600 (reftex-erase-buffer) 600 (reftex-erase-buffer)
601 (setq counter (not counter))) 601 (setq counter (not counter)))
602 ((eq key ?%) 602 ((eq key ?%)
603 ;; toggle display of commented labels 603 ;; toggle display of commented labels
604 (reftex-erase-buffer) 604 (reftex-erase-buffer)
605 (setq commented (not commented))) 605 (setq commented (not commented)))
606 ((eq key ?l) 606 ((eq key ?l)
607 ;; reuse the last referenced label again 607 ;; reuse the last referenced label again
608 (setq entries reftex-last-used-reference) 608 (setq entries reftex-last-used-reference)
609 (throw 'exit t)) 609 (throw 'exit t))
610 ((eq key ?x) 610 ((eq key ?x)
611 ;; select an external document 611 ;; select an external document
612 (setq xr-index (reftex-select-external-document 612 (setq xr-index (reftex-select-external-document
613 xr-alist xr-index)) 613 xr-alist xr-index))
614 (setq buf (or (reftex-get-file-buffer-force 614 (setq buf (or (reftex-get-file-buffer-force
615 (cdr (nth xr-index xr-alist))) 615 (cdr (nth xr-index xr-alist)))
616 (error "Cannot switch document")) 616 (error "Cannot switch document"))
617 prefix (or (car (nth xr-index xr-alist)) "")) 617 prefix (or (car (nth xr-index xr-alist)) ""))
618 (set-buffer buf)
619 (reftex-access-scan-info))
620 ((stringp key)
621 (setq entries
622 (list
623 (list
624 (or (assoc key (symbol-value reftex-docstruct-symbol))
625 (list key typekey)))))
626 (throw 'exit t))
627 ((memq key '(?a ?A return))
628 (cond
629 (reftex-select-marked
630 (setq entries (nreverse reftex-select-marked)))
631 (data
632 (setq entries (list (list data))))
633 (t (setq entries nil)))
634 (when entries
635 (if (equal key ?a) (push 'concat entries))
636 (setq reftex-last-used-reference entries))
618 (set-buffer buf) 637 (set-buffer buf)
619 (reftex-access-scan-info))
620 ((stringp key)
621 (setq entries
622 (list
623 (list
624 (or (assoc key (symbol-value reftex-docstruct-symbol))
625 (list key typekey)))))
626 (throw 'exit t)) 638 (throw 'exit t))
627 ((memq key '(?a ?A return)) 639 (t (error "This should not happen (reftex-offer-label-menu)"))))))
628 (cond
629 (reftex-select-marked
630 (setq entries (nreverse reftex-select-marked)))
631 (data
632 (setq entries (list (list data))))
633 (t (setq entries nil)))
634 (when entries
635 (if (equal key ?a) (push 'concat entries))
636 (setq reftex-last-used-reference entries))
637 (set-buffer buf)
638 (throw 'exit t))
639 (t (error "This should not happen (reftex-offer-label-menu)"))))))
640 (save-excursion 640 (save-excursion
641 (while reftex-buffers-with-changed-invisibility 641 (while reftex-buffers-with-changed-invisibility
642 (set-buffer (car (car reftex-buffers-with-changed-invisibility))) 642 (set-buffer (car (car reftex-buffers-with-changed-invisibility)))
643 (setq buffer-invisibility-spec 643 (setq buffer-invisibility-spec
644 (cdr (pop reftex-buffers-with-changed-invisibility))))) 644 (cdr (pop reftex-buffers-with-changed-invisibility)))))
645 (mapcar (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf))) 645 (mapcar (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf)))
646 selection-buffers) 646 selection-buffers)
647 (reftex-kill-temporary-buffers)) 647 (reftex-kill-temporary-buffers))
648 ;; Add the prefixes, put together the relevant information in the form 648 ;; Add the prefixes, put together the relevant information in the form
649 ;; (LABEL TYPEKEY SEPARATOR) and return a list of those. 649 ;; (LABEL TYPEKEY SEPARATOR) and return a list of those.
650 (mapcar (lambda (x) 650 (mapcar (lambda (x)
651 (if (listp x) 651 (if (listp x)
652 (list (concat prefix (car (car x))) 652 (list (concat prefix (car (car x)))
653 (nth 1 (car x)) 653 (nth 1 (car x))
654 (nth 2 x)) 654 (nth 2 x))
655 x)) 655 x))
656 entries))) 656 entries)))
657 657
658(defun reftex-reparse-document (&optional buffer data key) 658(defun reftex-reparse-document (&optional buffer data key)
659 ;; Rescan the document. 659 ;; Rescan the document.
@@ -669,14 +669,14 @@ When called with 2 C-u prefix args, disable magic word recognition."
669 669
670(defun reftex-query-label-type () 670(defun reftex-query-label-type ()
671 ;; Ask for label type 671 ;; Ask for label type
672 (let ((key (reftex-select-with-char 672 (let ((key (reftex-select-with-char
673 reftex-type-query-prompt reftex-type-query-help 3))) 673 reftex-type-query-prompt reftex-type-query-help 3)))
674 (unless (member (char-to-string key) reftex-typekey-list) 674 (unless (member (char-to-string key) reftex-typekey-list)
675 (error "No such label type: %s" (char-to-string key))) 675 (error "No such label type: %s" (char-to-string key)))
676 (char-to-string key))) 676 (char-to-string key)))
677 677
678(defun reftex-show-label-location (data forward no-revisit 678(defun reftex-show-label-location (data forward no-revisit
679 &optional stay error) 679 &optional stay error)
680 ;; View the definition site of a label in another window. 680 ;; View the definition site of a label in another window.
681 ;; DATA is an entry from the docstruct list. 681 ;; DATA is an entry from the docstruct list.
682 ;; FORWARD indicates if the label is likely forward from current point. 682 ;; FORWARD indicates if the label is likely forward from current point.
@@ -685,53 +685,53 @@ When called with 2 C-u prefix args, disable magic word recognition."
685 ;; ERROR means throw an error exception when the label cannot be found. 685 ;; ERROR means throw an error exception when the label cannot be found.
686 ;; If ERROR is nil, the return value of this function indicates success. 686 ;; If ERROR is nil, the return value of this function indicates success.
687 (let* ((this-window (selected-window)) 687 (let* ((this-window (selected-window))
688 (errorf (if error 'error 'message)) 688 (errorf (if error 'error 'message))
689 label file buffer re found) 689 label file buffer re found)
690 690
691 (catch 'exit 691 (catch 'exit
692 (setq label (nth 0 data) 692 (setq label (nth 0 data)
693 file (nth 3 data)) 693 file (nth 3 data))
694 694
695 (unless file 695 (unless file
696 (funcall errorf "Unknown label - reparse might help") 696 (funcall errorf "Unknown label - reparse might help")
697 (throw 'exit nil)) 697 (throw 'exit nil))
698 698
699 ;; Goto the file in another window 699 ;; Goto the file in another window
700 (setq buffer 700 (setq buffer
701 (if no-revisit 701 (if no-revisit
702 (reftex-get-buffer-visiting file) 702 (reftex-get-buffer-visiting file)
703 (reftex-get-file-buffer-force 703 (reftex-get-file-buffer-force
704 file (not reftex-keep-temporary-buffers)))) 704 file (not reftex-keep-temporary-buffers))))
705 (if buffer 705 (if buffer
706 ;; good - the file is available 706 ;; good - the file is available
707 (switch-to-buffer-other-window buffer) 707 (switch-to-buffer-other-window buffer)
708 ;; we have got a problem here. The file does not exist. 708 ;; we have got a problem here. The file does not exist.
709 ;; Let' get out of here.. 709 ;; Let' get out of here..
710 (funcall errorf "Label %s not found" label) 710 (funcall errorf "Label %s not found" label)
711 (throw 'exit nil)) 711 (throw 'exit nil))
712 712
713 ;; search for that label 713 ;; search for that label
714 (setq re (format reftex-find-label-regexp-format (regexp-quote label))) 714 (setq re (format reftex-find-label-regexp-format (regexp-quote label)))
715 (setq found 715 (setq found
716 (if forward 716 (if forward
717 (re-search-forward re nil t) 717 (re-search-forward re nil t)
718 (re-search-backward re nil t))) 718 (re-search-backward re nil t)))
719 (unless found 719 (unless found
720 (goto-char (point-min)) 720 (goto-char (point-min))
721 (unless (setq found (re-search-forward re nil t)) 721 (unless (setq found (re-search-forward re nil t))
722 ;; Ooops. Must be in a macro with distributed args. 722 ;; Ooops. Must be in a macro with distributed args.
723 (setq found 723 (setq found
724 (re-search-forward 724 (re-search-forward
725 (format reftex-find-label-regexp-format2 725 (format reftex-find-label-regexp-format2
726 (regexp-quote label)) nil t)))) 726 (regexp-quote label)) nil t))))
727 (if (match-end 3) 727 (if (match-end 3)
728 (progn 728 (progn
729 (reftex-highlight 0 (match-beginning 3) (match-end 3)) 729 (reftex-highlight 0 (match-beginning 3) (match-end 3))
730 (reftex-show-entry (match-beginning 3) (match-end 3)) 730 (reftex-show-entry (match-beginning 3) (match-end 3))
731 (recenter '(4)) 731 (recenter '(4))
732 (unless stay (select-window this-window))) 732 (unless stay (select-window this-window)))
733 (select-window this-window) 733 (select-window this-window)
734 (funcall errorf "Label %s not found" label)) 734 (funcall errorf "Label %s not found" label))
735 found))) 735 found)))
736 736
737(defvar font-lock-mode) 737(defvar font-lock-mode)
@@ -744,34 +744,34 @@ When called with 2 C-u prefix args, disable magic word recognition."
744 (re-search-forward "[\n\r]" nil 1 n) (point)))) 744 (re-search-forward "[\n\r]" nil 1 n) (point))))
745 (cond 745 (cond
746 ((and (boundp 'buffer-invisibility-spec) buffer-invisibility-spec 746 ((and (boundp 'buffer-invisibility-spec) buffer-invisibility-spec
747 (get-char-property (1+ beg-hlt) 'invisible)) 747 (get-char-property (1+ beg-hlt) 'invisible))
748 ;; Invisible with text properties. That is easy to change. 748 ;; Invisible with text properties. That is easy to change.
749 (push (cons (current-buffer) buffer-invisibility-spec) 749 (push (cons (current-buffer) buffer-invisibility-spec)
750 reftex-buffers-with-changed-invisibility) 750 reftex-buffers-with-changed-invisibility)
751 (setq buffer-invisibility-spec nil)) 751 (setq buffer-invisibility-spec nil))
752 ((string-match "\r" (buffer-substring beg end)) 752 ((string-match "\r" (buffer-substring beg end))
753 ;; Invisible with selective display. We need to copy it. 753 ;; Invisible with selective display. We need to copy it.
754 (let ((string (buffer-substring-no-properties beg end))) 754 (let ((string (buffer-substring-no-properties beg end)))
755 (switch-to-buffer "*RefTeX Context Copy*") 755 (switch-to-buffer "*RefTeX Context Copy*")
756 (setq buffer-read-only nil) 756 (setq buffer-read-only nil)
757 (erase-buffer) 757 (erase-buffer)
758 (insert string) 758 (insert string)
759 (subst-char-in-region (point-min) (point-max) ?\r ?\n t) 759 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
760 (goto-char (- beg-hlt beg)) 760 (goto-char (- beg-hlt beg))
761 (reftex-highlight 0 (1+ (- beg-hlt beg)) (1+ (- end-hlt beg))) 761 (reftex-highlight 0 (1+ (- beg-hlt beg)) (1+ (- end-hlt beg)))
762 (if (reftex-refontify) 762 (if (reftex-refontify)
763 (when (or (not (eq major-mode 'latex-mode)) 763 (when (or (not (eq major-mode 'latex-mode))
764 (not font-lock-mode)) 764 (not font-lock-mode))
765 (latex-mode) 765 (latex-mode)
766 (run-hook-with-args 766 (run-hook-with-args
767 'reftex-pre-refontification-functions 767 'reftex-pre-refontification-functions
768 reftex-call-back-to-this-buffer 'reftex-hidden) 768 reftex-call-back-to-this-buffer 'reftex-hidden)
769 (turn-on-font-lock)) 769 (turn-on-font-lock))
770 (when (or (not (eq major-mode 'fundamental-mode)) 770 (when (or (not (eq major-mode 'fundamental-mode))
771 font-lock-mode) 771 font-lock-mode)
772 (fundamental-mode))) 772 (fundamental-mode)))
773 (run-hooks 'reftex-display-copied-context-hook) 773 (run-hooks 'reftex-display-copied-context-hook)
774 (setq buffer-read-only t)))))) 774 (setq buffer-read-only t))))))
775 775
776(defun reftex-varioref-vref () 776(defun reftex-varioref-vref ()
777 "Insert a reference using the `\\vref' macro from the varioref package." 777 "Insert a reference using the `\\vref' macro from the varioref package."
@@ -782,15 +782,15 @@ When called with 2 C-u prefix args, disable magic word recognition."
782 "Insert a reference using the `\\fref' macro from the fancyref package." 782 "Insert a reference using the `\\fref' macro from the fancyref package."
783 (interactive) 783 (interactive)
784 (let ((reftex-format-ref-function 'reftex-format-fref) 784 (let ((reftex-format-ref-function 'reftex-format-fref)
785 ;;(reftex-guess-label-type nil) ;FIXME do we want this???? 785 ;;(reftex-guess-label-type nil) ;FIXME do we want this????
786 ) 786 )
787 (reftex-reference))) 787 (reftex-reference)))
788(defun reftex-fancyref-Fref () 788(defun reftex-fancyref-Fref ()
789 "Insert a reference using the `\\Fref' macro from the fancyref package." 789 "Insert a reference using the `\\Fref' macro from the fancyref package."
790 (interactive) 790 (interactive)
791 (let ((reftex-format-ref-function 'reftex-format-Fref) 791 (let ((reftex-format-ref-function 'reftex-format-Fref)
792 ;;(reftex-guess-label-type nil) ;FIXME do we want this???? 792 ;;(reftex-guess-label-type nil) ;FIXME do we want this????
793 ) 793 )
794 (reftex-reference))) 794 (reftex-reference)))
795 795
796(defun reftex-format-vref (label fmt) 796(defun reftex-format-vref (label fmt)
@@ -802,26 +802,36 @@ When called with 2 C-u prefix args, disable magic word recognition."
802(defun reftex-format-fref (label def-fmt) 802(defun reftex-format-fref (label def-fmt)
803 (format "\\fref{%s}" label)) 803 (format "\\fref{%s}" label))
804 804
805
806;(defun reftex-goto-label ()
807; (interactive)
808; (reftex-access-scan-info)
809; (let* ((docstruct (symbol-value reftex-docstruct-symbol))
810; (label (completing-read "Label: " docstruct
811; (lambda (x) (stringp (car x))) t))
812; (selection (assoc label docstruct)))
813; (reftex-show-label-location selection t nil 'stay)
814; (reftex-unhighlight 0)))
815
805(defun reftex-goto-label (&optional other-window) 816(defun reftex-goto-label (&optional other-window)
806 "Prompt for a label (with completion) and jump to the location of this label. 817 "Prompt for a label (with completion) and jump to the location of this label.
807Optional prefix argument OTHER-WINDOW goes to the label in another window." 818Optional prefix argument OTHER-WINDOW goes to the label in another window."
808 (interactive "P") 819 (interactive "P")
809 (reftex-access-scan-info) 820 (reftex-access-scan-info)
810 (let* ((wcfg (current-window-configuration)) 821 (let* ((wcfg (current-window-configuration))
811 (docstruct (symbol-value reftex-docstruct-symbol)) 822 (docstruct (symbol-value reftex-docstruct-symbol))
812 (label (completing-read "Label: " docstruct 823 (label (completing-read "Label: " docstruct
813 (lambda (x) (stringp (car x))) t)) 824 (lambda (x) (stringp (car x))) t))
814 (selection (assoc label docstruct)) 825 (selection (assoc label docstruct))
815 (where (progn 826 (where (progn
816 (reftex-show-label-location selection t nil 'stay) 827 (reftex-show-label-location selection t nil 'stay)
817 (point-marker)))) 828 (point-marker))))
818 (unless other-window 829 (unless other-window
819 (set-window-configuration wcfg) 830 (set-window-configuration wcfg)
820 (switch-to-buffer (marker-buffer where)) 831 (switch-to-buffer (marker-buffer where))
821 (goto-char where)) 832 (goto-char where))
822 (reftex-unhighlight 0))) 833 (reftex-unhighlight 0)))
823 834
824 835
825 836
826;;; arch-tag: 52f14032-fb76-4d31-954f-750c72415675
827;;; reftex-ref.el ends here 837;;; reftex-ref.el ends here
diff --git a/lisp/textmodes/reftex-sel.el b/lisp/textmodes/reftex-sel.el
index 3074e83b681..cd9119ea746 100644
--- a/lisp/textmodes/reftex-sel.el
+++ b/lisp/textmodes/reftex-sel.el
@@ -1,8 +1,8 @@
1;;; reftex-sel.el --- the selection modes for RefTeX 1;;; reftex-sel.el --- the selection modes for RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -38,7 +38,7 @@ started with the command \\[reftex-reference].")
38(defun reftex-select-label-mode () 38(defun reftex-select-label-mode ()
39 "Major mode for selecting a label in a LaTeX document. 39 "Major mode for selecting a label in a LaTeX document.
40This buffer was created with RefTeX. 40This buffer was created with RefTeX.
41It only has a meaningful keymap when you are in the middle of a 41It only has a meaningful keymap when you are in the middle of a
42selection process. 42selection process.
43To select a label, move the cursor to it and press RET. 43To select a label, move the cursor to it and press RET.
44Press `?' for a summary of important key bindings. 44Press `?' for a summary of important key bindings.
@@ -54,7 +54,7 @@ During a selection process, these are the local bindings.
54 (make-local-hook 'pre-command-hook) 54 (make-local-hook 'pre-command-hook)
55 (make-local-hook 'post-command-hook)) 55 (make-local-hook 'post-command-hook))
56 (setq major-mode 'reftex-select-label-mode 56 (setq major-mode 'reftex-select-label-mode
57 mode-name "LSelect") 57 mode-name "LSelect")
58 (set (make-local-variable 'reftex-select-marked) nil) 58 (set (make-local-variable 'reftex-select-marked) nil)
59 (when (syntax-table-p reftex-latex-syntax-table) 59 (when (syntax-table-p reftex-latex-syntax-table)
60 (set-syntax-table reftex-latex-syntax-table)) 60 (set-syntax-table reftex-latex-syntax-table))
@@ -69,7 +69,7 @@ started with the command \\[reftex-citation].")
69(defun reftex-select-bib-mode () 69(defun reftex-select-bib-mode ()
70 "Major mode for selecting a citation key in a LaTeX document. 70 "Major mode for selecting a citation key in a LaTeX document.
71This buffer was created with RefTeX. 71This buffer was created with RefTeX.
72It only has a meaningful keymap when you are in the middle of a 72It only has a meaningful keymap when you are in the middle of a
73selection process. 73selection process.
74In order to select a citation, move the cursor to it and press RET. 74In order to select a citation, move the cursor to it and press RET.
75Press `?' for a summary of important key bindings. 75Press `?' for a summary of important key bindings.
@@ -84,7 +84,7 @@ During a selection process, these are the local bindings.
84 (make-local-hook 'pre-command-hook) 84 (make-local-hook 'pre-command-hook)
85 (make-local-hook 'post-command-hook)) 85 (make-local-hook 'post-command-hook))
86 (setq major-mode 'reftex-select-bib-mode 86 (setq major-mode 'reftex-select-bib-mode
87 mode-name "BSelect") 87 mode-name "BSelect")
88 (set (make-local-variable 'reftex-select-marked) nil) 88 (set (make-local-variable 'reftex-select-marked) nil)
89 ;; We do not set a local map - reftex-select-item does this. 89 ;; We do not set a local map - reftex-select-item does this.
90 (run-hooks 'reftex-select-bib-mode-hook)) 90 (run-hooks 'reftex-select-bib-mode-hook))
@@ -99,18 +99,18 @@ During a selection process, these are the local bindings.
99;;; (set-buffer buf) 99;;; (set-buffer buf)
100;;; (reftex-access-scan-info) 100;;; (reftex-access-scan-info)
101;;; (let* ((rest (memq here-am-I (symbol-value reftex-docstruct-symbol))) 101;;; (let* ((rest (memq here-am-I (symbol-value reftex-docstruct-symbol)))
102;;; entry) 102;;; entry)
103;;; (while (setq entry (pop rest)) 103;;; (while (setq entry (pop rest))
104;;; (if (or (and typekey 104;;; (if (or (and typekey
105;;; (stringp (car entry)) 105;;; (stringp (car entry))
106;;; (or (equal typekey " ") 106;;; (or (equal typekey " ")
107;;; (equal typekey (nth 1 entry)))) 107;;; (equal typekey (nth 1 entry))))
108;;; (and toc (eq (car entry) 'toc)) 108;;; (and toc (eq (car entry) 'toc))
109;;; (and index (eq (car entry) 'index)) 109;;; (and index (eq (car entry) 'index))
110;;; (and file 110;;; (and file
111;;; (memq (car entry) '(bof eof file-error)))) 111;;; (memq (car entry) '(bof eof file-error))))
112;;; (throw 'exit entry))) 112;;; (throw 'exit entry)))
113;;; nil)))) 113;;; nil))))
114 114
115(defun reftex-get-offset (buf here-am-I &optional typekey toc index file) 115(defun reftex-get-offset (buf here-am-I &optional typekey toc index file)
116 ;; Find the correct offset data, like insert-docstruct would, but faster. 116 ;; Find the correct offset data, like insert-docstruct would, but faster.
@@ -122,24 +122,24 @@ During a selection process, these are the local bindings.
122 (set-buffer buf) 122 (set-buffer buf)
123 (reftex-access-scan-info) 123 (reftex-access-scan-info)
124 (let* ((rest (symbol-value reftex-docstruct-symbol)) 124 (let* ((rest (symbol-value reftex-docstruct-symbol))
125 lastentry entry) 125 lastentry entry)
126 (while (setq entry (pop rest)) 126 (while (setq entry (pop rest))
127 (if (or (and typekey 127 (if (or (and typekey
128 (stringp (car entry)) 128 (stringp (car entry))
129 (or (equal typekey " ") 129 (or (equal typekey " ")
130 (equal typekey (nth 1 entry)))) 130 (equal typekey (nth 1 entry))))
131 (and toc (eq (car entry) 'toc)) 131 (and toc (eq (car entry) 'toc))
132 (and index (eq (car entry) 'index)) 132 (and index (eq (car entry) 'index))
133 (and file 133 (and file
134 (memq (car entry) '(bof eof file-error)))) 134 (memq (car entry) '(bof eof file-error))))
135 (setq lastentry entry)) 135 (setq lastentry entry))
136 (if (eq entry here-am-I) 136 (if (eq entry here-am-I)
137 (throw 'exit (or lastentry entry)))) 137 (throw 'exit (or lastentry entry))))
138 nil)))) 138 nil))))
139 139
140(defun reftex-insert-docstruct 140(defun reftex-insert-docstruct
141 (buf toc labels index-entries files context counter show-commented 141 (buf toc labels index-entries files context counter show-commented
142 here-I-am xr-prefix toc-buffer) 142 here-I-am xr-prefix toc-buffer)
143 ;; Insert an excerpt of the docstruct list. 143 ;; Insert an excerpt of the docstruct list.
144 ;; Return the data property of the entry corresponding to HERE-I-AM. 144 ;; Return the data property of the entry corresponding to HERE-I-AM.
145 ;; BUF is the buffer which has the correct docstruct-symbol. 145 ;; BUF is the buffer which has the correct docstruct-symbol.
@@ -163,18 +163,18 @@ During a selection process, these are the local bindings.
163 (context-indent 163 (context-indent
164 (concat ". " 164 (concat ". "
165 (if toc (make-string (* 7 reftex-level-indent) ?\ ) ""))) 165 (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
166 (mouse-face 166 (mouse-face
167 (if (memq reftex-highlight-selection '(mouse both)) 167 (if (memq reftex-highlight-selection '(mouse both))
168 reftex-mouse-selected-face 168 reftex-mouse-selected-face
169 nil)) 169 nil))
170 (label-face (reftex-verified-face reftex-label-face 170 (label-face (reftex-verified-face reftex-label-face
171 'font-lock-constant-face 171 'font-lock-constant-face
172 'font-lock-reference-face)) 172 'font-lock-reference-face))
173 (index-face (reftex-verified-face reftex-index-face 173 (index-face (reftex-verified-face reftex-index-face
174 'font-lock-constant-face 174 'font-lock-constant-face
175 'font-lock-reference-face)) 175 'font-lock-reference-face))
176 all cell text label typekey note comment master-dir-re 176 all cell text label typekey note comment master-dir-re
177 prev-inserted offset from to index-tag docstruct-symbol) 177 prev-inserted offset from to index-tag docstruct-symbol)
178 178
179 ;; Pop to buffer buf to get the correct buffer-local variables 179 ;; Pop to buffer buf to get the correct buffer-local variables
180 (save-excursion 180 (save-excursion
@@ -184,7 +184,7 @@ During a selection process, these are the local bindings.
184 (reftex-access-scan-info) 184 (reftex-access-scan-info)
185 185
186 (setq docstruct-symbol reftex-docstruct-symbol 186 (setq docstruct-symbol reftex-docstruct-symbol
187 all (symbol-value reftex-docstruct-symbol) 187 all (symbol-value reftex-docstruct-symbol)
188 reftex-active-toc nil 188 reftex-active-toc nil
189 master-dir-re 189 master-dir-re
190 (concat "\\`" (regexp-quote 190 (concat "\\`" (regexp-quote
@@ -192,7 +192,7 @@ During a selection process, these are the local bindings.
192 192
193 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol) 193 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
194 (set (make-local-variable 'reftex-prefix) 194 (set (make-local-variable 'reftex-prefix)
195 (cdr (assoc labels reftex-typekey-to-prefix-alist))) 195 (cdr (assoc labels reftex-typekey-to-prefix-alist)))
196 (if (equal reftex-prefix " ") (setq reftex-prefix nil)) 196 (if (equal reftex-prefix " ") (setq reftex-prefix nil))
197 197
198 ;; Walk the docstruct and insert the appropriate stuff 198 ;; Walk the docstruct and insert the appropriate stuff
@@ -204,14 +204,14 @@ During a selection process, these are the local bindings.
204 (cond 204 (cond
205 205
206 ((memq (car cell) '(bib thebib label-numbers appendix 206 ((memq (car cell) '(bib thebib label-numbers appendix
207 master-dir bibview-cache is-multi xr xr-doc))) 207 master-dir bibview-cache is-multi xr xr-doc)))
208 ;; These are currently ignored 208 ;; These are currently ignored
209 209
210 ((memq (car cell) '(bof eof file-error)) 210 ((memq (car cell) '(bof eof file-error))
211 ;; Beginning or end of a file 211 ;; Beginning or end of a file
212 (when files 212 (when files
213 (setq prev-inserted cell) 213 (setq prev-inserted cell)
214; (if (eq offset 'attention) (setq offset cell)) 214; (if (eq offset 'attention) (setq offset cell))
215 (insert 215 (insert
216 " File " (if (string-match master-dir-re (nth 1 cell)) 216 " File " (if (string-match master-dir-re (nth 1 cell))
217 (substring (nth 1 cell) (match-end 0)) 217 (substring (nth 1 cell) (match-end 0))
@@ -219,41 +219,41 @@ During a selection process, these are the local bindings.
219 (cond ((eq (car cell) 'bof) " starts here\n") 219 (cond ((eq (car cell) 'bof) " starts here\n")
220 ((eq (car cell) 'eof) " ends here\n") 220 ((eq (car cell) 'eof) " ends here\n")
221 ((eq (car cell) 'file-error) " was not found\n"))) 221 ((eq (car cell) 'file-error) " was not found\n")))
222 (setq to (point)) 222 (setq to (point))
223 (when font 223 (when font
224 (put-text-property from to 224 (put-text-property from to
225 'face reftex-file-boundary-face)) 225 'face reftex-file-boundary-face))
226 (when toc-buffer 226 (when toc-buffer
227 (if mouse-face 227 (if mouse-face
228 (put-text-property from (1- to) 228 (put-text-property from (1- to)
229 'mouse-face mouse-face)) 229 'mouse-face mouse-face))
230 (put-text-property from to :data cell)))) 230 (put-text-property from to :data cell))))
231 231
232 ((eq (car cell) 'toc) 232 ((eq (car cell) 'toc)
233 ;; a table of contents entry 233 ;; a table of contents entry
234 (when (and toc 234 (when (and toc
235 (<= (nth 5 cell) reftex-toc-max-level)) 235 (<= (nth 5 cell) reftex-toc-max-level))
236 (setq prev-inserted cell) 236 (setq prev-inserted cell)
237; (if (eq offset 'attention) (setq offset cell)) 237; (if (eq offset 'attention) (setq offset cell))
238 (setq reftex-active-toc cell) 238 (setq reftex-active-toc cell)
239 (insert (concat toc-indent (nth 2 cell) "\n")) 239 (insert (concat toc-indent (nth 2 cell) "\n"))
240 (setq to (point)) 240 (setq to (point))
241 (when font 241 (when font
242 (put-text-property from to 242 (put-text-property from to
243 'face reftex-section-heading-face)) 243 'face reftex-section-heading-face))
244 (when toc-buffer 244 (when toc-buffer
245 (if mouse-face 245 (if mouse-face
246 (put-text-property from (1- to) 246 (put-text-property from (1- to)
247 'mouse-face mouse-face)) 247 'mouse-face mouse-face))
248 (put-text-property from to :data cell)) 248 (put-text-property from to :data cell))
249 (goto-char to))) 249 (goto-char to)))
250 250
251 ((stringp (car cell)) 251 ((stringp (car cell))
252 ;; a label 252 ;; a label
253 (when (null (nth 2 cell)) 253 (when (null (nth 2 cell))
254 ;; No context yet. Quick update. 254 ;; No context yet. Quick update.
255 (setcdr cell (cdr (reftex-label-info-update cell))) 255 (setcdr cell (cdr (reftex-label-info-update cell)))
256 (put docstruct-symbol 'modified t)) 256 (put docstruct-symbol 'modified t))
257 257
258 (setq label (car cell) 258 (setq label (car cell)
259 typekey (nth 1 cell) 259 typekey (nth 1 cell)
@@ -262,27 +262,27 @@ During a selection process, these are the local bindings.
262 note (nth 5 cell)) 262 note (nth 5 cell))
263 263
264 (when (and labels 264 (when (and labels
265 (or (eq labels t) 265 (or (eq labels t)
266 (string= typekey labels) 266 (string= typekey labels)
267 (string= labels " ")) 267 (string= labels " "))
268 (or show-commented (null comment))) 268 (or show-commented (null comment)))
269 269
270 ;; Yes we want this one 270 ;; Yes we want this one
271 (incf cnt) 271 (incf cnt)
272 (setq prev-inserted cell) 272 (setq prev-inserted cell)
273; (if (eq offset 'attention) (setq offset cell)) 273; (if (eq offset 'attention) (setq offset cell))
274 274
275 (setq label (concat xr-prefix label)) 275 (setq label (concat xr-prefix label))
276 (when comment (setq label (concat "% " label))) 276 (when comment (setq label (concat "% " label)))
277 (insert label-indent label) 277 (insert label-indent label)
278 (when font 278 (when font
279 (setq to (point)) 279 (setq to (point))
280 (put-text-property 280 (put-text-property
281 (- (point) (length label)) to 281 (- (point) (length label)) to
282 'face (if comment 282 'face (if comment
283 'font-lock-comment-face 283 'font-lock-comment-face
284 label-face)) 284 label-face))
285 (goto-char to)) 285 (goto-char to))
286 286
287 (insert (if counter (format " (%d) " cnt) "") 287 (insert (if counter (format " (%d) " cnt) "")
288 (if comment " LABEL IS COMMENTED OUT " "") 288 (if comment " LABEL IS COMMENTED OUT " "")
@@ -294,46 +294,46 @@ During a selection process, these are the local bindings.
294 (insert context-indent text "\n") 294 (insert context-indent text "\n")
295 (setq to (point))) 295 (setq to (point)))
296 (put-text-property from to :data cell) 296 (put-text-property from to :data cell)
297 (when mouse-face 297 (when mouse-face
298 (put-text-property from (1- to) 298 (put-text-property from (1- to)
299 'mouse-face mouse-face)) 299 'mouse-face mouse-face))
300 (goto-char to))) 300 (goto-char to)))
301 301
302 ((eq (car cell) 'index) 302 ((eq (car cell) 'index)
303 ;; index entry 303 ;; index entry
304 (when (and index-entries 304 (when (and index-entries
305 (or (eq t index-entries) 305 (or (eq t index-entries)
306 (string= index-entries (nth 1 cell)))) 306 (string= index-entries (nth 1 cell))))
307 (setq prev-inserted cell) 307 (setq prev-inserted cell)
308; (if (eq offset 'attention) (setq offset cell)) 308; (if (eq offset 'attention) (setq offset cell))
309 (setq index-tag (format "<%s>" (nth 1 cell))) 309 (setq index-tag (format "<%s>" (nth 1 cell)))
310 (and font 310 (and font
311 (put-text-property 0 (length index-tag) 311 (put-text-property 0 (length index-tag)
312 'face reftex-index-tag-face index-tag)) 312 'face reftex-index-tag-face index-tag))
313 (insert label-indent index-tag " " (nth 7 cell)) 313 (insert label-indent index-tag " " (nth 7 cell))
314 314
315 (when font 315 (when font
316 (setq to (point)) 316 (setq to (point))
317 (put-text-property 317 (put-text-property
318 (- (point) (length (nth 7 cell))) to 318 (- (point) (length (nth 7 cell))) to
319 'face index-face) 319 'face index-face)
320 (goto-char to)) 320 (goto-char to))
321 (insert "\n") 321 (insert "\n")
322 (setq to (point)) 322 (setq to (point))
323 323
324 (when context 324 (when context
325 (insert context-indent (nth 2 cell) "\n") 325 (insert context-indent (nth 2 cell) "\n")
326 (setq to (point))) 326 (setq to (point)))
327 (put-text-property from to :data cell) 327 (put-text-property from to :data cell)
328 (when mouse-face 328 (when mouse-face
329 (put-text-property from (1- to) 329 (put-text-property from (1- to)
330 'mouse-face mouse-face)) 330 'mouse-face mouse-face))
331 (goto-char to)))) 331 (goto-char to))))
332 332
333 (if (eq cell here-I-am) 333 (if (eq cell here-I-am)
334 (setq offset 'attention)) 334 (setq offset 'attention))
335 (if (and prev-inserted (eq offset 'attention)) 335 (if (and prev-inserted (eq offset 'attention))
336 (setq offset prev-inserted)) 336 (setq offset prev-inserted))
337 ) 337 )
338 338
339 (when (reftex-refontify) 339 (when (reftex-refontify)
@@ -351,18 +351,18 @@ During a selection process, these are the local bindings.
351 (goto-char (point-min)) 351 (goto-char (point-min))
352 (let (loc pos) 352 (let (loc pos)
353 (while locations 353 (while locations
354 (setq loc (pop locations)) 354 (setq loc (pop locations))
355 (cond 355 (cond
356 ((null loc)) 356 ((null loc))
357 ((listp loc) 357 ((listp loc)
358 (setq pos (text-property-any (point-min) (point-max) :data loc)) 358 (setq pos (text-property-any (point-min) (point-max) :data loc))
359 (when pos 359 (when pos
360 (goto-char pos) 360 (goto-char pos)
361 (throw 'exit t))) 361 (throw 'exit t)))
362 ((integerp loc) 362 ((integerp loc)
363 (when (<= loc (count-lines (point-min) (point-max))) 363 (when (<= loc (count-lines (point-min) (point-max)))
364 (goto-line loc) 364 (goto-line loc)
365 (throw 'exit t))))) 365 (throw 'exit t)))))
366 (goto-char fallback)))) 366 (goto-char fallback))))
367 367
368(defvar reftex-last-data nil) 368(defvar reftex-last-data nil)
@@ -370,8 +370,8 @@ During a selection process, these are the local bindings.
370(defvar reftex-select-marked nil) 370(defvar reftex-select-marked nil)
371 371
372(defun reftex-select-item (prompt help-string keymap 372(defun reftex-select-item (prompt help-string keymap
373 &optional offset 373 &optional offset
374 call-back cb-flag) 374 call-back cb-flag)
375;; Select an item, using PROMPT. The function returns a key indicating 375;; Select an item, using PROMPT. The function returns a key indicating
376;; an exit status, along with a data structure indicating which item was 376;; an exit status, along with a data structure indicating which item was
377;; selected. 377;; selected.
@@ -393,36 +393,36 @@ During a selection process, these are the local bindings.
393 (save-window-excursion 393 (save-window-excursion
394 (setq truncate-lines t) 394 (setq truncate-lines t)
395 395
396 ;; Find a good starting point 396 ;; Find a good starting point
397 (reftex-find-start-point 397 (reftex-find-start-point
398 (point-min) offset reftex-last-data reftex-last-line) 398 (point-min) offset reftex-last-data reftex-last-line)
399 (beginning-of-line 1) 399 (beginning-of-line 1)
400 (set (make-local-variable 'reftex-last-follow-point) (point)) 400 (set (make-local-variable 'reftex-last-follow-point) (point))
401 401
402 (unwind-protect 402 (unwind-protect
403 (progn 403 (progn
404 (use-local-map keymap) 404 (use-local-map keymap)
405 (add-hook 'pre-command-hook 'reftex-select-pre-command-hook nil t) 405 (add-hook 'pre-command-hook 'reftex-select-pre-command-hook nil t)
406 (add-hook 'post-command-hook 'reftex-select-post-command-hook nil t) 406 (add-hook 'post-command-hook 'reftex-select-post-command-hook nil t)
407 (princ prompt) 407 (princ prompt)
408 (set-marker reftex-recursive-edit-marker (point)) 408 (set-marker reftex-recursive-edit-marker (point))
409 ;; XEmacs does not run post-command-hook here 409 ;; XEmacs does not run post-command-hook here
410 (and (featurep 'xemacs) (run-hooks 'post-command-hook)) 410 (and (featurep 'xemacs) (run-hooks 'post-command-hook))
411 (recursive-edit)) 411 (recursive-edit))
412 412
413 (set-marker reftex-recursive-edit-marker nil) 413 (set-marker reftex-recursive-edit-marker nil)
414 (save-excursion 414 (save-excursion
415 (set-buffer selection-buffer) 415 (set-buffer selection-buffer)
416 (use-local-map nil) 416 (use-local-map nil)
417 (remove-hook 'pre-command-hook 'reftex-select-pre-command-hook t) 417 (remove-hook 'pre-command-hook 'reftex-select-pre-command-hook t)
418 (remove-hook 'post-command-hook 418 (remove-hook 'post-command-hook
419 'reftex-select-post-command-hook t)) 419 'reftex-select-post-command-hook t))
420 ;; Kill the mark overlays 420 ;; Kill the mark overlays
421 (mapcar (lambda (c) (delete-overlay (nth 1 c))) 421 (mapcar (lambda (c) (delete-overlay (nth 1 c)))
422 reftex-select-marked))))) 422 reftex-select-marked)))))
423 423
424 (set (make-local-variable 'reftex-last-line) 424 (set (make-local-variable 'reftex-last-line)
425 (+ (count-lines (point-min) (point)) (if (bolp) 1 0))) 425 (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))
426 (set (make-local-variable 'reftex-last-data) last-data) 426 (set (make-local-variable 'reftex-last-data) last-data)
427 (reftex-kill-buffer "*RefTeX Help*") 427 (reftex-kill-buffer "*RefTeX Help*")
428 (setq reftex-callback-fwd (not reftex-callback-fwd)) ;; ;-))) 428 (setq reftex-callback-fwd (not reftex-callback-fwd)) ;; ;-)))
@@ -451,25 +451,25 @@ During a selection process, these are the local bindings.
451 (let (b e) 451 (let (b e)
452 (setq data (get-text-property (point) :data)) 452 (setq data (get-text-property (point) :data))
453 (setq last-data (or data last-data)) 453 (setq last-data (or data last-data))
454 454
455 (when (and data cb-flag 455 (when (and data cb-flag
456 (not (equal reftex-last-follow-point (point)))) 456 (not (equal reftex-last-follow-point (point))))
457 (setq reftex-last-follow-point (point)) 457 (setq reftex-last-follow-point (point))
458 (funcall call-back data reftex-callback-fwd 458 (funcall call-back data reftex-callback-fwd
459 (not reftex-revisit-to-follow))) 459 (not reftex-revisit-to-follow)))
460 (if data 460 (if data
461 (setq b (or (previous-single-property-change 461 (setq b (or (previous-single-property-change
462 (1+ (point)) :data) 462 (1+ (point)) :data)
463 (point-min)) 463 (point-min))
464 e (or (next-single-property-change 464 e (or (next-single-property-change
465 (point) :data) 465 (point) :data)
466 (point-max))) 466 (point-max)))
467 (setq b (point) e (point))) 467 (setq b (point) e (point)))
468 (and (memq reftex-highlight-selection '(cursor both)) 468 (and (memq reftex-highlight-selection '(cursor both))
469 (reftex-highlight 1 b e)) 469 (reftex-highlight 1 b e))
470 (if (or (not (pos-visible-in-window-p b)) 470 (if (or (not (pos-visible-in-window-p b))
471 (not (pos-visible-in-window-p e))) 471 (not (pos-visible-in-window-p e)))
472 (recenter '(4))) 472 (recenter '(4)))
473 (unless (current-message) 473 (unless (current-message)
474 (princ prompt)))) 474 (princ prompt))))
475 475
@@ -518,12 +518,12 @@ Useful for large TOC's."
518 (let (pos) 518 (let (pos)
519 (cond 519 (cond
520 ((and (local-variable-p 'reftex-last-data (current-buffer)) 520 ((and (local-variable-p 'reftex-last-data (current-buffer))
521 reftex-last-data 521 reftex-last-data
522 (setq pos (text-property-any (point-min) (point-max) 522 (setq pos (text-property-any (point-min) (point-max)
523 :data reftex-last-data))) 523 :data reftex-last-data)))
524 (goto-char pos)) 524 (goto-char pos))
525 ((and (local-variable-p 'reftex-last-line (current-buffer)) 525 ((and (local-variable-p 'reftex-last-line (current-buffer))
526 (integerp reftex-last-line)) 526 (integerp reftex-last-line))
527 (goto-line reftex-last-line)) 527 (goto-line reftex-last-line))
528 (t (ding))))) 528 (t (ding)))))
529(defun reftex-select-toggle-follow () 529(defun reftex-select-toggle-follow ()
@@ -542,20 +542,20 @@ Useful for large TOC's."
542 "Toggle the macro used for referencing the label between \\ref and \\vref." 542 "Toggle the macro used for referencing the label between \\ref and \\vref."
543 (interactive) 543 (interactive)
544 (setq refstyle 544 (setq refstyle
545 (cond ((string= refstyle "\\ref") "\\fref") 545 (cond ((string= refstyle "\\ref") "\\fref")
546 ((string= refstyle "\\fref") "\\Fref") 546 ((string= refstyle "\\fref") "\\Fref")
547 (t "\\ref"))) 547 (t "\\ref")))
548 (force-mode-line-update)) 548 (force-mode-line-update))
549(defun reftex-select-show-insertion-point () 549(defun reftex-select-show-insertion-point ()
550 "Show the point from where selection was started in another window." 550 "Show the point from where selection was started in another window."
551 (interactive) 551 (interactive)
552 (let ((this-window (selected-window))) 552 (let ((this-window (selected-window)))
553 (unwind-protect 553 (unwind-protect
554 (progn 554 (progn
555 (switch-to-buffer-other-window 555 (switch-to-buffer-other-window
556 (marker-buffer reftex-select-return-marker)) 556 (marker-buffer reftex-select-return-marker))
557 (goto-char (marker-position reftex-select-return-marker)) 557 (goto-char (marker-position reftex-select-return-marker))
558 (recenter '(4))) 558 (recenter '(4)))
559 (select-window this-window)))) 559 (select-window this-window))))
560(defun reftex-select-callback () 560(defun reftex-select-callback ()
561 "Show full context in another window." 561 "Show full context in another window."
@@ -575,16 +575,16 @@ Useful for large TOC's."
575(defun reftex-select-read-label () 575(defun reftex-select-read-label ()
576 "Use minibuffer to read a label to reference, with completion." 576 "Use minibuffer to read a label to reference, with completion."
577 (interactive) 577 (interactive)
578 (let ((label (completing-read 578 (let ((label (completing-read
579 "Label: " (symbol-value reftex-docstruct-symbol) 579 "Label: " (symbol-value reftex-docstruct-symbol)
580 nil nil reftex-prefix))) 580 nil nil reftex-prefix)))
581 (unless (or (equal label "") (equal label reftex-prefix)) 581 (unless (or (equal label "") (equal label reftex-prefix))
582 (throw 'myexit label)))) 582 (throw 'myexit label))))
583(defun reftex-select-read-cite () 583(defun reftex-select-read-cite ()
584 "Use minibuffer to read a citation key with completion." 584 "Use minibuffer to read a citation key with completion."
585 (interactive) 585 (interactive)
586 (let* ((key (completing-read "Citation key: " found-list)) 586 (let* ((key (completing-read "Citation key: " found-list))
587 (entry (assoc key found-list))) 587 (entry (assoc key found-list)))
588 (cond 588 (cond
589 ((or (null key) (equal key ""))) 589 ((or (null key) (equal key "")))
590 (entry 590 (entry
@@ -597,23 +597,23 @@ Useful for large TOC's."
597 "Mark the entry." 597 "Mark the entry."
598 (interactive) 598 (interactive)
599 (let* ((data (get-text-property (point) :data)) 599 (let* ((data (get-text-property (point) :data))
600 boe eoe ovl) 600 boe eoe ovl)
601 (or data (error "No entry to mark at point")) 601 (or data (error "No entry to mark at point"))
602 (if (assq data reftex-select-marked) 602 (if (assq data reftex-select-marked)
603 (error "Entry is already marked")) 603 (error "Entry is already marked"))
604 (setq boe (or (previous-single-property-change (1+ (point)) :data) 604 (setq boe (or (previous-single-property-change (1+ (point)) :data)
605 (point-min)) 605 (point-min))
606 eoe (or (next-single-property-change (point) :data) (point-max))) 606 eoe (or (next-single-property-change (point) :data) (point-max)))
607 (setq ovl (make-overlay boe eoe)) 607 (setq ovl (make-overlay boe eoe))
608 (push (list data ovl separator) reftex-select-marked) 608 (push (list data ovl separator) reftex-select-marked)
609 (overlay-put ovl 'face reftex-select-mark-face) 609 (overlay-put ovl 'face reftex-select-mark-face)
610 (if (featurep 'xemacs) 610 (if (featurep 'xemacs)
611 ;; before-string property is broken in Emacs 611 ;; before-string property is broken in Emacs
612 (overlay-put ovl 'before-string 612 (overlay-put ovl 'before-string
613 (if separator 613 (if separator
614 (format "*%c%d* " separator 614 (format "*%c%d* " separator
615 (length reftex-select-marked)) 615 (length reftex-select-marked))
616 (format "*%d* " (length reftex-select-marked))))) 616 (format "*%d* " (length reftex-select-marked)))))
617 (message "Entry has mark no. %d" (length reftex-select-marked)))) 617 (message "Entry has mark no. %d" (length reftex-select-marked))))
618 618
619(defun reftex-select-mark-comma () 619(defun reftex-select-mark-comma ()
@@ -633,25 +633,25 @@ Useful for large TOC's."
633 "Unmark the entry." 633 "Unmark the entry."
634 (interactive) 634 (interactive)
635 (let* ((data (get-text-property (point) :data)) 635 (let* ((data (get-text-property (point) :data))
636 (cell (assq data reftex-select-marked)) 636 (cell (assq data reftex-select-marked))
637 (ovl (nth 1 cell)) 637 (ovl (nth 1 cell))
638 (cnt 0) 638 (cnt 0)
639 sep) 639 sep)
640 (unless cell 640 (unless cell
641 (error "No marked entry at point")) 641 (error "No marked entry at point"))
642 (and ovl (delete-overlay ovl)) 642 (and ovl (delete-overlay ovl))
643 (setq reftex-select-marked (delq cell reftex-select-marked)) 643 (setq reftex-select-marked (delq cell reftex-select-marked))
644 (if (featurep 'xemacs) 644 (if (featurep 'xemacs)
645 ;; before-string property is broken in Emacs 645 ;; before-string property is broken in Emacs
646 (progn 646 (progn
647 (setq cnt (1+ (length reftex-select-marked))) 647 (setq cnt (1+ (length reftex-select-marked)))
648 (mapcar (lambda (c) 648 (mapcar (lambda (c)
649 (setq sep (nth 2 c)) 649 (setq sep (nth 2 c))
650 (overlay-put (nth 1 c) 'before-string 650 (overlay-put (nth 1 c) 'before-string
651 (if sep 651 (if sep
652 (format "*%c%d* " sep (decf cnt)) 652 (format "*%c%d* " sep (decf cnt))
653 (format "*%d* " (decf cnt))))) 653 (format "*%d* " (decf cnt)))))
654 reftex-select-marked))) 654 reftex-select-marked)))
655 (message "Entry no longer marked"))) 655 (message "Entry no longer marked")))
656 656
657(defun reftex-select-help () 657(defun reftex-select-help ()
@@ -664,27 +664,27 @@ Useful for large TOC's."
664;; Common bindings in reftex-select-label-map and reftex-select-bib-map 664;; Common bindings in reftex-select-label-map and reftex-select-bib-map
665(let ((map (make-sparse-keymap))) 665(let ((map (make-sparse-keymap)))
666 (substitute-key-definition 666 (substitute-key-definition
667 'next-line 'reftex-select-next map global-map) 667 'next-line 'reftex-select-next map global-map)
668 (substitute-key-definition 668 (substitute-key-definition
669 'previous-line 'reftex-select-previous map global-map) 669 'previous-line 'reftex-select-previous map global-map)
670 (substitute-key-definition 670 (substitute-key-definition
671 'keyboard-quit 'reftex-select-keyboard-quit map global-map) 671 'keyboard-quit 'reftex-select-keyboard-quit map global-map)
672 (substitute-key-definition 672 (substitute-key-definition
673 'newline 'reftex-select-accept map global-map) 673 'newline 'reftex-select-accept map global-map)
674 674
675 (loop for x in 675 (loop for x in
676 '((" " . reftex-select-callback) 676 '((" " . reftex-select-callback)
677 ("n" . reftex-select-next) 677 ("n" . reftex-select-next)
678 ([(down)] . reftex-select-next) 678 ([(down)] . reftex-select-next)
679 ("p" . reftex-select-previous) 679 ("p" . reftex-select-previous)
680 ([(up)] . reftex-select-previous) 680 ([(up)] . reftex-select-previous)
681 ("f" . reftex-select-toggle-follow) 681 ("f" . reftex-select-toggle-follow)
682 ("\C-m" . reftex-select-accept) 682 ("\C-m" . reftex-select-accept)
683 ([(return)] . reftex-select-accept) 683 ([(return)] . reftex-select-accept)
684 ("q" . reftex-select-quit) 684 ("q" . reftex-select-quit)
685 ("." . reftex-select-show-insertion-point) 685 ("." . reftex-select-show-insertion-point)
686 ("?" . reftex-select-help)) 686 ("?" . reftex-select-help))
687 do (define-key map (car x) (cdr x))) 687 do (define-key map (car x) (cdr x)))
688 688
689 ;; The mouse-2 binding 689 ;; The mouse-2 binding
690 (if (featurep 'xemacs) 690 (if (featurep 'xemacs)
@@ -693,7 +693,7 @@ Useful for large TOC's."
693 693
694 ;; Digit arguments 694 ;; Digit arguments
695 (loop for key across "0123456789" do 695 (loop for key across "0123456789" do
696 (define-key map (vector (list key)) 'digit-argument)) 696 (define-key map (vector (list key)) 'digit-argument))
697 (define-key map "-" 'negative-argument) 697 (define-key map "-" 'negative-argument)
698 698
699 ;; Make two maps 699 ;; Make two maps
@@ -703,41 +703,40 @@ Useful for large TOC's."
703;; Specific bindings in reftex-select-label-map 703;; Specific bindings in reftex-select-label-map
704(loop for key across "aAcgFlrRstx#%" do 704(loop for key across "aAcgFlrRstx#%" do
705 (define-key reftex-select-label-map (vector (list key)) 705 (define-key reftex-select-label-map (vector (list key))
706 (list 'lambda '() 706 (list 'lambda '()
707 "Press `?' during selection to find out about this key." 707 "Press `?' during selection to find out about this key."
708 '(interactive) (list 'throw '(quote myexit) key)))) 708 '(interactive) (list 'throw '(quote myexit) key))))
709 709
710(loop for x in 710(loop for x in
711 '(("b" . reftex-select-jump-to-previous) 711 '(("b" . reftex-select-jump-to-previous)
712 ("z" . reftex-select-jump) 712 ("z" . reftex-select-jump)
713 ("v" . reftex-select-toggle-varioref) 713 ("v" . reftex-select-toggle-varioref)
714 ("V" . reftex-select-toggle-fancyref) 714 ("V" . reftex-select-toggle-fancyref)
715 ("m" . reftex-select-mark) 715 ("m" . reftex-select-mark)
716 ("u" . reftex-select-unmark) 716 ("u" . reftex-select-unmark)
717 ("," . reftex-select-mark-comma) 717 ("," . reftex-select-mark-comma)
718 ("-" . reftex-select-mark-to) 718 ("-" . reftex-select-mark-to)
719 ("+" . reftex-select-mark-and) 719 ("+" . reftex-select-mark-and)
720 ([(tab)] . reftex-select-read-label) 720 ([(tab)] . reftex-select-read-label)
721 ("\C-i" . reftex-select-read-label) 721 ("\C-i" . reftex-select-read-label)
722 ("\C-c\C-n" . reftex-select-next-heading) 722 ("\C-c\C-n" . reftex-select-next-heading)
723 ("\C-c\C-p" . reftex-select-previous-heading)) 723 ("\C-c\C-p" . reftex-select-previous-heading))
724 do 724 do
725 (define-key reftex-select-label-map (car x) (cdr x))) 725 (define-key reftex-select-label-map (car x) (cdr x)))
726 726
727;; Specific bindings in reftex-select-bib-map 727;; Specific bindings in reftex-select-bib-map
728(loop for key across "grRaA" do 728(loop for key across "grRaA" do
729 (define-key reftex-select-bib-map (vector (list key)) 729 (define-key reftex-select-bib-map (vector (list key))
730 (list 'lambda '() 730 (list 'lambda '()
731 "Press `?' during selection to find out about this key." 731 "Press `?' during selection to find out about this key."
732 '(interactive) (list 'throw '(quote myexit) key)))) 732 '(interactive) (list 'throw '(quote myexit) key))))
733 733
734(loop for x in 734(loop for x in
735 '(("\C-i" . reftex-select-read-cite) 735 '(("\C-i" . reftex-select-read-cite)
736 ([(tab)] . reftex-select-read-cite) 736 ([(tab)] . reftex-select-read-cite)
737 ("m" . reftex-select-mark) 737 ("m" . reftex-select-mark)
738 ("u" . reftex-select-unmark)) 738 ("u" . reftex-select-unmark))
739 do (define-key reftex-select-bib-map (car x) (cdr x))) 739 do (define-key reftex-select-bib-map (car x) (cdr x)))
740
741 740
742;;; arch-tag: 842078ff-0586-4e0b-957e-536e08218464 741
743;;; reftex-sel.el ends here 742;;; reftex-sel.el ends here
diff --git a/lisp/textmodes/reftex-toc.el b/lisp/textmodes/reftex-toc.el
index 4d31c8caf19..414760747e3 100644
--- a/lisp/textmodes/reftex-toc.el
+++ b/lisp/textmodes/reftex-toc.el
@@ -1,8 +1,8 @@
1;;; reftex-toc.el --- RefTeX's table of contents mode 1;;; reftex-toc.el --- RefTeX's table of contents mode
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -46,23 +46,21 @@ Here are all local bindings.
46 (interactive) 46 (interactive)
47 (kill-all-local-variables) 47 (kill-all-local-variables)
48 (setq major-mode 'reftex-toc-mode 48 (setq major-mode 'reftex-toc-mode
49 mode-name "TOC") 49 mode-name "TOC")
50 (use-local-map reftex-toc-map) 50 (use-local-map reftex-toc-map)
51 (set (make-local-variable 'transient-mark-mode) t)
52 (set (make-local-variable 'zmacs-regions) t)
53 (set (make-local-variable 'revert-buffer-function) 'reftex-toc-revert) 51 (set (make-local-variable 'revert-buffer-function) 'reftex-toc-revert)
54 (set (make-local-variable 'reftex-toc-include-labels-indicator) "") 52 (set (make-local-variable 'reftex-toc-include-labels-indicator) "")
55 (set (make-local-variable 'reftex-toc-max-level-indicator) 53 (set (make-local-variable 'reftex-toc-max-level-indicator)
56 (if (= reftex-toc-max-level 100) 54 (if (= reftex-toc-max-level 100)
57 "ALL" 55 "ALL"
58 (int-to-string reftex-toc-max-level))) 56 (int-to-string reftex-toc-max-level)))
59 (setq mode-line-format 57 (setq mode-line-format
60 (list "---- " 'mode-line-buffer-identification 58 (list "---- " 'mode-line-buffer-identification
61 " " 'global-mode-string " (" mode-name ")" 59 " " 'global-mode-string " (" mode-name ")"
62 " L<" 'reftex-toc-include-labels-indicator ">" 60 " L<" 'reftex-toc-include-labels-indicator ">"
63 " I<" 'reftex-toc-include-index-indicator ">" 61 " I<" 'reftex-toc-include-index-indicator ">"
64 " T<" 'reftex-toc-max-level-indicator ">" 62 " T<" 'reftex-toc-max-level-indicator ">"
65 " -%-")) 63 " -%-"))
66 (setq truncate-lines t) 64 (setq truncate-lines t)
67 (when (featurep 'xemacs) 65 (when (featurep 'xemacs)
68 ;; XEmacs needs the call to make-local-hook 66 ;; XEmacs needs the call to make-local-hook
@@ -93,26 +91,20 @@ n / p next-line / previous-line
93SPC Show the corresponding location of the LaTeX document. 91SPC Show the corresponding location of the LaTeX document.
94TAB Goto the location and keep the *toc* window. 92TAB Goto the location and keep the *toc* window.
95RET Goto the location and hide the *toc* window (also on mouse-2). 93RET Goto the location and hide the *toc* window (also on mouse-2).
96< / > Promote / Demote section, or all sections in region.
97C-c > Display Index. With prefix arg, restrict index to current section. 94C-c > Display Index. With prefix arg, restrict index to current section.
98q / k Hide/Kill *toc* buffer, return to position of reftex-toc command. 95q / k Hide/Kill *toc* buffer, return to position of reftex-toc command.
99l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders. 96l i c F Toggle display of [l]abels, [i]ndex, [c]ontext, [F]ile borders.
100t Change maximum toc depth (e.g. `3 t' hides levels greater than 3). 97t Change maximum toc depth (e.g. `3 t' hides levels greater than 3).
101f / g Toggle follow mode / Refresh *toc* buffer. 98f / a / g Toggle follow mode / toggle auto recenter / Refresh *toc* buffer.
102a / d Toggle auto recenter / Toggle dedicated frame
103r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document. 99r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document.
104. In other window, show position from where `reftex-toc' was called. 100. In other window, show position from where `reftex-toc' was called.
105M-% Global search and replace to rename label at point.
106x Switch to TOC of external document (with LaTeX package `xr'). 101x Switch to TOC of external document (with LaTeX package `xr').
107z Jump to a specific section (e.g. '3 z' goes to section 3).") 102z Jump to a specific section (e.g. '3 z' goes to section 3")
108 103
109(defun reftex-toc (&optional rebuild reuse) 104(defun reftex-toc (&optional rebuild)
110 "Show the table of contents for the current document. 105 "Show the table of contents for the current document.
111When called with a raw C-u prefix, rescan the document first." 106When called with a raw C-u prefix, rescan the document first."
112 107
113;; The REUSE argument means, search all visible frames for a window
114;; displaying the toc window. If yes, reuse this window.
115
116 (interactive) 108 (interactive)
117 109
118 (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file))) 110 (if (or (not (string= reftex-last-toc-master (reftex-TeX-master-file)))
@@ -137,50 +129,40 @@ When called with a raw C-u prefix, rescan the document first."
137 (reftex-access-scan-info current-prefix-arg) 129 (reftex-access-scan-info current-prefix-arg)
138 130
139 (let* ((this-buf (current-buffer)) 131 (let* ((this-buf (current-buffer))
140 (docstruct-symbol reftex-docstruct-symbol) 132 (docstruct-symbol reftex-docstruct-symbol)
141 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) 133 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
142 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) 134 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
143 (here-I-am (if (boundp 'reftex-rebuilding-toc) 135 (here-I-am (if (boundp 'reftex-rebuilding-toc)
144 (get 'reftex-toc :reftex-data) 136 (get 'reftex-toc :reftex-data)
145 (car (reftex-where-am-I)))) 137 (car (reftex-where-am-I))))
146 (unsplittable (if (fboundp 'frame-property) 138 offset)
147 (frame-property (selected-frame) 'unsplittable) 139
148 (frame-parameter (selected-frame) 'unsplittable))) 140 (if (get-buffer-window "*toc*")
149 offset toc-window) 141 (select-window (get-buffer-window "*toc*"))
150
151 (if (setq toc-window (get-buffer-window
152 "*toc*"
153 (if reuse 'visible)))
154 (select-window toc-window)
155 (when (or (not reftex-toc-keep-other-windows) 142 (when (or (not reftex-toc-keep-other-windows)
156 (< (window-height) (* 2 window-min-height))) 143 (< (window-height) (* 2 window-min-height)))
157 (delete-other-windows)) 144 (delete-other-windows))
158 145
159 (setq reftex-last-window-width (window-width) 146 (setq reftex-last-window-width (window-width)
160 reftex-last-window-height (window-height)) ; remember 147 reftex-last-window-height (window-height)) ; remember
161 148 (if reftex-toc-split-windows-horizontally
162 (unless unsplittable 149 (split-window-horizontally
163 (if reftex-toc-split-windows-horizontally 150 (floor (* (frame-width) reftex-toc-split-windows-horizontally-fraction)))
164 (split-window-horizontally 151 (split-window))
165 (floor (* (window-width)
166 reftex-toc-split-windows-fraction)))
167 (split-window-vertically
168 (floor (* (window-height)
169 reftex-toc-split-windows-fraction)))))
170 152
171 (let ((default-major-mode 'reftex-toc-mode)) 153 (let ((default-major-mode 'reftex-toc-mode))
172 (switch-to-buffer "*toc*"))) 154 (switch-to-buffer "*toc*")))
173 155
174 (or (eq major-mode 'reftex-toc-mode) (reftex-toc-mode)) 156 (or (eq major-mode 'reftex-toc-mode) (reftex-toc-mode))
175 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol) 157 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
176 (setq reftex-toc-include-labels-indicator 158 (setq reftex-toc-include-labels-indicator
177 (if (eq reftex-toc-include-labels t) 159 (if (eq reftex-toc-include-labels t)
178 "ALL" 160 "ALL"
179 reftex-toc-include-labels)) 161 reftex-toc-include-labels))
180 (setq reftex-toc-include-index-indicator 162 (setq reftex-toc-include-index-indicator
181 (if (eq reftex-toc-include-index-entries t) 163 (if (eq reftex-toc-include-index-entries t)
182 "ALL" 164 "ALL"
183 reftex-toc-include-index-entries)) 165 reftex-toc-include-index-entries))
184 166
185 (cond 167 (cond
186 ((= (buffer-size) 0) 168 ((= (buffer-size) 0)
@@ -200,34 +182,34 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
200 (put-text-property (point-min) (1+ (point-min)) 'xr-alist xr-alist) 182 (put-text-property (point-min) (1+ (point-min)) 'xr-alist xr-alist)
201 183
202 (setq offset 184 (setq offset
203 (reftex-insert-docstruct 185 (reftex-insert-docstruct
204 this-buf 186 this-buf
205 t ; include toc 187 t ; include toc
206 reftex-toc-include-labels 188 reftex-toc-include-labels
207 reftex-toc-include-index-entries 189 reftex-toc-include-index-entries
208 reftex-toc-include-file-boundaries 190 reftex-toc-include-file-boundaries
209 reftex-toc-include-context 191 reftex-toc-include-context
210 nil ; counter 192 nil ; counter
211 nil ; commented 193 nil ; commented
212 here-I-am 194 here-I-am
213 "" ; xr-prefix 195 "" ; xr-prefix
214 t ; a toc buffer 196 t ; a toc buffer
215 )) 197 ))
216 198
217 (run-hooks 'reftex-display-copied-context-hook) 199 (run-hooks 'reftex-display-copied-context-hook)
218 (message "Building *toc* buffer...done.") 200 (message "Building *toc* buffer...done.")
219 (setq buffer-read-only t)) 201 (setq buffer-read-only t))
220 (t 202 (t
221 ;; Only compute the offset 203 ;; Only compute the offset
222 (setq offset 204 (setq offset
223 (or (reftex-get-offset this-buf here-I-am 205 (or (reftex-get-offset this-buf here-I-am
224 (if reftex-toc-include-labels " " nil) 206 (if reftex-toc-include-labels " " nil)
225 t 207 t
226 reftex-toc-include-index-entries 208 reftex-toc-include-index-entries
227 reftex-toc-include-file-boundaries) 209 reftex-toc-include-file-boundaries)
228 (reftex-last-assoc-before-elt 210 (reftex-last-assoc-before-elt
229 'toc here-I-am 211 'toc here-I-am
230 (symbol-value reftex-docstruct-symbol)))) 212 (symbol-value reftex-docstruct-symbol))))
231 (put 'reftex-toc :reftex-line 3) 213 (put 'reftex-toc :reftex-line 3)
232 (goto-line 3) 214 (goto-line 3)
233 (beginning-of-line))) 215 (beginning-of-line)))
@@ -239,27 +221,27 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
239(defun reftex-toc-recenter (&optional arg) 221(defun reftex-toc-recenter (&optional arg)
240 "Display the TOC window and highlight line corresponding to current position." 222 "Display the TOC window and highlight line corresponding to current position."
241 (interactive "P") 223 (interactive "P")
242 (let ((buf (current-buffer)) 224 (let ((buf (current-buffer)))
243 (frame (selected-frame))) 225 (reftex-toc arg)
244 (reftex-toc arg t)
245 (if (= (count-lines 1 (point)) 2) 226 (if (= (count-lines 1 (point)) 2)
246 (let ((current-prefix-arg nil)) 227 (let ((current-prefix-arg nil))
247 (select-window (get-buffer-window buf frame)) 228 (select-window (get-buffer-window buf))
248 (reftex-toc nil t))) 229 (reftex-toc nil)))
249 (and (> (point) 1) 230 (and (> (point) 1)
250 (not (get-text-property (point) 'intangible)) 231 (not (get-text-property (point) 'intangible))
251 (memq reftex-highlight-selection '(cursor both)) 232 (memq reftex-highlight-selection '(cursor both))
252 (reftex-highlight 2 233 (reftex-highlight 2
253 (or (previous-single-property-change 234 (or (previous-single-property-change
254 (min (point-max) (1+ (point))) :data) 235 (min (point-max) (1+ (point))) :data)
255 (point-min)) 236 (point-min))
256 (or (next-single-property-change (point) :data) 237 (or (next-single-property-change (point) :data)
257 (point-max)))) 238 (point-max))))
258 (select-window (get-buffer-window buf frame)))) 239 (select-window (get-buffer-window buf))))
259 240
260(defun reftex-toc-pre-command-hook () 241(defun reftex-toc-pre-command-hook ()
261 ;; used as pre command hook in *toc* buffer 242 ;; used as pre command hook in *toc* buffer
262 (reftex-unhighlight 0) 243 (reftex-unhighlight 0)
244;; (reftex-unhighlight 1) ;; remove highlight on leaving buffer.
263 ) 245 )
264 246
265(defun reftex-toc-post-command-hook () 247(defun reftex-toc-post-command-hook ()
@@ -267,52 +249,37 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
267 (when (get-text-property (point) :data) 249 (when (get-text-property (point) :data)
268 (put 'reftex-toc :reftex-data (get-text-property (point) :data)) 250 (put 'reftex-toc :reftex-data (get-text-property (point) :data))
269 (and (> (point) 1) 251 (and (> (point) 1)
270 (not (get-text-property (point) 'intangible)) 252 (not (get-text-property (point) 'intangible))
271 (memq reftex-highlight-selection '(cursor both)) 253 (memq reftex-highlight-selection '(cursor both))
272 (reftex-highlight 2 254 (reftex-highlight 2
273 (or (previous-single-property-change (1+ (point)) :data) 255 (or (previous-single-property-change (1+ (point)) :data)
274 (point-min)) 256 (point-min))
275 (or (next-single-property-change (point) :data) 257 (or (next-single-property-change (point) :data)
276 (point-max))))) 258 (point-max)))))
277 (if (integerp reftex-toc-follow-mode) 259 (if (integerp reftex-toc-follow-mode)
278 ;; remove delayed action 260 ;; remove delayed action
279 (setq reftex-toc-follow-mode t) 261 (setq reftex-toc-follow-mode t)
280 (and (not (reftex-toc-dframe-p)) 262 (and reftex-toc-follow-mode
281 reftex-toc-follow-mode 263 (not (equal reftex-last-follow-point (point)))
282 (not (equal reftex-last-follow-point (point))) 264 ;; show context in other window
283 ;; show context in other window 265 (setq reftex-last-follow-point (point))
284 (setq reftex-last-follow-point (point)) 266 (condition-case nil
285 (condition-case nil 267 (reftex-toc-visit-location nil (not reftex-revisit-to-follow))
286 (reftex-toc-visit-location nil (not reftex-revisit-to-follow)) 268 (error t)))))
287 (error t)))))
288 269
289(defun reftex-re-enlarge () 270(defun reftex-re-enlarge ()
290 ;; Enlarge window to a remembered size. 271 ;; Enlarge window to a remembered size.
291 (if reftex-toc-split-windows-horizontally 272 (if reftex-toc-split-windows-horizontally
292 (enlarge-window-horizontally 273 (enlarge-window-horizontally
293 (max 0 (- (or reftex-last-window-width (window-width)) 274 (max 0 (- (or reftex-last-window-width (window-width))
294 (window-width)))) 275 (window-width))))
295 (enlarge-window 276 (enlarge-window
296 (max 0 (- (or reftex-last-window-height (window-height)) 277 (max 0 (- (or reftex-last-window-height (window-height))
297 (window-height)))))) 278 (window-height))))))
298
299(defun reftex-toc-dframe-p (&optional frame error)
300 ;; Check if FRAME is the dedicated TOC frame.
301 ;; If yes, and ERROR is non-nil, throw an error.
302 (setq frame (or frame (selected-frame)))
303 (let ((res (equal
304 (if (fboundp 'frame-property)
305 (frame-property frame 'name)
306 (frame-parameter frame 'name))
307 "RefTeX TOC Frame")))
308 (if (and res error)
309 (error "This frame is view-only. Use `C-c =' to create toc window for commands."))
310 res))
311 279
312(defun reftex-toc-show-help () 280(defun reftex-toc-show-help ()
313 "Show a summary of special key bindings." 281 "Show a summary of special key bindings."
314 (interactive) 282 (interactive)
315 (reftex-toc-dframe-p nil 'error)
316 (with-output-to-temp-buffer "*RefTeX Help*" 283 (with-output-to-temp-buffer "*RefTeX Help*"
317 (princ reftex-toc-help)) 284 (princ reftex-toc-help))
318 (reftex-enlarge-to-fit "*RefTeX Help*" t) 285 (reftex-enlarge-to-fit "*RefTeX Help*" t)
@@ -323,29 +290,25 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
323(defun reftex-toc-next (&optional arg) 290(defun reftex-toc-next (&optional arg)
324 "Move to next selectable item." 291 "Move to next selectable item."
325 (interactive "p") 292 (interactive "p")
326 (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
327 (setq reftex-callback-fwd t) 293 (setq reftex-callback-fwd t)
328 (or (eobp) (forward-char 1)) 294 (or (eobp) (forward-char 1))
329 (goto-char (or (next-single-property-change (point) :data) 295 (goto-char (or (next-single-property-change (point) :data)
330 (point)))) 296 (point))))
331(defun reftex-toc-previous (&optional arg) 297(defun reftex-toc-previous (&optional arg)
332 "Move to previous selectable item." 298 "Move to previous selectable item."
333 (interactive "p") 299 (interactive "p")
334 (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
335 (setq reftex-callback-fwd nil) 300 (setq reftex-callback-fwd nil)
336 (goto-char (or (previous-single-property-change (point) :data) 301 (goto-char (or (previous-single-property-change (point) :data)
337 (point)))) 302 (point))))
338(defun reftex-toc-next-heading (&optional arg) 303(defun reftex-toc-next-heading (&optional arg)
339 "Move to next table of contentes line." 304 "Move to next table of contentes line."
340 (interactive "p") 305 (interactive "p")
341 (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
342 (end-of-line) 306 (end-of-line)
343 (re-search-forward "^ " nil t arg) 307 (re-search-forward "^ " nil t arg)
344 (beginning-of-line)) 308 (beginning-of-line))
345(defun reftex-toc-previous-heading (&optional arg) 309(defun reftex-toc-previous-heading (&optional arg)
346 "Move to previous table of contentes line." 310 "Move to previous table of contentes line."
347 (interactive "p") 311 (interactive "p")
348 (if (boundp 'zmacs-region-stays) (setq zmacs-region-stays t))
349 (re-search-backward "^ " nil t arg)) 312 (re-search-backward "^ " nil t arg))
350(defun reftex-toc-toggle-follow () 313(defun reftex-toc-toggle-follow ()
351 "Toggle follow (other window follows with context)." 314 "Toggle follow (other window follows with context)."
@@ -356,16 +319,16 @@ SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
356 "Toggle inclusion of file boundaries in *toc* buffer." 319 "Toggle inclusion of file boundaries in *toc* buffer."
357 (interactive) 320 (interactive)
358 (setq reftex-toc-include-file-boundaries 321 (setq reftex-toc-include-file-boundaries
359 (not reftex-toc-include-file-boundaries)) 322 (not reftex-toc-include-file-boundaries))
360 (reftex-toc-revert)) 323 (reftex-toc-revert))
361(defun reftex-toc-toggle-labels (arg) 324(defun reftex-toc-toggle-labels (arg)
362 "Toggle inclusion of labels in *toc* buffer. 325 "Toggle inclusion of labels in *toc* buffer.
363With prefix ARG, prompt for a label type and include only labels of 326With prefix ARG, prompt for a label type and include only labels of
364that specific type." 327that specific type."
365 (interactive "P") 328 (interactive "P")
366 (setq reftex-toc-include-labels 329 (setq reftex-toc-include-labels
367 (if arg (reftex-query-label-type) 330 (if arg (reftex-query-label-type)
368 (not reftex-toc-include-labels))) 331 (not reftex-toc-include-labels)))
369 (reftex-toc-revert)) 332 (reftex-toc-revert))
370(defun reftex-toc-toggle-index (arg) 333(defun reftex-toc-toggle-index (arg)
371 "Toggle inclusion of index in *toc* buffer. 334 "Toggle inclusion of index in *toc* buffer.
@@ -373,8 +336,8 @@ With prefix arg, prompt for an index tag and include only entries of that
373specific index." 336specific index."
374 (interactive "P") 337 (interactive "P")
375 (setq reftex-toc-include-index-entries 338 (setq reftex-toc-include-index-entries
376 (if arg (reftex-index-select-tag) 339 (if arg (reftex-index-select-tag)
377 (not reftex-toc-include-index-entries))) 340 (not reftex-toc-include-index-entries)))
378 (reftex-toc-revert)) 341 (reftex-toc-revert))
379(defun reftex-toc-toggle-context () 342(defun reftex-toc-toggle-context ()
380 "Toggle inclusion of label context in *toc* buffer. 343 "Toggle inclusion of label context in *toc* buffer.
@@ -388,57 +351,46 @@ When no prefix is given, set the max level to a large number, so that all
388levels are shown. For eaxample, to set the level to 3, type `3 m'." 351levels are shown. For eaxample, to set the level to 3, type `3 m'."
389 (interactive "P") 352 (interactive "P")
390 (setq reftex-toc-max-level (if arg 353 (setq reftex-toc-max-level (if arg
391 (prefix-numeric-value arg) 354 (prefix-numeric-value arg)
392 100)) 355 100))
393 (setq reftex-toc-max-level-indicator 356 (setq reftex-toc-max-level-indicator
394 (if arg (int-to-string reftex-toc-max-level) "ALL")) 357 (if arg (int-to-string reftex-toc-max-level) "ALL"))
395 (reftex-toc-revert)) 358 (reftex-toc-revert))
396(defun reftex-toc-view-line () 359(defun reftex-toc-view-line ()
397 "View document location in other window." 360 "View document location in other window."
398 (interactive) 361 (interactive)
399 (reftex-toc-dframe-p nil 'error)
400 (reftex-toc-visit-location)) 362 (reftex-toc-visit-location))
401(defun reftex-toc-goto-line-and-hide () 363(defun reftex-toc-goto-line-and-hide ()
402 "Go to document location in other window. Hide the *toc* window." 364 "Go to document location in other window. Hide the *toc* window."
403 (interactive) 365 (interactive)
404 (reftex-toc-dframe-p nil 'error)
405 (reftex-toc-visit-location 'hide)) 366 (reftex-toc-visit-location 'hide))
406(defun reftex-toc-goto-line () 367(defun reftex-toc-goto-line ()
407 "Go to document location in other window. *toc* window stays." 368 "Go to document location in other window. *toc* window stays."
408 (interactive) 369 (interactive)
409 (reftex-toc-dframe-p nil 'error)
410 (reftex-toc-visit-location t)) 370 (reftex-toc-visit-location t))
411(defun reftex-toc-mouse-goto-line-and-hide (ev) 371(defun reftex-toc-mouse-goto-line-and-hide (ev)
412 "Go to document location in other window. Hide the *toc* window." 372 "Go to document location in other window. Hide the *toc* window."
413 (interactive "e") 373 (interactive "e")
414 (mouse-set-point ev) 374 (mouse-set-point ev)
415 (reftex-toc-dframe-p nil 'error)
416 (reftex-toc-visit-location 'hide)) 375 (reftex-toc-visit-location 'hide))
417(defun reftex-toc-show-calling-point () 376(defun reftex-toc-show-calling-point ()
418 "Show point where reftex-toc was called from." 377 "Show point where reftex-toc was called from."
419 (interactive) 378 (interactive)
420 (reftex-toc-dframe-p nil 'error)
421 (let ((this-window (selected-window))) 379 (let ((this-window (selected-window)))
422 (unwind-protect 380 (unwind-protect
423 (progn 381 (progn
424 (switch-to-buffer-other-window 382 (switch-to-buffer-other-window
425 (marker-buffer reftex-toc-return-marker)) 383 (marker-buffer reftex-toc-return-marker))
426 (goto-char (marker-position reftex-toc-return-marker)) 384 (goto-char (marker-position reftex-toc-return-marker))
427 (recenter '(4))) 385 (recenter '(4)))
428 (select-window this-window)))) 386 (select-window this-window))))
429(defun reftex-toc-quit () 387(defun reftex-toc-quit ()
430 "Hide the *toc* window and do not move point. 388 "Hide the *toc* window and do not move point."
431If the toc window is the only window on the dedicated TOC frame, the frame
432is destroyed."
433 (interactive) 389 (interactive)
434 (if (and (one-window-p) 390 (or (one-window-p) (delete-window))
435 (reftex-toc-dframe-p) 391 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
436 (> (length (frame-list)) 1)) 392 (reftex-re-enlarge)
437 (delete-frame) 393 (goto-char (or (marker-position reftex-toc-return-marker) (point))))
438 (or (one-window-p) (delete-window))
439 (switch-to-buffer (marker-buffer reftex-toc-return-marker))
440 (reftex-re-enlarge)
441 (goto-char (or (marker-position reftex-toc-return-marker) (point)))))
442(defun reftex-toc-quit-and-kill () 394(defun reftex-toc-quit-and-kill ()
443 "Kill the *toc* buffer." 395 "Kill the *toc* buffer."
444 (interactive) 396 (interactive)
@@ -452,41 +404,37 @@ is destroyed."
452This works just like `reftex-display-index' from a LaTeX buffer. 404This works just like `reftex-display-index' from a LaTeX buffer.
453With prefix arg 1, restrict index to the section at point." 405With prefix arg 1, restrict index to the section at point."
454 (interactive "P") 406 (interactive "P")
455 (reftex-toc-dframe-p nil 'error)
456 (let ((data (get-text-property (point) :data)) 407 (let ((data (get-text-property (point) :data))
457 (docstruct (symbol-value reftex-docstruct-symbol)) 408 (docstruct (symbol-value reftex-docstruct-symbol))
458 bor eor restr) 409 bor eor restr)
459 (when (equal arg 2) 410 (when (equal arg 2)
460 (setq bor (reftex-last-assoc-before-elt 'toc data docstruct) 411 (setq bor (reftex-last-assoc-before-elt 'toc data docstruct)
461 eor (assoc 'toc (cdr (memq bor docstruct))) 412 eor (assoc 'toc (cdr (memq bor docstruct)))
462 restr (list (nth 6 bor) bor eor))) 413 restr (list (nth 6 bor) bor eor)))
463 (reftex-toc-goto-line) 414 (reftex-toc-goto-line)
464 (reftex-display-index (if restr nil arg) restr))) 415 (reftex-display-index (if restr nil arg) restr)))
465
466;; Rescanning the document and rebuilding the TOC buffer.
467(defun reftex-toc-rescan (&rest ignore) 416(defun reftex-toc-rescan (&rest ignore)
468 "Regenerate the *toc* buffer by reparsing file of section at point." 417 "Regenerate the *toc* buffer by reparsing file of section at point."
469 (interactive) 418 (interactive)
470 (if (and reftex-enable-partial-scans 419 (if (and reftex-enable-partial-scans
471 (null current-prefix-arg)) 420 (null current-prefix-arg))
472 (let* ((data (get-text-property (point) :data)) 421 (let* ((data (get-text-property (point) :data))
473 (what (car data)) 422 (what (car data))
474 (file (cond ((eq what 'toc) (nth 3 data)) 423 (file (cond ((eq what 'toc) (nth 3 data))
475 ((memq what '(eof bof file-error)) (nth 1 data)) 424 ((memq what '(eof bof file-error)) (nth 1 data))
476 ((stringp what) (nth 3 data)) 425 ((stringp what) (nth 3 data))
477 ((eq what 'index) (nth 3 data)))) 426 ((eq what 'index) (nth 3 data))))
478 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0)))) 427 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
479 (if (not file) 428 (if (not file)
480 (error "Don't know which file to rescan. Try `C-u r'") 429 (error "Don't know which file to rescan. Try `C-u r'")
481 (put 'reftex-toc :reftex-line line) 430 (put 'reftex-toc :reftex-line line)
482 (switch-to-buffer-other-window 431 (switch-to-buffer-other-window
483 (reftex-get-file-buffer-force file)) 432 (reftex-get-file-buffer-force file))
484 (setq current-prefix-arg '(4)) 433 (setq current-prefix-arg '(4))
485 (let ((reftex-rebuilding-toc t)) 434 (let ((reftex-rebuilding-toc t))
486 (reftex-toc)))) 435 (reftex-toc))))
487 (reftex-toc-Rescan)) 436 (reftex-toc-Rescan))
488 (reftex-kill-temporary-buffers)) 437 (reftex-kill-temporary-buffers))
489
490(defun reftex-toc-Rescan (&rest ignore) 438(defun reftex-toc-Rescan (&rest ignore)
491 "Regenerate the *toc* buffer by reparsing the entire document." 439 "Regenerate the *toc* buffer by reparsing the entire document."
492 (interactive) 440 (interactive)
@@ -497,38 +445,28 @@ With prefix arg 1, restrict index to the section at point."
497 (setq current-prefix-arg '(16)) 445 (setq current-prefix-arg '(16))
498 (let ((reftex-rebuilding-toc t)) 446 (let ((reftex-rebuilding-toc t))
499 (reftex-toc))) 447 (reftex-toc)))
500
501(defun reftex-toc-revert (&rest ignore) 448(defun reftex-toc-revert (&rest ignore)
502 "Regenerate the *toc* from the internal lists." 449 "Regenerate the *toc* from the internal lists."
503 (interactive) 450 (interactive)
504 (let ((unsplittable 451 (switch-to-buffer-other-window
505 (if (fboundp 'frame-property) 452 (reftex-get-file-buffer-force reftex-last-toc-file))
506 (frame-property (selected-frame) 'unsplittable)
507 (frame-parameter (selected-frame) 'unsplittable)))
508 (reftex-rebuilding-toc t))
509 (if unsplittable
510 (switch-to-buffer
511 (reftex-get-file-buffer-force reftex-last-toc-file))
512 (switch-to-buffer-other-window
513 (reftex-get-file-buffer-force reftex-last-toc-file))))
514 (reftex-erase-buffer "*toc*") 453 (reftex-erase-buffer "*toc*")
515 (setq current-prefix-arg nil) 454 (setq current-prefix-arg nil)
516 (reftex-toc t)) 455 (let ((reftex-rebuilding-toc t))
517 456 (reftex-toc t)))
518(defun reftex-toc-external (&rest ignore) 457(defun reftex-toc-external (&rest ignore)
519 "Switch to table of contents of an external document." 458 "Switch to table of contents of an external document."
520 (interactive) 459 (interactive)
521 (reftex-toc-dframe-p nil 'error)
522 (let* ((old-buf (current-buffer)) 460 (let* ((old-buf (current-buffer))
523 (xr-alist (get-text-property 1 'xr-alist)) 461 (xr-alist (get-text-property 1 'xr-alist))
524 (xr-index (reftex-select-external-document 462 (xr-index (reftex-select-external-document
525 xr-alist 0))) 463 xr-alist 0)))
526 (switch-to-buffer-other-window (or (reftex-get-file-buffer-force 464 (switch-to-buffer-other-window (or (reftex-get-file-buffer-force
527 (cdr (nth xr-index xr-alist))) 465 (cdr (nth xr-index xr-alist)))
528 (error "Cannot switch document"))) 466 (error "Cannot switch document")))
529 (reftex-toc) 467 (reftex-toc)
530 (if (equal old-buf (current-buffer)) 468 (if (equal old-buf (current-buffer))
531 (message "") 469 (message "")
532 (message "Switched document")))) 470 (message "Switched document"))))
533 471
534(defun reftex-toc-jump (arg) 472(defun reftex-toc-jump (arg)
@@ -541,254 +479,6 @@ Useful for large TOC's."
541 nil t) 479 nil t)
542 (beginning-of-line)) 480 (beginning-of-line))
543 481
544;; Promotion/Demotion stuff
545
546(defun reftex-toc-demote (&optional arg)
547 "Demote section at point. If region is active, apply to all in region."
548 (interactive "p")
549 (reftex-toc-do-promote 1))
550(defun reftex-toc-promote (&optional arg)
551 "Promote section at point. If region is active, apply to all in region."
552 (interactive "p")
553 (reftex-toc-do-promote -1))
554(defun reftex-toc-do-promote (delta)
555 "Workhorse for reftex-toc-promote and reftex-to-demote.
556Changes the level of sections in the current region, or just the section at
557point."
558 ;; We should not do anything unless we are sure this is going to work for
559 ;; each section in the region. Therefore we first collect information and
560 ;; test.
561 (let* ((start-line (+ (count-lines (point-min) (point))
562 (if (bolp) 1 0)))
563 (mark-line (if (reftex-region-active-p)
564 (save-excursion (goto-char (mark))
565 (+ (count-lines (point-min) (point))
566 (if (bolp) 1 0)))))
567 (start-pos (point))
568 (pro-or-de (if (> delta 0) "de" "pro"))
569 beg end entries data sections nsec mpos msg)
570 (setq msg
571 (catch 'exit
572 (if (reftex-region-active-p)
573 ;; A region is dangerous, check if we have a brandnew scan,
574 ;; to make sure we are not missing any section statements.
575 (if (not (reftex-toc-check-docstruct))
576 (reftex-toc-load-all-files-for-promotion) ;; exits
577 (setq beg (min (point) (mark))
578 end (max (point) (mark))))
579 (setq beg (point) end (point)))
580 (goto-char beg)
581 (while (and (setq data (get-text-property (point) :data))
582 (<= (point) end))
583 (if (eq (car data) 'toc) (push (cons data (point)) entries))
584 (goto-char (or (next-single-property-change (point) :data)
585 (point-max))))
586 (setq entries (nreverse entries))
587 ;; Get the relevant section numbers, for an informative message
588 (goto-char start-pos)
589 (setq sections (reftex-toc-extract-section-number (car entries)))
590 (if (> (setq nsec (length entries)) 1)
591 (setq sections
592 (concat sections "-"
593 (reftex-toc-extract-section-number
594 (nth (1- nsec) entries)))))
595 ;; Run through the list and prepare the changes.
596 (setq entries (mapcar 'reftex-toc-promote-prepare entries))
597 ;; Ask for permission
598 (if (or (not reftex-toc-confirm-promotion) ; never confirm
599 (and (integerp reftex-toc-confirm-promotion) ; confirm if many
600 (< nsec reftex-toc-confirm-promotion))
601 (yes-or-no-p ; ask
602 (format "%s %d toc-entr%s (section%s %s)? "
603 (if (< delta 0) "Promote" "Demote")
604 nsec
605 (if (= 1 nsec) "y" "ies")
606 (if (= 1 nsec) "" "s")
607 sections)))
608 nil ; we have permission, do nothing
609 (error "Abort")) ; abort, we don't have permission
610 ;; Do the changes
611 (mapcar 'reftex-toc-promote-action entries)
612 ;; Rescan the document and rebuilt the toc buffer
613 (save-window-excursion
614 (reftex-toc-Rescan))
615 (reftex-toc-restore-region start-line mark-line)
616 (message "%d section%s %smoted"
617 nsec (if (= 1 nsec) "" "s") pro-or-de)
618 nil))
619 (if msg (progn (ding) (message msg)))))
620
621(defvar delta)
622(defvar mpos)
623(defvar pro-or-de)
624(defvar start-pos)
625(defvar start-line)
626(defvar mark-line)
627
628(defun reftex-toc-restore-region (point-line &optional mark-line)
629 (if mark-line
630 (progn (goto-line mark-line)
631 (setq mpos (point))))
632 (if point-line (goto-line point-line))
633 (if mark-line
634 (progn
635 (set-mark mpos)
636 (if (fboundp 'zmacs-activate-region)
637 (zmacs-activate-region)
638 (setq mark-active t
639 deactivate-mark nil)))))
640
641(defun reftex-toc-promote-prepare (x)
642 "Look at a toc entry and see if we could pro/demote it.
643Expects the level change DELTA to be dynamically scoped into this function.
644This function prepares everything for the changes, but does not do it.
645The return value is a list with information needed when doing the
646promotion/demotion later."
647 (let* ((data (car x))
648 (toc-point (cdr x))
649 (marker (nth 4 data))
650 (literal (nth 7 data))
651 (load nil)
652 (name nil)
653 ;; Here follows some paranoid code to make very sure we are not
654 ;; going to break anything
655 (name1 ; dummy
656 (if (and (markerp marker) (marker-buffer marker))
657 ;; Buffer is still live and we have the marker.
658 (progn
659 (save-excursion
660 ;; Goto the buffer and check of section is unchanged
661 (set-buffer (marker-buffer marker))
662 (goto-char (marker-position marker))
663 (if (looking-at (regexp-quote literal))
664 ;; OK, get the makro name
665 (progn
666 (beginning-of-line 1)
667 (if (looking-at reftex-section-regexp)
668 (setq name (reftex-match-string 2))
669 (error "Something is wrong! Contact maintainer!")))
670 ;; Section has changed, request scan and loading
671 ;; We use a variable to delay until after the safe-exc.
672 ;; because otherwise we loose the region.
673 (setq load t)))
674 ;; Scan document and load all files, this exits command
675 (if load (reftex-toc-load-all-files-for-promotion))) ; exits
676 ;; We don't have a live marker: scan and load files.
677 (reftex-toc-load-all-files-for-promotion)))
678 (level (cdr (assoc name reftex-section-levels-all)))
679 (dummy (if (not (integerp level))
680 (progn
681 (goto-char toc-point)
682 (error "Cannot %smote special sections" pro-or-de))))
683 ;; Delta is dynamically scoped into here...
684 (newlevel (if (>= level 0) (+ delta level) (- level delta)))
685 (dummy2 (if (or (and (>= level 0) (= newlevel -1))
686 (and (< level 0) (= newlevel 0)))
687 (error "Cannot %smote \\%s" pro-or-de name)))
688 (newname (reftex-toc-newhead-from-alist newlevel name
689 reftex-section-levels-all)))
690 (if (and name newname)
691 (list data name newname toc-point)
692 (goto-char toc-point)
693 (error "Cannot %smote \\%s" pro-or-de name))))
694
695(defun reftex-toc-promote-action (x)
696 "Change the level of a toc entry.
697DELTA and PRO-OR-DE are assumed to be dynamically scoped into this function."
698 (let* ((data (car x))
699 (name (nth 1 x))
700 (newname (nth 2 x))
701 (marker (nth 4 data)))
702 (save-excursion
703 (set-buffer (marker-buffer marker))
704 (goto-char (marker-position marker))
705 (if (looking-at (concat "\\([ \t]*\\\\\\)" (regexp-quote name)))
706 (replace-match (concat "\\1" newname))
707 (error "Fatal error during %smotion" pro-or-de)))))
708
709(defun reftex-toc-extract-section-number (entry)
710 "Get the numbering of a toc entry, for message purposes."
711 (if (string-match "\\s-*\\(\\S-+\\)" (nth 2 (car entry)))
712 (match-string 1 (nth 2 (car entry)))
713 "?"))
714
715(defun reftex-toc-newhead-from-alist (nlevel head alist)
716 "Get new heading with level NLEVEL from ALIST.
717If there are no such entries, return nil.
718If there are several different entries with same new level, choose
719the one with the smallest distance to the assocation of HEAD in the alist.
720This makes it possible for promotion to work several sets of headings,
721if these sets are sorted blocks in the alist."
722 (let* ((al alist)
723 (ass (assoc head al))
724 (pos (length (memq ass al)))
725 dist (mindist 1000) newhead)
726 (while al
727 (if (equal (cdar al) nlevel)
728 (progn
729 (setq dist (abs (- (length al) pos)))
730 (if (< dist mindist)
731 (setq newhead (car (car al))
732 mindist dist))))
733 (setq al (cdr al)))
734 newhead))
735
736(defun reftex-toc-check-docstruct ()
737 "Check if the current docstruct is fully up to date and all files visited."
738 ;; We do this by checking if all sections are on the right position
739 (let ((docstruct (symbol-value reftex-docstruct-symbol))
740 entry marker empoint)
741 (catch 'exit
742 (while (setq entry (pop docstruct))
743 (if (eq (car entry) 'toc)
744 (progn
745 (setq marker (nth 4 entry)
746 empoint (nth 8 entry))
747 (if (not (and (markerp marker)
748 (marker-buffer marker)
749 (= (marker-position marker) empoint)))
750 (throw 'exit nil)))))
751 t)))
752
753(defun reftex-toc-load-all-files-for-promotion ()
754 "Make sure all files of the document are being visited by buffers,
755and that the scanning info is absolutely up to date.
756We do this by rescanning with reftex-keep-temporary-buffers bound to t.
757The variable PRO-OR-DE is assumed to be dynamically scoped into thes function.
758When finished, we exit with an error message."
759 (let ((reftex-keep-temporary-buffers t))
760 (reftex-toc-Rescan)
761 (reftex-toc-restore-region start-line mark-line)
762 (throw 'exit
763 (format "TOC had to be updated first. Please check selection and repeat the command." pro-or-de))))
764
765(defun reftex-toc-rename-label ()
766 "Rename the currently selected label in the *TOC* buffer.
767This launches a global search and replace in order to rename a label.
768Renaming a label is hardly ever necessary - the only exeption is after
769promotion/demotion in connection with a package like fancyref, where the
770label prefix determines the wording of a reference."
771 (interactive)
772 (let* ((toc (get-text-property (point) :data))
773 (label (car toc)) newlabel)
774 (if (not (stringp label))
775 (error "This is not a label entry."))
776 (setq newlabel (read-string (format "Rename label \"%s\" to:" label)))
777 (if (assoc newlabel (symbol-value reftex-docstruct-symbol))
778 (if (not (y-or-n-p
779 (format "Label '%s' exists. Use anyway? " label)))
780 (error "Abort")))
781 (save-excursion
782 (save-window-excursion
783 (reftex-toc-visit-location t)
784 (condition-case nil
785 (reftex-query-replace-document
786 (concat "{" (regexp-quote label) "}")
787 (format "{%s}" newlabel))
788 (error t))))
789 (reftex-toc-rescan)))
790
791
792(defun reftex-toc-visit-location (&optional final no-revisit) 482(defun reftex-toc-visit-location (&optional final no-revisit)
793 ;; Visit the tex file corresponding to the toc entry on the current line. 483 ;; Visit the tex file corresponding to the toc entry on the current line.
794 ;; If FINAL is t, stay there 484 ;; If FINAL is t, stay there
@@ -804,9 +494,9 @@ label prefix determines the wording of a reference."
804 show-window show-buffer match) 494 show-window show-buffer match)
805 495
806 (unless toc (error "Don't know which toc line to visit")) 496 (unless toc (error "Don't know which toc line to visit"))
807 497
808 (cond 498 (cond
809 499
810 ((eq (car toc) 'toc) 500 ((eq (car toc) 'toc)
811 ;; a toc entry 501 ;; a toc entry
812 (setq match (reftex-toc-find-section toc no-revisit))) 502 (setq match (reftex-toc-find-section toc no-revisit)))
@@ -818,19 +508,19 @@ label prefix determines the wording of a reference."
818 ((memq (car toc) '(bof eof)) 508 ((memq (car toc) '(bof eof))
819 ;; A file entry 509 ;; A file entry
820 (setq match 510 (setq match
821 (let ((where (car toc)) 511 (let ((where (car toc))
822 (file (nth 1 toc))) 512 (file (nth 1 toc)))
823 (if (or (not no-revisit) (reftex-get-buffer-visiting file)) 513 (if (or (not no-revisit) (reftex-get-buffer-visiting file))
824 (progn 514 (progn
825 (switch-to-buffer-other-window 515 (switch-to-buffer-other-window
826 (reftex-get-file-buffer-force file nil)) 516 (reftex-get-file-buffer-force file nil))
827 (goto-char (if (eq where 'bof) (point-min) (point-max)))) 517 (goto-char (if (eq where 'bof) (point-min) (point-max))))
828 (message reftex-no-follow-message) nil)))) 518 (message reftex-no-follow-message) nil))))
829 519
830 ((stringp (car toc)) 520 ((stringp (car toc))
831 ;; a label 521 ;; a label
832 (setq match (reftex-show-label-location toc reftex-callback-fwd 522 (setq match (reftex-show-label-location toc reftex-callback-fwd
833 no-revisit t)))) 523 no-revisit t))))
834 524
835 (setq show-window (selected-window) 525 (setq show-window (selected-window)
836 show-buffer (current-buffer)) 526 show-buffer (current-buffer))
@@ -852,46 +542,46 @@ label prefix determines the wording of a reference."
852 ;; If `show-window' is still live, show-buffer is already visible 542 ;; If `show-window' is still live, show-buffer is already visible
853 ;; so let's not make it visible in yet-another-window. 543 ;; so let's not make it visible in yet-another-window.
854 (if (window-live-p show-window) 544 (if (window-live-p show-window)
855 (set-buffer show-buffer) 545 (select-window show-window)
856 (switch-to-buffer show-buffer)) 546 (switch-to-buffer show-buffer))
857 (reftex-re-enlarge)) 547 (reftex-re-enlarge))
858 (t nil)))) 548 (t nil))))
859 549
860(defun reftex-toc-find-section (toc &optional no-revisit) 550(defun reftex-toc-find-section (toc &optional no-revisit)
861 (let* ((file (nth 3 toc)) 551 (let* ((file (nth 3 toc))
862 (marker (nth 4 toc)) 552 (marker (nth 4 toc))
863 (level (nth 5 toc)) 553 (level (nth 5 toc))
864 (literal (nth 7 toc)) 554 (literal (nth 7 toc))
865 (emergency-point (nth 8 toc)) 555 (emergency-point (nth 8 toc))
866 (match 556 (match
867 (cond 557 (cond
868 ((and (markerp marker) (marker-buffer marker)) 558 ((and (markerp marker) (marker-buffer marker))
869 ;; Buffer is still live and we have the marker. Should be easy. 559 ;; Buffer is still live and we have the marker. Should be easy.
870 (switch-to-buffer-other-window (marker-buffer marker)) 560 (switch-to-buffer-other-window (marker-buffer marker))
871 (goto-char (marker-position marker)) 561 (goto-char (marker-position marker))
872 (or (looking-at (regexp-quote literal)) 562 (or (looking-at (regexp-quote literal))
873 (looking-at (reftex-make-regexp-allow-for-ctrl-m literal)) 563 (looking-at (reftex-make-regexp-allow-for-ctrl-m literal))
874 (looking-at (reftex-make-desperate-section-regexp literal)) 564 (looking-at (reftex-make-desperate-section-regexp literal))
875 (looking-at (concat "\\\\" 565 (looking-at (concat "\\\\"
876 (regexp-quote 566 (regexp-quote
877 (car 567 (car
878 (rassq level 568 (rassq level
879 reftex-section-levels-all))) 569 reftex-section-levels-all)))
880 "[[{]?")))) 570 "[[{]?"))))
881 ((or (not no-revisit) 571 ((or (not no-revisit)
882 (reftex-get-buffer-visiting file)) 572 (reftex-get-buffer-visiting file))
883 ;; Marker is lost. Use the backup method. 573 ;; Marker is lost. Use the backup method.
884 (switch-to-buffer-other-window 574 (switch-to-buffer-other-window
885 (reftex-get-file-buffer-force file nil)) 575 (reftex-get-file-buffer-force file nil))
886 (goto-char (or emergency-point (point-min))) 576 (goto-char (or emergency-point (point-min)))
887 (or (looking-at (regexp-quote literal)) 577 (or (looking-at (regexp-quote literal))
888 (let ((len (length literal))) 578 (let ((len (length literal)))
889 (or (reftex-nearest-match (regexp-quote literal) len) 579 (or (reftex-nearest-match (regexp-quote literal) len)
890 (reftex-nearest-match 580 (reftex-nearest-match
891 (reftex-make-regexp-allow-for-ctrl-m literal) len) 581 (reftex-make-regexp-allow-for-ctrl-m literal) len)
892 (reftex-nearest-match 582 (reftex-nearest-match
893 (reftex-make-desperate-section-regexp literal) len))))) 583 (reftex-make-desperate-section-regexp literal) len)))))
894 (t (message reftex-no-follow-message) nil)))) 584 (t (message reftex-no-follow-message) nil))))
895 (when match 585 (when match
896 (goto-char (match-beginning 0)) 586 (goto-char (match-beginning 0))
897 (if (not (= (point) (point-max))) (recenter 1)) 587 (if (not (= (point) (point-max))) (recenter 1))
@@ -913,17 +603,15 @@ label prefix determines the wording of a reference."
913 (setq old (substring old (match-end 0)))) 603 (setq old (substring old (match-end 0))))
914 new)) 604 new))
915 605
916;; Auto recentering of TOC window
917 606
918(defun reftex-recenter-toc-when-idle () 607(defun reftex-recenter-toc-when-idle ()
919 (and (> (buffer-size) 5) 608 (and (> (buffer-size) 5)
920 reftex-mode 609 reftex-mode
921 (not (active-minibuffer-window)) 610 (not (active-minibuffer-window))
922 (fboundp 'reftex-toc-mode) 611 (fboundp 'reftex-toc-mode)
923 (get-buffer-window "*toc*" 'visible) 612 (get-buffer-window "*toc*")
924 (string= reftex-last-toc-master (reftex-TeX-master-file)) 613 (string= reftex-last-toc-master (reftex-TeX-master-file))
925 (let (current-prefix-arg) 614 (reftex-toc-recenter)))
926 (reftex-toc-recenter))))
927 615
928(defun reftex-toggle-auto-toc-recenter () 616(defun reftex-toggle-auto-toc-recenter ()
929 "Toggle the automatic recentering of the toc window. 617 "Toggle the automatic recentering of the toc window.
@@ -932,73 +620,20 @@ section."
932 (interactive) 620 (interactive)
933 (if reftex-toc-auto-recenter-timer 621 (if reftex-toc-auto-recenter-timer
934 (progn 622 (progn
935 (if (featurep 'xemacs) 623 (if (featurep 'xemacs)
936 (delete-itimer reftex-toc-auto-recenter-timer) 624 (delete-itimer reftex-toc-auto-recenter-timer)
937 (cancel-timer reftex-toc-auto-recenter-timer)) 625 (cancel-timer reftex-toc-auto-recenter-timer))
938 (setq reftex-toc-auto-recenter-timer nil) 626 (setq reftex-toc-auto-recenter-timer nil)
939 (message "Automatic recentering of toc windwo was turned off")) 627 (message "Automatic recentering of toc buffer was turned off"))
940 (setq reftex-toc-auto-recenter-timer 628 (setq reftex-toc-auto-recenter-timer
941 (if (featurep 'xemacs) 629 (if (featurep 'xemacs)
942 (start-itimer "RefTeX Idle Timer for recenter" 630 (start-itimer "RefTeX Idle Timer for recenter"
943 'reftex-recenter-toc-when-idle 631 'reftex-recenter-toc-when-idle
944 reftex-idle-time reftex-idle-time t) 632 reftex-idle-time reftex-idle-time t)
945 (run-with-idle-timer 633 (run-with-idle-timer
946 reftex-idle-time t 'reftex-recenter-toc-when-idle))) 634 reftex-idle-time t 'reftex-recenter-toc-when-idle)))
947 (message "Automatic recentering of toc window was turned on"))) 635 (message "Automatic recentering of toc window was turned on")))
948 636
949(defun reftex-toc-toggle-dedicated-frame ()
950 "Toggle the display of a separate frame for the TOC.
951This frame is not used by the `reftex-toc' commands, but it is useful to
952always show the current section in connection with the option
953`reftex-auto-recenter-toc'."
954 (interactive)
955 (catch 'exit
956 (let* ((frames (frame-list)) frame
957 (get-frame-prop-func (if (fboundp 'frame-property)
958 'frame-property
959 'frame-parameter)))
960 (while (setq frame (pop frames))
961 (if (equal (funcall get-frame-prop-func frame 'name)
962 "RefTeX TOC Frame")
963 (progn
964 (delete-frame frame)
965 (throw 'exit nil))))
966 (reftex-make-separate-toc-frame))))
967
968(defun reftex-make-separate-toc-frame ()
969 ;; Create a new fame showing only the toc buffer.
970 (let ((current-frame (selected-frame))
971 (current-window (selected-window))
972 (current-toc-window (get-buffer-window "*toc*" 'visible))
973 current-toc-frame)
974 (if (and current-toc-window
975 (not (equal (selected-frame) (window-frame current-toc-window))))
976 nil
977 (setq current-toc-frame
978 (make-frame
979 '((name . "RefTeX TOC Frame")
980 (height . 20) (width . 60)
981 (unsplittable . t)
982 (minibuffer . nil)
983 (default-toolbar-visible-p . nil)
984 (menubar-visible-p . nil)
985 (horizontal-scrollbar-visible-p . nil))))
986 (select-frame current-toc-frame)
987 (switch-to-buffer "*toc*")
988 (select-frame current-frame)
989 (if (fboundp 'focus-frame) (focus-frame current-frame)
990 (if (fboundp 'x-focus-frame) (x-focus-frame current-frame)))
991 (select-window current-window)
992 (when (eq reftex-auto-recenter-toc 'frame)
993 (unless reftex-toc-auto-recenter-timer
994 (reftex-toggle-auto-toc-recenter))
995 (add-hook 'delete-frame-hook 'reftex-toc-delete-frame-hook)))))
996
997(defun reftex-toc-delete-frame-hook (frame)
998 (if (and reftex-toc-auto-recenter-timer
999 (reftex-toc-dframe-p frame))
1000 (progn
1001 (reftex-toggle-auto-toc-recenter))))
1002 637
1003;; Table of Contents map 638;; Table of Contents map
1004(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)]) 639(define-key reftex-toc-map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
@@ -1010,57 +645,47 @@ always show the current section in connection with the option
1010 'previous-line 'reftex-toc-previous reftex-toc-map global-map) 645 'previous-line 'reftex-toc-previous reftex-toc-map global-map)
1011 646
1012(loop for x in 647(loop for x in
1013 '(("n" . reftex-toc-next) 648 '(("n" . reftex-toc-next)
1014 ("p" . reftex-toc-previous) 649 ("p" . reftex-toc-previous)
1015 ("?" . reftex-toc-show-help) 650 ("?" . reftex-toc-show-help)
1016 (" " . reftex-toc-view-line) 651 (" " . reftex-toc-view-line)
1017 ("\C-m" . reftex-toc-goto-line-and-hide) 652 ("\C-m" . reftex-toc-goto-line-and-hide)
1018 ("\C-i" . reftex-toc-goto-line) 653 ("\C-i" . reftex-toc-goto-line)
1019 ("\C-c>" . reftex-toc-display-index) 654 ("\C-c>". reftex-toc-display-index)
1020 ("r" . reftex-toc-rescan) 655 ("r" . reftex-toc-rescan)
1021 ("R" . reftex-toc-Rescan) 656 ("R" . reftex-toc-Rescan)
1022 ("g" . revert-buffer) 657 ("g" . revert-buffer)
1023 ("q" . reftex-toc-quit); 658 ("q" . reftex-toc-quit)
1024 ("k" . reftex-toc-quit-and-kill) 659 ("k" . reftex-toc-quit-and-kill)
1025 ("f" . reftex-toc-toggle-follow); 660 ("f" . reftex-toc-toggle-follow)
1026 ("a" . reftex-toggle-auto-toc-recenter) 661 ("a" . reftex-toggle-auto-toc-recenter)
1027 ("d" . reftex-toc-toggle-dedicated-frame) 662 ("F" . reftex-toc-toggle-file-boundary)
1028 ("F" . reftex-toc-toggle-file-boundary) 663 ("i" . reftex-toc-toggle-index)
1029 ("i" . reftex-toc-toggle-index) 664 ("l" . reftex-toc-toggle-labels)
1030 ("l" . reftex-toc-toggle-labels) 665 ("t" . reftex-toc-max-level)
1031 ("t" . reftex-toc-max-level) 666 ("c" . reftex-toc-toggle-context)
1032 ("c" . reftex-toc-toggle-context) 667 ("%" . reftex-toc-toggle-commented)
1033; ("%" . reftex-toc-toggle-commented) 668 ("x" . reftex-toc-external)
1034 ("\M-%" . reftex-toc-rename-label) 669 ("z" . reftex-toc-jump)
1035 ("x" . reftex-toc-external) 670 ("." . reftex-toc-show-calling-point)
1036 ("z" . reftex-toc-jump) 671 ("\C-c\C-n" . reftex-toc-next-heading)
1037 ("." . reftex-toc-show-calling-point) 672 ("\C-c\C-p" . reftex-toc-previous-heading))
1038 ("\C-c\C-n" . reftex-toc-next-heading)
1039 ("\C-c\C-p" . reftex-toc-previous-heading)
1040 (">" . reftex-toc-demote)
1041 ("<" . reftex-toc-promote))
1042 do (define-key reftex-toc-map (car x) (cdr x))) 673 do (define-key reftex-toc-map (car x) (cdr x)))
1043 674
1044(loop for key across "0123456789" do 675(loop for key across "0123456789" do
1045 (define-key reftex-toc-map (vector (list key)) 'digit-argument)) 676 (define-key reftex-toc-map (vector (list key)) 'digit-argument))
1046(define-key reftex-toc-map "-" 'negative-argument) 677(define-key reftex-toc-map "-" 'negative-argument)
1047 678
1048(easy-menu-define 679(easy-menu-define
1049 reftex-toc-menu reftex-toc-map 680 reftex-toc-menu reftex-toc-map
1050 "Menu for Table of Contents buffer" 681 "Menu for Table of Contents buffer"
1051 '("TOC" 682 '("TOC"
1052 ["Show Location" reftex-toc-view-line t] 683 ["Show Location" reftex-toc-view-line t]
1053 ["Go To Location" reftex-toc-goto-line t] 684 ["Go To Location" reftex-toc-goto-line t]
1054 ["Exit & Go To Location" reftex-toc-goto-line-and-hide t] 685 ["Exit & Go To Location" reftex-toc-goto-line-and-hide t]
1055 ["Show Calling Point" reftex-toc-show-calling-point t] 686 ["Index" reftex-toc-display-index t]
1056 ["Quit" reftex-toc-quit t] 687 ["Quit" reftex-toc-quit t]
1057 "--" 688 "--"
1058 ("Edit"
1059 ["Promote" reftex-toc-promote t]
1060 ["Demote" reftex-toc-demote t]
1061 ["Rename Label" reftex-toc-rename-label t])
1062 "--"
1063 ["Index" reftex-toc-display-index t]
1064 ["External Document TOC " reftex-toc-external t] 689 ["External Document TOC " reftex-toc-external t]
1065 "--" 690 "--"
1066 ("Update" 691 ("Update"
@@ -1078,14 +703,10 @@ always show the current section in connection with the option
1078 ["Context" reftex-toc-toggle-context :style toggle 703 ["Context" reftex-toc-toggle-context :style toggle
1079 :selected reftex-toc-include-context] 704 :selected reftex-toc-include-context]
1080 "--" 705 "--"
1081 ["Follow Mode" reftex-toc-toggle-follow :style toggle 706 ["Follow Mode" reftex-toc-toggle-follow :style toggle
1082 :selected reftex-toc-follow-mode] 707 :selected reftex-toc-follow-mode])
1083 ["Auto Recenter" reftex-toggle-auto-toc-recenter :style toggle
1084 :selected reftex-toc-auto-recenter-timer]
1085 ["Dedicated Frame" reftex-toc-toggle-dedicated-frame t])
1086 "--" 708 "--"
1087 ["Help" reftex-toc-show-help t])) 709 ["Help" reftex-toc-show-help t]))
1088 710
1089 711
1090;;; arch-tag: 92400ce2-0b86-4c89-a606-4ed71acea17e 712;;; reftex-toc.el ends here
1091;;; reftex-toc.el ends here \ No newline at end of file
diff --git a/lisp/textmodes/reftex-vars.el b/lisp/textmodes/reftex-vars.el
index 53357342c51..91deb85056a 100644
--- a/lisp/textmodes/reftex-vars.el
+++ b/lisp/textmodes/reftex-vars.el
@@ -1,8 +1,8 @@
1;;; reftex-vars.el --- configuration variables for RefTeX 1;;; reftex-vars.el --- configuration variables for RefTeX
2;; Copyright (c) 1997, 1998, 1999, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6 6
7;; This file is part of GNU Emacs. 7;; This file is part of GNU Emacs.
8 8
@@ -13,11 +13,11 @@
13 13
14;; GNU Emacs is distributed in the hope that it will be useful, 14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the 16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details. 17;; GNU General Public License for more details.
18 18
19;; You should have received a copy of the GNU General Public License 19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs; see the file COPYING If not, write to the 20;; along with GNU Emacs; see the file COPYING. If not, write to the
21;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22;; Boston, MA 02111-1307, USA. 22;; Boston, MA 02111-1307, USA.
23 23
@@ -93,28 +93,28 @@
93 (LaTeX "LaTeX default environments" 93 (LaTeX "LaTeX default environments"
94 (("section" ?s "%S" "~\\ref{%s}" (nil . t) 94 (("section" ?s "%S" "~\\ref{%s}" (nil . t)
95 (regexp "parts?" "chapters?" "chap\\." "sections?" "sect?\\." 95 (regexp "parts?" "chapters?" "chap\\." "sections?" "sect?\\."
96 "paragraphs?" "par\\." 96 "paragraphs?" "par\\."
97 "\\\\S" "\247" "Teile?" "Kapitel" "Kap\\." "Abschnitte?" 97 "\\\\S" "\247" "Teile?" "Kapitel" "Kap\\." "Abschnitte?"
98 "appendi\\(x\\|ces\\)" "App\\." "Anh\"?ange?" "Anh\\.")) 98 "appendi\\(x\\|ces\\)" "App\\." "Anh\"?ange?" "Anh\\."))
99 99
100 ("enumerate" ?i "item:" "~\\ref{%s}" item 100 ("enumerate" ?i "item:" "~\\ref{%s}" item
101 (regexp "items?" "Punkte?")) 101 (regexp "items?" "Punkte?"))
102 102
103 ("equation" ?e "eq:" "~(\\ref{%s})" t 103 ("equation" ?e "eq:" "~(\\ref{%s})" t
104 (regexp "equations?" "eqs?\\." "eqn\\." "Gleichung\\(en\\)?" "Gl\\.")) 104 (regexp "equations?" "eqs?\\." "eqn\\." "Gleichung\\(en\\)?" "Gl\\."))
105 ("eqnarray" ?e "eq:" nil eqnarray-like) 105 ("eqnarray" ?e "eq:" nil eqnarray-like)
106 106
107 ("figure" ?f "fig:" "~\\ref{%s}" caption 107 ("figure" ?f "fig:" "~\\ref{%s}" caption
108 (regexp "figure?[sn]?" "figs?\\." "Abbildung\\(en\\)?" "Abb\\.")) 108 (regexp "figure?[sn]?" "figs?\\." "Abbildung\\(en\\)?" "Abb\\."))
109 ("figure*" ?f nil nil caption) 109 ("figure*" ?f nil nil caption)
110 110
111 ("table" ?t "tab:" "~\\ref{%s}" caption 111 ("table" ?t "tab:" "~\\ref{%s}" caption
112 (regexp "tables?" "tab\\." "Tabellen?")) 112 (regexp "tables?" "tab\\." "Tabellen?"))
113 ("table*" ?t nil nil caption) 113 ("table*" ?t nil nil caption)
114 114
115 ("\\footnote[]{}" ?n "fn:" "~\\ref{%s}" 2 115 ("\\footnote[]{}" ?n "fn:" "~\\ref{%s}" 2
116 (regexp "footnotes?" "Fussnoten?")) 116 (regexp "footnotes?" "Fussnoten?"))
117 117
118 ("any" ?\ " " "~\\ref{%s}" nil) 118 ("any" ?\ " " "~\\ref{%s}" nil)
119 119
120 ;; The label macro is hard coded, but it *could* be defined like this: 120 ;; The label macro is hard coded, but it *could* be defined like this:
@@ -141,19 +141,6 @@ distribution. Mixed-case symbols are convenience aliases.")
141 (?A . "\\citeauthor*{%l}") 141 (?A . "\\citeauthor*{%l}")
142 (?y . "\\citeyear{%l}") 142 (?y . "\\citeyear{%l}")
143 (?n . "\\nocite{%l}"))) 143 (?n . "\\nocite{%l}")))
144 (amsrefs "The AMSRefs package"
145 ((?\C-m . "\\cite{%l}")
146 (?p . "\\cite{%l}")
147 (?P . "\\cites{%l}")
148 (?t . "\\ocite{%l}")
149 (?T . "\\ocites{%l}")
150 (?y . "\\ycite{%l}")
151 (?Y . "\\ycites{%l}")
152 (?a . "\\citeauthor{%l}")
153 (?A . "\\citeauthory{%l}")
154 (?f . "\\fullcite{%l}")
155 (?F . "\\fullocite{%l}")
156 (?n . "\\nocite{%l}")))
157 (bibentry "The Bibentry package" 144 (bibentry "The Bibentry package"
158 "\\bibentry{%l}") 145 "\\bibentry{%l}")
159 (harvard "The Harvard package" 146 (harvard "The Harvard package"
@@ -191,20 +178,20 @@ The following conventions are valid for all alist entries:
191`?t' should point to a textual citation (citation as a noun). 178`?t' should point to a textual citation (citation as a noun).
192`?p' should point to a parenthetical citation.") 179`?p' should point to a parenthetical citation.")
193 180
194(defconst reftex-index-macros-builtin 181(defconst reftex-index-macros-builtin
195 '((default "Default \\index and \\glossary macros" 182 '((default "Default \\index and \\glossary macros"
196 (("\\index{*}" "idx" ?i "" nil t) 183 (("\\index{*}" "idx" ?i "" nil t)
197 ("\\glossary{*}" "glo" ?g "" nil t))) 184 ("\\glossary{*}" "glo" ?g "" nil t)))
198 (multind "The multind.sty package" 185 (multind "The multind.sty package"
199 (("\\index{}{*}" 1 ?i "" nil t))) 186 (("\\index{}{*}" 1 ?i "" nil t)))
200 (index "The index.sty package" 187 (index "The index.sty package"
201 (("\\index[]{*}" 1 ?i "" nil t) 188 (("\\index[]{*}" 1 ?i "" nil t)
202 ("\\index*[]{*}" 1 ?I "" nil nil))) 189 ("\\index*[]{*}" 1 ?I "" nil nil)))
203 (Index-Shortcut "index.sty with \\shortindexingon" 190 (Index-Shortcut "index.sty with \\shortindexingon"
204 (("\\index[]{*}" 1 ?i "" nil t) 191 (("\\index[]{*}" 1 ?i "" nil t)
205 ("\\index*[]{*}" 1 ?I "" nil nil) 192 ("\\index*[]{*}" 1 ?I "" nil nil)
206 ("^[]{*}" 1 ?^ "" texmathp t) 193 ("^[]{*}" 1 ?^ "" texmathp t)
207 ("_[]{*}" 1 ?_ "" texmathp nil)))) 194 ("_[]{*}" 1 ?_ "" texmathp nil))))
208 "Builtin stuff for reftex-index-macros. 195 "Builtin stuff for reftex-index-macros.
209Lower-case symbols correspond to a style file of the same name in the LaTeX 196Lower-case symbols correspond to a style file of the same name in the LaTeX
210distribution. Mixed-case symbols are convenience aliases.") 197distribution. Mixed-case symbols are convenience aliases.")
@@ -215,8 +202,8 @@ distribution. Mixed-case symbols are convenience aliases.")
215(defgroup reftex nil 202(defgroup reftex nil
216 "LaTeX label and citation support." 203 "LaTeX label and citation support."
217 :tag "RefTeX" 204 :tag "RefTeX"
218 :link '(url-link :tag "Home Page" 205 :link '(url-link :tag "Home Page"
219 "http://zon.astro.uva.nl/~dominik/Tools/") 206 "http://strw.leidenuniv.nl/~dominik/Tools/")
220 :link '(emacs-commentary-link :tag "Commentary in reftex.el" "reftex.el") 207 :link '(emacs-commentary-link :tag "Commentary in reftex.el" "reftex.el")
221 :link '(custom-manual "(reftex)Top") 208 :link '(custom-manual "(reftex)Top")
222 :prefix "reftex-" 209 :prefix "reftex-"
@@ -253,6 +240,7 @@ needs to be larger."
253 ("subsubsection" . 4) 240 ("subsubsection" . 4)
254 ("paragraph" . 5) 241 ("paragraph" . 5)
255 ("subparagraph" . 6) 242 ("subparagraph" . 6)
243 ("subsubparagraph" . 7)
256 ("addchap" . -1) ; KOMA-Script 244 ("addchap" . -1) ; KOMA-Script
257 ("addsec" . -2) ; KOMA-Script 245 ("addsec" . -2) ; KOMA-Script
258;;; ("minisec" . -7) ; KOMA-Script 246;;; ("minisec" . -7) ; KOMA-Script
@@ -263,19 +251,14 @@ The car of each cons cell is the name of the section macro (without
263the backslash). The cdr is a number indicating its level. A negative 251the backslash). The cdr is a number indicating its level. A negative
264level means the same level as the positive value, but the section will 252level means the same level as the positive value, but the section will
265never get a number. The cdr may also be a function which will be called 253never get a number. The cdr may also be a function which will be called
266to after the section-re matched to determine the level. 254to after the section-re matched to determine the level."
267This list is also used for promotion and demption of sectioning commands.
268If you are using a document class which has several sets of sectioning
269commands, promotion only works correctly if this list is sorted first
270by set, then within each set by level. The promotion commands always
271select the nearest entry with the correct new level."
272 :group 'reftex-table-of-contents-browser 255 :group 'reftex-table-of-contents-browser
273 :set 'reftex-set-dirty 256 :set 'reftex-set-dirty
274 :type '(repeat 257 :type '(repeat
275 (cons (string :tag "sectioning macro" "") 258 (cons (string :tag "sectioning macro" "")
276 (choice 259 (choice
277 (number :tag "level " 0) 260 (number :tag "level " 0)
278 (symbol :tag "function " my-level-func))))) 261 (symbol :tag "function " my-level-func)))))
279 262
280(defcustom reftex-toc-max-level 100 263(defcustom reftex-toc-max-level 100
281 "*The maximum level of toc entries which will be included in the TOC. 264 "*The maximum level of toc entries which will be included in the TOC.
@@ -295,43 +278,27 @@ and also do not show up in chapter numbers."
295 :type 'boolean) 278 :type 'boolean)
296 279
297 280
298(defcustom reftex-auto-recenter-toc 'frame 281(defcustom reftex-auto-recenter-toc nil
299 "*Non-nil means, turn automatic recentering of *TOC* window on. 282 "*Non-nil means, initially turn automatic recentering of toc on.
300When active, the *TOC* window will always show the section you 283When active, the *TOC* buffer will always show the section you
301are currently working in. Recentering happens whenever Emacs is idle for 284are currently working in. Recentering happens whenever Emacs is idle for
302more than `reftex-idle-time' seconds. 285more than `reftex-idle-time' seconds.
303 286This feature can be turned on and off from the menu
304Value t means, turn on immediately when RefTeX gets started. Then, 287(Ref->Options)."
305recentering will work for any toc window created during the session.
306
307Value 'frame (the default) means, turn automatic recentering on only while the
308dedicated TOC frame does exist, and do the recentering only in that frame. So
309when creating that frame (with \"d\" key in an ordinary TOC window), the
310automatic recentering is turned on. When the frame gets destroyed, automatic
311recentering is turned off again.
312
313This feature can be turned on and off from the menu
314\(Ref->Options)."
315 :group 'reftex-table-of-contents-browser 288 :group 'reftex-table-of-contents-browser
316 :type '(choice 289 :type 'boolean)
317 (const :tag "never" nil) 290
318 (const :tag "always" t)
319 (const :tag "in dedicated frame only" frame)))
320
321(defcustom reftex-toc-split-windows-horizontally nil 291(defcustom reftex-toc-split-windows-horizontally nil
322 "*Non-nil means, create TOC window by splitting window horizontally." 292 "*Non-nil means, create TOC window by splitting window horizontally."
323 :group 'reftex-table-of-contents-browser 293 :group 'reftex-table-of-contents-browser
324 :type 'boolean) 294 :type 'boolean)
325 295
326(defcustom reftex-toc-split-windows-fraction .3 296(defcustom reftex-toc-split-windows-horizontally-fraction .5
327 "*Fraction of the width or height of the frame to be used for TOC window. 297 "*Fraction of the horizontal width of the frame to be used for TOC window.
328See also `reftex-toc-split-windows-horizontally'." 298Only relevant when `reftex-toc-split-windows-horizontally' is non-nil."
329 :group 'reftex-table-of-contents-browser 299 :group 'reftex-table-of-contents-browser
330 :type 'number) 300 :type 'number)
331 301
332(defvar reftex-toc-split-windows-horizontally-fraction 0.5
333 "This variable is obsolete, use `reftex-toc-split-windows-fraction' instead.")
334
335(defcustom reftex-toc-keep-other-windows t 302(defcustom reftex-toc-keep-other-windows t
336 "*Non-nil means, split the selected window to display the *toc* buffer. 303 "*Non-nil means, split the selected window to display the *toc* buffer.
337This helps to keep the window configuration, but makes the *toc* small. 304This helps to keep the window configuration, but makes the *toc* small.
@@ -358,17 +325,6 @@ This flag can be toggled from within the *toc* buffer with the `i' key."
358 :group 'reftex-table-of-contents-browser 325 :group 'reftex-table-of-contents-browser
359 :type 'boolean) 326 :type 'boolean)
360 327
361(defcustom reftex-toc-confirm-promotion 2
362 "*Non-nil means, promotion/demotion commands first prompt for confirmation.
363When nil, the command is executed immediately. When this is an integer
364N, ask for confirmation only if N or more section commands are going to be
365changed."
366 :group 'reftex-table-of-contents-browser
367 :type '(choice
368 (const :tag "Never" nil)
369 (const :tag "Always" t)
370 (number :tag "When more than N sections" :value 2)))
371
372(defcustom reftex-toc-include-context nil 328(defcustom reftex-toc-include-context nil
373 "*Non-nil means, include context with labels in the *toc* buffer. 329 "*Non-nil means, include context with labels in the *toc* buffer.
374Context will only be shown when labels are visible as well. 330Context will only be shown when labels are visible as well.
@@ -407,22 +363,22 @@ When nil, follow-mode will be suspended for stuff in unvisited files."
407 363
408(defcustom reftex-default-label-alist-entries 364(defcustom reftex-default-label-alist-entries
409 '(amsmath endnotes fancybox floatfig longtable picinpar 365 '(amsmath endnotes fancybox floatfig longtable picinpar
410 rotating sidecap subfigure supertab wrapfig LaTeX) 366 rotating sidecap subfigure supertab wrapfig LaTeX)
411 "Default label alist specifications. LaTeX should always be the last entry. 367 "Default label alist specifications. LaTeX should always be the last entry.
412The value of this variable is a list of symbols with associations in the 368The value of this variable is a list of symbols with associations in the
413constant `reftex-label-alist-builtin'. Check that constant for a full list 369constant `reftex-label-alist-builtin'. Check that constant for a full list
414of options." 370of options."
415 :group 'reftex-defining-label-environments 371 :group 'reftex-defining-label-environments
416 :set 'reftex-set-dirty 372 :set 'reftex-set-dirty
417 :type `(set 373 :type `(set
418 :indent 4 374 :indent 4
419 :inline t 375 :inline t
420 :greedy t 376 :greedy t
421 ,@(mapcar 377 ,@(mapcar
422 (lambda (x) 378 (lambda (x)
423 (list 'const :tag (concat (symbol-name (nth 0 x)) 379 (list 'const :tag (concat (symbol-name (nth 0 x))
424 ": " (nth 1 x)) 380 ": " (nth 1 x))
425 (nth 0 x))) 381 (nth 0 x)))
426 reftex-label-alist-builtin))) 382 reftex-label-alist-builtin)))
427 383
428(defcustom reftex-label-alist nil 384(defcustom reftex-label-alist nil
@@ -570,10 +526,10 @@ list. However, builtin defaults should normally be set with the variable
570 (choice :tag "Environment or \\macro " 526 (choice :tag "Environment or \\macro "
571 (const :tag "Ignore, just use typekey" nil) 527 (const :tag "Ignore, just use typekey" nil)
572 (string "") 528 (string "")
573 (symbol :tag "Special parser" my-parser)) 529 (symbol :tag "Special parser" my-parser))
574 (choice :tag "Type specification " 530 (choice :tag "Type specification "
575 (const :tag "unspecified, like in \\label" nil) 531 (const :tag "unspecified, like in \\label" nil)
576 (character :tag "Char " ?a)) 532 (character :tag "Char " ?a))
577 (choice :tag "Label prefix string " 533 (choice :tag "Label prefix string "
578 (const :tag "Default" nil) 534 (const :tag "Default" nil)
579 (string :tag "String" "lab:")) 535 (string :tag "String" "lab:"))
@@ -581,44 +537,44 @@ list. However, builtin defaults should normally be set with the variable
581 (const :tag "Default" nil) 537 (const :tag "Default" nil)
582 (string :tag "String" "~\\ref{%s}")) 538 (string :tag "String" "~\\ref{%s}"))
583 (choice :tag "Context method " 539 (choice :tag "Context method "
584 (const :tag "Default position" t) 540 (const :tag "Default position" t)
585 (const :tag "After label" nil) 541 (const :tag "After label" nil)
586 (number :tag "Macro arg nr" 1) 542 (number :tag "Macro arg nr" 1)
587 (regexp :tag "Regexp" "") 543 (regexp :tag "Regexp" "")
588 (const :tag "Caption in float" caption) 544 (const :tag "Caption in float" caption)
589 (const :tag "Item in list" item) 545 (const :tag "Item in list" item)
590 (const :tag "Eqnarray-like" eqnarray-like) 546 (const :tag "Eqnarray-like" eqnarray-like)
591 (const :tag "Alignat-like" alignat-like) 547 (const :tag "Alignat-like" alignat-like)
592 (symbol :tag "Function" my-func)) 548 (symbol :tag "Function" my-func))
593 (repeat :tag "Magic words" :extra-offset 2 (string)) 549 (repeat :tag "Magic words" :extra-offset 2 (string))
594 (option (choice :tag "Make TOC entry " 550 (option (choice :tag "Make TOC entry "
595 (const :tag "No entry" nil) 551 (const :tag "No entry" nil)
596 (integer :tag "Level" :value -3)))) 552 (integer :tag "Level" :value -3))))
597 (choice 553 (choice
598 :tag "Package" 554 :tag "Package"
599 :value AMSTeX 555 :value AMSTeX
600 ,@(mapcar 556 ,@(mapcar
601 (lambda (x) 557 (lambda (x)
602 (list 'const :tag (concat (symbol-name (nth 0 x))) 558 (list 'const :tag (concat (symbol-name (nth 0 x)))
603 (nth 0 x))) 559 (nth 0 x)))
604 reftex-label-alist-builtin))))) 560 reftex-label-alist-builtin)))))
605 561
606(defcustom reftex-section-prefixes '((0 . "part:") (1 . "cha:") (t . "sec:")) 562(defcustom reftex-section-prefixes '((0 . "part:") (1 . "cha:") (t . "sec:"))
607 "Prefixes for section labels. 563 "Prefixes for section labels.
608When the label prefix given in an entry in `reftex-label-alist' contains `%S', 564When the label prefix given in an entry in `reftex-label-alist' contains `%S',
609this list is used to determine the correct prefix string depending on the 565this list is used to determine the correct prefix string depending on the
610current section level. 566current section level.
611The list is an alist, with each entry of the form (KEY . PREFIX) 567The list is an alist, with each entry of the form (KEY . PREFIX)
612Possible keys are sectioning macro names like `chapter', section levels 568Possible keys are sectioning macro names like `chapter', section levels
613\(as given in `reftex-section-levels'), and t for the default." 569(as given in `reftex-section-levels'), and t for the default."
614 :group 'reftex-defining-label-environments 570 :group 'reftex-defining-label-environments
615 :type '(repeat 571 :type '(repeat
616 (cons :value (0 . "") 572 (cons :value (0 . "")
617 (choice 573 (choice
618 (string :tag "macro name") 574 (string :tag "macro name")
619 (integer :tag "section level") 575 (integer :tag "section level")
620 (const :tag "default" t)) 576 (const :tag "default" t))
621 (string :tag "Prefix")))) 577 (string :tag "Prefix"))))
622 578
623(defcustom reftex-default-context-regexps 579(defcustom reftex-default-context-regexps
624 '((caption . "\\\\\\(rot\\)?caption\\*?[[{]") 580 '((caption . "\\\\\\(rot\\)?caption\\*?[[{]")
@@ -631,7 +587,7 @@ the final regular expression - so %s will be replaced with the environment
631or macro." 587or macro."
632 :group 'reftex-defining-label-environments 588 :group 'reftex-defining-label-environments
633 :type '(repeat (cons (symbol) (regexp)))) 589 :type '(repeat (cons (symbol) (regexp))))
634 590
635(defcustom reftex-special-environment-functions nil 591(defcustom reftex-special-environment-functions nil
636 "List of functions to be called when trying to figure out current environment. 592 "List of functions to be called when trying to figure out current environment.
637These are special functions to detect \"environments\" which do not 593These are special functions to detect \"environments\" which do not
@@ -677,7 +633,7 @@ And here is the setup for RefTeX:
677 (let ((pos (point)) p1) 633 (let ((pos (point)) p1)
678 (save-excursion 634 (save-excursion
679 ;; Search for any of the linguex item macros at the beginning of a line 635 ;; Search for any of the linguex item macros at the beginning of a line
680 (if (re-search-backward 636 (if (re-search-backward
681 \"^[ \\t]*\\\\(\\\\\\\\\\\\(ex\\\\|a\\\\|b\\\\|c\\\\|d\\\\|e\\\\|f\\\\)g?\\\\.\\\\)\" bound t) 637 \"^[ \\t]*\\\\(\\\\\\\\\\\\(ex\\\\|a\\\\|b\\\\|c\\\\|d\\\\|e\\\\|f\\\\)g?\\\\.\\\\)\" bound t)
682 (progn 638 (progn
683 (setq p1 (match-beginning 1)) 639 (setq p1 (match-beginning 1))
@@ -687,7 +643,7 @@ And here is the setup for RefTeX:
687 nil 643 nil
688 ;; OK, we got it 644 ;; OK, we got it
689 (cons \"linguex\" p1))) 645 (cons \"linguex\" p1)))
690 ;; Return nil for not found 646 ;; Return nil for not found
691 nil)))) 647 nil))))
692 648
6933. Tell RefTeX to use this function 6493. Tell RefTeX to use this function
@@ -734,7 +690,7 @@ indicating the label types for which it should be true. The strings work
734like character classes. 690like character classes.
735Thus, the combination may be set differently for each label type. The 691Thus, the combination may be set differently for each label type. The
736default settings \"s\" and \"sft\" mean: Derive section labels from headings 692default settings \"s\" and \"sft\" mean: Derive section labels from headings
737\(with confirmation). Prompt for figure and table labels. Use simple labels 693(with confirmation). Prompt for figure and table labels. Use simple labels
738without confirmation for everything else. 694without confirmation for everything else.
739The available label types are: s (section), f (figure), t (table), i (item), 695The available label types are: s (section), f (figure), t (table), i (item),
740e (equation), n (footnote), N (endnote), plus any definitions in 696e (equation), n (footnote), N (endnote), plus any definitions in
@@ -795,7 +751,7 @@ DOWNCASE t: Downcase words before using them."
795 (repeat :tag "Ignore words" 751 (repeat :tag "Ignore words"
796 :entry-format " %i %d %v" 752 :entry-format " %i %d %v"
797 (string :tag "")) 753 (string :tag ""))
798 (option (boolean :tag "Downcase words ")))) 754 (option (boolean :tag "Downcase words "))))
799 755
800(defcustom reftex-label-illegal-re "[^-a-zA-Z0-9_+=:;,.]" 756(defcustom reftex-label-illegal-re "[^-a-zA-Z0-9_+=:;,.]"
801 "Regexp matching characters not legal in labels." 757 "Regexp matching characters not legal in labels."
@@ -871,7 +827,7 @@ get one interactively during selection from the label menu."
871 (choice :tag "Hide short context " ,@reftex-tmp) 827 (choice :tag "Hide short context " ,@reftex-tmp)
872 (choice :tag "Follow context in other window " ,@reftex-tmp) 828 (choice :tag "Follow context in other window " ,@reftex-tmp)
873 (choice :tag "Show commented labels " ,@reftex-tmp) 829 (choice :tag "Show commented labels " ,@reftex-tmp)
874 (choice :tag "Obsolete flag, Don't use. " ,@reftex-tmp) 830 (choice :tag "Obsolete flag. Don't use. " ,@reftex-tmp)
875 (choice :tag "Show begin/end of included files" ,@reftex-tmp))) 831 (choice :tag "Show begin/end of included files" ,@reftex-tmp)))
876 832
877(defcustom reftex-multiref-punctuation '((?, . ", ") (?- . "--") (?+ . " and ")) 833(defcustom reftex-multiref-punctuation '((?, . ", ") (?- . "--") (?+ . " and "))
@@ -886,7 +842,7 @@ This is used to string together whole reference sets, like
886 842
887(defcustom reftex-vref-is-default nil 843(defcustom reftex-vref-is-default nil
888 "*Non-nil means, the varioref macro \\vref is used as default. 844 "*Non-nil means, the varioref macro \\vref is used as default.
889In the selection buffer, the `v' key toggles the reference macro between 845In the selection buffer, the `v' key toggles the reference macro between
890`\\ref' and `\\vref'. The value of this variable determines the default 846`\\ref' and `\\vref'. The value of this variable determines the default
891which is active when entering the selection process. 847which is active when entering the selection process.
892Instead of nil or t, this may also be a string of type letters indicating 848Instead of nil or t, this may also be a string of type letters indicating
@@ -896,7 +852,7 @@ the label types for which it should be true."
896 852
897(defcustom reftex-fref-is-default nil 853(defcustom reftex-fref-is-default nil
898 "*Non-nil means, the fancyref macro \\fref is used as default. 854 "*Non-nil means, the fancyref macro \\fref is used as default.
899In the selection buffer, the `V' key toggles the reference macro between 855In the selection buffer, the `V' key toggles the reference macro between
900`\\ref', `\\fref' and `\\Fref'. The value of this variable determines 856`\\ref', `\\fref' and `\\Fref'. The value of this variable determines
901the default which is active when entering the selection process. 857the default which is active when entering the selection process.
902Instead of nil or t, this may also be a string of type letters indicating 858Instead of nil or t, this may also be a string of type letters indicating
@@ -920,7 +876,7 @@ a label type. If you set this variable to nil, RefTeX will always prompt."
920 876
921(defcustom reftex-format-ref-function nil 877(defcustom reftex-format-ref-function nil
922 "Function which produces the string to insert as a reference. 878 "Function which produces the string to insert as a reference.
923Normally should be nil, because the format to insert a reference can 879Normally should be nil, because the format to insert a reference can
924already be specified in `reftex-label-alist'. 880already be specified in `reftex-label-alist'.
925This hook also is used by the special commands to insert `\\vref' and `\\fref' 881This hook also is used by the special commands to insert `\\vref' and `\\fref'
926references, so even if you set this, your setting will be ignored by 882references, so even if you set this, your setting will be ignored by
@@ -1001,13 +957,13 @@ It is also possible to access all other BibTeX database fields:
1001%i institution %j journal %k key %m month 957%i institution %j journal %k key %m month
1002%n number %o organization %p pages %P first page 958%n number %o organization %p pages %P first page
1003%r address %s school %u publisher %t title 959%r address %s school %u publisher %t title
1004%v volume %y year 960%v volume %y year
1005%B booktitle, abbreviated %T title, abbreviated 961%B booktitle, abbreviated %T title, abbreviated
1006 962
1007Usually, only %l is needed. The other stuff is mainly for the echo area 963Usually, only %l is needed. The other stuff is mainly for the echo area
1008display, and for (setq reftex-comment-citations t). 964display, and for (setq reftex-comment-citations t).
1009 965
1010%< as a special operator kills punctuation and space around it after the 966%< as a special operator kills punctuation and space around it after the
1011string has been formatted. 967string has been formatted.
1012 968
1013Beware that all this only works with BibTeX database files. When 969Beware that all this only works with BibTeX database files. When
@@ -1019,7 +975,7 @@ will be prompted for a character to select one of the possible format
1019strings. 975strings.
1020 In order to configure this variable, you can either set 976 In order to configure this variable, you can either set
1021`reftex-cite-format' directly yourself or set it to the SYMBOL of one of 977`reftex-cite-format' directly yourself or set it to the SYMBOL of one of
1022the predefined styles. The predefined symbols are those which have an 978the predefined styles. The predefined symbols are those which have an
1023association in the constant `reftex-cite-format-builtin'. 979association in the constant `reftex-cite-format-builtin'.
1024E.g.: (setq reftex-cite-format 'natbib)" 980E.g.: (setq reftex-cite-format 'natbib)"
1025 :group 'reftex-citation-support 981 :group 'reftex-citation-support
@@ -1077,7 +1033,7 @@ This is a list of 3 strings.
1077 1033
1078(defcustom reftex-format-cite-function nil 1034(defcustom reftex-format-cite-function nil
1079 "Function which produces the string to insert as a citation. 1035 "Function which produces the string to insert as a citation.
1080Normally should be nil, because the format to insert a reference can 1036Normally should be nil, because the format to insert a reference can
1081already be specified in `reftex-cite-format'. 1037already be specified in `reftex-cite-format'.
1082The function will be called with two arguments, the CITATION KEY and the 1038The function will be called with two arguments, the CITATION KEY and the
1083DEFAULT FORMAT, which is taken from `reftex-cite-format'. The function 1039DEFAULT FORMAT, which is taken from `reftex-cite-format'. The function
@@ -1110,16 +1066,16 @@ you will be asked for confirmation to turn it on and rescan the document."
1110These correspond to the makeindex keywords LEVEL ENCAP ACTUAL QUOTE ESCAPE." 1066These correspond to the makeindex keywords LEVEL ENCAP ACTUAL QUOTE ESCAPE."
1111 :group 'reftex-index-support 1067 :group 'reftex-index-support
1112 :type '(list 1068 :type '(list
1113 (string :tag "LEVEL separator") 1069 (string :tag "LEVEL separator")
1114 (string :tag "ENCAP char ") 1070 (string :tag "ENCAP char ")
1115 (string :tag "ACTUAL char ") 1071 (string :tag "ACTUAL char ")
1116 (string :tag "QUOTE char ") 1072 (string :tag "QUOTE char ")
1117 (string :tag "ESCAPE char "))) 1073 (string :tag "ESCAPE char ")))
1118 1074
1119(defcustom reftex-index-macros nil 1075(defcustom reftex-index-macros nil
1120 "Macros which define index entries. The structure is 1076 "Macros which define index entries. The structure is
1121 1077
1122\(MACRO INDEX-TAG KEY PREFIX EXCLUDE REPEAT) 1078(MACRO INDEX-TAG KEY PREFIX EXCLUDE REPEAT)
1123 1079
1124MACRO is the macro. Arguments should be denoted by empty braces like 1080MACRO is the macro. Arguments should be denoted by empty braces like
1125\\index[]{*}. Use square brackets to denote optional arguments. The star 1081\\index[]{*}. Use square brackets to denote optional arguments. The star
@@ -1160,43 +1116,43 @@ package here."
1160 :group 'reftex-index-support 1116 :group 'reftex-index-support
1161 :set 'reftex-set-dirty 1117 :set 'reftex-set-dirty
1162 :type `(list 1118 :type `(list
1163 (repeat 1119 (repeat
1164 :inline t 1120 :inline t
1165 (list :value ("" "idx" ?a "" nil) 1121 (list :value ("" "idx" ?a "" nil)
1166 (string :tag "Macro with args") 1122 (string :tag "Macro with args")
1167 (choice :tag "Index Tag " 1123 (choice :tag "Index Tag "
1168 (string) 1124 (string)
1169 (integer :tag "Macro arg Nr" :value 1)) 1125 (integer :tag "Macro arg Nr" :value 1))
1170 (character :tag "Access Key ") 1126 (character :tag "Access Key ")
1171 (string :tag "Key Prefix ") 1127 (string :tag "Key Prefix ")
1172 (symbol :tag "Exclusion hook ") 1128 (symbol :tag "Exclusion hook ")
1173 (boolean :tag "Repeat Outside "))) 1129 (boolean :tag "Repeat Outside ")))
1174 (option 1130 (option
1175 :tag "Package:" 1131 :tag "Package:"
1176 (choice :tag "Package" 1132 (choice :tag "Package"
1177 :value index 1133 :value index
1178 ,@(mapcar 1134 ,@(mapcar
1179 (lambda (x) 1135 (lambda (x)
1180 (list 'const :tag (concat (symbol-name (nth 0 x)) 1136 (list 'const :tag (concat (symbol-name (nth 0 x))
1181 ": " (nth 1 x)) 1137 ": " (nth 1 x))
1182 (nth 0 x))) 1138 (nth 0 x)))
1183 reftex-index-macros-builtin))))) 1139 reftex-index-macros-builtin)))))
1184 1140
1185(defcustom reftex-index-default-macro '(?i "idx") 1141(defcustom reftex-index-default-macro '(?i "idx")
1186 "The default index macro for \\[reftex-index-selection-or-word]. 1142 "The default index macro for \\[reftex-index-selection-or-word].
1187This is a list with (MACRO-KEY DEFAULT-TAG). 1143This is a list with (MACRO-KEY DEFAULT-TAG).
1188 1144
1189MACRO-KEY: Character identifying an index macro - see `reftex-index-macros'. 1145MACRO-KEY: Character identifying an index macro - see `reftex-index-macros'.
1190DEFAULT-TAG: This is the tag to be used if the macro requires a TAG argument. 1146DEFAULT-TAG: This is the tag to be used if the macro requires a TAG argument.
1191 When this is nil and a TAG is needed, RefTeX will ask for it. 1147 When this is nil and a TAG is needed, RefTeX will ask for it.
1192 When this is the empty string and the TAG argument of the index 1148 When this is the empty string and the TAG argument of the index
1193 macro is optional, the TAG argument will be omitted." 1149 macro is optional, the TAG argument will be omitted."
1194 :group 'reftex-index-support 1150 :group 'reftex-index-support
1195 :type '(list 1151 :type '(list
1196 (character :tag "Character identifying default macro") 1152 (character :tag "Character identifying default macro")
1197 (choice :tag "Default index tag " 1153 (choice :tag "Default index tag "
1198 (const nil) 1154 (const nil)
1199 (string)))) 1155 (string))))
1200 1156
1201(defcustom reftex-index-default-tag "idx" 1157(defcustom reftex-index-default-tag "idx"
1202 "Default index tag. 1158 "Default index tag.
@@ -1210,16 +1166,16 @@ nil Do not provide a default index
1210last The last used index tag will be offered as default." 1166last The last used index tag will be offered as default."
1211 :group 'reftex-index-support 1167 :group 'reftex-index-support
1212 :type '(choice 1168 :type '(choice
1213 (const :tag "no default" nil) 1169 (const :tag "no default" nil)
1214 (const :tag "last used " 'last) 1170 (const :tag "last used " 'last)
1215 (string :tag "index tag " "idx"))) 1171 (string :tag "index tag " "idx")))
1216 1172
1217(defcustom reftex-index-math-format "$%s$" 1173(defcustom reftex-index-math-format "$%s$"
1218 "Format of index entries when copied from inside math mode. 1174 "Format of index entries when copied from inside math mode.
1219When `reftex-index-selection-or-word' is executed inside TeX math mode, 1175When `reftex-index-selection-or-word' is executed inside TeX math mode,
1220the index key copied from the buffer is processed with this format string 1176the index key copied from the buffer is processed with this format string
1221through the `format' function. This can be used to add the math delimiters 1177through the `format' function. This can be used to add the math delimiters
1222\(e.g. `$') to the string. 1178(e.g. `$') to the string.
1223Requires the `texmathp.el' library which is part of AUCTeX." 1179Requires the `texmathp.el' library which is part of AUCTeX."
1224 :group 'reftex-index-support 1180 :group 'reftex-index-support
1225 :type 'string) 1181 :type 'string)
@@ -1273,8 +1229,8 @@ at one of these points, no word boundary is required there."
1273If the function returns nil, the current match is skipped." 1229If the function returns nil, the current match is skipped."
1274 :group 'reftex-index-support 1230 :group 'reftex-index-support
1275 :type '(choice 1231 :type '(choice
1276 (const :tag "No verification" nil) 1232 (const :tag "No verification" nil)
1277 (function))) 1233 (function)))
1278 1234
1279(defcustom reftex-index-phrases-skip-indexed-matches nil 1235(defcustom reftex-index-phrases-skip-indexed-matches nil
1280 "*Non-nil means, skip matches which appear to be indexed already. 1236 "*Non-nil means, skip matches which appear to be indexed already.
@@ -1282,7 +1238,7 @@ When doing global indexing from the phrases buffer, searches for some
1282phrases may match at places where that phrase was already indexed. In 1238phrases may match at places where that phrase was already indexed. In
1283particular when indexing an already processed document again, this 1239particular when indexing an already processed document again, this
1284will even be the norm. When this variable is non-nil, RefTeX checks if 1240will even be the norm. When this variable is non-nil, RefTeX checks if
1285the match is inside an index macro argument, or if an index macro is directly 1241the match is an index macro argument, or if an index macro is directly
1286before or after the phrase. If that is the case, that match will 1242before or after the phrase. If that is the case, that match will
1287be ignored." 1243be ignored."
1288 :group 'reftex-index-support 1244 :group 'reftex-index-support
@@ -1326,7 +1282,7 @@ to that section."
1326 1282
1327(defcustom reftex-index-include-context nil 1283(defcustom reftex-index-include-context nil
1328 "*Non-nil means, display the index definition context in the index buffer. 1284 "*Non-nil means, display the index definition context in the index buffer.
1329This flag may also be toggled from the index buffer with the `c' key." 1285This flag may also be toggled from the index buffer with the `c' key."
1330 :group 'reftex-index-support 1286 :group 'reftex-index-support
1331 :type 'boolean) 1287 :type 'boolean)
1332 1288
@@ -1349,9 +1305,9 @@ This is used when `reftex-view-crossref' is called with point in an
1349argument of a macro. Note that crossref viewing for citations, 1305argument of a macro. Note that crossref viewing for citations,
1350references (both ways) and index entries is hard-coded. This variable 1306references (both ways) and index entries is hard-coded. This variable
1351is only to configure additional structures for which crossreference 1307is only to configure additional structures for which crossreference
1352viewing can be useful. Each entry has the structure 1308viewing can be useful. Each entry has the structure
1353 1309
1354\(MACRO-RE SEARCH-RE HIGHLIGHT). 1310(MACRO-RE SEARCH-RE HIGHLIGHT).
1355 1311
1356MACRO-RE is matched against the macro. SEARCH-RE is the regexp used 1312MACRO-RE is matched against the macro. SEARCH-RE is the regexp used
1357to search for cross references. `%s' in this regexp is replaced with 1313to search for cross references. `%s' in this regexp is replaced with
@@ -1359,8 +1315,8 @@ with the macro argument at point. HIGHLIGHT is an integer indicating
1359which subgroup of the match should be highlighted." 1315which subgroup of the match should be highlighted."
1360 :group 'reftex-viewing-cross-references 1316 :group 'reftex-viewing-cross-references
1361 :type '(repeat (group (regexp :tag "Macro Regexp ") 1317 :type '(repeat (group (regexp :tag "Macro Regexp ")
1362 (string :tag "Search Regexp ") 1318 (string :tag "Search Regexp ")
1363 (integer :tag "Highlight Group")))) 1319 (integer :tag "Highlight Group"))))
1364 1320
1365(defcustom reftex-auto-view-crossref t 1321(defcustom reftex-auto-view-crossref t
1366 "*Non-nil means, initially turn automatic viewing of crossref info on. 1322 "*Non-nil means, initially turn automatic viewing of crossref info on.
@@ -1370,12 +1326,12 @@ argument of a \\ref or \\cite macro, and no other message is being
1370displayed, the echo area will display information about that cross 1326displayed, the echo area will display information about that cross
1371reference. You can also set the variable to the symbol `window'. In 1327reference. You can also set the variable to the symbol `window'. In
1372this case a small temporary window is used for the display. 1328this case a small temporary window is used for the display.
1373This feature can be turned on and off from the menu 1329This feature can be turned on and off from the menu
1374\(Ref->Options)." 1330(Ref->Options)."
1375 :group 'reftex-viewing-cross-references 1331 :group 'reftex-viewing-cross-references
1376 :type '(choice (const :tag "off" nil) 1332 :type '(choice (const :tag "off" nil)
1377 (const :tag "in Echo Area" t) 1333 (const :tag "in Echo Area" t)
1378 (const :tag "in Other Window" window))) 1334 (const :tag "in Other Window" window)))
1379 1335
1380(defcustom reftex-idle-time 1.2 1336(defcustom reftex-idle-time 1.2
1381 "*Time (secs) Emacs has to be idle before automatic crossref display is done. 1337 "*Time (secs) Emacs has to be idle before automatic crossref display is done.
@@ -1416,7 +1372,7 @@ Several entries are possible.
1416- If an element is the name of an environment variable, its content is used. 1372- If an element is the name of an environment variable, its content is used.
1417- If an element starts with an exclamation mark, it is used as a command 1373- If an element starts with an exclamation mark, it is used as a command
1418 to retrieve the path. A typical command with the kpathsearch library would 1374 to retrieve the path. A typical command with the kpathsearch library would
1419 be `!kpsewhich -show-path=.tex'. 1375 be `!kpsewhich -show-path=.tex'.
1420- Otherwise the element itself is interpreted as a path. 1376- Otherwise the element itself is interpreted as a path.
1421Multiple directories can be separated by the system dependent `path-separator'. 1377Multiple directories can be separated by the system dependent `path-separator'.
1422Directories ending in `//' or `!!' will be expanded recursively. 1378Directories ending in `//' or `!!' will be expanded recursively.
@@ -1431,7 +1387,7 @@ Several entries are possible.
1431- If an element is the name of an environment variable, its content is used. 1387- If an element is the name of an environment variable, its content is used.
1432- If an element starts with an exclamation mark, it is used as a command 1388- If an element starts with an exclamation mark, it is used as a command
1433 to retrieve the path. A typical command with the kpathsearch library would 1389 to retrieve the path. A typical command with the kpathsearch library would
1434 be `!kpsewhich -show-path=.bib'. 1390 be `!kpsewhich -show-path=.bib'.
1435- Otherwise the element itself is interpreted as a path. 1391- Otherwise the element itself is interpreted as a path.
1436Multiple directories can be separated by the system dependent `path-separator'. 1392Multiple directories can be separated by the system dependent `path-separator'.
1437Directories ending in `//' or `!!' will be expanded recursively. 1393Directories ending in `//' or `!!' will be expanded recursively.
@@ -1442,7 +1398,7 @@ See also `reftex-use-external-file-finders'."
1442 :type '(repeat (string :tag "Specification"))) 1398 :type '(repeat (string :tag "Specification")))
1443 1399
1444(defcustom reftex-file-extensions '(("tex" . (".tex" ".ltx")) 1400(defcustom reftex-file-extensions '(("tex" . (".tex" ".ltx"))
1445 ("bib" . (".bib"))) 1401 ("bib" . (".bib")))
1446 "*Association list with file extensions for different file types. 1402 "*Association list with file extensions for different file types.
1447This is a list of items, each item is like: (TYPE . (DEF-EXT OTHER-EXT ...)) 1403This is a list of items, each item is like: (TYPE . (DEF-EXT OTHER-EXT ...))
1448 1404
@@ -1457,7 +1413,7 @@ If you are using AUCTeX, you also need to add new extensions to
1457TeX-file-extensions." 1413TeX-file-extensions."
1458 :group 'reftex-finding-files 1414 :group 'reftex-finding-files
1459 :type '(repeat (cons (string :tag "File type") 1415 :type '(repeat (cons (string :tag "File type")
1460 (repeat (string :tag "Extension"))))) 1416 (repeat (string :tag "Extension")))))
1461 1417
1462(defcustom reftex-search-unrecursed-path-first t 1418(defcustom reftex-search-unrecursed-path-first t
1463 "*Non-nil means, search all specified directories before trying recursion. 1419 "*Non-nil means, search all specified directories before trying recursion.
@@ -1476,13 +1432,13 @@ Normally, RefTeX searches the paths given in the environment variables
1476TEXINPUTS and BIBINPUTS to find TeX files and BibTeX database files. 1432TEXINPUTS and BIBINPUTS to find TeX files and BibTeX database files.
1477With this option turned on, it calls an external program specified in the 1433With this option turned on, it calls an external program specified in the
1478option `reftex-external-file-finders' instead. As a side effect, 1434option `reftex-external-file-finders' instead. As a side effect,
1479the variables `reftex-texpath-environment-variables' and 1435the variables `reftex-texpath-environment-variables' and
1480`reftex-bibpath-environment-variables' will be ignored." 1436`reftex-bibpath-environment-variables' will be ignored."
1481 :group 'reftex-finding-files 1437 :group 'reftex-finding-files
1482 :type 'boolean) 1438 :type 'boolean)
1483 1439
1484(defcustom reftex-external-file-finders '(("tex" . "kpsewhich -format=.tex %f") 1440(defcustom reftex-external-file-finders '(("tex" . "kpsewhich -format=.tex %f")
1485 ("bib" . "kpsewhich -format=.bib %f")) 1441 ("bib" . "kpsewhich -format=.bib %f"))
1486 "*Association list with external programs to call for finding files. 1442 "*Association list with external programs to call for finding files.
1487Each entry is a cons cell (TYPE . PROGRAM). 1443Each entry is a cons cell (TYPE . PROGRAM).
1488TYPE is either \"tex\" or \"bib\". PROGRAM is the external program to use with 1444TYPE is either \"tex\" or \"bib\". PROGRAM is the external program to use with
@@ -1491,7 +1447,7 @@ Note that these commands will be executed directly, not via a shell.
1491Only relevant when `reftex-use-external-file-finders' is non-nil." 1447Only relevant when `reftex-use-external-file-finders' is non-nil."
1492 :group 'reftex-finding-files 1448 :group 'reftex-finding-files
1493 :type '(repeat (cons (string :tag "File type") 1449 :type '(repeat (cons (string :tag "File type")
1494 (string :tag "Program ")))) 1450 (string :tag "Program "))))
1495 1451
1496;; Tuning the parser ---------------------------------------------------- 1452;; Tuning the parser ----------------------------------------------------
1497 1453
@@ -1567,7 +1523,7 @@ list."
1567(defcustom reftex-save-parse-info nil 1523(defcustom reftex-save-parse-info nil
1568 "*Non-nil means, save information gathered with parsing in a file. 1524 "*Non-nil means, save information gathered with parsing in a file.
1569The file MASTER.rel in the same directory as MASTER.tex is used to save the 1525The file MASTER.rel in the same directory as MASTER.tex is used to save the
1570information. When this variable is t, 1526information. When this variable is t,
1571- accessing the parsing information for the first time in an editing session 1527- accessing the parsing information for the first time in an editing session
1572 will read that file (if available) instead of parsing the document. 1528 will read that file (if available) instead of parsing the document.
1573- exiting Emacs or killing a buffer in reftex-mode will cause a new version 1529- exiting Emacs or killing a buffer in reftex-mode will cause a new version
@@ -1651,10 +1607,10 @@ Changing this variable requires to rebuild the selection and *toc* buffers
1651to become effective (keys `g' or `r')." 1607to become effective (keys `g' or `r')."
1652 :group 'reftex-fontification-configurations 1608 :group 'reftex-fontification-configurations
1653 :type '(choice 1609 :type '(choice
1654 (const :tag "Never" nil) 1610 (const :tag "Never" nil)
1655 (const :tag "Cursor driven" cursor) 1611 (const :tag "Cursor driven" cursor)
1656 (const :tag "Mouse driven" mouse) 1612 (const :tag "Mouse driven" mouse)
1657 (const :tag "Mouse and Cursor driven." both))) 1613 (const :tag "Mouse and Cursor driven." both)))
1658 1614
1659(defcustom reftex-cursor-selected-face 'highlight 1615(defcustom reftex-cursor-selected-face 'highlight
1660 "Face name to highlight cursor selected item in toc and selection buffers. 1616 "Face name to highlight cursor selected item in toc and selection buffers.
@@ -1760,18 +1716,18 @@ RefTeX uses `fset' to take over the function calls. Changing the variable
1760may require a restart of Emacs in order to become effective." 1716may require a restart of Emacs in order to become effective."
1761 :group 'reftex-miscellaneous-configurations 1717 :group 'reftex-miscellaneous-configurations
1762 :group 'LaTeX 1718 :group 'LaTeX
1763 :type '(choice 1719 :type '(choice
1764 (const :tag "No plug-ins" nil) 1720 (const :tag "No plug-ins" nil)
1765 (const :tag "All possible plug-ins" t) 1721 (const :tag "All possible plug-ins" t)
1766 (list 1722 (list
1767 :tag "Individual choice" 1723 :tag "Individual choice"
1768 :value (t t t t t) 1724 :value (t t t t t)
1769 (boolean :tag "supply label in new sections and environments") 1725 (boolean :tag "supply label in new sections and environments")
1770 (boolean :tag "supply argument for macros like `\\label' ") 1726 (boolean :tag "supply argument for macros like `\\label' ")
1771 (boolean :tag "supply argument for macros like `\\ref' ") 1727 (boolean :tag "supply argument for macros like `\\ref' ")
1772 (boolean :tag "supply argument for macros like `\\cite' ") 1728 (boolean :tag "supply argument for macros like `\\cite' ")
1773 (boolean :tag "supply argument for macros like `\\index' ") 1729 (boolean :tag "supply argument for macros like `\\index' ")
1774 ))) 1730 )))
1775 1731
1776(defcustom reftex-allow-detached-macro-args nil 1732(defcustom reftex-allow-detached-macro-args nil
1777 "*Non-nil means, allow arguments of macros to be detached by whitespace. 1733 "*Non-nil means, allow arguments of macros to be detached by whitespace.
@@ -1791,8 +1747,6 @@ construct: \\bbb [xxx] {aaa}."
1791 :group 'reftex-miscellaneous-configurations 1747 :group 'reftex-miscellaneous-configurations
1792 :type 'hook) 1748 :type 'hook)
1793 1749
1794
1795(provide 'reftex-vars) 1750(provide 'reftex-vars)
1796 1751
1797;;; arch-tag: 9591ea34-ef39-4431-90b7-c115eaf5e16f
1798;;; reftex-vars.el ends here 1752;;; reftex-vars.el ends here
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index c00400a7b96..e0ac95ecfab 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -1,8 +1,8 @@
1;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX 1;;; reftex.el --- minor mode for doing \label, \ref, \cite, \index in LaTeX
2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. 2;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
3 3
4;; Author: Carsten Dominik <dominik@science.uva.nl> 4;; Author: Carsten Dominik <dominik@science.uva.nl>
5;; Version: 4.21 5;; Version: 4.18
6;; Keywords: tex 6;; Keywords: tex
7 7
8;; This file is part of GNU Emacs. 8;; This file is part of GNU Emacs.
@@ -25,7 +25,7 @@
25;;--------------------------------------------------------------------------- 25;;---------------------------------------------------------------------------
26;; 26;;
27;;; Commentary: 27;;; Commentary:
28;; 28;;
29;; RefTeX is a minor mode with distinct support for \ref, \label, \cite, 29;; RefTeX is a minor mode with distinct support for \ref, \label, \cite,
30;; and \index commands in (multi-file) LaTeX documents. 30;; and \index commands in (multi-file) LaTeX documents.
31;; - A table of contents provides easy access to any part of a document. 31;; - A table of contents provides easy access to any part of a document.
@@ -64,13 +64,13 @@
64;; 64;;
65;; The documentation in various formats is also available at 65;; The documentation in various formats is also available at
66;; 66;;
67;; http://zon.astro.uva.nl/~dominik/Tools/ 67;; http://www.strw.leidenuniv.nl/~dominik/Tools/
68;; 68;;
69;;--------------------------------------------------------------------------- 69;;---------------------------------------------------------------------------
70;; 70;;
71;; Introduction 71;; Introduction
72;; ************ 72;; ************
73;; 73;;
74;; RefTeX is a specialized package for support of labels, references, 74;; RefTeX is a specialized package for support of labels, references,
75;; citations, and the index in LaTeX. RefTeX wraps itself round 4 LaTeX 75;; citations, and the index in LaTeX. RefTeX wraps itself round 4 LaTeX
76;; macros: `\label', `\ref', `\cite', and `\index'. Using these macros 76;; macros: `\label', `\ref', `\cite', and `\index'. Using these macros
@@ -79,13 +79,13 @@
79;; time-consuming tasks almost entirely. It also provides functions to 79;; time-consuming tasks almost entirely. It also provides functions to
80;; display the structure of a document and to move around in this 80;; display the structure of a document and to move around in this
81;; structure quickly. 81;; structure quickly.
82;; 82;;
83;; *Note Imprint::, for information about who to contact for help, bug 83;; *Note Imprint::, for information about who to contact for help, bug
84;; reports or suggestions. 84;; reports or suggestions.
85;; 85;;
86;; Environment 86;; Environment
87;; =========== 87;; ===========
88;; 88;;
89;; RefTeX needs to access all files which are part of a multifile 89;; RefTeX needs to access all files which are part of a multifile
90;; document, and the BibTeX database files requested by the 90;; document, and the BibTeX database files requested by the
91;; `\bibliography' command. To find these files, RefTeX will require a 91;; `\bibliography' command. To find these files, RefTeX will require a
@@ -94,26 +94,26 @@
94;; which are also used by RefTeX. However, on some systems these 94;; which are also used by RefTeX. However, on some systems these
95;; variables do not contain the full search path. If RefTeX does not work 95;; variables do not contain the full search path. If RefTeX does not work
96;; for you because it cannot find some files, read *Note Finding Files::. 96;; for you because it cannot find some files, read *Note Finding Files::.
97;; 97;;
98;; Entering RefTeX Mode 98;; Entering RefTeX Mode
99;; ==================== 99;; ====================
100;; 100;;
101;; To turn RefTeX Mode on and off in a particular buffer, use `M-x 101;; To turn RefTeX Mode on and off in a particular buffer, use `M-x
102;; reftex-mode'. To turn on RefTeX Mode for all LaTeX files, add the 102;; reftex-mode'. To turn on RefTeX Mode for all LaTeX files, add the
103;; following lines to your `.emacs' file: 103;; following lines to your `.emacs' file:
104;; 104;;
105;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode 105;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; with AUCTeX LaTeX mode
106;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode 106;; (add-hook 'latex-mode-hook 'turn-on-reftex) ; with Emacs latex mode
107;; 107;;
108;; RefTeX in a Nutshell 108;; RefTeX in a Nutshell
109;; ==================== 109;; ====================
110;; 110;;
111;; 1. Table of Contents 111;; 1. Table of Contents
112;; Typing `C-c =' (`reftex-toc') will show a table of contents of the 112;; Typing `C-c =' (`reftex-toc') will show a table of contents of the
113;; document. This buffer can display sections, labels and index 113;; document. This buffer can display sections, labels and index
114;; entries defined in the document. From the buffer, you can jump 114;; entries defined in the document. From the buffer, you can jump
115;; quickly to every part of your document. Press `?' to get help. 115;; quickly to every part of your document. Press `?' to get help.
116;; 116;;
117;; 2. Labels and References 117;; 2. Labels and References
118;; RefTeX helps to create unique labels and to find the correct key 118;; RefTeX helps to create unique labels and to find the correct key
119;; for references quickly. It distinguishes labels for different 119;; for references quickly. It distinguishes labels for different
@@ -121,7 +121,7 @@
121;; others), and can be configured to recognize any additional labeled 121;; others), and can be configured to recognize any additional labeled
122;; environments you have defined yourself (variable 122;; environments you have defined yourself (variable
123;; `reftex-label-alist'). 123;; `reftex-label-alist').
124;; 124;;
125;; * Creating Labels 125;; * Creating Labels
126;; Type `C-c (' (`reftex-label') to insert a label at point. 126;; Type `C-c (' (`reftex-label') to insert a label at point.
127;; RefTeX will either 127;; RefTeX will either
@@ -130,17 +130,17 @@
130;; tables) or 130;; tables) or
131;; - insert a simple label made of a prefix and a number (all 131;; - insert a simple label made of a prefix and a number (all
132;; other environments) 132;; other environments)
133;; 133;;
134;; Which labels are created how is configurable with the variable 134;; Which labels are created how is configurable with the variable
135;; `reftex-insert-label-flags'. 135;; `reftex-insert-label-flags'.
136;; 136;;
137;; * Referencing Labels 137;; * Referencing Labels
138;; To make a reference, type `C-c )' (`reftex-reference'). This 138;; To make a reference, type `C-c )' (`reftex-reference'). This
139;; shows an outline of the document with all labels of a certain 139;; shows an outline of the document with all labels of a certain
140;; type (figure, equation,...) and some label context. 140;; type (figure, equation,...) and some label context.
141;; Selecting a label inserts a `\ref{LABEL}' macro into the 141;; Selecting a label inserts a `\ref{LABEL}' macro into the
142;; original buffer. 142;; original buffer.
143;; 143;;
144;; 3. Citations 144;; 3. Citations
145;; Typing `C-c [' (`reftex-citation') will let you specify a regular 145;; Typing `C-c [' (`reftex-citation') will let you specify a regular
146;; expression to search in current BibTeX database files (as 146;; expression to search in current BibTeX database files (as
@@ -149,7 +149,7 @@
149;; sorted. The selected article is referenced as `\cite{KEY}' (see 149;; sorted. The selected article is referenced as `\cite{KEY}' (see
150;; the variable `reftex-cite-format' if you want to insert different 150;; the variable `reftex-cite-format' if you want to insert different
151;; macros). 151;; macros).
152;; 152;;
153;; 4. Index Support 153;; 4. Index Support
154;; RefTeX helps to enter index entries. It also compiles all entries 154;; RefTeX helps to enter index entries. It also compiles all entries
155;; into an alphabetically sorted `*Index*' buffer which you can use 155;; into an alphabetically sorted `*Index*' buffer which you can use
@@ -157,25 +157,25 @@
157;; index macros and can be configured to recognize any additional 157;; index macros and can be configured to recognize any additional
158;; macros you have defined (`reftex-index-macros'). Multiple indices 158;; macros you have defined (`reftex-index-macros'). Multiple indices
159;; are supported. 159;; are supported.
160;; 160;;
161;; * Creating Index Entries 161;; * Creating Index Entries
162;; To index the current selection or the word at point, type 162;; To index the current selection or the word at point, type
163;; `C-c /' (`reftex-index-selection-or-word'). The default macro 163;; `C-c /' (`reftex-index-selection-or-word'). The default macro
164;; `reftex-index-default-macro' will be used. For a more 164;; `reftex-index-default-macro' will be used. For a more
165;; complex entry type `C-c <' (`reftex-index'), select any of 165;; complex entry type `C-c <' (`reftex-index'), select any of
166;; the index macros and enter the arguments with completion. 166;; the index macros and enter the arguments with completion.
167;; 167;;
168;; * The Index Phrases File (Delayed Indexing) 168;; * The Index Phrases File (Delayed Indexing)
169;; Type `C-c \' (`reftex-index-phrase-selection-or-word') to add 169;; Type `C-c \' (`reftex-index-phrase-selection-or-word') to add
170;; the current word or selection to a special _index phrase 170;; the current word or selection to a special _index phrase
171;; file_. RefTeX can later search the document for occurrences 171;; file_. RefTeX can later search the document for occurrences
172;; of these phrases and let you interactively index the matches. 172;; of these phrases and let you interactively index the matches.
173;; 173;;
174;; * Displaying and Editing the Index 174;; * Displaying and Editing the Index
175;; To display the compiled index in a special buffer, type `C-c 175;; To display the compiled index in a special buffer, type `C-c
176;; >' (`reftex-display-index'). From that buffer you can check 176;; >' (`reftex-display-index'). From that buffer you can check
177;; and edit all entries. 177;; and edit all entries.
178;; 178;;
179;; 5. Viewing Cross-References 179;; 5. Viewing Cross-References
180;; When point is on the KEY argument of a cross-referencing macro 180;; When point is on the KEY argument of a cross-referencing macro
181;; (`\label', `\ref', `\cite', `\bibitem', `\index', and variations) 181;; (`\label', `\ref', `\cite', `\bibitem', `\index', and variations)
@@ -185,14 +185,14 @@
185;; When the enclosing macro is `\cite' or `\ref' and no other message 185;; When the enclosing macro is `\cite' or `\ref' and no other message
186;; occupies the echo area, information about the citation or label 186;; occupies the echo area, information about the citation or label
187;; will automatically be displayed in the echo area. 187;; will automatically be displayed in the echo area.
188;; 188;;
189;; 6. Multifile Documents 189;; 6. Multifile Documents
190;; Multifile Documents are fully supported. The included files must 190;; Multifile Documents are fully supported. The included files must
191;; have a file variable `TeX-master' or `tex-main-file' pointing to 191;; have a file variable `TeX-master' or `tex-main-file' pointing to
192;; the master file. RefTeX provides cross-referencing information 192;; the master file. RefTeX provides cross-referencing information
193;; from all parts of the document, and across document borders 193;; from all parts of the document, and across document borders
194;; (`xr.sty'). 194;; (`xr.sty').
195;; 195;;
196;; 7. Document Parsing 196;; 7. Document Parsing
197;; RefTeX needs to parse the document in order to find labels and 197;; RefTeX needs to parse the document in order to find labels and
198;; other information. It does it automatically once and updates its 198;; other information. It does it automatically once and updates its
@@ -201,23 +201,23 @@
201;; with a raw `C-u' prefix, or press the `r' key in the label 201;; with a raw `C-u' prefix, or press the `r' key in the label
202;; selection buffer, the table of contents buffer, or the index 202;; selection buffer, the table of contents buffer, or the index
203;; buffer. 203;; buffer.
204;; 204;;
205;; 8. AUCTeX 205;; 8. AUCTeX
206;; If your major LaTeX mode is AUCTeX, RefTeX can cooperate with it 206;; If your major LaTeX mode is AUCTeX, RefTeX can cooperate with it
207;; (see variable `reftex-plug-into-AUCTeX'). AUCTeX contains style 207;; (see variable `reftex-plug-into-AUCTeX'). AUCTeX contains style
208;; files which trigger appropriate settings in RefTeX, so that for 208;; files which trigger appropriate settings in RefTeX, so that for
209;; many of the popular LaTeX packages no additional customizations 209;; many of the popular LaTeX packages no additional customizations
210;; will be necessary. 210;; will be necessary.
211;; 211;;
212;; 9. Useful Settings 212;; 9. Useful Settings
213;; To make RefTeX faster for large documents, try these: 213;; To make RefTeX faster for large documents, try these:
214;; (setq reftex-enable-partial-scans t) 214;; (setq reftex-enable-partial-scans t)
215;; (setq reftex-save-parse-info t) 215;; (setq reftex-save-parse-info t)
216;; (setq reftex-use-multiple-selection-buffers t) 216;; (setq reftex-use-multiple-selection-buffers t)
217;; 217;;
218;; To integrate with AUCTeX, use 218;; To integrate with AUCTeX, use
219;; (setq reftex-plug-into-AUCTeX t) 219;; (setq reftex-plug-into-AUCTeX t)
220;; 220;;
221;; To make your own LaTeX macro definitions known to RefTeX, 221;; To make your own LaTeX macro definitions known to RefTeX,
222;; customize the variables 222;; customize the variables
223;; `reftex-label-alist' (for label macros/environments) 223;; `reftex-label-alist' (for label macros/environments)
@@ -227,7 +227,7 @@
227;; `reftex-index-default-macro' (to set the default macro) 227;; `reftex-index-default-macro' (to set the default macro)
228;; If you have a large number of macros defined, you may want to write 228;; If you have a large number of macros defined, you may want to write
229;; an AUCTeX style file to support them with both AUCTeX and RefTeX. 229;; an AUCTeX style file to support them with both AUCTeX and RefTeX.
230;; 230;;
231;; 10. Where Next? 231;; 10. Where Next?
232;; Go ahead and use RefTeX. Use its menus until you have picked up 232;; Go ahead and use RefTeX. Use its menus until you have picked up
233;; the key bindings. For an overview of what you can do in each of 233;; the key bindings. For an overview of what you can do in each of
@@ -236,13 +236,13 @@
236;; The first part of the manual explains in a tutorial way how to use 236;; The first part of the manual explains in a tutorial way how to use
237;; and customize RefTeX. The second part is a command and variable 237;; and customize RefTeX. The second part is a command and variable
238;; reference. 238;; reference.
239;; 239;;
240;;--------------------------------------------------------------------------- 240;;---------------------------------------------------------------------------
241;; 241;;
242;; AUTHOR 242;; AUTHOR
243;; ====== 243;; ======
244;; 244;;
245;; Carsten Dominik <dominik@science.uva.nl> 245;; Carsten Dominik <dominik@strw.LeidenUniv.nl>
246;; 246;;
247;; with contributions from Stephen Eglen 247;; with contributions from Stephen Eglen
248;; 248;;
@@ -250,7 +250,7 @@
250;; XEmacs 21.x. If you need to install it yourself, you can find a 250;; XEmacs 21.x. If you need to install it yourself, you can find a
251;; distribution at 251;; distribution at
252;; 252;;
253;; http://zon.astro.uva.nl/~dominik/Tools/ 253;; http://www.strw.leidenuniv.nl/~dominik/Tools/
254;; 254;;
255;; THANKS TO: 255;; THANKS TO:
256;; --------- 256;; ---------
@@ -282,12 +282,6 @@
282(defvar reftex-tables-dirty t 282(defvar reftex-tables-dirty t
283 "Flag showing if tables need to be re-computed.") 283 "Flag showing if tables need to be re-computed.")
284 284
285(eval-and-compile
286 (defun reftex-set-dirty (symbol value)
287 (setq reftex-tables-dirty t)
288 (set symbol value)))
289
290
291;;; ========================================================================= 285;;; =========================================================================
292;;; 286;;;
293;;; Configuration variables 287;;; Configuration variables
@@ -300,7 +294,7 @@
300;;; Define the formal stuff for a minor mode named RefTeX. 294;;; Define the formal stuff for a minor mode named RefTeX.
301;;; 295;;;
302 296
303(defconst reftex-version "RefTeX version 4.21" 297(defconst reftex-version "RefTeX version 4.18"
304 "Version string for RefTeX.") 298 "Version string for RefTeX.")
305 299
306(defvar reftex-mode nil 300(defvar reftex-mode nil
@@ -318,10 +312,10 @@
318 (setq reftex-syntax-table (copy-syntax-table)) 312 (setq reftex-syntax-table (copy-syntax-table))
319 (modify-syntax-entry ?\( "." reftex-syntax-table) 313 (modify-syntax-entry ?\( "." reftex-syntax-table)
320 (modify-syntax-entry ?\) "." reftex-syntax-table)) 314 (modify-syntax-entry ?\) "." reftex-syntax-table))
321 315
322(unless reftex-syntax-table-for-bib 316(unless reftex-syntax-table-for-bib
323 (setq reftex-syntax-table-for-bib 317 (setq reftex-syntax-table-for-bib
324 (copy-syntax-table reftex-syntax-table)) 318 (copy-syntax-table reftex-syntax-table))
325 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) 319 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib)
326 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib) 320 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib)
327 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib) 321 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib)
@@ -377,30 +371,30 @@ on the menu bar.
377 371
378 (if reftex-mode 372 (if reftex-mode
379 (progn 373 (progn
380 ;; Mode was turned on 374 ;; Mode was turned on
381 (easy-menu-add reftex-mode-menu) 375 (easy-menu-add reftex-mode-menu)
382 (and reftex-plug-into-AUCTeX 376 (and reftex-plug-into-AUCTeX
383 (reftex-plug-into-AUCTeX)) 377 (reftex-plug-into-AUCTeX))
384 (unless (get 'reftex-auto-view-crossref 'initialized) 378 (unless (get 'reftex-auto-view-crossref 'initialized)
385 (and reftex-auto-view-crossref 379 (and reftex-auto-view-crossref
386 (reftex-toggle-auto-view-crossref)) 380 (reftex-toggle-auto-view-crossref))
387 (put 'reftex-auto-view-crossref 'initialized t)) 381 (put 'reftex-auto-view-crossref 'initialized t))
388 (unless (get 'reftex-auto-recenter-toc 'initialized) 382 (unless (get 'reftex-auto-recenter-toc 'initialized)
389 (and (eq reftex-auto-recenter-toc t) 383 (and reftex-auto-recenter-toc
390 (reftex-toggle-auto-toc-recenter)) 384 (reftex-toggle-auto-toc-recenter))
391 (put 'reftex-auto-recenter-toc 'initialized t)) 385 (put 'reftex-auto-recenter-toc 'initialized t))
392 386
393 ;; Prepare the special syntax tables. 387 ;; Prepare the special syntax tables.
394 (setq reftex-syntax-table (copy-syntax-table (syntax-table))) 388 (setq reftex-syntax-table (copy-syntax-table (syntax-table)))
395 (modify-syntax-entry ?\( "." reftex-syntax-table) 389 (modify-syntax-entry ?\( "." reftex-syntax-table)
396 (modify-syntax-entry ?\) "." reftex-syntax-table) 390 (modify-syntax-entry ?\) "." reftex-syntax-table)
397 391
398 (setq reftex-syntax-table-for-bib 392 (setq reftex-syntax-table-for-bib
399 (copy-syntax-table reftex-syntax-table)) 393 (copy-syntax-table reftex-syntax-table))
400 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib) 394 (modify-syntax-entry ?\' "." reftex-syntax-table-for-bib)
401 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib) 395 (modify-syntax-entry ?\" "." reftex-syntax-table-for-bib)
402 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib) 396 (modify-syntax-entry ?\[ "." reftex-syntax-table-for-bib)
403 (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib) 397 (modify-syntax-entry ?\] "." reftex-syntax-table-for-bib)
404 398
405 (run-hooks 'reftex-mode-hook)) 399 (run-hooks 'reftex-mode-hook))
406 ;; Mode was turned off 400 ;; Mode was turned off
@@ -425,13 +419,13 @@ on the menu bar.
425 ;; This function should be installed in `kill-buffer-hook'. 419 ;; This function should be installed in `kill-buffer-hook'.
426 ;; We are careful to make sure nothing goes wring in this function. 420 ;; We are careful to make sure nothing goes wring in this function.
427 (when (and (boundp 'reftex-mode) reftex-mode 421 (when (and (boundp 'reftex-mode) reftex-mode
428 (boundp 'reftex-save-parse-info) reftex-save-parse-info 422 (boundp 'reftex-save-parse-info) reftex-save-parse-info
429 (boundp 'reftex-docstruct-symbol) reftex-docstruct-symbol 423 (boundp 'reftex-docstruct-symbol) reftex-docstruct-symbol
430 (symbol-value reftex-docstruct-symbol) 424 (symbol-value reftex-docstruct-symbol)
431 (get reftex-docstruct-symbol 'modified)) 425 (get reftex-docstruct-symbol 'modified))
432 ;; Write the file. 426 ;; Write the file.
433 (condition-case nil 427 (condition-case nil
434 (reftex-access-parse-file 'write) 428 (reftex-access-parse-file 'write)
435 (error nil)))) 429 (error nil))))
436 430
437(defun reftex-kill-emacs-hook () 431(defun reftex-kill-emacs-hook ()
@@ -439,9 +433,9 @@ on the menu bar.
439 ;; This function should be installed in `kill-emacs-hook'. 433 ;; This function should be installed in `kill-emacs-hook'.
440 (save-excursion 434 (save-excursion
441 (mapcar (lambda (buf) 435 (mapcar (lambda (buf)
442 (set-buffer buf) 436 (set-buffer buf)
443 (reftex-kill-buffer-hook)) 437 (reftex-kill-buffer-hook))
444 (buffer-list)))) 438 (buffer-list))))
445 439
446;;; ========================================================================= 440;;; =========================================================================
447;;; 441;;;
@@ -511,8 +505,8 @@ on the menu bar.
511 (put (symbol-value symbol) :master-index index) 505 (put (symbol-value symbol) :master-index index)
512 ;; Initialize if new symbols. 506 ;; Initialize if new symbols.
513 (when newflag 507 (when newflag
514 (set (symbol-value symbol) nil) 508 (set (symbol-value symbol) nil)
515 (put (symbol-value symbol) 'reftex-index-macros-style '(default)))) 509 (put (symbol-value symbol) 'reftex-index-macros-style '(default))))
516 510
517 ;; Return t if the symbols did already exist, nil when we've made them. 511 ;; Return t if the symbols did already exist, nil when we've made them.
518 (not newflag))) 512 (not newflag)))
@@ -535,10 +529,10 @@ on the menu bar.
535 ((master 529 ((master
536 (cond 530 (cond
537 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism. 531 ((fboundp 'TeX-master-file) ; AUCTeX is loaded. Use its mechanism.
538 (condition-case nil 532 (condition-case nil
539 (TeX-master-file t) 533 (TeX-master-file t)
540 (error (buffer-file-name)))) 534 (error (buffer-file-name))))
541 ((fboundp 'tex-main-file) (tex-main-file)) ; Emacs LaTeX mode 535 ((fboundp 'tex-main-file) (tex-main-file)) ; Emacs LaTeX mode
542 ((boundp 'TeX-master) ; The variable is defined - lets use it. 536 ((boundp 'TeX-master) ; The variable is defined - lets use it.
543 (cond 537 (cond
544 ((eq TeX-master t) 538 ((eq TeX-master t)
@@ -564,7 +558,7 @@ on the menu bar.
564 (buffer-file-name))))) 558 (buffer-file-name)))))
565 (cond 559 (cond
566 ((null master) 560 ((null master)
567 (error "Need a filename for this buffer, please save it first")) 561 (error "Need a filename for this buffer, please save it first"))
568 ((or (file-exists-p (concat master ".tex")) 562 ((or (file-exists-p (concat master ".tex"))
569 (reftex-get-buffer-visiting (concat master ".tex"))) 563 (reftex-get-buffer-visiting (concat master ".tex")))
570 ;; Ahh, an extra .tex was missing... 564 ;; Ahh, an extra .tex was missing...
@@ -575,7 +569,7 @@ on the menu bar.
575 ) 569 )
576 (t 570 (t
577 ;; Use buffer file name. 571 ;; Use buffer file name.
578 (buffer-file-name))) 572 (setq master (buffer-file-name))))
579 (expand-file-name master))) 573 (expand-file-name master)))
580 574
581(defun reftex-is-multi () 575(defun reftex-is-multi ()
@@ -593,15 +587,15 @@ for possible values. This function should be used from AUCTeX style files."
593 (unless reftex-docstruct-symbol 587 (unless reftex-docstruct-symbol
594 (reftex-tie-multifile-symbols)) 588 (reftex-tie-multifile-symbols))
595 (when (and reftex-docstruct-symbol 589 (when (and reftex-docstruct-symbol
596 (symbolp reftex-docstruct-symbol)) 590 (symbolp reftex-docstruct-symbol))
597 (put reftex-docstruct-symbol 'reftex-cite-format value))) 591 (put reftex-docstruct-symbol 'reftex-cite-format value)))
598 592
599(defun reftex-get-cite-format () 593(defun reftex-get-cite-format ()
600 ;; Return the current citation format. Either the document-local value in 594 ;; Return the current citation format. Either the document-local value in
601 ;; reftex-cite-format-symbol, or the global value in reftex-cite-format. 595 ;; reftex-cite-format-symbol, or the global value in reftex-cite-format.
602 (if (and reftex-docstruct-symbol 596 (if (and reftex-docstruct-symbol
603 (symbolp reftex-docstruct-symbol) 597 (symbolp reftex-docstruct-symbol)
604 (get reftex-docstruct-symbol 'reftex-cite-format)) 598 (get reftex-docstruct-symbol 'reftex-cite-format))
605 (get reftex-docstruct-symbol 'reftex-cite-format) 599 (get reftex-docstruct-symbol 'reftex-cite-format)
606 reftex-cite-format)) 600 reftex-cite-format))
607 601
@@ -617,22 +611,22 @@ the label information is recompiled on next use."
617 (unless reftex-docstruct-symbol 611 (unless reftex-docstruct-symbol
618 (reftex-tie-multifile-symbols)) 612 (reftex-tie-multifile-symbols))
619 (when (and reftex-docstruct-symbol 613 (when (and reftex-docstruct-symbol
620 (symbolp reftex-docstruct-symbol)) 614 (symbolp reftex-docstruct-symbol))
621 (let ((list (get reftex-docstruct-symbol 'reftex-index-macros-style)) 615 (let ((list (get reftex-docstruct-symbol 'reftex-index-macros-style))
622 entry changed) 616 entry changed)
623 (while entry-list 617 (while entry-list
624 (setq entry (pop entry-list)) 618 (setq entry (pop entry-list))
625 ;; When it is a symbol, remove all other symbols 619 ;; When it is a symbol, remove all other symbols
626 (and (symbolp entry) 620 (and (symbolp entry)
627 (not (memq entry list)) 621 (not (memq entry list))
628 (setq list (reftex-remove-symbols-from-list list))) 622 (setq list (reftex-remove-symbols-from-list list)))
629 ;; Add to list unless already member 623 ;; Add to list unless already member
630 (unless (member entry list) 624 (unless (member entry list)
631 (setq reftex-tables-dirty t 625 (setq reftex-tables-dirty t
632 changed t) 626 changed t)
633 (push entry list))) 627 (push entry list)))
634 (when changed 628 (when changed
635 (put reftex-docstruct-symbol 'reftex-index-macros-style list))))) 629 (put reftex-docstruct-symbol 'reftex-index-macros-style list)))))
636 630
637;;; ========================================================================= 631;;; =========================================================================
638;;; 632;;;
@@ -734,14 +728,14 @@ the label information is recompiled on next use."
734 728
735;; A list of all variables in the cache. 729;; A list of all variables in the cache.
736;; The cache is used to save the compiled versions of some variables. 730;; The cache is used to save the compiled versions of some variables.
737(defconst reftex-cache-variables 731(defconst reftex-cache-variables
738 '(reftex-memory ;; This MUST ALWAYS be the first! 732 '(reftex-memory ;; This MUST ALWAYS be the first!
739 733
740 ;; Outline 734 ;; Outline
741 reftex-section-levels-all 735 reftex-section-levels-all
742 736
743 ;; Labels 737 ;; Labels
744 reftex-env-or-mac-alist 738 reftex-env-or-mac-alist
745 reftex-special-env-parsers 739 reftex-special-env-parsers
746 reftex-macros-with-labels 740 reftex-macros-with-labels
747 reftex-label-mac-list 741 reftex-label-mac-list
@@ -757,7 +751,7 @@ the label information is recompiled on next use."
757 reftex-index-macro-alist 751 reftex-index-macro-alist
758 reftex-macros-with-index 752 reftex-macros-with-index
759 reftex-query-index-macro-prompt 753 reftex-query-index-macro-prompt
760 reftex-query-index-macro-help 754 reftex-query-index-macro-help
761 reftex-key-to-index-macro-alist 755 reftex-key-to-index-macro-alist
762 756
763 ;; Regular expressions 757 ;; Regular expressions
@@ -774,35 +768,35 @@ the label information is recompiled on next use."
774(defun reftex-ensure-compiled-variables () 768(defun reftex-ensure-compiled-variables ()
775 ;; Recompile the label alist when necessary 769 ;; Recompile the label alist when necessary
776 (let* ((mem reftex-memory) 770 (let* ((mem reftex-memory)
777 (cache (get reftex-docstruct-symbol 'reftex-cache)) 771 (cache (get reftex-docstruct-symbol 'reftex-cache))
778 (cmem (car cache)) 772 (cmem (car cache))
779 (alist reftex-label-alist) 773 (alist reftex-label-alist)
780 (levels (get reftex-docstruct-symbol 'reftex-section-levels)) 774 (levels (get reftex-docstruct-symbol 'reftex-section-levels))
781 (style (get reftex-docstruct-symbol 'reftex-label-alist-style)) 775 (style (get reftex-docstruct-symbol 'reftex-label-alist-style))
782 (default reftex-default-label-alist-entries) 776 (default reftex-default-label-alist-entries)
783 (index reftex-index-macros) 777 (index reftex-index-macros)
784 (istyle (get reftex-docstruct-symbol 'reftex-index-macros-style))) 778 (istyle (get reftex-docstruct-symbol 'reftex-index-macros-style)))
785 (cond 779 (cond
786 (reftex-tables-dirty (reftex-compile-variables)) 780 (reftex-tables-dirty (reftex-compile-variables))
787 ((and (eq alist (nth 0 mem)) 781 ((and (eq alist (nth 0 mem))
788 (eq levels (nth 1 mem)) 782 (eq levels (nth 1 mem))
789 (eq style (nth 2 mem)) 783 (eq style (nth 2 mem))
790 (eq default (nth 3 mem)) 784 (eq default (nth 3 mem))
791 (eq index (nth 4 mem)) 785 (eq index (nth 4 mem))
792 (eq istyle (nth 5 mem)))) ;; everything is OK 786 (eq istyle (nth 5 mem)))) ;; everything is OK
793 ((and (eq alist (nth 0 cmem)) 787 ((and (eq alist (nth 0 cmem))
794 (eq levels (nth 1 cmem)) 788 (eq levels (nth 1 cmem))
795 (eq style (nth 2 cmem)) 789 (eq style (nth 2 cmem))
796 (eq default (nth 2 cmem)) 790 (eq default (nth 2 cmem))
797 (eq index (nth 4 cmem)) 791 (eq index (nth 4 cmem))
798 (eq istyle (nth 5 cmem))) 792 (eq istyle (nth 5 cmem)))
799 ;; restore the cache 793 ;; restore the cache
800 (message "Restoring cache") 794 (message "Restoring cache")
801 (mapcar (lambda (sym) (set sym (pop cache))) reftex-cache-variables)) 795 (mapcar (lambda (sym) (set sym (pop cache))) reftex-cache-variables))
802 (t (reftex-compile-variables))))) 796 (t (reftex-compile-variables)))))
803 797
804(defun reftex-reset-mode () 798(defun reftex-reset-mode ()
805 "Reset RefTeX Mode. 799 "Reset RefTeX Mode.
806This will re-compile the configuration information and remove all 800This will re-compile the configuration information and remove all
807current scanning information and the parse file to enforce a rescan 801current scanning information and the parse file to enforce a rescan
808on next use." 802on next use."
@@ -810,18 +804,18 @@ on next use."
810 804
811 ;; Reset the file search path variables 805 ;; Reset the file search path variables
812 (loop for prop in '(status master-dir recursive-path rec-type) do 806 (loop for prop in '(status master-dir recursive-path rec-type) do
813 (put 'reftex-tex-path prop nil) 807 (put 'reftex-tex-path prop nil)
814 (put 'reftex-bib-path prop nil)) 808 (put 'reftex-bib-path prop nil))
815 809
816 ;; Kill temporary buffers associated with RefTeX - just in case they 810 ;; Kill temporary buffers associated with RefTeX - just in case they
817 ;; were not cleaned up properly 811 ;; were not cleaned up properly
818 (save-excursion 812 (save-excursion
819 (let ((buffer-list '("*RefTeX Help*" "*RefTeX Select*" 813 (let ((buffer-list '("*RefTeX Help*" "*RefTeX Select*"
820 "*Duplicate Labels*" "*toc*" " *RefTeX-scratch*")) 814 "*Duplicate Labels*" "*toc*" " *RefTeX-scratch*"))
821 buf) 815 buf)
822 (while (setq buf (pop buffer-list)) 816 (while (setq buf (pop buffer-list))
823 (if (get-buffer buf) 817 (if (get-buffer buf)
824 (kill-buffer buf)))) 818 (kill-buffer buf))))
825 (reftex-erase-all-selection-and-index-buffers)) 819 (reftex-erase-all-selection-and-index-buffers))
826 820
827 ;; Make sure the current document will be rescanned soon. 821 ;; Make sure the current document will be rescanned soon.
@@ -836,7 +830,6 @@ on next use."
836 830
837 (reftex-compile-variables)) 831 (reftex-compile-variables))
838 832
839;;;###autoload
840(defun reftex-reset-scanning-information () 833(defun reftex-reset-scanning-information ()
841 "Reset the symbols containing information from buffer scanning. 834 "Reset the symbols containing information from buffer scanning.
842This enforces rescanning the buffer on next use." 835This enforces rescanning the buffer on next use."
@@ -853,12 +846,12 @@ This enforces rescanning the buffer on next use."
853 846
854(defun reftex-erase-all-selection-and-index-buffers () 847(defun reftex-erase-all-selection-and-index-buffers ()
855 ;; Remove all selection buffers associated with current document. 848 ;; Remove all selection buffers associated with current document.
856 (mapcar 849 (mapcar
857 (lambda (type) 850 (lambda (type)
858 (reftex-erase-buffer (reftex-make-selection-buffer-name type))) 851 (reftex-erase-buffer (reftex-make-selection-buffer-name type)))
859 reftex-typekey-list) 852 reftex-typekey-list)
860 ;; Kill all index buffers 853 ;; Kill all index buffers
861 (mapcar 854 (mapcar
862 (lambda (tag) 855 (lambda (tag)
863 (reftex-kill-buffer (reftex-make-index-buffer-name tag))) 856 (reftex-kill-buffer (reftex-make-index-buffer-name tag)))
864 (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))) 857 (cdr (assoc 'index-tags (symbol-value reftex-docstruct-symbol)))))
@@ -874,34 +867,34 @@ This enforces rescanning the buffer on next use."
874 867
875 ;; Record that we have done this, and what we have used. 868 ;; Record that we have done this, and what we have used.
876 (setq reftex-tables-dirty nil) 869 (setq reftex-tables-dirty nil)
877 (setq reftex-memory 870 (setq reftex-memory
878 (list reftex-label-alist 871 (list reftex-label-alist
879 (get reftex-docstruct-symbol 'reftex-section-levels) 872 (get reftex-docstruct-symbol 'reftex-section-levels)
880 (get reftex-docstruct-symbol 'reftex-label-alist-style) 873 (get reftex-docstruct-symbol 'reftex-label-alist-style)
881 reftex-default-label-alist-entries 874 reftex-default-label-alist-entries
882 reftex-index-macros 875 reftex-index-macros
883 (get reftex-docstruct-symbol 'reftex-index-macros-style))) 876 (get reftex-docstruct-symbol 'reftex-index-macros-style)))
884 877
885 ;; Compile information in reftex-label-alist 878 ;; Compile information in reftex-label-alist
886 (let ((all (reftex-uniquify-by-car 879 (let ((all (reftex-uniquify-by-car
887 (reftex-splice-symbols-into-list 880 (reftex-splice-symbols-into-list
888 (append reftex-label-alist 881 (append reftex-label-alist
889 (get reftex-docstruct-symbol 882 (get reftex-docstruct-symbol
890 'reftex-label-alist-style) 883 'reftex-label-alist-style)
891 reftex-default-label-alist-entries) 884 reftex-default-label-alist-entries)
892 reftex-label-alist-builtin) 885 reftex-label-alist-builtin)
893 '(nil))) 886 '(nil)))
894 (all-index (reftex-uniquify-by-car 887 (all-index (reftex-uniquify-by-car
895 (reftex-splice-symbols-into-list 888 (reftex-splice-symbols-into-list
896 (append reftex-index-macros 889 (append reftex-index-macros
897 (get reftex-docstruct-symbol 890 (get reftex-docstruct-symbol
898 'reftex-index-macros-style) 891 'reftex-index-macros-style)
899 '(default)) 892 '(default))
900 reftex-index-macros-builtin))) 893 reftex-index-macros-builtin)))
901 entry env-or-mac typekeychar typekey prefix context word 894 entry env-or-mac typekeychar typekey prefix context word
902 fmt reffmt labelfmt wordlist qh-list macros-with-labels 895 fmt reffmt labelfmt wordlist qh-list macros-with-labels
903 nargs nlabel opt-args cell sum i 896 nargs nlabel opt-args cell sum i
904 macro verify repeat nindex tag key toc-level toc-levels) 897 macro verify repeat nindex tag key toc-level toc-levels)
905 898
906 (setq reftex-words-to-typekey-alist nil 899 (setq reftex-words-to-typekey-alist nil
907 reftex-typekey-list nil 900 reftex-typekey-list nil
@@ -930,7 +923,7 @@ This enforces rescanning the buffer on next use."
930 fmt (nth 2 entry) 923 fmt (nth 2 entry)
931 context (nth 3 entry) 924 context (nth 3 entry)
932 wordlist (nth 4 entry) 925 wordlist (nth 4 entry)
933 toc-level (nth 5 entry)) 926 toc-level (nth 5 entry))
934 (if (stringp wordlist) 927 (if (stringp wordlist)
935 ;; This is before version 2.04 - convert to new format 928 ;; This is before version 2.04 - convert to new format
936 (setq wordlist (nthcdr 4 entry))) 929 (setq wordlist (nthcdr 4 entry)))
@@ -942,66 +935,66 @@ This enforces rescanning the buffer on next use."
942 (setq fmt (list "\\label{%s}" fmt))) 935 (setq fmt (list "\\label{%s}" fmt)))
943 (setq labelfmt (car fmt) 936 (setq labelfmt (car fmt)
944 reffmt (nth 1 fmt)) 937 reffmt (nth 1 fmt))
945 ;; Note a new typekey 938 ;; Note a new typekey
946 (if typekey 939 (if typekey
947 (add-to-list 'reftex-typekey-list typekey)) 940 (add-to-list 'reftex-typekey-list typekey))
948 (if (and typekey prefix 941 (if (and typekey prefix
949 (not (assoc typekey reftex-typekey-to-prefix-alist))) 942 (not (assoc typekey reftex-typekey-to-prefix-alist)))
950 (add-to-list 'reftex-typekey-to-prefix-alist 943 (add-to-list 'reftex-typekey-to-prefix-alist
951 (cons typekey prefix))) 944 (cons typekey prefix)))
952 ;; Check if this is a macro or environment 945 ;; Check if this is a macro or environment
953 (cond 946 (cond
954 ((symbolp env-or-mac) 947 ((symbolp env-or-mac)
955 ;; A special parser function 948 ;; A special parser function
956 (unless (fboundp env-or-mac) 949 (unless (fboundp env-or-mac)
957 (message "Warning: %s does not seem to be a valid function" 950 (message "Warning: %s does not seem to be a valid function"
958 env-or-mac)) 951 env-or-mac))
959 (setq nargs nil nlabel nil opt-args nil) 952 (setq nargs nil nlabel nil opt-args nil)
960 (add-to-list 'reftex-special-env-parsers env-or-mac) 953 (add-to-list 'reftex-special-env-parsers env-or-mac)
961 (setq env-or-mac (symbol-name env-or-mac))) 954 (setq env-or-mac (symbol-name env-or-mac)))
962 ((string-match "\\`\\\\" env-or-mac) 955 ((string-match "\\`\\\\" env-or-mac)
963 ;; It's a macro 956 ;; It's a macro
964 (let ((result (reftex-parse-args env-or-mac))) 957 (let ((result (reftex-parse-args env-or-mac)))
965 (setq env-or-mac (or (first result) env-or-mac) 958 (setq env-or-mac (or (first result) env-or-mac)
966 nargs (second result) 959 nargs (second result)
967 nlabel (third result) 960 nlabel (third result)
968 opt-args (fourth result)) 961 opt-args (fourth result))
969 (if nlabel (add-to-list 'macros-with-labels env-or-mac))) 962 (if nlabel (add-to-list 'macros-with-labels env-or-mac)))
970 (if typekey (add-to-list 'reftex-label-mac-list env-or-mac))) 963 (if typekey (add-to-list 'reftex-label-mac-list env-or-mac)))
971 (t 964 (t
972 ;; It's an environment 965 ;; It's an environment
973 (setq nargs nil nlabel nil opt-args nil) 966 (setq nargs nil nlabel nil opt-args nil)
974 (cond ((string= env-or-mac "any")) 967 (cond ((string= env-or-mac "any"))
975 ((string= env-or-mac "")) 968 ((string= env-or-mac ""))
976 ((string= env-or-mac "section")) 969 ((string= env-or-mac "section"))
977 (t 970 (t
978 (add-to-list 'reftex-label-env-list env-or-mac) 971 (add-to-list 'reftex-label-env-list env-or-mac)
979 (if toc-level 972 (if toc-level
980 (let ((string (format "begin{%s}" env-or-mac))) 973 (let ((string (format "begin{%s}" env-or-mac)))
981 (or (assoc string toc-levels) 974 (or (assoc string toc-levels)
982 (push (cons string toc-level) toc-levels)))))))) 975 (push (cons string toc-level) toc-levels))))))))
983 ;; Translate some special context cases 976 ;; Translate some special context cases
984 (when (assq context reftex-default-context-regexps) 977 (when (assq context reftex-default-context-regexps)
985 (setq context 978 (setq context
986 (format 979 (format
987 (cdr (assq context reftex-default-context-regexps)) 980 (cdr (assq context reftex-default-context-regexps))
988 (regexp-quote env-or-mac)))) 981 (regexp-quote env-or-mac))))
989 ;; See if this is the first format for this typekey 982 ;; See if this is the first format for this typekey
990 (and reffmt 983 (and reffmt
991 (not (assoc typekey reftex-typekey-to-format-alist)) 984 (not (assoc typekey reftex-typekey-to-format-alist))
992 (push (cons typekey reffmt) reftex-typekey-to-format-alist)) 985 (push (cons typekey reffmt) reftex-typekey-to-format-alist))
993 ;; See if this is the first definition for this env-or-mac 986 ;; See if this is the first definition for this env-or-mac
994 (and (not (string= env-or-mac "any")) 987 (and (not (string= env-or-mac "any"))
995 (not (string= env-or-mac "")) 988 (not (string= env-or-mac ""))
996 (not (assoc env-or-mac reftex-env-or-mac-alist)) 989 (not (assoc env-or-mac reftex-env-or-mac-alist))
997 (push (list env-or-mac typekey context labelfmt 990 (push (list env-or-mac typekey context labelfmt
998 nargs nlabel opt-args) 991 nargs nlabel opt-args)
999 reftex-env-or-mac-alist)) 992 reftex-env-or-mac-alist))
1000 ;; Are the magic words regular expressions? Quote normal words. 993 ;; Are the magic words regular expressions? Quote normal words.
1001 (if (eq (car wordlist) 'regexp) 994 (if (eq (car wordlist) 'regexp)
1002 (setq wordlist (cdr wordlist)) 995 (setq wordlist (cdr wordlist))
1003 (setq wordlist (mapcar 'regexp-quote wordlist))) 996 (setq wordlist (mapcar 'regexp-quote wordlist)))
1004 ;; Remember the first association of each word. 997 ;; Remember the first association of each word.
1005 (while (stringp (setq word (pop wordlist))) 998 (while (stringp (setq word (pop wordlist)))
1006 (or (assoc word reftex-words-to-typekey-alist) 999 (or (assoc word reftex-words-to-typekey-alist)
1007 (push (cons word typekey) reftex-words-to-typekey-alist))) 1000 (push (cons word typekey) reftex-words-to-typekey-alist)))
@@ -1016,10 +1009,10 @@ This enforces rescanning the buffer on next use."
1016 (nreverse reftex-typekey-to-prefix-alist)) 1009 (nreverse reftex-typekey-to-prefix-alist))
1017 1010
1018 ;; Prepare the typekey query prompt and help string. 1011 ;; Prepare the typekey query prompt and help string.
1019 (setq qh-list 1012 (setq qh-list
1020 (sort qh-list 1013 (sort qh-list
1021 (lambda (x1 x2) 1014 (lambda (x1 x2)
1022 (string< (downcase (car x1)) (downcase (car x2)))))) 1015 (string< (downcase (car x1)) (downcase (car x2))))))
1023 (setq reftex-type-query-prompt 1016 (setq reftex-type-query-prompt
1024 (concat "Label type: [" 1017 (concat "Label type: ["
1025 (mapconcat (lambda(x) (format "%s" (car x))) 1018 (mapconcat (lambda(x) (format "%s" (car x)))
@@ -1027,164 +1020,164 @@ This enforces rescanning the buffer on next use."
1027 "]")) 1020 "]"))
1028 ;; In the help string, we need to wrap lines... 1021 ;; In the help string, we need to wrap lines...
1029 (setq reftex-type-query-help 1022 (setq reftex-type-query-help
1030 (concat 1023 (concat
1031 "SELECT A LABEL TYPE:\n--------------------\n" 1024 "SELECT A LABEL TYPE:\n--------------------\n"
1032 (mapconcat 1025 (mapconcat
1033 (lambda(x) 1026 (lambda(x)
1034 (setq sum 0) 1027 (setq sum 0)
1035 (format " [%s] %s" 1028 (format " [%s] %s"
1036 (car x) 1029 (car x)
1037 (mapconcat (lambda(env) 1030 (mapconcat (lambda(env)
1038 (setq sum (+ sum (length env))) 1031 (setq sum (+ sum (length env)))
1039 (if (< sum 60) 1032 (if (< sum 60)
1040 env 1033 env
1041 (setq sum 0) 1034 (setq sum 0)
1042 (concat "\n " env))) 1035 (concat "\n " env)))
1043 (cdr x) " "))) 1036 (cdr x) " ")))
1044 qh-list "\n"))) 1037 qh-list "\n")))
1045 1038
1046 ;; Convert magic words to regular expressions. We make regular expressions 1039 ;; Convert magic words to regular expressions. We make regular expressions
1047 ;; which allow for some chars from the ref format to be in the buffer. 1040 ;; which allow for some chars from the ref format to be in the buffer.
1048 ;; These characters will be seen and removed. 1041 ;; These characters will be seen and removed.
1049 (setq reftex-words-to-typekey-alist 1042 (setq reftex-words-to-typekey-alist
1050 (mapcar 1043 (mapcar
1051 (lambda (x) 1044 (lambda (x)
1052 (setq word (car x) 1045 (setq word (car x)
1053 typekey (cdr x) 1046 typekey (cdr x)
1054 fmt (cdr (assoc typekey reftex-typekey-to-format-alist))) 1047 fmt (cdr (assoc typekey reftex-typekey-to-format-alist)))
1055 (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\(")) 1048 (setq word (concat "\\W\\(" word "[ \t\n\r]*\\)\\("))
1056 (setq i 0) 1049 (setq i 0)
1057 (while (and (< i 10) ; maximum number of format chars allowed 1050 (while (and (< i 10) ; maximum number of format chars allowed
1058 (< i (length fmt)) 1051 (< i (length fmt))
1059 (not (member (aref fmt i) '(?%)))) 1052 (not (member (aref fmt i) '(?%))))
1060 (setq word (concat word "\\|" (regexp-quote 1053 (setq word (concat word "\\|" (regexp-quote
1061 (substring fmt 0 (1+ i))))) 1054 (substring fmt 0 (1+ i)))))
1062 (incf i)) 1055 (incf i))
1063 (cons (concat word "\\)\\=") typekey)) 1056 (cons (concat word "\\)\\=") typekey))
1064 (nreverse reftex-words-to-typekey-alist))) 1057 (nreverse reftex-words-to-typekey-alist)))
1065 1058
1066 ;; Parse the index macros 1059 ;; Parse the index macros
1067 (setq reftex-index-macro-alist nil 1060 (setq reftex-index-macro-alist nil
1068 reftex-key-to-index-macro-alist nil 1061 reftex-key-to-index-macro-alist nil
1069 reftex-macros-with-index nil) 1062 reftex-macros-with-index nil)
1070 (while all-index 1063 (while all-index
1071 (setq entry (car all-index) 1064 (setq entry (car all-index)
1072 macro (car entry) 1065 macro (car entry)
1073 tag (nth 1 entry) 1066 tag (nth 1 entry)
1074 key (nth 2 entry) 1067 key (nth 2 entry)
1075 prefix (or (nth 3 entry) "") 1068 prefix (or (nth 3 entry) "")
1076 verify (nth 4 entry) 1069 verify (nth 4 entry)
1077 ;; For repeat, we need to be compatible with older code 1070 ;; For repeat, we need to be compatible with older code
1078 ;; This information used to be given only for the default macro, 1071 ;; This information used to be given only for the default macro,
1079 ;; but later we required to have it for *every* index macro 1072 ;; but later we required to have it for *every* index macro
1080 repeat (cond ((> (length entry) 5) (nth 5 entry)) 1073 repeat (cond ((> (length entry) 5) (nth 5 entry))
1081 ((and (eq key (car reftex-index-default-macro)) 1074 ((and (eq key (car reftex-index-default-macro))
1082 (> (length reftex-index-default-macro) 2)) 1075 (> (length reftex-index-default-macro) 2))
1083 ;; User has old setting - respect it 1076 ;; User has old setting - respect it
1084 (nth 2 reftex-index-default-macro)) 1077 (nth 2 reftex-index-default-macro))
1085 (t t)) 1078 (t t))
1086 all-index (cdr all-index)) 1079 all-index (cdr all-index))
1087 (let ((result (reftex-parse-args macro))) 1080 (let ((result (reftex-parse-args macro)))
1088 (setq macro (or (first result) macro) 1081 (setq macro (or (first result) macro)
1089 nargs (second result) 1082 nargs (second result)
1090 nindex (third result) 1083 nindex (third result)
1091 opt-args (fourth result)) 1084 opt-args (fourth result))
1092 (unless (member macro reftex-macros-with-index) 1085 (unless (member macro reftex-macros-with-index)
1093 ;; 0 1 2 3 4 5 6 7 1086 ;; 0 1 2 3 4 5 6 7
1094 (push (list macro tag prefix verify nargs nindex opt-args repeat) 1087 (push (list macro tag prefix verify nargs nindex opt-args repeat)
1095 reftex-index-macro-alist) 1088 reftex-index-macro-alist)
1096 (or (assoc key reftex-key-to-index-macro-alist) 1089 (or (assoc key reftex-key-to-index-macro-alist)
1097 (push (list key macro) reftex-key-to-index-macro-alist)) 1090 (push (list key macro) reftex-key-to-index-macro-alist))
1098 (push macro reftex-macros-with-index)))) 1091 (push macro reftex-macros-with-index))))
1099 ;; Make the prompt and help string for index macros query 1092 ;; Make the prompt and help string for index macros query
1100 (setq reftex-key-to-index-macro-alist 1093 (setq reftex-key-to-index-macro-alist
1101 (sort reftex-key-to-index-macro-alist 1094 (sort reftex-key-to-index-macro-alist
1102 (lambda (a b) (< (downcase (car a)) (downcase (car b)))))) 1095 (lambda (a b) (< (downcase (car a)) (downcase (car b))))))
1103 (setq reftex-query-index-macro-prompt 1096 (setq reftex-query-index-macro-prompt
1104 (concat "Index macro: [" 1097 (concat "Index macro: ["
1105 (mapconcat (lambda (x) (char-to-string (car x))) 1098 (mapconcat (lambda (x) (char-to-string (car x)))
1106 reftex-key-to-index-macro-alist "") 1099 reftex-key-to-index-macro-alist "")
1107 "]")) 1100 "]"))
1108 (setq i 0 1101 (setq i 0
1109 reftex-query-index-macro-help 1102 reftex-query-index-macro-help
1110 (concat 1103 (concat
1111 "SELECT A MACRO:\n---------------\n" 1104 "SELECT A MACRO:\n---------------\n"
1112 (mapconcat 1105 (mapconcat
1113 (lambda(x) 1106 (lambda(x)
1114 (format "[%c] %-20.20s%s" (car x) (nth 1 x) 1107 (format "[%c] %-20.20s%s" (car x) (nth 1 x)
1115 (if (= 0 (mod (incf i) 3)) "\n" ""))) 1108 (if (= 0 (mod (incf i) 3)) "\n" "")))
1116 reftex-key-to-index-macro-alist ""))) 1109 reftex-key-to-index-macro-alist "")))
1117 1110
1118 ;; Make the full list of section levels 1111 ;; Make the full list of section levels
1119 (setq reftex-section-levels-all 1112 (setq reftex-section-levels-all
1120 (append toc-levels 1113 (append toc-levels
1121 (get reftex-docstruct-symbol 'reftex-section-levels) 1114 (get reftex-docstruct-symbol 'reftex-section-levels)
1122 reftex-section-levels)) 1115 reftex-section-levels))
1123 1116
1124 ;; Calculate the regular expressions 1117 ;; Calculate the regular expressions
1125 (let* ( 1118 (let* (
1126; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*") 1119; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
1127 (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because 1120 (wbol "\\(^\\)[ \t]*") ; Need to keep the empty group because
1128 ;;; because match number are hard coded 1121 ;;; because match number are hard coded
1129 (label-re "\\\\label{\\([^}]*\\)}") 1122 (label-re "\\\\label{\\([^}]*\\)}")
1130 (include-re (concat wbol 1123 (include-re (concat wbol
1131 "\\\\\\(" 1124 "\\\\\\("
1132 (mapconcat 'identity 1125 (mapconcat 'identity
1133 reftex-include-file-commands "\\|") 1126 reftex-include-file-commands "\\|")
1134 "\\)[{ \t]+\\([^} \t\n\r]+\\)")) 1127 "\\)[{ \t]+\\([^} \t\n\r]+\\)"))
1135 (section-re 1128 (section-re
1136 (concat wbol "\\\\\\(" 1129 (concat wbol "\\\\\\("
1137 (mapconcat (lambda (x) (regexp-quote (car x))) 1130 (mapconcat (lambda (x) (regexp-quote (car x)))
1138 reftex-section-levels-all "\\|") 1131 reftex-section-levels-all "\\|")
1139 "\\)\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n]")) 1132 "\\)\\*?\\(\\[[^]]*\\]\\)?[[{ \t\r\n]"))
1140 (appendix-re (concat wbol "\\(\\\\appendix\\)")) 1133 (appendix-re (concat wbol "\\(\\\\appendix\\)"))
1141 (macro-re 1134 (macro-re
1142 (if macros-with-labels 1135 (if macros-with-labels
1143 (concat "\\(" 1136 (concat "\\("
1144 (mapconcat 'regexp-quote macros-with-labels "\\|") 1137 (mapconcat 'regexp-quote macros-with-labels "\\|")
1145 "\\)[[{]") 1138 "\\)[[{]")
1146 "")) 1139 ""))
1147 (index-re 1140 (index-re
1148 (concat "\\(" 1141 (concat "\\("
1149 (mapconcat 'regexp-quote reftex-macros-with-index "\\|") 1142 (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
1150 "\\)[[{]")) 1143 "\\)[[{]"))
1151 (find-index-re-format 1144 (find-index-re-format
1152 (concat "\\(" 1145 (concat "\\("
1153 (mapconcat 'regexp-quote reftex-macros-with-index "\\|") 1146 (mapconcat 'regexp-quote reftex-macros-with-index "\\|")
1154 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]")) 1147 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
1155 (find-label-re-format 1148 (find-label-re-format
1156 (concat "\\(" 1149 (concat "\\("
1157 (mapconcat 'regexp-quote (append '("\\label") 1150 (mapconcat 'regexp-quote (append '("\\label")
1158 macros-with-labels) "\\|") 1151 macros-with-labels) "\\|")
1159 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]")) 1152 "\\)\\([[{][^]}]*[]}]\\)*[[{]\\(%s\\)[]}]"))
1160 (index-level-re 1153 (index-level-re
1161 (regexp-quote (nth 0 reftex-index-special-chars))) 1154 (regexp-quote (nth 0 reftex-index-special-chars)))
1162 (index-key-end-re ;; ^]- not allowed 1155 (index-key-end-re ;; ^]- not allowed
1163 (concat "[^" (nth 3 reftex-index-special-chars) "]" 1156 (concat "[^" (nth 3 reftex-index-special-chars) "]"
1164 "[" (nth 1 reftex-index-special-chars) 1157 "[" (nth 1 reftex-index-special-chars)
1165 (nth 2 reftex-index-special-chars) "]")) 1158 (nth 2 reftex-index-special-chars) "]"))
1166 ) 1159 )
1167 (setq reftex-section-regexp section-re 1160 (setq reftex-section-regexp section-re
1168 reftex-section-or-include-regexp 1161 reftex-section-or-include-regexp
1169 (concat section-re "\\|" include-re) 1162 (concat section-re "\\|" include-re)
1170 reftex-everything-regexp 1163 reftex-everything-regexp
1171 (concat label-re "\\|" section-re "\\|" include-re 1164 (concat label-re "\\|" section-re "\\|" include-re
1172 "\\|" appendix-re 1165 "\\|" appendix-re
1173 "\\|" index-re 1166 "\\|" index-re
1174 (if macros-with-labels "\\|" "") macro-re) 1167 (if macros-with-labels "\\|" "") macro-re)
1175 reftex-everything-regexp-no-index 1168 reftex-everything-regexp-no-index
1176 (concat label-re "\\|" section-re "\\|" include-re 1169 (concat label-re "\\|" section-re "\\|" include-re
1177 "\\|" appendix-re 1170 "\\|" appendix-re
1178 "\\|" "\\(\\\\6\\\\3\\\\1\\)" ; This is unlikely to match 1171 "\\|" "\\(\\\\6\\\\3\\\\1\\)" ; This is unlikely to match
1179 (if macros-with-labels "\\|" "") macro-re) 1172 (if macros-with-labels "\\|" "") macro-re)
1180 reftex-index-re index-re 1173 reftex-index-re index-re
1181 reftex-index-level-re index-level-re 1174 reftex-index-level-re index-level-re
1182 reftex-index-key-end-re index-key-end-re 1175 reftex-index-key-end-re index-key-end-re
1183 reftex-macros-with-labels macros-with-labels 1176 reftex-macros-with-labels macros-with-labels
1184 reftex-find-index-entry-regexp-format find-index-re-format 1177 reftex-find-index-entry-regexp-format find-index-re-format
1185 reftex-find-label-regexp-format find-label-re-format 1178 reftex-find-label-regexp-format find-label-re-format
1186 reftex-find-label-regexp-format2 1179 reftex-find-label-regexp-format2
1187 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]") 1180 "\\([]} \t\n\r]\\)\\([[{]\\)\\(%s\\)[]}]")
1188 (message "Compiling label environment definitions...done"))) 1181 (message "Compiling label environment definitions...done")))
1189 (put reftex-docstruct-symbol 'reftex-cache 1182 (put reftex-docstruct-symbol 'reftex-cache
1190 (mapcar 'symbol-value reftex-cache-variables))) 1183 (mapcar 'symbol-value reftex-cache-variables)))
@@ -1202,8 +1195,8 @@ This enforces rescanning the buffer on next use."
1202 (when (eq ?\[ (string-to-char args)) 1195 (when (eq ?\[ (string-to-char args))
1203 (push cnt opt-list)) 1196 (push cnt opt-list))
1204 (when (and (match-end 1) 1197 (when (and (match-end 1)
1205 (not nlabel)) 1198 (not nlabel))
1206 (setq nlabel cnt)) 1199 (setq nlabel cnt))
1207 (setq args (substring args (match-end 0)))) 1200 (setq args (substring args (match-end 0))))
1208 (list must-match cnt nlabel opt-list))) 1201 (list must-match cnt nlabel opt-list)))
1209 nil)) 1202 nil))
@@ -1227,14 +1220,14 @@ This enforces rescanning the buffer on next use."
1227 (reftex-ensure-compiled-variables) 1220 (reftex-ensure-compiled-variables)
1228 1221
1229 (when (or (null (symbol-value reftex-docstruct-symbol)) 1222 (when (or (null (symbol-value reftex-docstruct-symbol))
1230 (member rescan '(t 1 (4) (16)))) 1223 (member rescan '(t 1 (4) (16))))
1231 ;; The docstruct will change: Remove selection buffers. 1224 ;; The docstruct will change: Remove selection buffers.
1232 (save-excursion 1225 (save-excursion
1233 (reftex-erase-buffer "*toc*") 1226 (reftex-erase-buffer "*toc*")
1234 (reftex-erase-all-selection-and-index-buffers))) 1227 (reftex-erase-all-selection-and-index-buffers)))
1235 1228
1236 (if (and (null (symbol-value reftex-docstruct-symbol)) 1229 (if (and (null (symbol-value reftex-docstruct-symbol))
1237 (not (member rescan '(t 1 (4) (16)))) 1230 (not (member rescan '(t 1 (4) (16))))
1238 reftex-save-parse-info) 1231 reftex-save-parse-info)
1239 ;; Try to read the stuff from a file 1232 ;; Try to read the stuff from a file
1240 (reftex-access-parse-file 'read)) 1233 (reftex-access-parse-file 'read))
@@ -1248,6 +1241,7 @@ This enforces rescanning the buffer on next use."
1248 ;; Scan whatever was required by the caller. 1241 ;; Scan whatever was required by the caller.
1249 (reftex-do-parse rescan file)))) 1242 (reftex-do-parse rescan file))))
1250 1243
1244;;;###autoload
1251(defun reftex-scanning-info-available-p () 1245(defun reftex-scanning-info-available-p ()
1252 "Is the scanning info about the current document available?" 1246 "Is the scanning info about the current document available?"
1253 (unless reftex-docstruct-symbol 1247 (unless reftex-docstruct-symbol
@@ -1255,7 +1249,7 @@ This enforces rescanning the buffer on next use."
1255 (and (symbolp reftex-docstruct-symbol) 1249 (and (symbolp reftex-docstruct-symbol)
1256 (symbol-value reftex-docstruct-symbol) 1250 (symbol-value reftex-docstruct-symbol)
1257 t)) 1251 t))
1258 1252
1259(defun reftex-silence-toc-markers (list n) 1253(defun reftex-silence-toc-markers (list n)
1260 ;; Set all toc markers in the first N entries in list to nil 1254 ;; Set all toc markers in the first N entries in list to nil
1261 (while (and list (> (decf n) -1)) 1255 (while (and list (> (decf n) -1))
@@ -1268,12 +1262,12 @@ This enforces rescanning the buffer on next use."
1268 "Perform ACTION on the parse file (the .rel file). 1262 "Perform ACTION on the parse file (the .rel file).
1269Valid actions are: readable, restore, read, kill, write." 1263Valid actions are: readable, restore, read, kill, write."
1270 (let* ((list (symbol-value reftex-docstruct-symbol)) 1264 (let* ((list (symbol-value reftex-docstruct-symbol))
1271 (docstruct-symbol reftex-docstruct-symbol) 1265 (docstruct-symbol reftex-docstruct-symbol)
1272 (master (reftex-TeX-master-file)) 1266 (master (reftex-TeX-master-file))
1273 (enable-local-variables nil) 1267 (enable-local-variables nil)
1274 (file (if (string-match "\\.[a-zA-Z]+\\'" master) 1268 (file (if (string-match "\\.[a-zA-Z]+\\'" master)
1275 (concat (substring master 0 (match-beginning 0)) 1269 (concat (substring master 0 (match-beginning 0))
1276 reftex-parse-file-extension) 1270 reftex-parse-file-extension)
1277 (concat master reftex-parse-file-extension)))) 1271 (concat master reftex-parse-file-extension))))
1278 (cond 1272 (cond
1279 ((eq action 'readable) 1273 ((eq action 'readable)
@@ -1285,31 +1279,31 @@ Valid actions are: readable, restore, read, kill, write."
1285 (reftex-tie-multifile-symbols)) 1279 (reftex-tie-multifile-symbols))
1286 (if (file-exists-p file) 1280 (if (file-exists-p file)
1287 ;; load the file and return t for success 1281 ;; load the file and return t for success
1288 (condition-case nil 1282 (condition-case nil
1289 (progn (load-file file) t) 1283 (progn (load-file file) t)
1290 (error (set reftex-docstruct-symbol nil) 1284 (error (set reftex-docstruct-symbol nil)
1291 (error "Error while loading file %s" file))) 1285 (error "Error while loading file %s" file)))
1292 ;; Throw an exception if the file does not exist 1286 ;; Throw an exception if the file does not exist
1293 (error "No restore file %s" file))) 1287 (error "No restore file %s" file)))
1294 ((eq action 'read) 1288 ((eq action 'read)
1295 (put reftex-docstruct-symbol 'modified nil) 1289 (put reftex-docstruct-symbol 'modified nil)
1296 (if (file-exists-p file) 1290 (if (file-exists-p file)
1297 ;; load the file and return t for success 1291 ;; load the file and return t for success
1298 (condition-case nil 1292 (condition-case nil
1299 (progn 1293 (progn
1300 (load-file file) 1294 (load-file file)
1301 (reftex-check-parse-consistency) 1295 (reftex-check-parse-consistency)
1302 t) 1296 t)
1303 (error (message "Error while restoring file %s" file) 1297 (error (message "Error while restoring file %s" file)
1304 (set reftex-docstruct-symbol nil) 1298 (set reftex-docstruct-symbol nil)
1305 nil)) 1299 nil))
1306 ;; return nil for failure, but no exception 1300 ;; return nil for failure, but no exception
1307 nil)) 1301 nil))
1308 ((eq action 'kill) 1302 ((eq action 'kill)
1309 ;; Remove the file 1303 ;; Remove the file
1310 (when (and (file-exists-p file) (file-writable-p file)) 1304 (when (and (file-exists-p file) (file-writable-p file))
1311 (message "Unlinking file %s" file) 1305 (message "Unlinking file %s" file)
1312 (delete-file file))) 1306 (delete-file file)))
1313 (t 1307 (t
1314 (put docstruct-symbol 'modified nil) 1308 (put docstruct-symbol 'modified nil)
1315 (save-excursion 1309 (save-excursion
@@ -1325,20 +1319,20 @@ Valid actions are: readable, restore, read, kill, write."
1325 (insert "(set reftex-docstruct-symbol '(\n\n") 1319 (insert "(set reftex-docstruct-symbol '(\n\n")
1326 (let ((standard-output (current-buffer))) 1320 (let ((standard-output (current-buffer)))
1327 (mapcar 1321 (mapcar
1328 (lambda (x) 1322 (lambda (x)
1329 (cond ((eq (car x) 'toc) 1323 (cond ((eq (car x) 'toc)
1330 ;; A toc entry. Do not save the marker. 1324 ;; A toc entry. Do not save the marker.
1331 ;; Save the markers position at position 8 1325 ;; Save the markers position at position 8
1332 (print (list 'toc "toc" (nth 2 x) (nth 3 x) 1326 (print (list 'toc "toc" (nth 2 x) (nth 3 x)
1333 nil (nth 5 x) (nth 6 x) (nth 7 x) 1327 nil (nth 5 x) (nth 6 x) (nth 7 x)
1334 (or (and (markerp (nth 4 x)) 1328 (or (and (markerp (nth 4 x))
1335 (marker-position (nth 4 x))) 1329 (marker-position (nth 4 x)))
1336 (nth 8 x))))) 1330 (nth 8 x)))))
1337 ((and (not (eq t reftex-support-index)) 1331 ((and (not (eq t reftex-support-index))
1338 (eq (car x) 'index)) 1332 (eq (car x) 'index))
1339 ;; Don't save index entries 1333 ;; Don't save index entries
1340 ) 1334 )
1341 (t (print x)))) 1335 (t (print x))))
1342 list)) 1336 list))
1343 (insert "))\n\n") 1337 (insert "))\n\n")
1344 (save-buffer 0) 1338 (save-buffer 0)
@@ -1351,29 +1345,29 @@ Valid actions are: readable, restore, read, kill, write."
1351 1345
1352 ;; Check if the master is the same: when moving a document, this will see it. 1346 ;; Check if the master is the same: when moving a document, this will see it.
1353 (let* ((real-master (reftex-TeX-master-file)) 1347 (let* ((real-master (reftex-TeX-master-file))
1354 (parsed-master 1348 (parsed-master
1355 (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol))))) 1349 (nth 1 (assq 'bof (symbol-value reftex-docstruct-symbol)))))
1356 (unless (string= (file-truename real-master) (file-truename parsed-master)) 1350 (unless (string= (file-truename real-master) (file-truename parsed-master))
1357 (message "Master file name in load file is different: %s versus %s" 1351 (message "Master file name in load file is different: %s versus %s"
1358 parsed-master real-master) 1352 parsed-master real-master)
1359 (error "Master file name error"))) 1353 (error "Master file name error")))
1360 1354
1361 ;; Check for the existence of all document files 1355 ;; Check for the existence of all document files
1362;;; (let* ((all (symbol-value reftex-docstruct-symbol))) 1356;;; (let* ((all (symbol-value reftex-docstruct-symbol)))
1363;;; (while all 1357;;; (while all
1364;;; (when (and (eq (car (car all)) 'bof) 1358;;; (when (and (eq (car (car all)) 'bof)
1365;;; (not (file-regular-p (nth 1 (car all))))) 1359;;; (not (file-regular-p (nth 1 (car all)))))
1366;;; (message "File %s in saved parse info not avalable" (cdr (car all))) 1360;;; (message "File %s in saved parse info not avalable" (cdr (car all)))
1367;;; (error "File not found")) 1361;;; (error "File not found"))
1368;;; (setq all (cdr all)))) 1362;;; (setq all (cdr all))))
1369 ) 1363 )
1370 1364
1371(defun reftex-select-external-document (xr-alist xr-index) 1365(defun reftex-select-external-document (xr-alist xr-index)
1372 ;; Return index of an external document. 1366 ;; Return index of an external document.
1373 (let* ((len (length xr-alist)) (highest (1- (+ ?0 len))) 1367 (let* ((len (length xr-alist)) (highest (1- (+ ?0 len)))
1374 (prompt (format "[%c-%c] Select TAB: Read prefix with completion" 1368 (prompt (format "[%c-%c] Select TAB: Read prefix with completion"
1375 ?0 highest)) 1369 ?0 highest))
1376 key prefix) 1370 key prefix)
1377 (cond 1371 (cond
1378 ((= len 1) 1372 ((= len 1)
1379 (message "No external documents available") 1373 (message "No external documents available")
@@ -1382,27 +1376,27 @@ Valid actions are: readable, restore, read, kill, write."
1382 (- 1 xr-index)) 1376 (- 1 xr-index))
1383 (t 1377 (t
1384 (save-excursion 1378 (save-excursion
1385 (let* ((length (apply 'max (mapcar 1379 (let* ((length (apply 'max (mapcar
1386 (lambda(x) (length (car x))) xr-alist))) 1380 (lambda(x) (length (car x))) xr-alist)))
1387 (fmt (format " [%%c] %%-%ds %%s\n" length)) 1381 (fmt (format " [%%c] %%-%ds %%s\n" length))
1388 (n (1- ?0))) 1382 (n (1- ?0)))
1389 (setq key 1383 (setq key
1390 (reftex-select-with-char 1384 (reftex-select-with-char
1391 prompt 1385 prompt
1392 (concat 1386 (concat
1393 "SELECT EXTERNAL DOCUMENT\n------------------------\n" 1387 "SELECT EXTERNAL DOCUMENT\n------------------------\n"
1394 (mapconcat 1388 (mapconcat
1395 (lambda (x) 1389 (lambda (x)
1396 (format fmt (incf n) (or (car x) "") 1390 (format fmt (incf n) (or (car x) "")
1397 (abbreviate-file-name (cdr x)))) 1391 (abbreviate-file-name (cdr x))))
1398 xr-alist "")) 1392 xr-alist ""))
1399 nil t)) 1393 nil t))
1400 (cond 1394 (cond
1401 ((and (>= key ?0) (<= key highest)) (- key ?0)) 1395 ((and (>= key ?0) (<= key highest)) (- key ?0))
1402 ((= key ?\C-i) 1396 ((= key ?\C-i)
1403 (setq prefix (completing-read "Prefix: " xr-alist nil t)) 1397 (setq prefix (completing-read "Prefix: " xr-alist nil t))
1404 (- len (length (memq (assoc prefix xr-alist) xr-alist)))) 1398 (- len (length (memq (assoc prefix xr-alist) xr-alist))))
1405 (t (error "Illegal document selection [%c]" key))))))))) 1399 (t (error "Illegal document selection [%c]" key)))))))))
1406 1400
1407;;; ========================================================================= 1401;;; =========================================================================
1408;;; 1402;;;
@@ -1414,65 +1408,65 @@ If the file does not have any of the legal extensions for TYPE,
1414try first the default extension and only then the naked file name. 1408try first the default extension and only then the naked file name.
1415When DIE is non-nil, throw an error if file not found." 1409When DIE is non-nil, throw an error if file not found."
1416 (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t))) 1410 (let* ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t)))
1417 (extensions (cdr (assoc type reftex-file-extensions))) 1411 (extensions (cdr (assoc type reftex-file-extensions)))
1418 (def-ext (car extensions)) 1412 (def-ext (car extensions))
1419 (ext-re (concat "\\(" 1413 (ext-re (concat "\\("
1420 (mapconcat 'regexp-quote extensions "\\|") 1414 (mapconcat 'regexp-quote extensions "\\|")
1421 "\\)\\'")) 1415 "\\)\\'"))
1422 (files (if (string-match ext-re file) 1416 (files (if (string-match ext-re file)
1423 (cons file nil) 1417 (cons file nil)
1424 (cons (concat file def-ext) file))) 1418 (cons (concat file def-ext) file)))
1425 path old-path file1) 1419 path old-path file1)
1426 (cond 1420 (cond
1427 ((file-name-absolute-p file) 1421 ((file-name-absolute-p file)
1428 (setq file1 1422 (setq file1
1429 (or 1423 (or
1430 (and (car files) (file-regular-p (car files)) (car files)) 1424 (and (car files) (file-regular-p (car files)) (car files))
1431 (and (cdr files) (file-regular-p (cdr files)) (cdr files))))) 1425 (and (cdr files) (file-regular-p (cdr files)) (cdr files)))))
1432 ((and reftex-use-external-file-finders 1426 ((and reftex-use-external-file-finders
1433 (assoc type reftex-external-file-finders)) 1427 (assoc type reftex-external-file-finders))
1434 (setq file1 (reftex-find-file-externally file type master-dir))) 1428 (setq file1 (reftex-find-file-externally file type master-dir)))
1435 (t 1429 (t
1436 (while (and (null file1) rec-values) 1430 (while (and (null file1) rec-values)
1437 (setq path (reftex-access-search-path 1431 (setq path (reftex-access-search-path
1438 type (pop rec-values) master-dir file)) 1432 type (pop rec-values) master-dir file))
1439 (if (or (null old-path) 1433 (if (or (null old-path)
1440 (not (eq old-path path))) 1434 (not (eq old-path path)))
1441 (setq old-path path 1435 (setq old-path path
1442 path (cons master-dir path) 1436 path (cons master-dir path)
1443 file1 (or (and (car files) 1437 file1 (or (and (car files)
1444 (reftex-find-file-on-path 1438 (reftex-find-file-on-path
1445 (car files) path master-dir)) 1439 (car files) path master-dir))
1446 (and (cdr files) 1440 (and (cdr files)
1447 (reftex-find-file-on-path 1441 (reftex-find-file-on-path
1448 (cdr files) path master-dir)))))))) 1442 (cdr files) path master-dir))))))))
1449 (cond (file1 file1) 1443 (cond (file1 file1)
1450 (die (error "No such file: %s" file) nil) 1444 (die (error "No such file: %s" file) nil)
1451 (t (message "No such file: %s (ignored)" file) nil)))) 1445 (t (message "No such file: %s (ignored)" file) nil))))
1452 1446
1453(defun reftex-find-file-externally (file type &optional master-dir) 1447(defun reftex-find-file-externally (file type &optional master-dir)
1454 ;; Use external program to find FILE. 1448 ;; Use external program to find FILE.
1455 ;; The program is taken from `reftex-external-file-finders'. 1449 ;; The program is taken from `reftex-external-file-finders'.
1456 ;; Interprete relative path definitions starting from MASTER-DIR. 1450 ;; Interprete relative path definitions starting from MASTER-DIR.
1457 (let ((default-directory (or master-dir default-directory)) 1451 (let ((default-directory (or master-dir default-directory))
1458 (prg (cdr (assoc type reftex-external-file-finders))) 1452 (prg (cdr (assoc type reftex-external-file-finders)))
1459 out) 1453 out)
1460 (if (string-match "%f" prg) 1454 (if (string-match "%f" prg)
1461 (setq prg (replace-match file t t prg))) 1455 (setq prg (replace-match file t t prg)))
1462 (setq out (apply 'reftex-process-string (split-string prg))) 1456 (setq out (apply 'reftex-process-string (split-string prg)))
1463 (if (string-match "[ \t\n]+\\'" out) ; chomp 1457 (if (string-match "[ \t\n]+\\'" out) ; chomp
1464 (setq out (replace-match "" nil nil out))) 1458 (setq out (replace-match "" nil nil out)))
1465 (cond ((equal out "") nil) 1459 (cond ((equal out "") nil)
1466 ((file-regular-p out) (expand-file-name out master-dir)) 1460 ((file-regular-p out) (expand-file-name out master-dir))
1467 (t nil)))) 1461 (t nil))))
1468 1462
1469(defun reftex-process-string (program &rest args) 1463(defun reftex-process-string (program &rest args)
1470 "Execute PROGRAM with arguments ARGS and return its STDOUT as a string." 1464 "Execute PROGRAM with arguments ARGS and return its STDOUT as a string."
1471 (let ((calling-dir default-directory)) ; remember default directory 1465 (let ((calling-dir default-directory)) ; remember default directory
1472 (with-output-to-string 1466 (with-output-to-string
1473 (with-current-buffer standard-output 1467 (with-current-buffer standard-output
1474 (let ((default-directory calling-dir)) ; set default directory 1468 (let ((default-directory calling-dir)) ; set default directory
1475 (apply 'call-process program nil '(t nil) nil args)))))) 1469 (apply 'call-process program nil '(t nil) nil args))))))
1476 1470
1477(defun reftex-access-search-path (type &optional recurse master-dir file) 1471(defun reftex-access-search-path (type &optional recurse master-dir file)
1478 ;; Access path from environment variables. TYPE is either "tex" or "bib". 1472 ;; Access path from environment variables. TYPE is either "tex" or "bib".
@@ -1486,51 +1480,51 @@ When DIE is non-nil, throw an error if file not found."
1486 (when (null (get pathvar 'status)) 1480 (when (null (get pathvar 'status))
1487 ;; Get basic path 1481 ;; Get basic path
1488 (set pathvar 1482 (set pathvar
1489 (reftex-uniq 1483 (reftex-uniq
1490 (reftex-parse-colon-path 1484 (reftex-parse-colon-path
1491 (mapconcat 1485 (mapconcat
1492 (lambda(x) 1486 (lambda(x)
1493 (if (string-match "^!" x) 1487 (if (string-match "^!" x)
1494 (apply 'reftex-process-string 1488 (apply 'reftex-process-string
1495 (split-string (substring x 1))) 1489 (split-string (substring x 1)))
1496 (or (getenv x) x))) 1490 (or (getenv x) x)))
1497 ;; For consistency, the next line should look like this: 1491 ;; For consistency, the next line should look like this:
1498 ;; (cdr (assoc type reftex-path-environment)) 1492 ;; (cdr (assoc type reftex-path-environment))
1499 ;; However, historically we have separate options for the 1493 ;; However, historically we have separate options for the
1500 ;; environment variables, so we have to do this: 1494 ;; environment variables, so we have to do this:
1501 (symbol-value (intern (concat "reftex-" type 1495 (symbol-value (intern (concat "reftex-" type
1502 "path-environment-variables"))) 1496 "path-environment-variables")))
1503 path-separator)))) 1497 path-separator))))
1504 (put pathvar 'status 'split) 1498 (put pathvar 'status 'split)
1505 ;; Check if we have recursive elements 1499 ;; Check if we have recursive elements
1506 (let ((path (symbol-value pathvar)) dir rec) 1500 (let ((path (symbol-value pathvar)) dir rec)
1507 (while (setq dir (pop path)) 1501 (while (setq dir (pop path))
1508 (when (string= (substring dir -2) "//") 1502 (when (string= (substring dir -2) "//")
1509 (if (file-name-absolute-p dir) 1503 (if (file-name-absolute-p dir)
1510 (setq rec (or rec 'absolute)) 1504 (setq rec (or rec 'absolute))
1511 (setq rec 'relative)))) 1505 (setq rec 'relative))))
1512 (put pathvar 'rec-type rec))) 1506 (put pathvar 'rec-type rec)))
1513 1507
1514 (if recurse 1508 (if recurse
1515 ;; Return the recursive expansion of the path 1509 ;; Return the recursive expansion of the path
1516 (cond 1510 (cond
1517 ((not (get pathvar 'rec-type)) 1511 ((not (get pathvar 'rec-type))
1518 ;; Path does not contain recursive elements - use simple path 1512 ;; Path does not contain recursive elements - use simple path
1519 (symbol-value pathvar)) 1513 (symbol-value pathvar))
1520 ((or (not (get pathvar 'recursive-path)) 1514 ((or (not (get pathvar 'recursive-path))
1521 (and (eq (get pathvar 'rec-type) 'relative) 1515 (and (eq (get pathvar 'rec-type) 'relative)
1522 (not (equal master-dir (get pathvar 'master-dir))))) 1516 (not (equal master-dir (get pathvar 'master-dir)))))
1523 ;; Either: We don't have a recursive expansion yet. 1517 ;; Either: We don't have a recursive expansion yet.
1524 ;; or: Relative recursive path elements need to be expanded 1518 ;; or: Relative recursive path elements need to be expanded
1525 ;; relative to new default directory 1519 ;; relative to new default directory
1526 (message "Expanding search path to find %s file: %s ..." type file) 1520 (message "Expanding search path to find %s file: %s ..." type file)
1527 (put pathvar 'recursive-path 1521 (put pathvar 'recursive-path
1528 (reftex-expand-path (symbol-value pathvar) master-dir)) 1522 (reftex-expand-path (symbol-value pathvar) master-dir))
1529 (put pathvar 'master-dir master-dir) 1523 (put pathvar 'master-dir master-dir)
1530 (get pathvar 'recursive-path)) 1524 (get pathvar 'recursive-path))
1531 (t 1525 (t
1532 ;; Recursive path computed earlier is still OK. 1526 ;; Recursive path computed earlier is still OK.
1533 (get pathvar 'recursive-path))) 1527 (get pathvar 'recursive-path)))
1534 ;; The simple path was requested 1528 ;; The simple path was requested
1535 (symbol-value pathvar)))) 1529 (symbol-value pathvar))))
1536 1530
@@ -1540,15 +1534,15 @@ When DIE is non-nil, throw an error if file not found."
1540 (catch 'exit 1534 (catch 'exit
1541 (when (file-name-absolute-p file) 1535 (when (file-name-absolute-p file)
1542 (if (file-regular-p file) 1536 (if (file-regular-p file)
1543 (throw 'exit file) 1537 (throw 'exit file)
1544 (throw 'exit nil))) 1538 (throw 'exit nil)))
1545 (let* ((thepath path) file1 dir) 1539 (let* ((thepath path) file1 dir)
1546 (while (setq dir (pop thepath)) 1540 (while (setq dir (pop thepath))
1547 (when (string= (substring dir -2) "//") 1541 (when (string= (substring dir -2) "//")
1548 (setq dir (substring dir 0 -1))) 1542 (setq dir (substring dir 0 -1)))
1549 (setq file1 (expand-file-name file (expand-file-name dir def-dir))) 1543 (setq file1 (expand-file-name file (expand-file-name dir def-dir)))
1550 (if (file-regular-p file1) 1544 (if (file-regular-p file1)
1551 (throw 'exit file1))) 1545 (throw 'exit file1)))
1552 ;; No such file 1546 ;; No such file
1553 nil))) 1547 nil)))
1554 1548
@@ -1557,8 +1551,8 @@ When DIE is non-nil, throw an error if file not found."
1557 ;; Trailing ! or !! will be converted into `//' (emTeX convention) 1551 ;; Trailing ! or !! will be converted into `//' (emTeX convention)
1558 (mapcar 1552 (mapcar
1559 (lambda (dir) 1553 (lambda (dir)
1560 (if (string-match "\\(//+\\|/*!+\\)\\'" dir) 1554 (if (string-match "\\(//+\\|/*!+\\)\\'" dir)
1561 (setq dir (replace-match "//" t t dir))) 1555 (setq dir (replace-match "//" t t dir)))
1562 (file-name-as-directory dir)) 1556 (file-name-as-directory dir))
1563 (delete "" (split-string path (concat path-separator "+"))))) 1557 (delete "" (split-string path (concat path-separator "+")))))
1564 1558
@@ -1568,15 +1562,15 @@ When DIE is non-nil, throw an error if file not found."
1568 (let (path1 dir recursive) 1562 (let (path1 dir recursive)
1569 (while (setq dir (pop path)) 1563 (while (setq dir (pop path))
1570 (if (setq recursive (string= (substring dir -2) "//")) 1564 (if (setq recursive (string= (substring dir -2) "//"))
1571 (setq dir (substring dir 0 -1))) 1565 (setq dir (substring dir 0 -1)))
1572 (if (and recursive 1566 (if (and recursive
1573 (not (file-name-absolute-p dir))) 1567 (not (file-name-absolute-p dir)))
1574 (setq dir (expand-file-name dir default-dir))) 1568 (setq dir (expand-file-name dir default-dir)))
1575 (if recursive 1569 (if recursive
1576 ;; Expand recursively 1570 ;; Expand recursively
1577 (setq path1 (append (reftex-recursive-directory-list dir) path1)) 1571 (setq path1 (append (reftex-recursive-directory-list dir) path1))
1578 ;; Keep unchanged 1572 ;; Keep unchanged
1579 (push dir path1))) 1573 (push dir path1)))
1580 (nreverse path1))) 1574 (nreverse path1)))
1581 1575
1582(defun reftex-recursive-directory-list (dir) 1576(defun reftex-recursive-directory-list (dir)
@@ -1584,18 +1578,18 @@ When DIE is non-nil, throw an error if file not found."
1584 (let ((path (list dir)) path1 file files) 1578 (let ((path (list dir)) path1 file files)
1585 (while (setq dir (pop path)) 1579 (while (setq dir (pop path))
1586 (when (file-directory-p dir) 1580 (when (file-directory-p dir)
1587 (setq files (nreverse (directory-files dir t "[^.]"))) 1581 (setq files (nreverse (directory-files dir t "[^.]")))
1588 (while (setq file (pop files)) 1582 (while (setq file (pop files))
1589 (if (file-directory-p file) 1583 (if (file-directory-p file)
1590 (push (file-name-as-directory file) path))) 1584 (push (file-name-as-directory file) path)))
1591 (push dir path1))) 1585 (push dir path1)))
1592 path1)) 1586 path1))
1593 1587
1594(defun reftex-uniq (list) 1588(defun reftex-uniq (list)
1595 (let (new) 1589 (let (new)
1596 (while list 1590 (while list
1597 (or (member (car list) new) 1591 (or (member (car list) new)
1598 (push (car list) new)) 1592 (push (car list) new))
1599 (pop list)) 1593 (pop list))
1600 (nreverse new))) 1594 (nreverse new)))
1601 1595
@@ -1658,8 +1652,8 @@ When DIE is non-nil, throw an error if file not found."
1658 "Show the table of contents for the current document." t) 1652 "Show the table of contents for the current document." t)
1659(autoload 'reftex-toc-recenter "reftex-toc" 1653(autoload 'reftex-toc-recenter "reftex-toc"
1660 "Display the TOC window and highlight line corresponding to current position." t) 1654 "Display the TOC window and highlight line corresponding to current position." t)
1661(autoload 'reftex-toggle-auto-toc-recenter "reftex-toc" 1655(autoload 'reftex-toggle-auto-toc-recenter "reftex-toc" t)
1662 "Toggle automatic recentering of TOC window." t) 1656
1663 1657
1664;;; ========================================================================= 1658;;; =========================================================================
1665;;; 1659;;;
@@ -1797,13 +1791,6 @@ When DIE is non-nil, throw an error if file not found."
1797 (when (match-beginning n) 1791 (when (match-beginning n)
1798 (buffer-substring-no-properties (match-beginning n) (match-end n)))) 1792 (buffer-substring-no-properties (match-beginning n) (match-end n))))
1799 1793
1800(defun reftex-region-active-p ()
1801 "Is transient-mark-mode on and the region active?
1802Works on both Emacs and XEmacs."
1803 (if (featurep 'xemacs)
1804 (and zmacs-regions (region-active-p))
1805 (and transient-mark-mode mark-active)))
1806
1807(defun reftex-kill-buffer (buffer) 1794(defun reftex-kill-buffer (buffer)
1808 ;; Kill buffer if it exists. 1795 ;; Kill buffer if it exists.
1809 (and (setq buffer (get-buffer buffer)) 1796 (and (setq buffer (get-buffer buffer))
@@ -1861,7 +1848,7 @@ Works on both Emacs and XEmacs."
1861 (let* ((elt (car (member elt list))) (ex (not exclusive)) ass last-ass) 1848 (let* ((elt (car (member elt list))) (ex (not exclusive)) ass last-ass)
1862 (while (and (setq ass (assoc key list)) 1849 (while (and (setq ass (assoc key list))
1863 (setq list (memq ass list)) 1850 (setq list (memq ass list))
1864 (or ex (not (eq elt (car list)))) 1851 (or ex (not (eq elt (car list))))
1865 (memq elt list)) 1852 (memq elt list))
1866 (setq last-ass ass 1853 (setq last-ass ass
1867 list (cdr list))) 1854 list (cdr list)))
@@ -1875,22 +1862,22 @@ Works on both Emacs and XEmacs."
1875 (let (rtn) 1862 (let (rtn)
1876 (while list 1863 (while list
1877 (if (funcall predicate (car list)) 1864 (if (funcall predicate (car list))
1878 (push (if completion 1865 (push (if completion
1879 (list (nth nth (car list))) 1866 (list (nth nth (car list)))
1880 (nth nth (car list))) 1867 (nth nth (car list)))
1881 rtn)) 1868 rtn))
1882 (setq list (cdr list))) 1869 (setq list (cdr list)))
1883 (nreverse rtn))) 1870 (nreverse rtn)))
1884 1871
1885(defun reftex-make-selection-buffer-name (type &optional index) 1872(defun reftex-make-selection-buffer-name (type &optional index)
1886 ;; Make unique name for a selection buffer. 1873 ;; Make unique name for a selection buffer.
1887 (format " *RefTeX[%s][%d]*" 1874 (format " *RefTeX[%s][%d]*"
1888 type (or index (get reftex-docstruct-symbol :master-index) 0))) 1875 type (or index (get reftex-docstruct-symbol :master-index) 0)))
1889 1876
1890(defun reftex-make-index-buffer-name (tag &optional cnt) 1877(defun reftex-make-index-buffer-name (tag &optional cnt)
1891 ;; Make unique name for an index buffer. 1878 ;; Make unique name for an index buffer.
1892 (format "*Index[%s][%d]*" 1879 (format "*Index[%s][%d]*"
1893 tag (or cnt (get reftex-docstruct-symbol :master-index) 0))) 1880 tag (or cnt (get reftex-docstruct-symbol :master-index) 0)))
1894 1881
1895(defun reftex-truncate (string ncols &optional ellipses padding) 1882(defun reftex-truncate (string ncols &optional ellipses padding)
1896 ;; Truncate STRING to NCOLS characters. 1883 ;; Truncate STRING to NCOLS characters.
@@ -1898,11 +1885,11 @@ Works on both Emacs and XEmacs."
1898 ;; white space to NCOLS characters. When ELLIPSES is non-nil and the 1885 ;; white space to NCOLS characters. When ELLIPSES is non-nil and the
1899 ;; string needs to be truncated, replace last 3 characters by dots. 1886 ;; string needs to be truncated, replace last 3 characters by dots.
1900 (setq string 1887 (setq string
1901 (if (<= (length string) ncols) 1888 (if (<= (length string) ncols)
1902 string 1889 string
1903 (if ellipses 1890 (if ellipses
1904 (concat (substring string 0 (- ncols 3)) "...") 1891 (concat (substring string 0 (- ncols 3)) "...")
1905 (substring string 0 ncols)))) 1892 (substring string 0 ncols))))
1906 (if padding 1893 (if padding
1907 (format (format "%%-%ds" ncols) string) 1894 (format (format "%%-%ds" ncols) string)
1908 string)) 1895 string))
@@ -1912,8 +1899,8 @@ Works on both Emacs and XEmacs."
1912 ;; If POS is given, calculate distances relative to it. 1899 ;; If POS is given, calculate distances relative to it.
1913 ;; Return nil if there is no match. 1900 ;; Return nil if there is no match.
1914 (let ((pos (point)) 1901 (let ((pos (point))
1915 (dist (or max-length (length regexp))) 1902 (dist (or max-length (length regexp)))
1916 match1 match2 match) 1903 match1 match2 match)
1917 (goto-char (min (+ pos dist) (point-max))) 1904 (goto-char (min (+ pos dist) (point-max)))
1918 (when (re-search-backward regexp nil t) 1905 (when (re-search-backward regexp nil t)
1919 (setq match1 (match-data))) 1906 (setq match1 (match-data)))
@@ -1949,14 +1936,14 @@ Works on both Emacs and XEmacs."
1949 ;; Enlarge other window displaying buffer to show whole buffer if possible. 1936 ;; Enlarge other window displaying buffer to show whole buffer if possible.
1950 ;; If KEEP-CURRENT in non-nil, current buffer must remain visible. 1937 ;; If KEEP-CURRENT in non-nil, current buffer must remain visible.
1951 (let* ((win1 (selected-window)) 1938 (let* ((win1 (selected-window))
1952 (buf1 (current-buffer)) 1939 (buf1 (current-buffer))
1953 (win2 (get-buffer-window buf2))) ;; Only on current frame. 1940 (win2 (get-buffer-window buf2))) ;; Only on current frame.
1954 (when win2 1941 (when win2
1955 (select-window win2) 1942 (select-window win2)
1956 (unless (and (pos-visible-in-window-p (point-min)) 1943 (unless (and (pos-visible-in-window-p 1)
1957 (pos-visible-in-window-p (point-max))) 1944 (pos-visible-in-window-p (point-max)))
1958 (enlarge-window (1+ (- (count-lines (point-min) (point-max)) 1945 (enlarge-window (1+ (- (count-lines 1 (point-max))
1959 (reftex-window-height)))))) 1946 (reftex-window-height))))))
1960 (cond 1947 (cond
1961 ((window-live-p win1) (select-window win1)) 1948 ((window-live-p win1) (select-window win1))
1962 (keep-current 1949 (keep-current
@@ -1971,37 +1958,37 @@ Works on both Emacs and XEmacs."
1971 (let ((char ?\?)) 1958 (let ((char ?\?))
1972 (save-window-excursion 1959 (save-window-excursion
1973 (catch 'exit 1960 (catch 'exit
1974 (message (concat prompt " (?=Help)")) 1961 (message (concat prompt " (?=Help)"))
1975 (when (or (sit-for (or delay-time 0)) 1962 (when (or (sit-for (or delay-time 0))
1976 (= ?\? (setq char (read-char-exclusive)))) 1963 (= ?\? (setq char (read-char-exclusive))))
1977 (reftex-kill-buffer "*RefTeX Select*") 1964 (reftex-kill-buffer "*RefTeX Select*")
1978 (switch-to-buffer-other-window "*RefTeX Select*") 1965 (switch-to-buffer-other-window "*RefTeX Select*")
1979 (insert help-string) 1966 (insert help-string)
1980 (goto-char 1) 1967 (goto-char 1)
1981 (unless (and (pos-visible-in-window-p (point-min)) 1968 (unless (and (pos-visible-in-window-p (point-min))
1982 (pos-visible-in-window-p (point-max))) 1969 (pos-visible-in-window-p (point-max)))
1983 (enlarge-window (1+ (- (count-lines (point-min) (point-max)) 1970 (enlarge-window (1+ (- (count-lines (point-min) (point-max))
1984 (reftex-window-height))))) 1971 (reftex-window-height)))))
1985 (setq truncate-lines t)) 1972 (setq truncate-lines t))
1986 (if (and (pos-visible-in-window-p (point-min)) 1973 (if (and (pos-visible-in-window-p (point-min))
1987 (pos-visible-in-window-p (point-max))) 1974 (pos-visible-in-window-p (point-max)))
1988 nil 1975 nil
1989 (setq prompt (concat prompt (if scroll " (SPC/DEL=Scroll)" "")))) 1976 (setq prompt (concat prompt (if scroll " (SPC/DEL=Scroll)" ""))))
1990 (message prompt) 1977 (message prompt)
1991 (and (equal char ?\?) (setq char (read-char-exclusive))) 1978 (and (equal char ?\?) (setq char (read-char-exclusive)))
1992 (while t 1979 (while t
1993 (cond ((equal char ?\C-g) (keyboard-quit)) 1980 (cond ((equal char ?\C-g) (keyboard-quit))
1994 ((equal char ?\?)) 1981 ((equal char ?\?))
1995 ((and scroll (equal char ?\ )) 1982 ((and scroll (equal char ?\ ))
1996 (condition-case nil (scroll-up) (error nil)) 1983 (condition-case nil (scroll-up) (error nil))
1997 (message prompt)) 1984 (message prompt))
1998 ((and scroll (equal char ?\C-? )) 1985 ((and scroll (equal char ?\C-? ))
1999 (condition-case nil (scroll-down) (error nil)) 1986 (condition-case nil (scroll-down) (error nil))
2000 (message prompt)) 1987 (message prompt))
2001 (t (message "") 1988 (t (message "")
2002 (throw 'exit char))) 1989 (throw 'exit char)))
2003 (setq char (read-char-exclusive))))))) 1990 (setq char (read-char-exclusive)))))))
2004 1991
2005 1992
2006(defun reftex-make-regexp-allow-for-ctrl-m (string) 1993(defun reftex-make-regexp-allow-for-ctrl-m (string)
2007 ;; convert STRING into a regexp, allowing ^M for \n and vice versa 1994 ;; convert STRING into a regexp, allowing ^M for \n and vice versa
@@ -2024,14 +2011,14 @@ Works on both Emacs and XEmacs."
2024;; Define `current-message' for compatibility with XEmacs prior to 20.4 2011;; Define `current-message' for compatibility with XEmacs prior to 20.4
2025(defvar message-stack) 2012(defvar message-stack)
2026(if (and (featurep 'xemacs) 2013(if (and (featurep 'xemacs)
2027 (not (fboundp 'current-message))) 2014 (not (fboundp 'current-message)))
2028 (defun current-message (&optional frame) 2015 (defun current-message (&optional frame)
2029 (cdr (car message-stack)))) 2016 (cdr (car message-stack))))
2030 2017
2031(defun reftex-visited-files (list) 2018(defun reftex-visited-files (list)
2032 ;; Takes a list of filenames and returns the buffers of those already visited 2019 ;; Takes a list of filenames and returns the buffers of those already visited
2033 (delq nil (mapcar (lambda (x) (if (reftex-get-buffer-visiting x) x nil)) 2020 (delq nil (mapcar (lambda (x) (if (reftex-get-buffer-visiting x) x nil))
2034 list))) 2021 list)))
2035 2022
2036(defun reftex-get-file-buffer-force (file &optional mark-to-kill) 2023(defun reftex-get-file-buffer-force (file &optional mark-to-kill)
2037 ;; Return a buffer visiting file. Make one, if necessary. 2024 ;; Return a buffer visiting file. Make one, if necessary.
@@ -2062,7 +2049,7 @@ Works on both Emacs and XEmacs."
2062 (let ((format-alist nil) 2049 (let ((format-alist nil)
2063 (auto-mode-alist (reftex-auto-mode-alist)) 2050 (auto-mode-alist (reftex-auto-mode-alist))
2064 (default-major-mode 'fundamental-mode) 2051 (default-major-mode 'fundamental-mode)
2065 (enable-local-variables nil) 2052 (enable-local-variables nil)
2066 (after-insert-file-functions nil)) 2053 (after-insert-file-functions nil))
2067 (setq buf (find-file-noselect file))) 2054 (setq buf (find-file-noselect file)))
2068 2055
@@ -2072,9 +2059,9 @@ Works on both Emacs and XEmacs."
2072 (set-buffer buf) 2059 (set-buffer buf)
2073 (run-hooks 'reftex-initialize-temporary-buffers)))) 2060 (run-hooks 'reftex-initialize-temporary-buffers))))
2074 2061
2075 ;; Lets see if we got a license to kill :-| 2062 ;; Lets see if we got a license to kill :-|
2076 (and mark-to-kill 2063 (and mark-to-kill
2077 (add-to-list 'reftex-buffers-to-kill buf)) 2064 (add-to-list 'reftex-buffers-to-kill buf))
2078 2065
2079 ;; Return the new buffer 2066 ;; Return the new buffer
2080 buf) 2067 buf)
@@ -2124,7 +2111,7 @@ Works on both Emacs and XEmacs."
2124 (let (rtn) 2111 (let (rtn)
2125 (while list 2112 (while list
2126 (unless (symbolp (car list)) 2113 (unless (symbolp (car list))
2127 (push (car list) rtn)) 2114 (push (car list) rtn))
2128 (setq list (cdr list))) 2115 (setq list (cdr list)))
2129 (nreverse rtn))) 2116 (nreverse rtn)))
2130 2117
@@ -2134,7 +2121,7 @@ Works on both Emacs and XEmacs."
2134 (while list 2121 (while list
2135 (setq elm (pop list)) 2122 (setq elm (pop list))
2136 (unless (member elm new) 2123 (unless (member elm new)
2137 (push elm new))) 2124 (push elm new)))
2138 (nreverse new))) 2125 (nreverse new)))
2139 2126
2140(defun reftex-uniquify-by-car (alist &optional keep-list) 2127(defun reftex-uniquify-by-car (alist &optional keep-list)
@@ -2150,11 +2137,11 @@ Works on both Emacs and XEmacs."
2150 2137
2151(defun reftex-abbreviate-title (string) 2138(defun reftex-abbreviate-title (string)
2152 (reftex-convert-string string "[-~ \t\n\r,;]" nil t t 2139 (reftex-convert-string string "[-~ \t\n\r,;]" nil t t
2153 5 40 nil 1 " " (nth 5 reftex-derive-label-parameters))) 2140 5 40 nil 1 " " (nth 5 reftex-derive-label-parameters)))
2154 2141
2155(defun reftex-convert-string (string split-re illegal-re dot keep-fp 2142(defun reftex-convert-string (string split-re illegal-re dot keep-fp
2156 nwords maxchar illegal abbrev sep 2143 nwords maxchar illegal abbrev sep
2157 ignore-words &optional downcase) 2144 ignore-words &optional downcase)
2158 "Convert a string (a sentence) to something shorter. 2145 "Convert a string (a sentence) to something shorter.
2159SPLIT-RE is the regular expression used to split the string into words. 2146SPLIT-RE is the regular expression used to split the string into words.
2160ILLEGAL-RE matches characters which are illegal in the final string. 2147ILLEGAL-RE matches characters which are illegal in the final string.
@@ -2172,14 +2159,14 @@ SEP String separating different words in the output string.
2172IGNORE-WORDS List of words which should be removed from the string." 2159IGNORE-WORDS List of words which should be removed from the string."
2173 2160
2174 (let* ((words0 (split-string string (or split-re "[ \t\n\r]"))) 2161 (let* ((words0 (split-string string (or split-re "[ \t\n\r]")))
2175 (reftex-label-illegal-re (or illegal-re "\000")) 2162 (reftex-label-illegal-re (or illegal-re "\000"))
2176 (abbrev-re (concat 2163 (abbrev-re (concat
2177 "\\`\\(" 2164 "\\`\\("
2178 (make-string (nth 0 reftex-abbrev-parameters) ?.) 2165 (make-string (nth 0 reftex-abbrev-parameters) ?.)
2179 "[" (nth 2 reftex-abbrev-parameters) "]*" 2166 "[" (nth 2 reftex-abbrev-parameters) "]*"
2180 "\\)" 2167 "\\)"
2181 "[" (nth 3 reftex-abbrev-parameters) "]" 2168 "[" (nth 3 reftex-abbrev-parameters) "]"
2182 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.))) 2169 (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.)))
2183 words word) 2170 words word)
2184 2171
2185 ;; Remove words from the ignore list or with funny characters 2172 ;; Remove words from the ignore list or with funny characters
@@ -2199,21 +2186,21 @@ IGNORE-WORDS List of words which should be removed from the string."
2199 ;; Restrict number of words 2186 ;; Restrict number of words
2200 (if (> (length words) nwords) 2187 (if (> (length words) nwords)
2201 (setcdr (nthcdr (1- nwords) words) nil)) 2188 (setcdr (nthcdr (1- nwords) words) nil))
2202 2189
2203 ;; First, try to use all words 2190 ;; First, try to use all words
2204 (setq string (mapconcat 'identity words sep)) 2191 (setq string (mapconcat 'identity words sep))
2205 2192
2206 ;; Abbreviate words if enforced by user settings or string length 2193 ;; Abbreviate words if enforced by user settings or string length
2207 (if (or (eq t abbrev) 2194 (if (or (eq t abbrev)
2208 (and abbrev 2195 (and abbrev
2209 (> (length string) maxchar))) 2196 (> (length string) maxchar)))
2210 (setq words 2197 (setq words
2211 (mapcar 2198 (mapcar
2212 (lambda (w) (if (string-match abbrev-re w) 2199 (lambda (w) (if (string-match abbrev-re w)
2213 (if dot 2200 (if dot
2214 (concat (match-string 1 w) ".") 2201 (concat (match-string 1 w) ".")
2215 (match-string 1 w)) 2202 (match-string 1 w))
2216 w)) 2203 w))
2217 words) 2204 words)
2218 string (mapconcat 'identity words sep))) 2205 string (mapconcat 'identity words sep)))
2219 2206
@@ -2263,47 +2250,47 @@ IGNORE-WORDS List of words which should be removed from the string."
2263 (and (reftex-use-fonts) 2250 (and (reftex-use-fonts)
2264 (or (eq t reftex-refontify-context) 2251 (or (eq t reftex-refontify-context)
2265 (and (eq 1 reftex-refontify-context) 2252 (and (eq 1 reftex-refontify-context)
2266 ;; Test of we use the font-lock version of x-symbol 2253 ;; Test of we use the font-lock version of x-symbol
2267 (and (featurep 'x-symbol-tex) (not (boundp 'x-symbol-mode))))))) 2254 (and (featurep 'x-symbol-tex) (not (boundp 'x-symbol-mode)))))))
2268 2255
2269(defvar font-lock-defaults-computed) 2256(defvar font-lock-defaults-computed)
2270(defun reftex-fontify-select-label-buffer (parent-buffer) 2257(defun reftex-fontify-select-label-buffer (parent-buffer)
2271 ;; Fontify the `*RefTeX Select*' buffer. Buffer is temporarily renamed to 2258 ;; Fontify the `*RefTeX Select*' buffer. Buffer is temporarily renamed to
2272 ;; start with none-SPC char, beacuse Font-Lock otherwise refuses operation. 2259 ;; start with none-SPC char, beacuse Font-Lock otherwise refuses operation.
2273 (run-hook-with-args 'reftex-pre-refontification-functions 2260 (run-hook-with-args 'reftex-pre-refontification-functions
2274 parent-buffer 'reftex-ref) 2261 parent-buffer 'reftex-ref)
2275 (let* ((oldname (buffer-name)) 2262 (let* ((oldname (buffer-name))
2276 (newname (concat "Fontify-me-" oldname))) 2263 (newname (concat "Fontify-me-" oldname)))
2277 (unwind-protect 2264 (unwind-protect
2278 (progn 2265 (progn
2279 ;; Rename buffer temporarily to start w/o space (because of font-lock) 2266 ;; Rename buffer temporarily to start w/o space (because of font-lock)
2280 (rename-buffer newname t) 2267 (rename-buffer newname t)
2281 (cond 2268 (cond
2282 ((fboundp 'font-lock-default-fontify-region) 2269 ((fboundp 'font-lock-default-fontify-region)
2283 ;; Good: we have the indirection functions 2270 ;; Good: we have the indirection functions
2284 (set (make-local-variable 'font-lock-fontify-region-function) 2271 (set (make-local-variable 'font-lock-fontify-region-function)
2285 'reftex-select-font-lock-fontify-region) 2272 'reftex-select-font-lock-fontify-region)
2286 (let ((major-mode 'latex-mode)) 2273 (let ((major-mode 'latex-mode))
2287 (font-lock-mode 1))) 2274 (font-lock-mode 1)))
2288 ((fboundp 'font-lock-set-defaults-1) 2275 ((fboundp 'font-lock-set-defaults-1)
2289 ;; Looks like the XEmacs font-lock stuff. 2276 ;; Looks like the XEmacs font-lock stuff.
2290 ;; FIXME: this is still kind of a hack, but it works. 2277 ;; FIXME: this is still kind of a hack, but it works.
2291 (set (make-local-variable 'font-lock-keywords) nil) 2278 (set (make-local-variable 'font-lock-keywords) nil)
2292 (let ((major-mode 'latex-mode) 2279 (let ((major-mode 'latex-mode)
2293 (font-lock-defaults-computed nil)) 2280 (font-lock-defaults-computed nil))
2294 (font-lock-set-defaults-1) 2281 (font-lock-set-defaults-1)
2295 (reftex-select-font-lock-fontify-region (point-min) (point-max)))) 2282 (reftex-select-font-lock-fontify-region (point-min) (point-max))))
2296 (t 2283 (t
2297 ;; Oops? 2284 ;; Oops?
2298 (message "Sorry: cannot refontify RefTeX Select buffer.")))) 2285 (message "Sorry: cannot refontify RefTeX Select buffer."))))
2299 (rename-buffer oldname)))) 2286 (rename-buffer oldname))))
2300 2287
2301(defun reftex-select-font-lock-fontify-region (beg end &optional loudly) 2288(defun reftex-select-font-lock-fontify-region (beg end &optional loudly)
2302 ;; Fontify a region, but only lines starting with a dot. 2289 ;; Fontify a region, but only lines starting with a dot.
2303 (let ((func (if (fboundp 'font-lock-default-fontify-region) 2290 (let ((func (if (fboundp 'font-lock-default-fontify-region)
2304 'font-lock-default-fontify-region 2291 'font-lock-default-fontify-region
2305 'font-lock-fontify-region)) 2292 'font-lock-fontify-region))
2306 beg1 end1) 2293 beg1 end1)
2307 (goto-char beg) 2294 (goto-char beg)
2308 (while (re-search-forward "^\\." end t) 2295 (while (re-search-forward "^\\." end t)
2309 (setq beg1 (point) end1 (progn (skip-chars-forward "^\n") (point))) 2296 (setq beg1 (point) end1 (progn (skip-chars-forward "^\n") (point)))
@@ -2322,9 +2309,9 @@ IGNORE-WORDS List of words which should be removed from the string."
2322 (let (face) 2309 (let (face)
2323 (catch 'exit 2310 (catch 'exit
2324 (while (setq face (pop faces)) 2311 (while (setq face (pop faces))
2325 (if (featurep 'xemacs) 2312 (if (featurep 'xemacs)
2326 (if (find-face face) (throw 'exit face)) 2313 (if (find-face face) (throw 'exit face))
2327 (if (facep face) (throw 'exit face))))))) 2314 (if (facep face) (throw 'exit face)))))))
2328 2315
2329;; Highlighting uses overlays. For XEmacs, we need the emulation. 2316;; Highlighting uses overlays. For XEmacs, we need the emulation.
2330(if (featurep 'xemacs) (require 'overlay)) 2317(if (featurep 'xemacs) (require 'overlay))
@@ -2334,14 +2321,14 @@ IGNORE-WORDS List of words which should be removed from the string."
2334 2321
2335;; Initialize the overlays 2322;; Initialize the overlays
2336(aset reftex-highlight-overlays 0 (make-overlay 1 1)) 2323(aset reftex-highlight-overlays 0 (make-overlay 1 1))
2337(overlay-put (aref reftex-highlight-overlays 0) 2324(overlay-put (aref reftex-highlight-overlays 0)
2338 'face 'highlight) 2325 'face 'highlight)
2339(aset reftex-highlight-overlays 1 (make-overlay 1 1)) 2326(aset reftex-highlight-overlays 1 (make-overlay 1 1))
2340(overlay-put (aref reftex-highlight-overlays 1) 2327(overlay-put (aref reftex-highlight-overlays 1)
2341 'face reftex-cursor-selected-face) 2328 'face reftex-cursor-selected-face)
2342(aset reftex-highlight-overlays 2 (make-overlay 1 1)) 2329(aset reftex-highlight-overlays 2 (make-overlay 1 1))
2343(overlay-put (aref reftex-highlight-overlays 2) 2330(overlay-put (aref reftex-highlight-overlays 2)
2344 'face reftex-cursor-selected-face) 2331 'face reftex-cursor-selected-face)
2345 2332
2346;; Two functions for activating and deactivation highlight overlays 2333;; Two functions for activating and deactivation highlight overlays
2347(defun reftex-highlight (index begin end &optional buffer) 2334(defun reftex-highlight (index begin end &optional buffer)
@@ -2359,30 +2346,30 @@ IGNORE-WORDS List of words which should be removed from the string."
2359 2346
2360;;; ========================================================================= 2347;;; =========================================================================
2361;;; 2348;;;
2362;;; Keybindings 2349;;; Keybindings
2363 2350
2364;; The default bindings in the mode map. 2351;; The default bindings in the mode map.
2365(loop for x in 2352(loop for x in
2366 '(("\C-c=" . reftex-toc) 2353 '(("\C-c=" . reftex-toc)
2367 ("\C-c-" . reftex-toc-recenter) 2354 ("\C-c-" . reftex-toc-recenter)
2368 ("\C-c(" . reftex-label) 2355 ("\C-c(" . reftex-label)
2369 ("\C-c)" . reftex-reference) 2356 ("\C-c)" . reftex-reference)
2370 ("\C-c[" . reftex-citation) 2357 ("\C-c[" . reftex-citation)
2371 ("\C-c<" . reftex-index) 2358 ("\C-c<" . reftex-index)
2372 ("\C-c>" . reftex-display-index) 2359 ("\C-c>" . reftex-display-index)
2373 ("\C-c/" . reftex-index-selection-or-word) 2360 ("\C-c/" . reftex-index-selection-or-word)
2374 ("\C-c\\" . reftex-index-phrase-selection-or-word) 2361 ("\C-c\\" . reftex-index-phrase-selection-or-word)
2375 ("\C-c|" . reftex-index-visit-phrases-buffer) 2362 ("\C-c|" . reftex-index-visit-phrases-buffer)
2376 ("\C-c&" . reftex-view-crossref)) 2363 ("\C-c&" . reftex-view-crossref))
2377 do (define-key reftex-mode-map (car x) (cdr x))) 2364 do (define-key reftex-mode-map (car x) (cdr x)))
2378 2365
2379;; Bind `reftex-mouse-view-crossref' only when the key is still free 2366;; Bind `reftex-mouse-view-crossref' only when the key is still free
2380(if (featurep 'xemacs) 2367(if (featurep 'xemacs)
2381 (unless (key-binding [(shift button2)]) 2368 (unless (key-binding [(shift button2)])
2382 (define-key reftex-mode-map [(shift button2)] 2369 (define-key reftex-mode-map [(shift button2)]
2383 'reftex-mouse-view-crossref)) 2370 'reftex-mouse-view-crossref))
2384 (unless (key-binding [(shift mouse-2)]) 2371 (unless (key-binding [(shift mouse-2)])
2385 (define-key reftex-mode-map [(shift mouse-2)] 2372 (define-key reftex-mode-map [(shift mouse-2)]
2386 'reftex-mouse-view-crossref))) 2373 'reftex-mouse-view-crossref)))
2387 2374
2388;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map 2375;; Bind `reftex-view-crossref-from-bibtex' in BibTeX mode map
@@ -2393,14 +2380,14 @@ IGNORE-WORDS List of words which should be removed from the string."
2393;; If the user requests so, she can have a few more bindings: 2380;; If the user requests so, she can have a few more bindings:
2394(when reftex-extra-bindings 2381(when reftex-extra-bindings
2395 (loop for x in 2382 (loop for x in
2396 '(("\C-ct" . reftex-toc) 2383 '(("\C-ct" . reftex-toc)
2397 ("\C-cl" . reftex-label) 2384 ("\C-cl" . reftex-label)
2398 ("\C-cr" . reftex-reference) 2385 ("\C-cr" . reftex-reference)
2399 ("\C-cc" . reftex-citation) 2386 ("\C-cc" . reftex-citation)
2400 ("\C-cv" . reftex-view-crossref) 2387 ("\C-cv" . reftex-view-crossref)
2401 ("\C-cg" . reftex-grep-document) 2388 ("\C-cg" . reftex-grep-document)
2402 ("\C-cs" . reftex-search-document)) 2389 ("\C-cs" . reftex-search-document))
2403 do (define-key reftex-mode-map (car x) (cdr x)))) 2390 do (define-key reftex-mode-map (car x) (cdr x))))
2404 2391
2405;;; ========================================================================= 2392;;; =========================================================================
2406;;; 2393;;;
@@ -2477,23 +2464,23 @@ IGNORE-WORDS List of words which should be removed from the string."
2477 :style toggle :selected reftex-plug-into-AUCTeX]) 2464 :style toggle :selected reftex-plug-into-AUCTeX])
2478 ("Reference Style" 2465 ("Reference Style"
2479 ["Default" (setq reftex-vref-is-default nil 2466 ["Default" (setq reftex-vref-is-default nil
2480 reftex-fref-is-default nil) 2467 reftex-fref-is-default nil)
2481 :style radio :selected (not (or reftex-vref-is-default 2468 :style radio :selected (not (or reftex-vref-is-default
2482 reftex-fref-is-default))] 2469 reftex-fref-is-default))]
2483 ["Varioref" (setq reftex-vref-is-default t 2470 ["Varioref" (setq reftex-vref-is-default t
2484 reftex-fref-is-default nil) 2471 reftex-fref-is-default nil)
2485 :style radio :selected reftex-vref-is-default] 2472 :style radio :selected reftex-vref-is-default]
2486 ["Fancyref" (setq reftex-fref-is-default t 2473 ["Fancyref" (setq reftex-fref-is-default t
2487 reftex-vref-is-default nil) 2474 reftex-vref-is-default nil)
2488 :style radio :selected reftex-fref-is-default]) 2475 :style radio :selected reftex-fref-is-default])
2489 ("Citation Style" 2476 ("Citation Style"
2490 ,@(mapcar 2477 ,@(mapcar
2491 (lambda (x) 2478 (lambda (x)
2492 (vector 2479 (vector
2493 (capitalize (symbol-name (car x))) 2480 (capitalize (symbol-name (car x)))
2494 (list 'reftex-set-cite-format (list 'quote (car x))) 2481 (list 'reftex-set-cite-format (list 'quote (car x)))
2495 :style 'radio :selected 2482 :style 'radio :selected
2496 (list 'eq (list 'reftex-get-cite-format) (list 'quote (car x))))) 2483 (list 'eq (list 'reftex-get-cite-format) (list 'quote (car x)))))
2497 reftex-cite-format-builtin) 2484 reftex-cite-format-builtin)
2498 "--" 2485 "--"
2499 "Sort Database Matches" 2486 "Sort Database Matches"
@@ -2508,13 +2495,13 @@ IGNORE-WORDS List of words which should be removed from the string."
2508 ("Index Style" 2495 ("Index Style"
2509 ,@(mapcar 2496 ,@(mapcar
2510 (lambda (x) 2497 (lambda (x)
2511 (vector 2498 (vector
2512 (capitalize (symbol-name (car x))) 2499 (capitalize (symbol-name (car x)))
2513 (list 'reftex-add-index-macros (list 'list (list 'quote (car x)))) 2500 (list 'reftex-add-index-macros (list 'list (list 'quote (car x))))
2514 :style 'radio :selected 2501 :style 'radio :selected
2515 (list 'memq (list 'quote (car x)) 2502 (list 'memq (list 'quote (car x))
2516 (list 'get 'reftex-docstruct-symbol 2503 (list 'get 'reftex-docstruct-symbol
2517 (list 'quote 'reftex-index-macros-style))))) 2504 (list 'quote 'reftex-index-macros-style)))))
2518 reftex-index-macros-builtin)) 2505 reftex-index-macros-builtin))
2519 "--" 2506 "--"
2520 ["Reset RefTeX Mode" reftex-reset-mode t] 2507 ["Reset RefTeX Mode" reftex-reset-mode t]
@@ -2522,7 +2509,7 @@ IGNORE-WORDS List of words which should be removed from the string."
2522 ("Customize" 2509 ("Customize"
2523 ["Browse RefTeX Group" reftex-customize t] 2510 ["Browse RefTeX Group" reftex-customize t]
2524 "--" 2511 "--"
2525 ["Build Full Customize Menu" reftex-create-customize-menu 2512 ["Build Full Customize Menu" reftex-create-customize-menu
2526 (fboundp 'customize-menu-create)]) 2513 (fboundp 'customize-menu-create)])
2527 ("Documentation" 2514 ("Documentation"
2528 ["Info" reftex-info t] 2515 ["Info" reftex-info t]
@@ -2538,17 +2525,17 @@ IGNORE-WORDS List of words which should be removed from the string."
2538 (interactive) 2525 (interactive)
2539 (if (fboundp 'customize-menu-create) 2526 (if (fboundp 'customize-menu-create)
2540 (progn 2527 (progn
2541 (easy-menu-change 2528 (easy-menu-change
2542 '("Ref") "Customize" 2529 '("Ref") "Customize"
2543 `(["Browse RefTeX group" reftex-customize t] 2530 `(["Browse RefTeX group" reftex-customize t]
2544 "--" 2531 "--"
2545 ,(customize-menu-create 'reftex) 2532 ,(customize-menu-create 'reftex)
2546 ["Set" Custom-set t] 2533 ["Set" Custom-set t]
2547 ["Save" Custom-save t] 2534 ["Save" Custom-save t]
2548 ["Reset to Current" Custom-reset-current t] 2535 ["Reset to Current" Custom-reset-current t]
2549 ["Reset to Saved" Custom-reset-saved t] 2536 ["Reset to Saved" Custom-reset-saved t]
2550 ["Reset to Standard Settings" Custom-reset-standard t])) 2537 ["Reset to Standard Settings" Custom-reset-standard t]))
2551 (message "\"Ref\"-menu now contains full customization menu")) 2538 (message "\"Ref\"-menu now contains full customization menu"))
2552 (error "Cannot expand menu (outdated version of cus-edit.el)"))) 2539 (error "Cannot expand menu (outdated version of cus-edit.el)")))
2553 2540
2554(defun reftex-show-commentary () 2541(defun reftex-show-commentary ()
@@ -2576,9 +2563,8 @@ With optional NODE, go directly to that node."
2576;;; That's it! ---------------------------------------------------------------- 2563;;; That's it! ----------------------------------------------------------------
2577 2564
2578(setq reftex-tables-dirty t) ; in case this file is evaluated by hand 2565(setq reftex-tables-dirty t) ; in case this file is evaluated by hand
2579(provide 'reftex) 2566(provide 'reftex)
2580 2567
2581;;;============================================================================ 2568;;;============================================================================
2582 2569
2583;;; arch-tag: 49e0da4e-bd5e-4cfc-a717-fb444fccb9e6
2584;;; reftex.el ends here 2570;;; reftex.el ends here
diff --git a/lisp/textmodes/sgml-mode.el b/lisp/textmodes/sgml-mode.el
index 6e7b2a9a51c..1028bb3122b 100644
--- a/lisp/textmodes/sgml-mode.el
+++ b/lisp/textmodes/sgml-mode.el
@@ -1954,5 +1954,4 @@ Can be used as a value for `html-mode-hook'."
1954 1954
1955(provide 'sgml-mode) 1955(provide 'sgml-mode)
1956 1956
1957;;; arch-tag: 9675da94-b7f9-4bda-ad19-73ed7b4fb401
1958;;; sgml-mode.el ends here 1957;;; sgml-mode.el ends here
diff --git a/lisp/textmodes/spell.el b/lisp/textmodes/spell.el
index c6289819c88..1923c867fb7 100644
--- a/lisp/textmodes/spell.el
+++ b/lisp/textmodes/spell.el
@@ -163,5 +163,4 @@ for example, \"word\"."
163 163
164(provide 'spell) 164(provide 'spell)
165 165
166;;; arch-tag: 7eabb848-9c76-431a-bcdb-0e0592d2db04
167;;; spell.el ends here 166;;; spell.el ends here
diff --git a/lisp/textmodes/table.el b/lisp/textmodes/table.el
index 44e82efc5b7..2edf604ecbf 100644
--- a/lisp/textmodes/table.el
+++ b/lisp/textmodes/table.el
@@ -5587,5 +5587,4 @@ It returns COLUMN unless STR contains some wide characters."
5587;; End: *** 5587;; End: ***
5588;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 5588;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
5589 5589
5590;;; arch-tag: 0d69b03e-aa5f-4e72-8806-5727217617e0
5591;;; table.el ends here 5590;;; table.el ends here
diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el
index cbf2f1cdef8..ca345f8b635 100644
--- a/lisp/textmodes/tex-mode.el
+++ b/lisp/textmodes/tex-mode.el
@@ -196,7 +196,7 @@ use."
196 :group 'tex-view) 196 :group 'tex-view)
197 197
198;;;###autoload 198;;;###autoload
199(defcustom tex-dvi-view-command '(if (eq window-system 'x) "xdvi" "dvi2tty * | cat -s") 199(defcustom tex-dvi-view-command '(if (eq window-system 'x) \"xdvi\" \"dvi2tty * | cat -s\")
200 "*Command used by \\[tex-view] to display a `.dvi' file. 200 "*Command used by \\[tex-view] to display a `.dvi' file.
201If it is a string, that specifies the command directly. 201If it is a string, that specifies the command directly.
202If this string contains an asterisk (`*'), that is replaced by the file name; 202If this string contains an asterisk (`*'), that is replaced by the file name;
@@ -2412,5 +2412,4 @@ There might be text before point."
2412 2412
2413(provide 'tex-mode) 2413(provide 'tex-mode)
2414 2414
2415;;; arch-tag: c0a680b1-63aa-4547-84b9-4193c29c0080
2416;;; tex-mode.el ends here 2415;;; tex-mode.el ends here
diff --git a/lisp/textmodes/texinfmt.el b/lisp/textmodes/texinfmt.el
index 3b135e1a081..59adecc2ed1 100644
--- a/lisp/textmodes/texinfmt.el
+++ b/lisp/textmodes/texinfmt.el
@@ -4334,5 +4334,4 @@ For example, invoke
4334;;; Place `provide' at end of file. 4334;;; Place `provide' at end of file.
4335(provide 'texinfmt) 4335(provide 'texinfmt)
4336 4336
4337;;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725
4338;;; texinfmt.el ends here 4337;;; texinfmt.el ends here
diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el
index 1bead17e10c..37da88410f9 100644
--- a/lisp/textmodes/texinfo.el
+++ b/lisp/textmodes/texinfo.el
@@ -1039,5 +1039,4 @@ You are prompted for the job number (use a number shown by a previous
1039 1039
1040(provide 'texinfo) 1040(provide 'texinfo)
1041 1041
1042;;; arch-tag: 005d7c38-43b9-4b7d-aa1d-aea69bae73e1
1043;;; texinfo.el ends here 1042;;; texinfo.el ends here
diff --git a/lisp/textmodes/texnfo-upd.el b/lisp/textmodes/texnfo-upd.el
index fb44acbff4f..43a6f0d0ac0 100644
--- a/lisp/textmodes/texnfo-upd.el
+++ b/lisp/textmodes/texnfo-upd.el
@@ -2039,5 +2039,4 @@ chapter."
2039;; Place `provide' at end of file. 2039;; Place `provide' at end of file.
2040(provide 'texnfo-upd) 2040(provide 'texnfo-upd)
2041 2041
2042;;; arch-tag: d21613a5-c32f-43f4-8af4-bfb1e7455842
2043;;; texnfo-upd.el ends here 2042;;; texnfo-upd.el ends here
diff --git a/lisp/textmodes/text-mode.el b/lisp/textmodes/text-mode.el
index 322ab098413..1d92b26b13e 100644
--- a/lisp/textmodes/text-mode.el
+++ b/lisp/textmodes/text-mode.el
@@ -178,5 +178,4 @@ The argument NLINES says how many lines to center."
178 (setq nlines (1+ nlines)) 178 (setq nlines (1+ nlines))
179 (forward-line -1))))) 179 (forward-line -1)))))
180 180
181;;; arch-tag: a07ccaad-da13-4d7b-9c61-cd04f5926aab
182;;; text-mode.el ends here 181;;; text-mode.el ends here
diff --git a/lisp/textmodes/tildify.el b/lisp/textmodes/tildify.el
index c8dcc4dba11..27452dc98d1 100644
--- a/lisp/textmodes/tildify.el
+++ b/lisp/textmodes/tildify.el
@@ -354,5 +354,4 @@ further questions)."
354;; coding: iso-latin-2 354;; coding: iso-latin-2
355;; End: 355;; End:
356 356
357;;; arch-tag: fc9b05a6-7355-4639-8170-dcf57853ba22
358;;; tildify.el ends here 357;;; tildify.el ends here
diff --git a/lisp/textmodes/two-column.el b/lisp/textmodes/two-column.el
index 71687f431c0..1e47a65a522 100644
--- a/lisp/textmodes/two-column.el
+++ b/lisp/textmodes/two-column.el
@@ -639,5 +639,4 @@ When autoscrolling is turned on, this also realigns the two buffers."
639 639
640(provide 'two-column) 640(provide 'two-column)
641 641
642;;; arch-tag: 2021b5ab-d3a4-4a8c-a21c-1936b0f9e6b1
643;;; two-column.el ends here 642;;; two-column.el ends here
diff --git a/lisp/textmodes/underline.el b/lisp/textmodes/underline.el
index 18f86eb55de..d6f08b5deea 100644
--- a/lisp/textmodes/underline.el
+++ b/lisp/textmodes/underline.el
@@ -62,5 +62,4 @@ which specify the range to operate on."
62 62
63(provide 'underline) 63(provide 'underline)
64 64
65;;; arch-tag: e7b48582-c3ea-4386-987a-87415f3c372a
66;;; underline.el ends here 65;;; underline.el ends here