annotate lisp/textmodes/reftex-index.el @ 44003:afbab80cfab0

*** empty log message ***
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 18 Mar 2002 14:56:35 +0000
parents 725125318c10
children 7522419c4db0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
1 ;;; reftex-index.el --- index support with RefTeX
27192
f70a80cecdd3 New version number.
Carsten Dominik <dominik@science.uva.nl>
parents: 27035
diff changeset
2 ;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
3
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
4 ;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl>
37998
706af946b1e7 * reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents: 34402
diff changeset
5 ;; Version: 4.16
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
6
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
7 ;; This file is part of GNU Emacs.
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
8
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
12 ;; any later version.
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
13
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
17 ;; GNU General Public License for more details.
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
18
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
19 ;; You should have received a copy of the GNU General Public License
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
22 ;; Boston, MA 02111-1307, USA.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
23
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
24 ;;; Commentary:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
25
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
26 ;;; Code:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
27
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
28 (eval-when-compile (require 'cl))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
29 (provide 'reftex-index)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
30 (require 'reftex)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
31 ;;;
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
32
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
33 (defvar mark-active)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
34 (defvar zmacs-regions)
25802
4c4fabd16782 Version number change
Carsten Dominik <dominik@science.uva.nl>
parents: 25280
diff changeset
35 (defvar transient-mark-mode)
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
36 (defun reftex-index-selection-or-word (&optional arg phrase)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
37 "Put selection or the word near point into the default index macro.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
38 This uses the information in `reftex-index-default-macro' to make an index
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
39 entry. The phrase indexed is the current selection or the word near point.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
40 When called with one `C-u' prefix, let the user have a chance to edit the
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
41 index entry. When called with 2 `C-u' as prefix, also ask for the index
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
42 macro and other stuff.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
43 When called inside TeX math mode as determined by the `texmathp.el' library
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
44 which is part of AUCTeX, the string is first processed with the
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
45 `reftex-index-math-format', which see."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
46 (interactive "P")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
47 (let* ((use-default (not (equal arg '(16)))) ; check for double prefix
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
48 ;; check if we have an active selection
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
49 (active (if (boundp 'zmacs-regions)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
50 (and zmacs-regions (region-exists-p)) ; XEmacs
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
51 (and transient-mark-mode mark-active))) ; Emacs
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
52 (beg (if active
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
53 (region-beginning)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
54 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
55 (skip-syntax-backward "w\\") (point))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
56 (end (if active
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
57 (region-end)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
58 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
59 (skip-syntax-forward "w\\") (point))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
60 (sel (buffer-substring beg end))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
61 (mathp (condition-case nil (texmathp) (error nil)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
62 (current-prefix-arg nil) ; we want to call reftex-index without prefix.
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
63 key def-char def-tag full-entry)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
64
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
65 (if phrase
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
66 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
67 (reftex-index-visit-phrases-buffer)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
68 (reftex-index-new-phrase sel))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
69
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
70 (if (equal sel "")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
71 ;; Nothing selected, no word, so use full reftex-index command
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
72 (reftex-index)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
73 ;; OK, we have something to index here.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
74 ;; Add the dollars when necessary
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
75 (setq key (if mathp
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
76 (format reftex-index-math-format sel)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
77 sel))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
78 ;; Get info from `reftex-index-default-macro'
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
79 (setq def-char (if use-default (car reftex-index-default-macro)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
80 (setq def-tag (if use-default (nth 1 reftex-index-default-macro)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
81 ;; Does the user want to edit the entry?
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
82 (setq full-entry (if arg
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
83 (reftex-index-complete-key
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
84 def-tag nil (cons key 0))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
85 key))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
86 ;; Delete what is in the buffer and make the index entry
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
87 (delete-region beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
88 (reftex-index def-char full-entry def-tag sel)))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
89
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
90 (defun reftex-index (&optional char key tag sel no-insert)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
91 "Query for an index macro and insert it along with its argments.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
92 The index macros available are those defined in `reftex-index-macro' or
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
93 by a call to `reftex-add-index-macros', typically from an AUCTeX style file.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
94 RefteX provides completion for the index tag and the index key, and
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
95 will prompt for other arguments."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
96
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
97 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
98
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
99 ;; Ensure access to scanning info
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
100 (reftex-ensure-index-support t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
101 (reftex-access-scan-info current-prefix-arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
102
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
103 ;; Find out which macro we are going to use
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
104 (let* ((char (or char
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
105 (reftex-select-with-char reftex-query-index-macro-prompt
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
106 reftex-query-index-macro-help)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
107 (macro (nth 1 (assoc char reftex-key-to-index-macro-alist)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
108 (entry (or (assoc macro reftex-index-macro-alist)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
109 (error "No index macro associated with %c" char)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
110 (ntag (nth 1 entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
111 (tag (or tag (nth 1 entry)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
112 (nargs (nth 4 entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
113 (nindex (nth 5 entry))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
114 (opt-args (nth 6 entry))
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
115 (repeat (nth 7 entry))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
116 opt tag1 value)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
117
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
118 ;; Get the supported arguments
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
119 (if (stringp tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
120 (setq tag1 tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
121 (setq tag1 (or (reftex-index-complete-tag tag opt-args) "")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
122 (setq key (or key
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
123 (reftex-index-complete-key
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
124 (if (string= tag1 "") "idx" tag1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
125 (member nindex opt-args))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
126
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
127 ;; Insert the macro and ask for any additional args
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
128 (insert macro)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
129 (loop for i from 1 to nargs do
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
130 (setq opt (member i opt-args)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
131 value (cond ((= nindex i) key)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
132 ((equal ntag i) tag1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
133 (t (read-string (concat "Macro arg nr. "
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
134 (int-to-string i)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
135 (if opt " (optional)" "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
136 ": ")))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
137 (unless (and opt (string= value ""))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
138 (insert (if opt "[" "{") value (if opt "]" "}"))))
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
139 (and repeat (stringp sel) (insert sel))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
140 (and key reftex-plug-into-AUCTeX (fboundp 'LaTeX-add-index-entries)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
141 (LaTeX-add-index-entries key))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
142 (reftex-index-update-taglist tag1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
143 (reftex-notice-new)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
144
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
145 (defun reftex-default-index ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
146 (cond ((null reftex-index-default-tag) nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
147 ((stringp reftex-index-default-tag) reftex-index-default-tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
148 (t (or (get reftex-docstruct-symbol 'default-index-tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
149 "idx"))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
150
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
151 (defun reftex-update-default-index (tag &optional tag-list)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
152 (if (and (not (equal tag ""))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
153 (stringp tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
154 (eq reftex-index-default-tag 'last)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
155 (or (null tag-list)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
156 (member tag tag-list)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
157 (put reftex-docstruct-symbol 'default-index-tag tag)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
158
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
159 (defun reftex-index-complete-tag (&optional itag opt-args)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
160 ;; Ask the user for a tag, completing on known tags.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
161 ;; ITAG is the argument number which contains the tag.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
162 ;; OPT-ARGS is a list of optional argument indices, as given by
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
163 ;; `reftex-parse-args'.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
164 (let* ((opt (and (integerp itag) (member itag opt-args)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
165 (index-tags (cdr (assq 'index-tags
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
166 (symbol-value reftex-docstruct-symbol))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
167 (default (reftex-default-index))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
168 (prompt (concat "Index tag"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
169 (if default (format " (default: %s)" default) "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
170 (if opt " (optional)" "") ": "))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
171 (tag (completing-read prompt (mapcar 'list index-tags))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
172 (if (and default (equal tag "")) (setq tag default))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
173 (reftex-update-default-index tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
174 tag))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
175
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
176 (defun reftex-index-select-tag ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
177 ;; Have the user select an index tag.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
178 ;; FIXME: should we cache tag-alist, prompt and help?
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
179 (let* ((index-tags (cdr (assoc 'index-tags
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
180 (symbol-value reftex-docstruct-symbol))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
181 (default (reftex-default-index)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
182 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
183 ((null index-tags)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
184 (error "No index tags available"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
185
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
186 ((= (length index-tags) 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
187 ;; Just one index, use it
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
188 (car index-tags))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
189
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
190 ((> (length index-tags) 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
191 ;; Several indices, ask.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
192 (let* ((tags (copy-sequence index-tags))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
193 (cnt 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
194 tag-alist i val len tag prompt help rpl)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
195 ;; Move idx and glo up in the list to ensure ?i and ?g shortcuts
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
196 (if (member "glo" tags)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
197 (setq tags (cons "glo" (delete "glo" tags))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
198 (if (member "idx" tags)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
199 (setq tags (cons "idx" (delete "idx" tags))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
200 ;; Find unique shortcuts for each index.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
201 (while (setq tag (pop tags))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
202 (setq len (length tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
203 i -1
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
204 val nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
205 (catch 'exit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
206 (while (and (< (incf i) len) (null val))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
207 (unless (assq (aref tag i) tag-alist)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
208 (push (list (aref tag i)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
209 tag
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
210 (concat (substring tag 0 i)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
211 "[" (substring tag i (incf i)) "]"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
212 (substring tag i)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
213 tag-alist)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
214 (throw 'exit t)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
215 (push (list (+ ?0 (incf cnt)) tag
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
216 (concat "[" (int-to-string cnt) "]:" tag))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
217 tag-alist)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
218 (setq tag-alist (nreverse tag-alist))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
219 ;; Compute Prompt and Help strings
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
220 (setq prompt
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
221 (concat
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
222 (format "Select Index%s: "
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
223 (if default (format " (Default <%s>)" default) ""))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
224 (mapconcat (lambda(x) (nth 2 x)) tag-alist " ")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
225 (setq help
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
226 (concat "Select an Index\n===============\n"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
227 (if default
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
228 (format "[^M] %s (the default)\n" default)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
229 "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
230 (mapconcat (lambda(x)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
231 (apply 'format "[%c] %s" x))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
232 tag-alist "\n")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
233 ;; Query the user for an index-tag
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
234 (setq rpl (reftex-select-with-char prompt help 3 t))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
235 (message "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
236 (if (and default (equal rpl ?\C-m))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
237 default
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
238 (if (assq rpl tag-alist)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
239 (progn
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
240 (reftex-update-default-index (nth 1 (assq rpl tag-alist)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
241 (nth 1 (assq rpl tag-alist)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
242 (error "No index tag associated with %c" rpl)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
243 (t (error "This should not happen (reftex-index-select-tag)")))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
244
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
245 (defun reftex-index-complete-key (&optional tag optional initial)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
246 ;; Read an index key, with completion.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
247 ;; Restrict completion table on index tag TAG.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
248 ;; OPTIONAL indicates if the arg is optional.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
249 (let* ((table (reftex-sublist-nth
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
250 (symbol-value reftex-docstruct-symbol) 6
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
251 (lambda(x) (and (eq (car x) 'index)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
252 (string= (nth 1 x) (or tag ""))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
253 t))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
254 (prompt (concat "Index key" (if optional " (optional)" "") ": "))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
255 (key (completing-read prompt table nil nil initial)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
256 key))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
257
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
258 (defun reftex-index-update-taglist (newtag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
259 ;; add NEWTAG to the list of available index tags.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
260 (let ((cell (assoc 'index-tags (symbol-value reftex-docstruct-symbol))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
261 (and newtag (cdr cell) (not (member newtag (cdr cell)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
262 (push newtag (cdr cell)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
263
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
264 (defvar reftex-index-map (make-sparse-keymap)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
265 "Keymap used for *Index* buffers.")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
266
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
267 (defvar reftex-index-menu)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
268
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
269 (defvar reftex-last-index-file nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
270 "Stores the file name from which `reftex-display-index' was called.")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
271 (defvar reftex-index-tag nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
272 "Stores the tag of the index in an index buffer.")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
273
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
274 (defvar reftex-index-return-marker (make-marker)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
275 "Marker which makes it possible to return from index to old position.")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
276
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
277 (defvar reftex-index-restriction-indicator nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
278 (defvar reftex-index-restriction-data nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
279
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
280 (defun reftex-index-mode ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
281 "Major mode for managing Index buffers for LaTeX files.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
282 This buffer was created with RefTeX.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
283 Press `?' for a summary of important key bindings, or check the menu.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
284
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
285 Here are all local bindings.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
286
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
287 \\{reftex-index-map}"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
288 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
289 (kill-all-local-variables)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
290 (setq major-mode 'reftex-index-mode
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
291 mode-name "RefTeX Index")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
292 (use-local-map reftex-index-map)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
293 (set (make-local-variable 'revert-buffer-function) 'reftex-index-revert)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
294 (set (make-local-variable 'reftex-index-restriction-data) nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
295 (set (make-local-variable 'reftex-index-restriction-indicator) nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
296 (setq mode-line-format
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
297 (list "---- " 'mode-line-buffer-identification
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
298 " " 'global-mode-string
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
299 " R<" 'reftex-index-restriction-indicator ">"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
300 " -%-"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
301 (setq truncate-lines t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
302 (make-local-variable 'reftex-last-follow-point)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
303 (easy-menu-add reftex-index-menu reftex-index-map)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
304 (add-hook 'post-command-hook 'reftex-index-post-command-hook nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
305 (add-hook 'pre-command-hook 'reftex-index-pre-command-hook nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
306 (run-hooks 'reftex-index-mode-hook))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
307
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
308 (defconst reftex-index-help
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
309 " AVAILABLE KEYS IN INDEX BUFFER
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
310 ==============================
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
311 ! A..Z Goto the section of entries starting with this letter.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
312 n / p next-entry / previous-entry
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
313 SPC / TAB Show/Goto the corresponding entry in the LaTeX document.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
314 RET Goto the entry and hide the *Index* window (also on mouse-2).
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
315 q / k Hide/Kill *Index* buffer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
316 C-c = Switch to the TOC buffer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
317 f / c Toggle follow mode / Toggle display of [c]ontext.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
318 g Refresh *Index* buffer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
319 r / C-u r Reparse the LaTeX document / Reparse entire LaTeX document.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
320 s Switch to a different index (for documents with multiple indices).
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
321 e / C-k Edit/Kill the entry.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
322 * | @ Edit specific part of entry: [*]key [|]attribute [@]visual
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
323 With prefix: kill that part.
41301
f13ec83c07b9 Doc fix.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38422
diff changeset
324 \( ) Toggle entry's beginning/end of page range property.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
325 _ ^ Add/Remove parent key (to make this item a subitem).
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
326 } / { Restrict Index to a single document section / Widen.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
327 < / > When restricted, move restriction to previous/next section.")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
328
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
329 (defun reftex-index-show-entry (data &optional no-revisit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
330 ;; Find an index entry associated with DATA and display it highlighted
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
331 ;; in another window. NO-REVISIT means we are not allowed to visit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
332 ;; files for this.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
333 ;; Note: This function just looks for the nearest match of the
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
334 ;; context string and may fail if the entry moved and an identical
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
335 ;; entry is close to the old position. Frequent rescans make this
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
336 ;; safer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
337 (let* ((file (nth 3 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
338 (literal (nth 2 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
339 (pos (nth 4 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
340 (re (regexp-quote literal))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
341 (match
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
342 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
343 ((or (not no-revisit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
344 (reftex-get-buffer-visiting file))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
345 (switch-to-buffer-other-window
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
346 (reftex-get-file-buffer-force file nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
347 (goto-char (or pos (point-min)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
348 (or (looking-at re)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
349 (reftex-nearest-match re (length literal))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
350 (t (message reftex-no-follow-message) nil))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
351 (when match
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
352 (goto-char (match-beginning 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
353 (recenter '(4))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
354 (reftex-highlight 0 (match-beginning 0) (match-end 0) (current-buffer)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
355 match))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
356
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
357 (defun reftex-display-index (&optional tag overriding-restriction
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
358 &rest locations)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
359 "Display a buffer with an index compiled from the current document.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
360 When the document has multiple indices, first prompts for the correct one.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
361 When index support is turned off, offer to turn it on.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
362 With one or two `C-u' prefixes, rescan document first.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
363 With prefix 2, restrict index to current document section.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
364 With prefix 3, restrict index to region."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
365
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
366 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
367
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
368 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4).
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
369 (let ((current-prefix-arg current-prefix-arg))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
370 (reftex-ensure-index-support t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
371 (reftex-access-scan-info current-prefix-arg))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
372
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
373 (set-marker reftex-index-return-marker (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
374 (setq reftex-last-follow-point 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
375
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
376 ;; Determine the correct index to process
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
377 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
378 (docstruct-symbol reftex-docstruct-symbol)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
379 (index-tag (or tag (reftex-index-select-tag)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
380 (master (reftex-TeX-master-file))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
381 (calling-file (buffer-file-name))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
382 (restriction
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
383 (or overriding-restriction
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
384 (and (interactive-p)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
385 (reftex-get-restriction current-prefix-arg docstruct))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
386 (locations
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
387 ;; See if we are on an index macro as initial position
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
388 (or locations
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
389 (let* ((what-macro (reftex-what-macro-safe 1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
390 (macro (car what-macro))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
391 (here-I-am (when (member macro reftex-macros-with-index)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
392 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
393 (goto-char (+ (cdr what-macro)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
394 (length macro)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
395 (reftex-move-over-touching-args)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
396 (reftex-where-am-I)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
397 (if (eq (car (car here-I-am)) 'index)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
398 (list (car here-I-am))))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
399 buffer-name)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
400
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
401 (setq buffer-name (reftex-make-index-buffer-name index-tag))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
402
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
403 ;; Goto the buffer and put it into the correct mode
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
404
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
405 (when (or restriction current-prefix-arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
406 (reftex-kill-buffer buffer-name))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
407
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
408 (if (get-buffer-window buffer-name)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
409 (select-window (get-buffer-window buffer-name))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
410 (let ((default-major-mode 'reftex-index-mode))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
411 (switch-to-buffer buffer-name)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
412
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
413 (or (eq major-mode 'reftex-index-mode) (reftex-index-mode))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
414
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
415 ;; If the buffer is currently restricted, empty it to force update.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
416 (when reftex-index-restriction-data
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
417 (reftex-erase-buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
418 (set (make-local-variable 'reftex-last-index-file) calling-file)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
419 (set (make-local-variable 'reftex-index-tag) index-tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
420 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
421 (if restriction
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
422 (setq reftex-index-restriction-indicator (car restriction)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
423 reftex-index-restriction-data (cdr restriction))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
424 (if (interactive-p)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
425 (setq reftex-index-restriction-indicator nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
426 reftex-index-restriction-data nil)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
427 (when (= (buffer-size) 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
428 ;; buffer is empty - fill it
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
429 (message "Building %s buffer..." buffer-name)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
430
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
431 (setq buffer-read-only nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
432 (insert (format
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
433 "INDEX <%s> on %s
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
434 Restriction: <%s>
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
435 SPC=view TAB=goto RET=goto+hide [e]dit [q]uit [r]escan [f]ollow [?]Help
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
436 ------------------------------------------------------------------------------
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
437 " index-tag (abbreviate-file-name master)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
438 (if (eq (car (car reftex-index-restriction-data)) 'toc)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
439 (nth 2 (car reftex-index-restriction-data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
440 reftex-index-restriction-indicator)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
441
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
442 (if (reftex-use-fonts)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
443 (put-text-property 1 (point) 'face reftex-index-header-face))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
444 (put-text-property 1 (point) 'intangible t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
445
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
446 (reftex-insert-index docstruct index-tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
447 (goto-char (point-min))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
448 (run-hooks 'reftex-display-copied-context-hook)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
449 (message "Building %s buffer...done." buffer-name)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
450 (setq buffer-read-only t))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
451 (and locations (apply 'reftex-find-start-point (point) locations))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
452 (if reftex-index-restriction-indicator
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
453 (message "Index restricted: <%s>" reftex-index-restriction-indicator))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
454
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
455 (defun reftex-insert-index (docstruct tag &optional update-one remark)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
456 ;; Insert an index into the current buffer. Entries are from the
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
457 ;; DOCSTRUCT.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
458 ;; TAG is the subindex to process.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
459 ;; UPDATE-ONE: When non-nil, delete the entry at point and replace
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
460 ;; it with whatever the DOCSTRUCT contains.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
461 ;; REMARK can be a note to add to the entry.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
462 (let* ((all docstruct)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
463 (indent " ")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
464 (context reftex-index-include-context)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
465 (context-indent (concat indent " "))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
466 (section-chars (mapcar 'identity reftex-index-section-letters))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
467 (this-section-char 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
468 (font (reftex-use-fonts))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
469 (bor (car reftex-index-restriction-data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
470 (eor (nth 1 reftex-index-restriction-data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
471 (mouse-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
472 (if (memq reftex-highlight-selection '(mouse both))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
473 reftex-mouse-selected-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
474 nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
475 (index-face (reftex-verified-face reftex-label-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
476 'font-lock-constant-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
477 'font-lock-reference-face))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
478 sublist cell from to first-char)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
479
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
480 ;; Make the sublist and sort it
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
481 (when bor
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
482 (setq all (or (memq bor all) all)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
483
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
484 (while (setq cell (pop all))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
485 (if (eq cell eor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
486 (setq all nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
487 (and (eq (car cell) 'index)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
488 (equal (nth 1 cell) tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
489 (push cell sublist))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
490 (setq sublist (sort (nreverse sublist)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
491 (lambda (a b) (string< (nth 8 a) (nth 8 b)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
492
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
493 (when update-one
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
494 ;; Delete the entry at place
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
495 (and (bolp) (forward-char 1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
496 (delete-region (previous-single-property-change (1+ (point)) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
497 (or (next-single-property-change (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
498 (point-max))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
499
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
500 ;; Walk through the list and insert all entries
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
501 (while (setq cell (pop sublist))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
502 (unless update-one
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
503 (setq first-char (upcase (string-to-char (nth 6 cell))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
504 (when (and (not (equal first-char this-section-char))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
505 (member first-char section-chars))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
506 ;; There is a new initial letter, so start a new section
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
507 (reftex-index-insert-new-letter first-char font)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
508 (setq section-chars (delete first-char section-chars)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
509 this-section-char first-char))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
510 (when (= this-section-char 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
511 (setq this-section-char ?!)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
512 (reftex-index-insert-new-letter this-section-char font)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
513
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
514 (setq from (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
515 (insert indent (nth 7 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
516 (when font
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
517 (setq to (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
518 (put-text-property
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
519 (- (point) (length (nth 7 cell))) to
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
520 'face index-face)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
521 (goto-char to))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
522
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
523 (when (or remark (nth 9 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
524 (and (< (current-column) 40)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
525 ;; FIXME: maybe this is too slow?
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
526 (insert (make-string (max (- 40 (current-column)) 0) ?\ )))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
527 (and (nth 9 cell) (insert " " (substring (nth 5 cell) (nth 9 cell))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
528 (and remark (insert " " remark)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
529
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
530 (insert "\n")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
531 (setq to (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
532
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
533 (when context
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
534 (insert context-indent (nth 2 cell) "\n")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
535 (setq to (point)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
536 (put-text-property from to :data cell)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
537 (when mouse-face
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
538 (put-text-property from (1- to)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
539 'mouse-face mouse-face))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
540 (goto-char to))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
541
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
542
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
543 (defun reftex-index-insert-new-letter (letter &optional font)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
544 ;; Start a new section in the index
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
545 (let ((from (point)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
546 (insert "\n" letter letter letter
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
547 "-----------------------------------------------------------------")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
548 (when font
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
549 (put-text-property from (point) 'face reftex-index-section-face))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
550 (insert "\n")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
551
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
552 (defun reftex-get-restriction (arg docstruct)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
553 ;; Interprete the prefix ARG and derive index restriction specs.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
554 (let* ((beg (min (point) (or (condition-case nil (mark) (error nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
555 (point-max))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
556 (end (max (point) (or (condition-case nil (mark) (error nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
557 (point-min))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
558 bor eor label here-I-am)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
559 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
560 ((eq arg 2)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
561 (setq here-I-am (car (reftex-where-am-I))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
562 bor (if (eq (car here-I-am) 'toc)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
563 here-I-am
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
564 (reftex-last-assoc-before-elt
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
565 'toc here-I-am docstruct))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
566 eor (car (memq (assq 'toc (cdr (memq bor docstruct))) docstruct))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
567 label (nth 6 bor)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
568 ((eq arg 3)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
569 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
570 (setq label "region")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
571 (goto-char beg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
572 (setq bor (car (reftex-where-am-I)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
573 (setq bor (nth 1 (memq bor docstruct)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
574 (goto-char end)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
575 (setq eor (nth 1 (memq (car (reftex-where-am-I)) docstruct)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
576 (t nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
577 (if (and label (or bor eor))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
578 (list label bor eor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
579 nil)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
580
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
581 (defun reftex-index-pre-command-hook ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
582 ;; Used as pre command hook in *Index* buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
583 (reftex-unhighlight 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
584 (reftex-unhighlight 1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
585
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
586 (defun reftex-index-post-command-hook ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
587 ;; Used in the post-command-hook for the *Index* buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
588 (when (get-text-property (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
589 (and (> (point) 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
590 (not (get-text-property (point) 'intangible))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
591 (memq reftex-highlight-selection '(cursor both))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
592 (reftex-highlight 1
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
593 (or (previous-single-property-change (1+ (point)) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
594 (point-min))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
595 (or (next-single-property-change (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
596 (point-max)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
597 (if (integerp reftex-index-follow-mode)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
598 ;; Remove delayed action
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
599 (setq reftex-index-follow-mode t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
600 (and reftex-index-follow-mode
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
601 (not (equal reftex-last-follow-point (point)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
602 ;; Show context in other window
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
603 (setq reftex-last-follow-point (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
604 (condition-case nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
605 (reftex-index-visit-location nil (not reftex-revisit-to-follow))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
606 (error t)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
607
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
608 (defun reftex-index-show-help ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
609 "Show a summary of special key bindings."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
610 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
611 (with-output-to-temp-buffer "*RefTeX Help*"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
612 (princ reftex-index-help))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
613 (reftex-enlarge-to-fit "*RefTeX Help*" t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
614 ;; If follow mode is active, arrange to delay it one command
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
615 (if reftex-index-follow-mode
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
616 (setq reftex-index-follow-mode 1)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
617
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
618 (defun reftex-index-next (&optional arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
619 "Move to next selectable item."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
620 (interactive "p")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
621 (setq reftex-callback-fwd t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
622 (or (eobp) (forward-char 1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
623 (goto-char (or (next-single-property-change (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
624 (point)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
625 (unless (get-text-property (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
626 (goto-char (or (next-single-property-change (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
627 (point)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
628 (defun reftex-index-previous (&optional arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
629 "Move to previous selectable item."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
630 (interactive "p")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
631 (setq reftex-callback-fwd nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
632 (goto-char (or (previous-single-property-change (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
633 (point)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
634 (unless (get-text-property (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
635 (goto-char (or (previous-single-property-change (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
636 (point)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
637 (defun reftex-index-toggle-follow ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
638 "Toggle follow (other window follows with context)."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
639 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
640 (setq reftex-last-follow-point -1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
641 (setq reftex-index-follow-mode (not reftex-index-follow-mode)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
642 (defun reftex-index-toggle-context ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
643 "Toggle inclusion of label context in *Index* buffer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
644 Label context is only displayed when the labels are there as well."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
645 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
646 (setq reftex-index-include-context (not reftex-index-include-context))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
647 (reftex-index-revert))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
648 (defun reftex-index-view-entry ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
649 "View document location in other window."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
650 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
651 (reftex-index-visit-location))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
652 (defun reftex-index-goto-entry-and-hide ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
653 "Go to document location in other window. Hide the *Index* window."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
654 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
655 (reftex-index-visit-location 'hide))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
656 (defun reftex-index-goto-entry ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
657 "Go to document location in other window. *Index* window stays."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
658 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
659 (reftex-index-visit-location t))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
660 (defun reftex-index-mouse-goto-line-and-hide (ev)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
661 "Go to document location in other window. Hide the *Index* window."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
662 (interactive "e")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
663 (mouse-set-point ev)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
664 (reftex-index-visit-location 'hide))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
665 (defun reftex-index-quit ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
666 "Hide the *Index* window and do not move point."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
667 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
668 (or (one-window-p) (delete-window))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
669 (switch-to-buffer (marker-buffer reftex-index-return-marker))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
670 (goto-char (or (marker-position reftex-index-return-marker) (point))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
671 (defun reftex-index-quit-and-kill ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
672 "Kill the *Index* buffer."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
673 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
674 (kill-buffer (current-buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
675 (or (one-window-p) (delete-window))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
676 (switch-to-buffer (marker-buffer reftex-index-return-marker))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
677 (goto-char (or (marker-position reftex-index-return-marker) (point))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
678 (defun reftex-index-goto-toc (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
679 "Switch to the table of contents of the current document.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
680 The function will go to the section where the entry at point was defined."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
681 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
682 (if (get-text-property (point) :data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
683 (reftex-index-goto-entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
684 (switch-to-buffer (marker-buffer reftex-index-return-marker)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
685 (delete-other-windows)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
686 (reftex-toc))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
687 (defun reftex-index-rescan (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
688 "Regenerate the *Index* buffer after reparsing file of section at point."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
689 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
690 (let ((index-tag reftex-index-tag))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
691 (if (and reftex-enable-partial-scans
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
692 (null current-prefix-arg))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
693 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
694 (file (nth 3 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
695 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
696 (if (not file)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
697 (error "Don't know which file to rescan. Try `C-u r'")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
698 (switch-to-buffer (reftex-get-file-buffer-force file))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
699 (setq current-prefix-arg '(4))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
700 (reftex-display-index index-tag nil line)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
701 (reftex-index-Rescan))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
702 (reftex-kill-temporary-buffers)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
703 (defun reftex-index-Rescan (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
704 "Regenerate the *Index* buffer after reparsing the entire document."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
705 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
706 (let ((index-tag reftex-index-tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
707 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
708 (switch-to-buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
709 (reftex-get-file-buffer-force reftex-last-index-file))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
710 (setq current-prefix-arg '(16))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
711 (reftex-display-index index-tag nil line)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
712 (defun reftex-index-revert (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
713 "Regenerate the *Index* from the internal lists. No reparsing os done."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
714 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
715 (let ((buf (current-buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
716 (index-tag reftex-index-tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
717 (data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
718 (line (+ (count-lines (point-min) (point)) (if (bolp) 1 0))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
719 (switch-to-buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
720 (reftex-get-file-buffer-force reftex-last-index-file))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
721 (reftex-erase-buffer buf)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
722 (setq current-prefix-arg nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
723 reftex-last-follow-point 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
724 (reftex-display-index index-tag nil data line)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
725 (defun reftex-index-switch-index-tag (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
726 "Switch to a different index of the same document."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
727 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
728 (switch-to-buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
729 (reftex-get-file-buffer-force reftex-last-index-file))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
730 (setq current-prefix-arg nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
731 (reftex-display-index))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
732
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
733 (defun reftex-index-restrict-to-section (&optional force)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
734 "Restrict index to entries defined in same document sect. as entry at point."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
735 ;; Optional FORCE means, even if point is not on an index entry.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
736 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
737 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
738 (docstruct (symbol-value reftex-docstruct-symbol))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
739 bor eor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
740 (if (and (not data) force)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
741 (setq data (assq 'toc docstruct)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
742 (when data
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
743 (setq bor (reftex-last-assoc-before-elt 'toc data docstruct)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
744 eor (car (memq (assq 'toc (cdr (memq bor docstruct)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
745 docstruct))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
746 reftex-index-restriction-data (list bor eor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
747 reftex-index-restriction-indicator (nth 6 bor) )))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
748 (reftex-index-revert))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
749
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
750 (defun reftex-index-widen (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
751 "Show the unrestricted index (all entries)."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
752 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
753 (setq reftex-index-restriction-indicator nil
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
754 reftex-index-restriction-data nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
755 (reftex-index-revert)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
756 (message "Index widened"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
757 (defun reftex-index-restriction-forward (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
758 "Restrict to previous section.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
759 When index is currently unrestricted, restrict it to a section.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
760 When index is restricted, select the next section as restriction criterion."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
761 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
762 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
763 (bor (nth 1 reftex-index-restriction-data)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
764 (if (or (not bor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
765 (not (eq (car bor) 'toc)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
766 (reftex-index-restrict-to-section t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
767 (setq reftex-index-restriction-indicator (nth 6 bor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
768 reftex-index-restriction-data
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
769 (list bor
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
770 (car (memq (assq 'toc (cdr (memq bor docstruct)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
771 docstruct))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
772 (reftex-index-revert))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
773 (defun reftex-index-restriction-backward (&rest ignore)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
774 "Restrict to next section.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
775 When index is currently unrestricted, restrict it to a section.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
776 When index is restricted, select the previous section as restriction criterion."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
777 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
778 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
779 (eor (car reftex-index-restriction-data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
780 (bor (reftex-last-assoc-before-elt 'toc eor docstruct t)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
781 (if (or (not bor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
782 (not (eq (car bor) 'toc)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
783 (reftex-index-restrict-to-section t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
784 (setq reftex-index-restriction-indicator (nth 6 bor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
785 reftex-index-restriction-data
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
786 (list bor eor))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
787 (reftex-index-revert))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
788
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
789 (defun reftex-index-visit-location (&optional final no-revisit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
790 ;; Visit the tex file corresponding to the index entry on the current line.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
791 ;; If FINAL is t, stay there
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
792 ;; If FINAL is 'hide, hide the *Index* window.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
793 ;; Otherwise, move cursor back into *Index* window.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
794 ;; NO-REVISIT means don't visit files, just use live biffers.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
795
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
796 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
797 (index-window (selected-window))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
798 show-window show-buffer match)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
799
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
800 (unless data (error "Don't know which index entry to visit"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
801
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
802 (if (eq (car data) 'index)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
803 (setq match (reftex-index-show-entry data no-revisit)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
804
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
805 (setq show-window (selected-window)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
806 show-buffer (current-buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
807
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
808 (unless match
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
809 (select-window index-window)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
810 (error "Cannot find location"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
811
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
812 (select-window index-window)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
813
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
814 ;; Use the `final' parameter to decide what to do next
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
815 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
816 ((eq final t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
817 (reftex-unhighlight 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
818 (select-window show-window))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
819 ((eq final 'hide)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
820 (reftex-unhighlight 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
821 (or (one-window-p) (delete-window))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
822 (switch-to-buffer show-buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
823 (t nil))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
824
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
825 (defun reftex-index-analyze-entry (data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
826 ;; This splits the index context so that key, attribute and visual
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
827 ;; values are accessible individually.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
828 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
829 (let* ((arg (nth 5 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
830 (context (nth 2 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
831 (sc reftex-index-special-chars)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
832 (boa (if (string-match (regexp-quote (concat "{" arg "}")) context)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
833 (1+ (match-beginning 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
834 (error "Something is wrong here")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
835 (eoa (1- (match-end 0)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
836 (boactual (if (string-match (concat "[^" (nth 3 sc) "]" (nth 2 sc))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
837 context boa)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
838 (1+ (match-beginning 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
839 eoa))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
840 (boattr (if (string-match (concat "[^" (nth 3 sc) "]" (nth 1 sc))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
841 context boa)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
842 (1+ (match-beginning 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
843 boactual))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
844 (pre (substring context 0 boa))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
845 (key (substring context boa boattr))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
846 (attr (substring context boattr boactual))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
847 (actual (substring context boactual eoa))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
848 (post (substring context eoa)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
849 (list pre key attr actual post)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
850
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
851 (defun reftex-index-edit ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
852 "Edit the index entry at point."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
853 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
854 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
855 old new)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
856 (unless data (error "Don't know which index entry to edit"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
857 (reftex-index-view-entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
858 (setq old (nth 2 data) new (read-string "Edit: " old))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
859 (reftex-index-change-entry new)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
860
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
861 (defun reftex-index-toggle-range-beginning ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
862 "Toggle the page range start attribute `|('."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
863 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
864 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
865 (bor (concat (nth 1 reftex-index-special-chars) "("))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
866 new analyze attr)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
867 (unless data (error "Don't know which index entry to edit"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
868 (setq analyze (reftex-index-analyze-entry data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
869 attr (nth 2 analyze))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
870 (setf (nth 2 analyze) (if (string= attr bor) "" bor))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
871 (setq new (apply 'concat analyze))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
872 (reftex-index-change-entry
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
873 new (if (string= (nth 2 analyze) bor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
874 "Entry is now START-OF-PAGE-RANGE"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
875 "START-OF-PAGE-RANGE canceled"))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
876
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
877 (defun reftex-index-toggle-range-end ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
878 "Toggle the page-range-end attribute `|)'."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
879 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
880 (let* ((data (get-text-property (point) :data))
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
881 (eor (concat (nth 1 reftex-index-special-chars) ")"))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
882 new analyze attr)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
883 (unless data (error "Don't know which index entry to edit"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
884 (setq analyze (reftex-index-analyze-entry data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
885 attr (nth 2 analyze))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
886 (setf (nth 2 analyze) (if (string= attr eor) "" eor))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
887 (setq new (apply 'concat analyze))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
888 (reftex-index-change-entry
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
889 new (if (string= (nth 2 analyze) eor)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
890 "Entry is now END-OF-PAGE-RANGE"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
891 "END-OF-PAGE-RANGE canceled"))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
892
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
893 (defun reftex-index-edit-key ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
894 "Edit the KEY part of the index entry."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
895 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
896 (reftex-index-edit-part nil 1 "" "Key: " t))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
897
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
898 (defun reftex-index-edit-attribute (&optional arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
899 "EDIT the ATTRIBUTE part of the entry. With arg: remove entire ATTRIBUTE."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
900 (interactive "P")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
901 (reftex-index-edit-part arg 2 (nth 1 reftex-index-special-chars)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
902 "Attribute: "))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
903
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
904 (defun reftex-index-edit-visual (&optional arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
905 "EDIT the VISUAL part of the entry. With arg: remove entire VISUAL string."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
906 (interactive "P")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
907 (reftex-index-edit-part arg 3 (nth 2 reftex-index-special-chars) "Visual: "))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
908
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
909 (defun reftex-index-edit-part (arg n initial prompt &optional dont-allow-empty)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
910 ;; This function does the work for all partial editing commands
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
911 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
912 new analyze opart npart)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
913 (unless data (error "Don't know which index entry to edit"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
914 ;; Analyze the whole context string
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
915 (setq analyze (reftex-index-analyze-entry data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
916 opart (nth n analyze))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
917 (and (> (length opart) 0) (setq opart (substring opart 1)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
918 ;; Have the user editing the part
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
919 (setq npart (if arg "" (read-string (concat prompt initial) opart)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
920 ;; Tests:
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
921 (cond ((string= npart opart)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
922 (error "Not changed"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
923 ((string= npart "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
924 (if dont-allow-empty
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
925 (error "Illegal value")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
926 (setf (nth n analyze) npart)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
927 (t (setf (nth n analyze) (concat initial npart))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
928 (setq new (apply 'concat analyze))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
929 ;; Change the entry and insert the changed version into the index.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
930 (reftex-index-change-entry
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
931 new (if (string= npart "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
932 (format "Deleted: %s" opart)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
933 (format "New value is: %s" npart)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
934
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
935 (defun reftex-index-level-down ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
936 "Make index entry a subitem of another entry."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
937 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
938 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
939 (docstruct (symbol-value reftex-docstruct-symbol))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
940 old new prefix key)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
941 (unless data (error "Don't know which index entry to change"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
942 (setq old (nth 2 data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
943 key (nth 6 data)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
944 prefix (completing-read
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
945 "Prefix: "
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
946 (reftex-sublist-nth
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
947 docstruct 6
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
948 (lambda (x)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
949 (and (eq (car x) 'index)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
950 (string= (nth 1 x) reftex-index-tag))) t)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
951 (unless (string-match
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
952 (concat (regexp-quote (car reftex-index-special-chars)) "\\'")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
953 prefix)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
954 (setq prefix (concat prefix (car reftex-index-special-chars))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
955 (if (string-match (regexp-quote key) old)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
956 (setq new (replace-match (concat prefix key) t t old))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
957 (error "Cannot construct new index key"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
958 (reftex-index-change-entry new (format "Added prefix: %s" prefix))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
959
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
960 (defun reftex-index-level-up ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
961 "Remove the highest level of a hierarchical index entry."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
962 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
963 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
964 old new prefix)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
965 (unless data (error "Don't know which entry to change"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
966 (setq old (nth 2 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
967 (if (string-match (concat "{\\([^" (nth 0 reftex-index-special-chars) "]*"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
968 "[^" (nth 3 reftex-index-special-chars) "]"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
969 (regexp-quote (nth 0 reftex-index-special-chars))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
970 "\\)")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
971 old)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
972 (setq prefix (substring old (match-beginning 1) (match-end 1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
973 new (concat (substring old 0 (match-beginning 1))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
974 (substring old (match-end 1))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
975 (error "Entry is not a subitem"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
976 (reftex-index-change-entry new (format "Removed prefix: %s" prefix))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
977
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
978 (defun reftex-index-kill ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
979 "FIXME: Not yet implemented"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
980 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
981 (error "This function is currently not implemented"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
982
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
983 (defun reftex-index-undo ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
984 "FIXME: Not yet implemented"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
985 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
986 (error "This function is currently not implemented"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
987
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
988 (defun reftex-index-change-entry (new &optional message)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
989 ;; Change the full context string of the index entry at point to
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
990 ;; NEW. This actually edits the buffer where the entry is defined.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
991
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
992 (let* ((data (get-text-property (point) :data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
993 old beg end info)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
994 (unless data (error "Cannot change entry"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
995 (reftex-index-view-entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
996 (setq beg (match-beginning 0) end (match-end 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
997 (setq old (nth 2 data))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
998 (and (equal old new) (error "Entry unchanged"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
999 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1000 (set-buffer (get-file-buffer (nth 3 data)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1001 (goto-char beg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1002 (unless (looking-at (regexp-quote old))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1003 (error "This should not happen (reftex-index-change-entry)"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1004 (delete-region beg end)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1005 (insert new)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1006 (goto-char (1- beg))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1007 (when (and (re-search-forward (reftex-everything-regexp) nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1008 (match-end 10)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1009 (< (abs (- (match-beginning 10) beg)) (length new))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1010 (setq info (reftex-index-info-safe buffer-file-name)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1011 (setcdr data (cdr info))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1012 (let ((buffer-read-only nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1013 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1014 (reftex-insert-index (list data) reftex-index-tag t
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1015 "EDITED")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1016 (setq reftex-last-follow-point 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1017 (and message (message message))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1018
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1019 ;; Index map
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1020 (define-key reftex-index-map (if (featurep 'xemacs) [(button2)] [(mouse-2)])
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1021 'reftex-index-mouse-goto-line-and-hide)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1022
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1023 (substitute-key-definition
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1024 'next-line 'reftex-index-next reftex-index-map global-map)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1025 (substitute-key-definition
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1026 'previous-line 'reftex-index-previous reftex-index-map global-map)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1027
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1028 (loop for x in
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1029 '(("n" . reftex-index-next)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1030 ("p" . reftex-index-previous)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1031 ("?" . reftex-index-show-help)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1032 (" " . reftex-index-view-entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1033 ("\C-m" . reftex-index-goto-entry-and-hide)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1034 ("\C-i" . reftex-index-goto-entry)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1035 ("\C-k" . reftex-index-kill)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1036 ("r" . reftex-index-rescan)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1037 ("R" . reftex-index-Rescan)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1038 ("g" . revert-buffer)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1039 ("q" . reftex-index-quit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1040 ("k" . reftex-index-quit-and-kill)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1041 ("f" . reftex-index-toggle-follow)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1042 ("s" . reftex-index-switch-index-tag)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1043 ("e" . reftex-index-edit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1044 ("^" . reftex-index-level-up)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1045 ("_" . reftex-index-level-down)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1046 ("}" . reftex-index-restrict-to-section)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1047 ("{" . reftex-index-widen)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1048 (">" . reftex-index-restriction-forward)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1049 ("<" . reftex-index-restriction-backward)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1050 ("(" . reftex-index-toggle-range-beginning)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1051 (")" . reftex-index-toggle-range-end)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1052 ("|" . reftex-index-edit-attribute)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1053 ("@" . reftex-index-edit-visual)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1054 ("*" . reftex-index-edit-key)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1055 ("\C-c=". reftex-index-goto-toc)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1056 ("c" . reftex-index-toggle-context))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1057 do (define-key reftex-index-map (car x) (cdr x)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1058
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1059 (loop for key across "0123456789" do
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1060 (define-key reftex-index-map (vector (list key)) 'digit-argument))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1061 (define-key reftex-index-map "-" 'negative-argument)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1062
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1063 ;; The capital letters and the exclamation mark
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1064 (loop for key across (concat "!" reftex-index-section-letters) do
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1065 (define-key reftex-index-map (vector (list key))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1066 (list 'lambda '() '(interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1067 (list 'reftex-index-goto-letter key))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1068
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1069 (defun reftex-index-goto-letter (char)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1070 "Go to the CHAR section in the index."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1071 (let ((pos (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1072 (case-fold-search nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1073 (goto-line 3)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1074 (if (re-search-forward (concat "^" (char-to-string char)) nil t)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1075 (progn
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1076 (beginning-of-line)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1077 (recenter 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1078 (reftex-index-next))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1079 (goto-char pos)
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1080 (if (eq char ?!)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1081 (error "This <%s> index does not contain entries sorted before the letters"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1082 reftex-index-tag)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1083 (error "This <%s> index does not contain entries starting with `%c'"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1084 reftex-index-tag char)))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1085
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1086 (easy-menu-define
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1087 reftex-index-menu reftex-index-map
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1088 "Menu for Index buffer"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1089 `("Index"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1090 ["Goto section A-Z"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1091 (message "To go to a section, just press any of: !%s"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1092 reftex-index-section-letters) t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1093 ["Show Entry" reftex-index-view-entry t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1094 ["Go To Entry" reftex-index-goto-entry t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1095 ["Exit & Go To Entry" reftex-index-goto-entry-and-hide t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1096 ["Table of Contents" reftex-index-goto-toc t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1097 ["Quit" reftex-index-quit t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1098 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1099 ("Update"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1100 ["Rebuilt *Index* Buffer" revert-buffer t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1101 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1102 ["Rescan One File" reftex-index-rescan reftex-enable-partial-scans]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1103 ["Rescan Entire Document" reftex-index-Rescan t])
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1104 ("Restrict"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1105 ["Restrict to section" reftex-index-restrict-to-section t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1106 ["Widen" reftex-index-widen reftex-index-restriction-indicator]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1107 ["Next Section" reftex-index-restriction-forward
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1108 reftex-index-restriction-indicator]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1109 ["Previous Section" reftex-index-restriction-backward
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1110 reftex-index-restriction-indicator])
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1111 ("Edit"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1112 ["Edit Entry" reftex-index-edit t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1113 ["Edit Key" reftex-index-edit-key t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1114 ["Edit Attribute" reftex-index-edit-attribute t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1115 ["Edit Visual" reftex-index-edit-visual t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1116 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1117 ["Add Parentkey" reftex-index-level-down t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1118 ["Remove Parentkey " reftex-index-level-up t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1119 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1120 ["Make Start-of-Range" reftex-index-toggle-range-beginning t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1121 ["Make End-of-Range" reftex-index-toggle-range-end t]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1122 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1123 ["Kill Entry" reftex-index-kill nil]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1124 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1125 ["Undo" reftex-index-undo nil])
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1126 ("Options"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1127 ["Context" reftex-index-toggle-context :style toggle
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1128 :selected reftex-index-include-context]
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1129 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1130 ["Follow Mode" reftex-index-toggle-follow :style toggle
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1131 :selected reftex-index-follow-mode])
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1132 "--"
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1133 ["Help" reftex-index-show-help t]))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
1134
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1135
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1136 ;;----------------------------------------------------------------------
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1137 ;; The Index Phrases File
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1138
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1139 ;; Some constants and variables
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1140 (defconst reftex-index-phrases-comment-regexp "^[ \t]*%.*"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1141 "Regular expression to match comment lines in phrases buffer")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1142 (defconst reftex-index-phrases-macrodef-regexp
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1143 "^\\(>>>INDEX_MACRO_DEFINITION:\\)[ \t]+\\(\\S-\\)\\( *\t[ \t]*\\)\\([^\t]*[^ \t]\\)\\( *\t[ \t]*\\)\\(\\S-+\\)"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1144 "Regular expression to match macro definition lines the phrases buffer.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1145 ;(defconst reftex-index-phrases-macrodef-regexp
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1146 ; "^\\(>>>INDEX_MACRO_DEFINITION:\\)[ \t]+\\(\\S-\\)\\([ \t]*\\)\\([^\t]*[^ \t]\\)\\([ \t]*\\)\\(nil\\|t\\)[ \t]*$"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1147 ; "Regular expression to match macro definition lines the phrases buffer.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1148 ;This version would allow just spaces as separators.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1149 (defconst reftex-index-phrases-phrase-regexp1
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1150 "^\\(\\S-?\\)\\(\t\\)\\([^\t\n]*\\S-\\)\\([ \t]*\\)$"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1151 "Regular expression matching phrases which have no separate index key.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1152 (defconst reftex-index-phrases-phrase-regexp2
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1153 "^\\(\\S-?\\)\\(\t\\)\\([^\t]*\\S-\\)\\(\t[ \t]*\\)\\([^\n\t]*\\S-\\)[ \t]*$"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1154 "Regular expression matching phrases which have a separate index key.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1155 (defconst reftex-index-phrases-phrase-regexp12
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1156 "^\\(\\S-?\\)\\(\t\\)\\([^\n\t]*\\S-\\)\\(\\(\t[ \t]*\\)\\([^\n\t]*\\S-\\)\\)?[ \t]*$"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1157 "Regular expression matching all types of phrase lines.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1158 (defvar reftex-index-phrases-macro-data nil
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1159 "Alist containing the information taken from the macro definition lines.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1160 This gets refreshed in every phrases command.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1161 (defvar reftex-index-phrases-files nil
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1162 "List of document files relevant for the phrases file.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1163
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1164 (defvar reftex-index-phrases-font-lock-keywords nil
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1165 "Font lock keywords for reftex-index-phrases-mode.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1166 (defvar reftex-index-phrases-font-lock-defaults nil
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1167 "Font lock defaults for reftex-index-phrases-mode.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1168 (defvar reftex-index-phrases-map (make-sparse-keymap)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1169 "Keymap used for *toc* buffer.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1170
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1171
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1172 (defun reftex-index-phrase-selection-or-word (arg)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1173 "Add current selection or word at point to the phrases buffer.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1174 When you are in transient-mark-mode and the region is active, the
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1175 selection will be used - otherwise the word at point.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1176 You get a chance to edit the entry in the phrases buffer - finish with
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1177 `C-c C-c'."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1178 (interactive "P")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1179 (set-marker reftex-index-return-marker (point))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1180 (reftex-index-selection-or-word arg 'phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1181 (if (eq major-mode 'reftex-index-phrases-mode)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1182 (message
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1183 (substitute-command-keys
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1184 "Return to LaTeX with \\[reftex-index-phrases-save-and-return]"))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1185
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1186 (defun reftex-index-visit-phrases-buffer ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1187 "Switch to the phrases buffer, initialize if empty."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1188 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1189 (reftex-access-scan-info)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1190 (let* ((master (reftex-TeX-master-file))
27192
f70a80cecdd3 New version number.
Carsten Dominik <dominik@science.uva.nl>
parents: 27035
diff changeset
1191 (name (concat (file-name-sans-extension master)
f70a80cecdd3 New version number.
Carsten Dominik <dominik@science.uva.nl>
parents: 27035
diff changeset
1192 reftex-index-phrase-file-extension)))
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1193 (find-file name)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1194 (unless (eq major-mode 'reftex-index-phrases-mode)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1195 (reftex-index-phrases-mode))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1196 (if (= (buffer-size) 0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1197 (reftex-index-initialize-phrases-buffer master))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1198
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1199 (defun reftex-index-initialize-phrases-buffer (&optional master)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1200 "Initialize the phrases buffer by creating the header.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1201 If the buffer is non-empty, delete the old header first."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1202 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1203 (let* ((case-fold-search t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1204 (default-key (car reftex-index-default-macro))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1205 (default-macro (nth 1 (assoc default-key
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1206 reftex-key-to-index-macro-alist)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1207 (macro-alist
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1208 (sort (copy-sequence reftex-index-macro-alist)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1209 (lambda (a b) (equal (car a) default-macro))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1210 macro entry key repeat)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1211
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1212 (if master (set (make-local-variable 'TeX-master)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1213 (file-name-nondirectory master)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1214
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1215 (when (> (buffer-size) 0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1216 (goto-char 1)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1217 (set-mark (point))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1218 (while (re-search-forward reftex-index-phrases-macrodef-regexp nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1219 (end-of-line))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1220 (beginning-of-line 2)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1221 (if (looking-at reftex-index-phrases-comment-regexp)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1222 (beginning-of-line 2))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1223 (while (looking-at "^[ \t]*$")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1224 (beginning-of-line 2))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1225 (cond ((fboundp 'zmacs-activate-region) (zmacs-activate-region))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1226 ((boundp 'make-active) (setq mark-active t)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1227 (if (yes-or-no-p "Delete and rebuilt header ")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1228 (delete-region (point-min) (point))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1229
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1230 ;; Insert the mode line
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1231 (insert
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1232 (format "%% -*- mode: reftex-index-phrases; TeX-master: \"%s\" -*-\n"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1233 (file-name-nondirectory (reftex-index-phrase-tex-master))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1234 ;; Insert the macro definitions
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1235 (insert "% Key Macro Format Repeat\n")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1236 (insert "%---------------------------------------------------------------------\n")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1237 (while (setq entry (pop macro-alist))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1238 (setq macro (car entry)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1239 repeat (nth 7 entry)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1240 key (car (delq nil (mapcar (lambda (x) (if (equal (nth 1 x) macro)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1241 (car x)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1242 nil))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1243 reftex-key-to-index-macro-alist))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1244 (insert (format ">>>INDEX_MACRO_DEFINITION:\t%s\t%-20s\t%s\n"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1245 (char-to-string key) (concat macro "{%s}")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1246 (if repeat "t" "nil"))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1247 (insert "%---------------------------------------------------------------------\n\n\n")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1248
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1249 (defvar TeX-master)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1250 (defun reftex-index-phrase-tex-master (&optional dir)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1251 "Return the name of the master file associated with a phrase buffer."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1252 (if (and (boundp 'TeX-master)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1253 (local-variable-p 'TeX-master (current-buffer))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1254 (stringp TeX-master))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1255 ;; We have a local variable which tells us which file to use
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1256 (expand-file-name TeX-master dir)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1257 ;; have to guess
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1258 (concat (file-name-sans-extension (buffer-file-name)) ".tex")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1259
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1260 (defun reftex-index-phrases-save-and-return ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1261 "Return to where the `reftex-index-phrase-selection-or-word' was called."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1262 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1263 (save-buffer)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1264 (switch-to-buffer (marker-buffer reftex-index-return-marker))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1265 (goto-char (or (marker-position reftex-index-return-marker) (point))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1266
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1267
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1268 (defvar reftex-index-phrases-menu)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1269 (defvar reftex-index-phrases-restrict-file nil)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1270 ;;;###autoload
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1271 (defun reftex-index-phrases-mode ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1272 "Major mode for managing the Index phrases of a LaTeX document.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1273 This buffer was created with RefTeX.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1274
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1275 To insert new phrases, use
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1276 - `C-c \\' in the LaTeX document to copy selection or word
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1277 - `\\[reftex-index-new-phrase]' in the phrases buffer.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1278
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1279 To index phrases use one of:
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1280
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1281 \\[reftex-index-this-phrase] index current phrase
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1282 \\[reftex-index-next-phrase] index next phrase (or N with prefix arg)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1283 \\[reftex-index-all-phrases] index all phrases
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1284 \\[reftex-index-remaining-phrases] index current and following phrases
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1285 \\[reftex-index-region-phrases] index the phrases in the region
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1286
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1287 You can sort the phrases in this buffer with \\[reftex-index-sort-phrases].
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1288 To display information about the phrase at point, use \\[reftex-index-phrases-info].
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1289
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1290 For more information see the RefTeX User Manual.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1291
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1292 Here are all local bindings.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1293
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1294 \\{reftex-index-phrases-map}"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1295 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1296 (kill-all-local-variables)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1297 (setq major-mode 'reftex-index-phrases-mode
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1298 mode-name "Phrases")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1299 (use-local-map reftex-index-phrases-map)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1300 (set (make-local-variable 'font-lock-defaults)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1301 reftex-index-phrases-font-lock-defaults)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1302 (easy-menu-add reftex-index-phrases-menu reftex-index-phrases-map)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1303 (set (make-local-variable 'reftex-index-phrases-marker) (make-marker))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1304 (run-hooks 'reftex-index-phrases-mode-hook))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1305 (add-hook 'reftex-index-phrases-mode-hook 'turn-on-font-lock)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1306
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1307 ;; Font Locking stuff
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1308 (let ((ss (if (featurep 'xemacs) 'secondary-selection ''secondary-selection)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1309 (setq reftex-index-phrases-font-lock-keywords
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1310 (list
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1311 (cons reftex-index-phrases-comment-regexp 'font-lock-comment-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1312 (list reftex-index-phrases-macrodef-regexp
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1313 '(1 font-lock-type-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1314 '(2 font-lock-keyword-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1315 (list 3 ss)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1316 '(4 font-lock-function-name-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1317 (list 5 ss)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1318 '(6 font-lock-string-face))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1319 (list reftex-index-phrases-phrase-regexp1
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1320 '(1 font-lock-keyword-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1321 (list 2 ss)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1322 '(3 font-lock-string-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1323 (list 4 ss))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1324 (list reftex-index-phrases-phrase-regexp2
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1325 '(1 font-lock-keyword-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1326 (list 2 ss)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1327 '(3 font-lock-string-face)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1328 (list 4 ss)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1329 '(5 font-lock-function-name-face))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1330 (cons "^\t$" ss)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1331 (setq reftex-index-phrases-font-lock-defaults
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1332 '((reftex-index-phrases-font-lock-keywords)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1333 nil t nil beginning-of-line))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1334 (put 'reftex-index-phrases-mode 'font-lock-defaults
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1335 reftex-index-phrases-font-lock-defaults) ; XEmacs
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1336 )
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1337
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1338 (defvar reftex-index-phrases-marker)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1339 (defun reftex-index-next-phrase (&optional arg)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1340 "Index the next ARG phrases in the phrases buffer."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1341 (interactive "p")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1342 (reftex-index-phrases-parse-header t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1343 (while (> arg 0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1344 (decf arg)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1345 (end-of-line)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1346 (if (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1347 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1348 (goto-char (match-beginning 0))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1349 (reftex-index-this-phrase))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1350 (error "No more phrase lines after point"))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1351
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1352 (defun reftex-index-this-phrase ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1353 "Index the phrase in the current line.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1354 Does a global search and replace in the entire document. At each
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1355 match, the user will be asked to confirm the replacement."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1356 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1357 (if (interactive-p) (reftex-index-phrases-parse-header t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1358 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1359 (beginning-of-line)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1360 (cond ((looking-at reftex-index-phrases-comment-regexp)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1361 (if (interactive-p) (error "Comment line")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1362 ((looking-at "^[ \t]*$")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1363 (if (interactive-p) (error "Empty line")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1364 ((looking-at reftex-index-phrases-macrodef-regexp)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1365 (if (interactive-p) (error "Macro definition line")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1366 ((looking-at reftex-index-phrases-phrase-regexp12)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1367 ;; This is a phrase
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1368 (let* ((char (if (not (equal (match-string 1) ""))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1369 (string-to-char (match-string 1))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1370 (phrase (match-string 3))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1371 (index-key (match-string 6))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1372 (macro-data (cdr (if (null char)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1373 (car reftex-index-phrases-macro-data)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1374 (assoc char reftex-index-phrases-macro-data))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1375 (macro-fmt (car macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1376 (repeat (nth 1 macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1377 (files
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1378 (cond ((and (stringp reftex-index-phrases-restrict-file)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1379 (file-regular-p reftex-index-phrases-restrict-file))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1380 (list reftex-index-phrases-restrict-file))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1381 ((stringp reftex-index-phrases-restrict-file)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1382 (error "Illegal restriction file %s"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1383 reftex-index-phrases-restrict-file))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1384 (t reftex-index-phrases-files)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1385 (as-words reftex-index-phrases-search-whole-words))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1386 (unless macro-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1387 (error "No macro associated with key %c" char))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1388 (unwind-protect
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1389 (let ((overlay-arrow-string "=>")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1390 (overlay-arrow-position
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1391 reftex-index-phrases-marker)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1392 (replace-count 0))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1393 ;; Show the overlay arrow
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1394 (move-marker reftex-index-phrases-marker
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1395 (match-beginning 0) (current-buffer))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1396 ;; Start the query-replace
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1397 (reftex-query-index-phrase-globally
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1398 files phrase macro-fmt
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1399 index-key repeat as-words)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1400 (message "%s replaced"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1401 (reftex-number replace-count "occurrence"))))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1402 (t (error "Cannot parse this line")))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1403
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1404 (defun reftex-index-all-phrases ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1405 "Index all phrases in the phrases buffer.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1406 Calls `reftex-index-this-phrase' on each line in the buffer."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1407 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1408 (reftex-index-region-phrases (point-min) (point-max)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1409
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1410 (defun reftex-index-remaining-phrases ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1411 "Index all phrases in the phrases buffer.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1412 Calls `reftex-index-this-phrase' on each line ay and below point in
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1413 the buffer."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1414 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1415 (beginning-of-line)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1416 (reftex-index-region-phrases (point) (point-max)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1417
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1418 (defun reftex-index-region-phrases (beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1419 "Index all phrases in the phrases buffer.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1420 Calls `reftex-index-this-phrase' on each line in the region."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1421 (interactive "r")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1422 (reftex-index-phrases-parse-header t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1423 (goto-char beg)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1424 (while (not (or (eobp)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1425 (>= (point) end)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1426 (save-excursion (reftex-index-this-phrase))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1427 (beginning-of-line 2)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1428
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1429 (defun reftex-index-phrases-parse-header (&optional get-files)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1430 "Parse the header of a phrases file to extract the macro definitions.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1431 The definitions get stored in `reftex-index-phrases-macro-data'.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1432 Also switches to the LaTeX document to find out which files belong to
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1433 the document and stores the list in `reftex-index-phrases-files'."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1434 (let* ((master (reftex-index-phrase-tex-master))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1435 buf)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1436 (if get-files
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1437 ;; Get the file list
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1438 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1439 (setq buf (reftex-get-file-buffer-force master))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1440 (unless buf (error "Master file %s not found" master))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1441 (set-buffer buf)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1442 (reftex-access-scan-info)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1443 (setq reftex-index-phrases-files
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1444 (reftex-all-document-files))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1445 ;; Parse the files header for macro definitions
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1446 (setq reftex-index-phrases-macro-data nil)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1447 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1448 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1449 (while (re-search-forward reftex-index-phrases-macrodef-regexp nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1450 (push (list
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1451 (string-to-char (match-string 2))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1452 (match-string 4)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1453 (equal (match-string 6) "t"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1454 reftex-index-phrases-macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1455 ;; Reverse the list, so that the first macro is first
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1456 (if (null reftex-index-phrases-macro-data)
27192
f70a80cecdd3 New version number.
Carsten Dominik <dominik@science.uva.nl>
parents: 27035
diff changeset
1457 (error "No valid MACRO DEFINITION line in %s file (make sure to use TAB separators)" reftex-index-phrase-file-extension))
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1458 (setq reftex-index-phrases-macro-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1459 (nreverse reftex-index-phrases-macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1460 (goto-char (point-min)))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1461
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1462 (defun reftex-index-phrases-apply-to-region (beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1463 "Index all index phrases in the current region.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1464 This works exactly like global indexing from the index phrases buffer,
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1465 but operation is restricted to the current region. This is useful if
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1466 you need to add/change text in an already indexed document and want to
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1467 index the new part without having to go over the unchanged parts again."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1468 (interactive "r")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1469 (let ((win-conf (current-window-configuration))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1470 (reftex-index-phrases-restrict-file (buffer-file-name)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1471 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1472 (save-restriction
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1473 (narrow-to-region beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1474 (unwind-protect
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1475 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1476 ;; Hide the region highlighting
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1477 (cond ((fboundp 'zmacs-deactivate-region) (zmacs-deactivate-region))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1478 ((fboundp 'deactivate-mark) (deactivate-mark)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1479 (delete-other-windows)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1480 (reftex-index-visit-phrases-buffer)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1481 (reftex-index-all-phrases))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1482 (set-window-configuration win-conf))))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1483
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1484 (defun reftex-index-new-phrase (&optional text)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1485 "Open a new line in the phrases buffer, insert TEXT."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1486 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1487 (if (and text (stringp text))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1488 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1489 ;; Check if the phrase is already in the buffer
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1490 (setq text (reftex-index-simplify-phrase text))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1491 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1492 (if (re-search-forward
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1493 (concat "^\\(\\S-*\\)\t\\(" (regexp-quote text)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1494 "\\) *[\t\n]") nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1495 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1496 (goto-char (match-end 2))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1497 (error "Phrase is already in phrases buffer")))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1498 ;; Add the new phrase line after the last in the buffer
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1499 (goto-char (point-max))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1500 (if (re-search-backward reftex-index-phrases-phrase-regexp12 nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1501 (end-of-line))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1502 (if (not (bolp))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1503 (insert "\n"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1504 (insert "\t")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1505 (if (and text (stringp text))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1506 (insert text)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1507
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1508 (defun reftex-index-find-next-conflict-phrase (&optional arg)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1509 "Find the next a phrase which is has conflicts in the phrase buffer.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1510 The command helps to find possible conflicts in the phrase indexing process.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1511 It searches downward from point for a phrase which is repeated elsewhere
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1512 in the buffer, or which is a subphrase of another phrase. If such a
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1513 phrase is found, the phrase info is displayed.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1514 To check the whole buffer, start at the beginning and continue by calling
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1515 this function repeatedly."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1516 (interactive "P")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1517 (if (catch 'exit
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1518 (while (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1519 (goto-char (match-beginning 3))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1520 (let* ((phrase (match-string 3))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1521 (case-fold-search reftex-index-phrases-case-fold-search)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1522 (re (reftex-index-phrases-find-dup-re phrase t)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1523 (if (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1524 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1525 (and (re-search-forward re nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1526 (re-search-forward re nil t)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1527 (throw 'exit t)))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1528 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1529 (reftex-index-phrases-info)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1530 (message "Phrase with match conflict discovered"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1531 (goto-char (point-max))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1532 (error "No further problematic phrases found")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1533
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1534 (defun reftex-index-phrases-info ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1535 "Display information about the phrase at point."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1536 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1537 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1538 (beginning-of-line)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1539 (unless (looking-at reftex-index-phrases-phrase-regexp12)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1540 (error "Not a phrase line"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1541 (save-match-data (reftex-index-phrases-parse-header t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1542 (let* ((char (if (not (equal (match-string 1) ""))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1543 (string-to-char (match-string 1))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1544 (phrase (match-string 3))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1545 (index-key (match-string 6))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1546 (index-keys (split-string
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1547 (or index-key phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1548 reftex-index-phrases-logical-or-regexp))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1549 (macro-data (cdr (if (null char)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1550 (car reftex-index-phrases-macro-data)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1551 (assoc char reftex-index-phrases-macro-data))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1552 (macro-fmt (car macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1553 (repeat (nth 1 macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1554 (as-words reftex-index-phrases-search-whole-words)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1555 (example (reftex-index-make-replace-string
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1556 macro-fmt (downcase phrase) (car index-keys) repeat))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1557 (re (reftex-index-make-phrase-regexp phrase as-words t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1558 (re1 (reftex-index-phrases-find-dup-re phrase))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1559 (re2 (reftex-index-phrases-find-dup-re phrase 'sub))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1560 superphrases
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1561 (nmatches 0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1562 (ntimes1 0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1563 (ntimes2 0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1564 (case-fold-search reftex-index-phrases-case-fold-search)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1565 file files buf)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1566 (setq files reftex-index-phrases-files)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1567 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1568 (save-restriction
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1569 (widen)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1570 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1571 (while (re-search-forward re1 nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1572 (incf ntimes1))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1573 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1574 (while (re-search-forward re2 nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1575 (push (cons (count-lines 1 (point)) (match-string 1)) superphrases)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1576 (incf ntimes2))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1577 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1578 (while (setq file (pop files))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1579 (setq buf (reftex-get-file-buffer-force file))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1580 (when buf
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1581 (set-buffer buf)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1582 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1583 (save-restriction
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1584 (widen)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1585 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1586 (let ((case-fold-search reftex-index-phrases-case-fold-search))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1587 (while (re-search-forward re nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1588 (or (reftex-in-comment)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1589 (incf nmatches)))))))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1590 (with-output-to-temp-buffer "*Help*"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1591 (princ (format " Phrase: %s\n" phrase))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1592 (princ (format " Macro key: %s\n" char))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1593 (princ (format " Macro format: %s\n" macro-fmt))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1594 (princ (format " Repeat: %s\n" repeat))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1595 (cond
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1596 (index-key
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1597 (let ((iks index-keys) (cnt 0) ik)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1598 (while (setq ik (pop iks))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1599 (princ (format "Index entry %d: %s\n" (incf cnt) ik)))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1600 (repeat
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1601 (princ (format " Index entry: %s\n" phrase)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1602 (t
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1603 (princ (format " Index key: <<Given by the match>>\n"))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1604 (princ (format " Example: %s\n" example))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1605 (terpri)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1606 (princ (format "Total matches: %s in %s\n"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1607 (reftex-number nmatches "match" "es")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1608 (reftex-number (length reftex-index-phrases-files)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1609 "LaTeX file")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1610 (princ (format " Uniqueness: Phrase occurs %s in phrase buffer\n"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1611 (reftex-number ntimes1 "time")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1612 (if (> ntimes2 1)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1613 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1614 (princ (format " Superphrases: Phrase matches the following %s in the phrase buffer:\n"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1615 (reftex-number ntimes2 "line")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1616 (mapcar (lambda(x)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1617 (princ (format " Line %4d: %s\n" (car x) (cdr x))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1618 (nreverse superphrases))))))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1619
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1620 (defun reftex-index-phrases-set-macro-key ()
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1621 "Change the macro key for the current line.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1622 Prompts for a macro key and insert is at the beginning of the line.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1623 If you reply with SPACE, the macro keyn will be removed, so that the
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1624 default macro will be used. If you reply with `RET', just prints
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1625 information about the currently selected macro."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1626 (interactive)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1627 (reftex-index-phrases-parse-header)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1628 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1629 (beginning-of-line)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1630 (unless (or (looking-at reftex-index-phrases-phrase-regexp12)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1631 (looking-at "\t"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1632 (error "This is not a phrase line"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1633 (let* ((nc (reftex-index-select-phrases-macro 0))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1634 (macro-data (assoc nc reftex-index-phrases-macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1635 macro-fmt repeat)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1636 (cond (macro-data)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1637 ((equal nc ?\ )
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1638 (setq nc ""
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1639 macro-data (car reftex-index-phrases-macro-data)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1640 ((equal nc ?\C-m)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1641 (setq nc (char-after (point)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1642 (if (equal nc ?\t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1643 (setq nc ""
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1644 macro-data (car reftex-index-phrases-macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1645 (setq macro-data (assoc nc reftex-index-phrases-macro-data))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1646 (t (error "No macro associated with %c" nc)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1647
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1648 (setq macro-fmt (nth 1 macro-data)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1649 repeat (nth 2 macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1650 (if macro-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1651 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1652 (if (looking-at "[^\t]") (delete-char 1))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1653 (insert nc)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1654 (message "Line will use %s %s repeat" macro-fmt
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1655 (if repeat "with" "without")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1656 (error "Abort")))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1657
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1658 (defun reftex-index-sort-phrases (&optional chars-first)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1659 "Sort the phrases lines in the buffer alphabetically.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1660 Normally, this looks only at the phrases. With a prefix arg CHARS-FIRST,
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1661 it first compares the macro identifying chars and then the phrases."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1662 (interactive "P")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1663 ;; Remember the current line, so that we can return
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1664 (let ((line (buffer-substring (progn (beginning-of-line) (point))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1665 (progn (end-of-line) (point))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1666 beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1667 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1668 ;; Find first and last phrase line in buffer
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1669 (setq beg
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1670 (and (re-search-forward reftex-index-phrases-phrase-regexp12 nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1671 (match-beginning 0)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1672 (goto-char (point-max))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1673 (setq end (re-search-backward reftex-index-phrases-phrase-regexp12 nil t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1674 (if end (setq end (progn (goto-char end) (end-of-line) (point))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1675 ;; Take the lines, sort them and re-insert.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1676 (if (and beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1677 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1678 (message "Sorting lines...")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1679 (let* ((lines (split-string (buffer-substring beg end) "\n"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1680 (lines1 (sort lines 'reftex-compare-phrase-lines)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1681 (message "Sorting lines...done")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1682 (let ((inhibit-quit t)) ;; make sure we do not loose lines
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1683 (delete-region beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1684 (insert (mapconcat 'identity lines1 "\n"))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1685 (goto-char (point-max))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1686 (re-search-backward (concat "^" (regexp-quote line) "$") nil t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1687 (error "Cannot find phrases lines to sort"))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1688
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1689 (defvar chars-first)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1690 (defun reftex-compare-phrase-lines (a b)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1691 "The comparison function used for sorting."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1692 (let (ca cb pa pb c-p p-p)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1693 (if (string-match reftex-index-phrases-phrase-regexp12 a)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1694 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1695 ;; Extract macro char and phrase-or-key for a
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1696 (setq ca (match-string 1 a)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1697 pa (downcase
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1698 (or (and reftex-index-phrases-sort-prefers-entry
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1699 (match-string 6 a))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1700 (match-string 3 a))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1701 (if (string-match reftex-index-phrases-phrase-regexp12 b)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1702 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1703 ;; Extract macro char and phrase-or-key for b
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1704 (setq cb (match-string 1 b)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1705 pb (downcase
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1706 (or (and reftex-index-phrases-sort-prefers-entry
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1707 (match-string 6 b))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1708 (match-string 3 b))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1709 (setq c-p (string< ca cb)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1710 p-p (string< pa pb))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1711 ;; Do the right comparison, based on the value of `chars-first'
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1712 ;; `chars-first' is bound locally in the calling function
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1713 (if chars-first
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1714 (if (string= ca cb) p-p c-p)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1715 (if (string= pa pb) c-p p-p)))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1716 ;; If line a does not match, the answer we return determines
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1717 ;; if non-matching lines are collected at the beginning.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1718 ;; When we return t here, non-matching lines form
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1719 ;; block separators for searches.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1720 (not reftex-index-phrases-sort-in-blocks))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1721
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1722 (defvar reftex-index-phrases-menu)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1723 (defun reftex-index-make-phrase-regexp (phrase &optional
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1724 as-words allow-newline)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1725 "Return a regexp matching PHRASE, even if distributed over lines.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1726 With optional arg AS-WORDS, require word boundary at beginning and end.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1727 With optional arg ALLOW-NEWLINE, allow single newline between words."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1728 (let* ((words (split-string phrase))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1729 (space-re (if allow-newline
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1730 "\\([ \t]*\\(\n[ \t]*\\)?\\|[ \t]\\)"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1731 "\\([ \t]+\\)")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1732 (concat (if (and as-words (string-match "\\`\\w" (car words)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1733 "\\<" "")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1734 (mapconcat (lambda (w) (regexp-quote (downcase w)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1735 words space-re)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1736 (if (and as-words
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1737 (string-match "\\w\\'" (nth (1- (length words)) words)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1738 "\\>" ""))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1739
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1740 (defun reftex-index-simplify-phrase (phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1741 "Make phrase single spaces and single line."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1742 (mapconcat 'identity (split-string phrase) " "))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1743
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1744 (defun reftex-index-phrases-find-dup-re (phrase &optional sub)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1745 "Return a regexp which matches variations of PHRASE (with additional space).
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1746 When SUB ins non-nil, the regexp will also match when PHRASE is a subphrase
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1747 of another phrase. The regexp works lonly in the phrase buffer."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1748 (concat (if sub "^\\S-?\t\\([^\t\n]*" "^\\S-?\t")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1749 (mapconcat 'regexp-quote (split-string phrase) " +")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1750 (if sub "[^\t\n]*\\)\\([\t\n]\\|$\\)" " *\\([\t\n]\\|$\\)")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1751
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1752 (defun reftex-index-make-replace-string (macro-fmt match index-key
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1753 &optional repeat mathp)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1754 "Return the string which can be used as replacement.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1755 Treats the logical `and' for index phrases."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1756 (let ((index-keys (split-string (or index-key match)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1757 reftex-index-phrases-logical-and-regexp)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1758 (concat
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1759 (mapconcat (lambda (x)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1760 (format macro-fmt
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1761 (format (if mathp reftex-index-math-format "%s") x)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1762 index-keys "")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1763 (if repeat (reftex-index-simplify-phrase match) ""))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1764
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1765 (defun reftex-query-index-phrase-globally (files &rest args)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1766 "Call `reftex-query-index-phrase' for all files in FILES."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1767 (let ((win-conf (current-window-configuration))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1768 (file))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1769 (unless files (error "No files"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1770 (unwind-protect
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1771 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1772 (switch-to-buffer-other-window (reftex-get-file-buffer-force
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1773 (car files)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1774 (catch 'no-more-files
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1775 (while (setq file (pop files))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1776 (switch-to-buffer (reftex-get-file-buffer-force file))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1777 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1778 (save-restriction
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1779 (unless (stringp reftex-index-phrases-restrict-file)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1780 (widen))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1781 (goto-char (point-min))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1782 (apply 'reftex-query-index-phrase args))))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1783 (reftex-unhighlight 0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1784 (set-window-configuration win-conf))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1785
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1786 (defconst reftex-index-phrases-help
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1787 " Keys for query-index search
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1788 ===========================
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1789 y Replace this match
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1790 n Skip this match
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1791 ! Replace this and all further matches in this file
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1792 q / Q Skip match, start next file / start next phrase
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1793 o Use a different indexing macro for this match
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1794 1 - 9 Select one of the multiple phrases
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1795 e Edit the replacement text
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1796 C-r Recursive edit.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1797 s / S Save this buffer / Save all document buffers
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1798 C-g Abort"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1799 "The help string for indexing phrases.")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1800
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1801 (defvar replace-count)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1802 (defun reftex-query-index-phrase (phrase macro-fmt &optional
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1803 index-key repeat as-words)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1804 "Search through buffer for PHRASE, and offer to replace it with an indexed
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1805 version. The index version is derived by applying `format' with MACRO-FMT
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1806 to INDEX-KEY or PHRASE. When REPEAT is non-nil, the PHRASE is inserted
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1807 again after the macro.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1808 AS-WORDS means, the search for PHRASE should require word boundaries at
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1809 both ends."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1810 (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow-newline))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1811 (case-fold-search reftex-index-phrases-case-fold-search)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1812 (index-keys (split-string
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1813 (or index-key phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1814 reftex-index-phrases-logical-or-regexp))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1815 (nkeys (length index-keys))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1816 (ckey (nth 0 index-keys))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1817 (all-yes nil)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1818 match rpl char beg end mathp)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1819 (unwind-protect
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1820 (while (re-search-forward re nil t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1821 (catch 'next-match
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1822 (setq match (match-string 0))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1823 (setq mathp
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1824 (save-match-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1825 (condition-case nil (texmathp) (error nil))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1826 (setq beg (car (match-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1827 end (nth 1 (match-data)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1828 (if (and reftex-index-phrases-skip-indexed-matches
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1829 (save-match-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1830 (reftex-index-phrase-match-is-indexed beg
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1831 end)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1832 (throw 'next-match nil))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1833 (reftex-highlight 0 (match-beginning 0) (match-end 0))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1834 (setq rpl
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1835 (save-match-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1836 (reftex-index-make-replace-string
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1837 macro-fmt (match-string 0) ckey repeat mathp)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1838 (while
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1839 (not
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1840 (catch 'loop
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1841 (message "REPLACE: %s? (yn!qoe%s?)"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1842 rpl
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1843 (if (> nkeys 1)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1844 (concat "1-" (int-to-string nkeys))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1845 ""))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1846 (setq char (if all-yes ?y (read-char-exclusive)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1847 (cond ((member char '(?y ?Y ?\ ))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1848 ;; Yes!
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1849 (replace-match rpl t t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1850 (incf replace-count)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1851 ;; See if we should insert newlines to shorten lines
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1852 (and reftex-index-phrases-wrap-long-lines
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1853 (reftex-index-phrases-fixup-line beg end))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1854 (throw 'loop t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1855 ((member char '(?n ?N ?\C-h ?\C-?));; FIXME: DEL
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1856 ;; No
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1857 (throw 'loop t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1858 ((equal char ?!)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1859 ;; Yes for all in this buffer
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1860 (setq all-yes t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1861 ((equal char ?q)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1862 ;; Stop this one in this file
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1863 (goto-char (point-max))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1864 (throw 'loop t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1865 ((equal char ?Q)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1866 ;; Stop this one
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1867 (throw 'no-more-files t))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1868 ((equal char ?s)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1869 (save-buffer))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1870 ((equal char ?S)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1871 (reftex-save-all-document-buffers))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1872 ((equal char ?\C-g)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1873 (keyboard-quit))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1874 ((member char '(?o ?O))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1875 ;; Select a differnt macro
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1876 (let* ((nc (reftex-index-select-phrases-macro 2))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1877 (macro-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1878 (cdr (assoc nc reftex-index-phrases-macro-data)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1879 (macro-fmt (car macro-data))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1880 (repeat (nth 1 macro-data)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1881 (if macro-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1882 (setq rpl (save-match-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1883 (reftex-index-make-replace-string
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1884 macro-fmt match
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1885 ckey repeat mathp)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1886 (ding))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1887 ((equal char ?\?)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1888 ;; Help
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1889 (with-output-to-temp-buffer "*Help*"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1890 (princ reftex-index-phrases-help)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1891 ((equal char ?\C-r)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1892 ;; Recursive edit
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1893 (save-match-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1894 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1895 (message
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1896 (substitute-command-keys
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1897 "Recursive edit. Resume with \\[exit-recursive-edit]"))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1898 (recursive-edit))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1899 ((equal char ?e)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1900 (setq rpl (read-string "Edit: " rpl)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1901 ((equal char ?0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1902 (setq ckey (or index-key phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1903 rpl (save-match-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1904 (reftex-index-make-replace-string
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1905 macro-fmt match ckey repeat mathp))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1906 ((and (> char ?0)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1907 (<= char (+ ?0 nkeys)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1908 (setq ckey (nth (1- (- char ?0)) index-keys)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1909 rpl (save-match-data
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1910 (reftex-index-make-replace-string
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1911 macro-fmt match ckey repeat mathp))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1912 (t (ding)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1913 nil)))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1914 (message "")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1915 (setq all-yes nil)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1916 (reftex-unhighlight 0))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1917
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1918 (defun reftex-index-phrase-match-is-indexed (beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1919 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1920 (goto-char end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1921 (let* ((this-macro (car (reftex-what-macro 1)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1922 (before-char (char-before beg))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1923 (after-char (char-after end))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1924 (before-macro
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1925 (and (> beg 2)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1926 (goto-char (1- beg))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1927 (memq (char-after (point)) '(?\] ?\}))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1928 (car (reftex-what-macro 1))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1929 (after-macro
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1930 (and (goto-char end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1931 (looking-at "\\(\\\\[a-zA-Z]+\\*?\\)[[{]")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1932 (match-string 1))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1933 (or (and this-macro
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1934 (member before-char '(?\{ ?\[))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1935 (member after-char '(?\} ?\]))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1936 (member this-macro reftex-macros-with-index))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1937 (and before-macro
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1938 (member before-macro reftex-macros-with-index))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1939 (and after-macro
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1940 (member after-macro reftex-macros-with-index))))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1941
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1942
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1943 (defun reftex-index-phrases-fixup-line (beg end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1944 "Insert newlines before BEG and/or after END to shorten line."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1945 (let (bol eol space1 space2)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1946 (save-excursion
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1947 ;; Find line boundaries and possible line breaks near BEG and END
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1948 (beginning-of-line)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1949 (setq bol (point))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1950 (end-of-line)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1951 (setq eol (point))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1952 (goto-char beg)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1953 (skip-chars-backward "^ \n")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1954 (if (and (equal (preceding-char) ?\ )
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1955 (string-match "\\S-" (buffer-substring bol (point))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1956 (setq space1 (1- (point))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1957 (goto-char end)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1958 (skip-chars-forward "^ \n")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1959 (if (and (equal (following-char) ?\ )
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1960 (string-match "\\S-" (buffer-substring (point) eol)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1961 (setq space2 (point)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1962 ;; Now check what we have and insert the newlines
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1963 (if (<= (- eol bol) fill-column)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1964 ;; Line is already short
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1965 nil
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1966 (cond
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1967 ((and (not space1) (not space2))) ; No spaces available
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1968 ((not space2) ; Do space1
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1969 (reftex-index-phrases-replace-space space1))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1970 ((not space1) ; Do space2
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1971 (reftex-index-phrases-replace-space space2))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1972 (t ; We have both spaces
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1973 (let ((l1 (- space1 bol))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1974 (l2 (- space2 space1))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1975 (l3 (- eol space2)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1976 (if (> l2 fill-column)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1977 ;; The central part alone is more than one line
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1978 (progn
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1979 (reftex-index-phrases-replace-space space1)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1980 (reftex-index-phrases-replace-space space2))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1981 (if (> (+ l1 l2) fill-column)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1982 ;; Need to split beginning
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1983 (reftex-index-phrases-replace-space space1))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1984 (if (> (+ l2 l3) fill-column)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1985 ;; Need to split end
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1986 (reftex-index-phrases-replace-space space2))))))))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1987
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1988 (defun reftex-index-phrases-replace-space (pos)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1989 "If there is a space at POS, replace it with a newline char.
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1990 Does not do a save-excursion."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1991 (when (equal (char-after pos) ?\ )
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1992 (goto-char pos)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1993 (delete-char 1)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1994 (insert "\n")))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1995
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1996 (defun reftex-index-select-phrases-macro (&optional delay)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1997 "Offer a list of possible index macros and have the user select one."
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1998 (let* ((prompt (concat "Select macro: ["
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
1999 (mapconcat (lambda (x) (char-to-string (car x)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2000 reftex-index-phrases-macro-data "")
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2001 "] "))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2002 (help (concat "Select an indexing macro\n========================\n"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2003 (mapconcat (lambda (x)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2004 (format " [%c] %s"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2005 (car x) (nth 1 x)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2006 reftex-index-phrases-macro-data "\n"))))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2007 (reftex-select-with-char prompt help delay)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2008
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2009 ;; Keybindings and Menu for phrases buffer
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2010
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2011 (loop for x in
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2012 '(("\C-c\C-c" . reftex-index-phrases-save-and-return)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2013 ("\C-c\C-x" . reftex-index-this-phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2014 ("\C-c\C-f" . reftex-index-next-phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2015 ("\C-c\C-r" . reftex-index-region-phrases)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2016 ("\C-c\C-a" . reftex-index-all-phrases)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2017 ("\C-c\C-d" . reftex-index-remaining-phrases)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2018 ("\C-c\C-s" . reftex-index-sort-phrases)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2019 ("\C-c\C-n" . reftex-index-new-phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2020 ("\C-c\C-m" . reftex-index-phrases-set-macro-key)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2021 ("\C-c\C-i" . reftex-index-phrases-info)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2022 ("\C-c\C-t" . reftex-index-find-next-conflict-phrase)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2023 ("\C-i" . self-insert-command))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2024 do (define-key reftex-index-phrases-map (car x) (cdr x)))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2025
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2026 (easy-menu-define
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2027 reftex-index-phrases-menu reftex-index-phrases-map
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2028 "Menu for Phrases buffer"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2029 '("Phrases"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2030 ["New Phrase" reftex-index-new-phrase t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2031 ["Set Phrase Macro" reftex-index-phrases-set-macro-key t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2032 ["Recreate File Header" reftex-index-initialize-phrases-buffer t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2033 "--"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2034 ("Sort Phrases"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2035 ["Sort" reftex-index-sort-phrases t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2036 "--"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2037 "Sort Options"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2038 ["by Search Phrase" (setq reftex-index-phrases-sort-prefers-entry nil)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2039 :style radio :selected (not reftex-index-phrases-sort-prefers-entry)]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2040 ["by Index Entry" (setq reftex-index-phrases-sort-prefers-entry t)
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2041 :style radio :selected reftex-index-phrases-sort-prefers-entry]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2042 ["in Blocks" (setq reftex-index-phrases-sort-in-blocks
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2043 (not reftex-index-phrases-sort-in-blocks))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2044 :style toggle :selected reftex-index-phrases-sort-in-blocks])
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2045 ["Describe Phrase" reftex-index-phrases-info t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2046 ["Next Phrase Conflict" reftex-index-find-next-conflict-phrase t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2047 "--"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2048 ("Find and Index in Document"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2049 ["Current Phrase" reftex-index-this-phrase t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2050 ["Next Phrase" reftex-index-next-phrase t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2051 ["Current and Following" reftex-index-remaining-phrases t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2052 ["Region Phrases" reftex-index-region-phrases t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2053 ["All Phrases" reftex-index-all-phrases t]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2054 "--"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2055 "Options"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2056 ["Match Whole Words" (setq reftex-index-phrases-search-whole-words
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2057 (not reftex-index-phrases-search-whole-words))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2058 :style toggle :selected reftex-index-phrases-search-whole-words]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2059 ["Case Sensitive Search" (setq reftex-index-phrases-case-fold-search
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2060 (not reftex-index-phrases-case-fold-search))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2061 :style toggle :selected (not
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2062 reftex-index-phrases-case-fold-search)]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2063 ["Wrap Long Lines" (setq reftex-index-phrases-wrap-long-lines
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2064 (not reftex-index-phrases-wrap-long-lines))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2065 :style toggle :selected reftex-index-phrases-wrap-long-lines]
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2066 ["Skip Indexed Matches" (setq reftex-index-phrases-skip-indexed-matches
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2067 (not reftex-index-phrases-skip-indexed-matches))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2068 :style toggle :selected reftex-index-phrases-skip-indexed-matches])
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2069 "--"
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2070 ["Save and Return" reftex-index-phrases-save-and-return t]))
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2071
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
2072
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
2073 ;;; reftex-index.el ends here