Mercurial > emacs
annotate lisp/textmodes/reftex-ref.el @ 58302:78096f4dea9d
(calc-poly-div-remainder): Declared it.
author | Jay Belanger <jay.p.belanger@gmail.com> |
---|---|
date | Wed, 17 Nov 2004 19:23:01 +0000 |
parents | 695cf19ef79e |
children | 9bad65481674 375f2633d815 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
1 ;;; reftex-ref.el --- code to create labels and references with RefTeX |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
2 ;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc. |
27035 | 3 |
46612
7522419c4db0
Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents:
38422
diff
changeset
|
4 ;; Author: Carsten Dominik <dominik@science.uva.nl> |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
5 ;; Version: 4.21 |
27035 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
25280 | 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 | 29 (provide 'reftex-ref) |
30 (require 'reftex) | |
31 ;;; | |
32 | |
33 (defun reftex-label-location (&optional bound) | |
34 "Return the environment or macro which determines the label type at point. | |
35 If optional BOUND is an integer, limit backward searches to that point." | |
36 | |
37 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound)) | |
38 (loc2 (reftex-what-environment reftex-label-env-list bound)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
39 (loc3 (reftex-what-special-env 1 bound)) |
25280 | 40 (p1 (or (cdr loc1) 0)) |
41 (p2 (or (cdr loc2) 0)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
42 (p3 (or (cdr loc3) 0)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
43 (pmax (max p1 p2 p3))) |
25280 | 44 |
45 (setq reftex-location-start pmax) | |
46 (cond | |
47 ((= p1 pmax) | |
48 ;; A macro. Default context after macro name. | |
49 (setq reftex-default-context-position (+ p1 (length (car loc1)))) | |
50 (or (car loc1) "section")) | |
51 ((= p2 pmax) | |
52 ;; An environment. Default context after \begin{name}. | |
53 (setq reftex-default-context-position (+ p2 8 (length (car loc2)))) | |
54 (or (car loc2) "section")) | |
55 ((= p3 pmax) | |
56 ;; A special. Default context right there. | |
57 (setq reftex-default-context-position p3) | |
58 (setq loc3 (car loc3)) | |
59 (cond ((null loc3) "section") | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
60 ((symbolp loc3) (symbol-name loc3)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
61 ((stringp loc3) loc3) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
62 (t "section"))) |
25280 | 63 (t ;; This should not happen, I think? |
64 "section")))) | |
65 | |
66 (defun reftex-label-info-update (cell) | |
67 ;; Update information about just one label in a different file. | |
68 ;; CELL contains the old info list | |
69 (let* ((label (nth 0 cell)) | |
70 (typekey (nth 1 cell)) | |
71 ;; (text (nth 2 cell)) | |
72 (file (nth 3 cell)) | |
73 (comment (nth 4 cell)) | |
74 (note (nth 5 cell)) | |
75 (buf (reftex-get-file-buffer-force | |
76 file (not (eq t reftex-keep-temporary-buffers))))) | |
77 (if (not buf) | |
78 (list label typekey "" file comment "LOST LABEL. RESCAN TO FIX.") | |
79 (save-excursion | |
80 (set-buffer buf) | |
81 (save-restriction | |
82 (widen) | |
83 (goto-char 1) | |
84 | |
85 (if (or (re-search-forward | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
86 (format reftex-find-label-regexp-format |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
87 (regexp-quote label)) nil t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
88 (re-search-forward |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
89 (format reftex-find-label-regexp-format2 |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
90 (regexp-quote label)) nil t)) |
25280 | 91 |
92 (progn | |
93 (backward-char 1) | |
94 (append (reftex-label-info label file) (list note))) | |
95 (list label typekey "" file "LOST LABEL. RESCAN TO FIX."))))))) | |
96 | |
97 (defun reftex-label-info (label &optional file bound derive env-or-mac) | |
98 ;; Return info list on LABEL at point. | |
99 (let* ((env-or-mac (or env-or-mac (reftex-label-location bound))) | |
100 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist))) | |
101 (file (or file (buffer-file-name))) | |
102 (parse (nth 2 (assoc env-or-mac reftex-env-or-mac-alist))) | |
103 (text (reftex-short-context env-or-mac parse reftex-location-start | |
104 derive)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
105 (in-comment (reftex-in-comment))) |
25280 | 106 (list label typekey text file in-comment))) |
107 | |
108 ;;; Creating labels --------------------------------------------------------- | |
109 | |
110 (defun reftex-label (&optional environment no-insert) | |
111 "Insert a unique label. Return the label. | |
112 If ENVIRONMENT is given, don't bother to find out yourself. | |
113 If NO-INSERT is non-nil, do not insert label into buffer. | |
114 With prefix arg, force to rescan document first. | |
115 When you are prompted to enter or confirm a label, and you reply with | |
116 just the prefix or an empty string, no label at all will be inserted. | |
117 A new label is also recorded into the label list. | |
118 This function is controlled by the settings of reftex-insert-label-flags." | |
119 | |
120 (interactive) | |
121 | |
122 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4). | |
123 (reftex-access-scan-info current-prefix-arg) | |
124 | |
125 ;; Find out what kind of environment this is and abort if necessary. | |
126 (if (or (not environment) | |
127 (not (assoc environment reftex-env-or-mac-alist))) | |
128 (setq environment (reftex-label-location))) | |
129 (unless environment | |
130 (error "Can't figure out what kind of label should be inserted")) | |
131 | |
132 ;; Ok, go ahead. | |
133 (catch 'exit | |
134 (let* ((entry (assoc environment reftex-env-or-mac-alist)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
135 (typekey (nth 1 entry)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
136 (format (nth 3 entry)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
137 (macro-cell (reftex-what-macro 1)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
138 (entry1 (assoc (car macro-cell) reftex-env-or-mac-alist)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
139 label naked prefix valid default force-prompt rescan-is-useful) |
25280 | 140 (when (and (or (nth 5 entry) (nth 5 entry1)) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
141 (memq (preceding-char) '(?\[ ?\{))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
142 ;; This is an argument of a label macro. Insert naked label. |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
143 (setq naked t format "%s")) |
25280 | 144 |
145 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
146 (concat typekey "-"))) |
25280 | 147 ;; Replace any escapes in the prefix |
148 (setq prefix (reftex-replace-prefix-escapes prefix)) | |
149 | |
150 ;; Make a default label. | |
151 (cond | |
152 | |
153 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
154 ;; Derive a label from context. |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
155 (setq reftex-active-toc (reftex-last-assoc-before-elt |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
156 'toc (car (reftex-where-am-I)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
157 (symbol-value reftex-docstruct-symbol))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
158 (setq default (reftex-no-props |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
159 (nth 2 (reftex-label-info " " nil nil t)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
160 ;; Catch the cases where the is actually no context available. |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
161 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
162 (string-match "ILLEGAL VALUE OF PARSE" default) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
163 (string-match "SECTION HEADING NOT FOUND" default) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
164 (string-match "HOOK ERROR" default) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
165 (string-match "^[ \t]*$" default)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
166 (setq default prefix |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
167 force-prompt t) ; need to prompt |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
168 (setq default |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
169 (concat prefix |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
170 (funcall reftex-string-to-label-function default))) |
25280 | 171 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
172 ;; Make it unique. |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
173 (setq default (reftex-uniquify-label default nil "-")))) |
25280 | 174 |
175 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
176 ;; Minimal default: the user will be prompted. |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
177 (setq default prefix)) |
25280 | 178 |
179 (t | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
180 ;; Make an automatic label. |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
181 (setq default (reftex-uniquify-label prefix t)))) |
25280 | 182 |
183 ;; Should we ask the user? | |
184 (if (or (reftex-typekey-check typekey | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
185 (nth 1 reftex-insert-label-flags)) ; prompt |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
186 force-prompt) |
25280 | 187 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
188 (while (not valid) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
189 ;; iterate until we get a legal label |
25280 | 190 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
191 (setq label (read-string |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
192 (if naked "Naked Label: " "Label: ") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
193 default)) |
25280 | 194 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
195 ;; Lets make sure that this is a legal label |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
196 (cond |
25280 | 197 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
198 ((string-match (concat "\\`\\(" (regexp-quote prefix) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
199 "\\)?[ \t]*\\'") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
200 label) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
201 ;; No label at all, please |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
202 (message "No label inserted.") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
203 (throw 'exit nil)) |
25280 | 204 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
205 ;; Test if label contains strange characters |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
206 ((string-match reftex-label-illegal-re label) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
207 (message "Label \"%s\" contains illegal characters" label) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
208 (ding) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
209 (sit-for 2)) |
25280 | 210 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
211 ;; Look it up in the label list |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
212 ((setq entry (assoc label |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
213 (symbol-value reftex-docstruct-symbol))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
214 (ding) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
215 (if (y-or-n-p |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
216 (format "Label '%s' exists. Use anyway? " label)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
217 (setq valid t))) |
25280 | 218 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
219 ;; Label is ok |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
220 (t |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
221 (setq valid t)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
222 (setq label default)) |
25280 | 223 |
224 ;; Insert the label into the label list | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
225 (let* ((here-I-am-info |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
226 (save-excursion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
227 (if (and (or naked no-insert) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
228 (integerp (cdr macro-cell))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
229 (goto-char (cdr macro-cell))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
230 (reftex-where-am-I))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
231 (here-I-am (car here-I-am-info)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
232 (note (if (cdr here-I-am-info) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
233 "" |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
234 "POSITION UNCERTAIN. RESCAN TO FIX.")) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
235 (file (buffer-file-name)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
236 (text nil) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
237 (tail (memq here-I-am (symbol-value reftex-docstruct-symbol)))) |
25280 | 238 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
239 (or (cdr here-I-am-info) (setq rescan-is-useful t)) |
25280 | 240 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
241 (when tail |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
242 (push (list label typekey text file nil note) (cdr tail)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
243 (put reftex-docstruct-symbol 'modified t))) |
25280 | 244 |
245 ;; Insert the label into the buffer | |
246 (unless no-insert | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
247 (insert |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
248 (if reftex-format-label-function |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
249 (funcall reftex-format-label-function label format) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
250 (format format label))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
251 (if (and reftex-plug-into-AUCTeX |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
252 (fboundp 'LaTeX-add-labels)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
253 ;; Tell AUCTeX about this |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
254 (LaTeX-add-labels label))) |
25280 | 255 |
256 ;; Delete the corresponding selection buffers to force update on next use. | |
257 (when reftex-auto-update-selection-buffers | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
258 (reftex-erase-buffer (reftex-make-selection-buffer-name typekey)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
259 (reftex-erase-buffer (reftex-make-selection-buffer-name " "))) |
25280 | 260 |
261 (when (and rescan-is-useful reftex-allow-automatic-rescan) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
262 (reftex-parse-one)) |
25280 | 263 |
264 ;; return value of the function is the label | |
265 label))) | |
266 | |
267 (defun reftex-string-to-label (string) | |
268 "Convert a string (a sentence) to a label. | |
269 Uses `reftex-derive-label-parameters' and `reftex-label-illegal-re'. It | |
270 also applies `reftex-translate-to-ascii-function' to the string." | |
271 (when (and reftex-translate-to-ascii-function | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
272 (fboundp reftex-translate-to-ascii-function)) |
25280 | 273 (setq string (funcall reftex-translate-to-ascii-function string))) |
274 (apply 'reftex-convert-string string | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
275 "[-~ \t\n\r,;]+" reftex-label-illegal-re nil nil |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
276 reftex-derive-label-parameters)) |
25280 | 277 |
278 (defun reftex-latin1-to-ascii (string) | |
279 ;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents | |
280 (let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy") | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
281 (emacsp (not (featurep 'xemacs)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
282 (mapconcat |
25280 | 283 (lambda (c) |
284 (cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1 | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
285 (char-to-string (aref tab (- c 128)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
286 ((and emacsp ; Not for XEmacs |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
287 (> c 2175) (< c 2304)) ; Mule Latin-1 |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
288 (char-to-string (aref tab (- c 2176)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
289 (t (char-to-string c)))) |
25280 | 290 string ""))) |
291 | |
292 (defun reftex-replace-prefix-escapes (prefix) | |
293 ;; Replace %escapes in a label prefix | |
294 (save-match-data | |
295 (let (letter (num 0) replace) | |
296 (while (string-match "\\%\\([a-zA-Z]\\)" prefix num) | |
297 (setq letter (match-string 1 prefix)) | |
298 (setq replace | |
299 (cond | |
300 ((equal letter "f") | |
301 (file-name-sans-extension | |
302 (file-name-nondirectory (buffer-file-name)))) | |
303 ((equal letter "F") | |
304 (let ((masterdir (file-name-directory (reftex-TeX-master-file))) | |
305 (file (file-name-sans-extension (buffer-file-name)))) | |
306 (if (string-match (concat "\\`" (regexp-quote masterdir)) | |
307 file) | |
308 (substring file (length masterdir)) | |
309 file))) | |
310 ((equal letter "u") | |
311 (or (user-login-name) "")) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
312 ((equal letter "S") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
313 (let* (macro level-exp level) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
314 (save-excursion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
315 (save-match-data |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
316 (when (re-search-backward reftex-section-regexp nil t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
317 (setq macro (reftex-match-string 2) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
318 level-exp (cdr (assoc macro reftex-section-levels-all)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
319 level (if (symbolp level-exp) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
320 (abs (save-match-data |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
321 (funcall level-exp))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
322 (abs level-exp)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
323 (cdr (or (assoc macro reftex-section-prefixes) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
324 (assoc level reftex-section-prefixes) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
325 (assq t reftex-section-prefixes) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
326 (list t "sec:"))))))) |
25280 | 327 (t ""))) |
328 (setq num (1- (+ (match-beginning 1) (length replace))) | |
329 prefix (replace-match replace nil nil prefix))) | |
330 prefix))) | |
331 | |
332 (defun reftex-uniquify-label (label &optional force separator) | |
333 ;; Make label unique by appending a number. | |
334 ;; Optional FORCE means, force appending a number, even if label is unique. | |
335 ;; Optional SEPARATOR is a string to stick between label and number. | |
336 | |
337 ;; Ensure access to scanning info | |
338 (reftex-access-scan-info) | |
339 | |
340 (cond | |
341 ((and (not force) | |
342 (not (assoc label (symbol-value reftex-docstruct-symbol)))) | |
343 label) | |
344 (t | |
345 (let* ((label-numbers (assq 'label-numbers | |
346 (symbol-value reftex-docstruct-symbol))) | |
347 (label-numbers-alist (cdr label-numbers)) | |
348 (cell (or (assoc label label-numbers-alist) | |
349 (car (setcdr label-numbers | |
350 (cons (cons label 0) | |
351 label-numbers-alist))))) | |
352 (num (1+ (cdr cell))) | |
353 (sep (or separator ""))) | |
354 (while (assoc (concat label sep (int-to-string num)) | |
355 (symbol-value reftex-docstruct-symbol)) | |
356 (incf num)) | |
357 (setcdr cell num) | |
358 (concat label sep (int-to-string num)))))) | |
359 | |
360 ;;; Referencing labels ------------------------------------------------------ | |
361 | |
362 ;; Help string for the reference label menu | |
363 (defconst reftex-select-label-prompt | |
364 "Select: [n]ext [p]revious [r]escan [ ]context e[x]tern [q]uit RET [?]HELP+more") | |
365 | |
366 (defconst reftex-select-label-help | |
367 " n / p Go to next/previous label (Cursor motion works as well) | |
368 C-c C-n/p Go to next/previous section heading. | |
369 b / l Jump back to previous selection / Reuse last referenced label. | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
370 z Jump to a specific section, e.g. '3 z' jumps to section 3. |
25280 | 371 g / s Update menu / Switch label type. |
372 r / C-u r Reparse document / Reparse entire document. | |
373 x Switch to label menu of external document (with LaTeX package `xr'). | |
374 F t c Toggle: [F]ile borders, [t]able of contents, [c]ontext | |
375 # % Toggle: [#] label counters, [%] labels in comments | |
376 SPC / f Show full context in other window / Toggle follow mode. | |
377 . Show insertion point in other window. | |
378 v / V Toggle \\ref <-> \\vref / Rotate \\ref <=> \\fref <=> \\Fref | |
379 TAB Enter a label with completion. | |
380 m , - + Mark entry. `,-+' also assign a separator. | |
381 a / A Put all marked entries into one/many \\ref commands. | |
382 q / RET Quit without referencing / Accept current label (also on mouse-2).") | |
383 | |
384 (defun reftex-reference (&optional type no-insert cut) | |
385 "Make a LaTeX reference. Look only for labels of a certain TYPE. | |
386 With prefix arg, force to rescan buffer for labels. This should only be | |
387 necessary if you have recently entered labels yourself without using | |
388 reftex-label. Rescanning of the buffer can also be requested from the | |
389 label selection menu. | |
390 The function returns the selected label or nil. | |
391 If NO-INSERT is non-nil, do not insert \\ref command, just return label. | |
392 When called with 2 C-u prefix args, disable magic word recognition." | |
393 | |
394 (interactive) | |
395 | |
396 ;; check for active recursive edits | |
397 (reftex-check-recursive-edit) | |
398 | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
399 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4) |
25280 | 400 (reftex-access-scan-info current-prefix-arg) |
401 | |
402 (unless type | |
403 ;; guess type from context | |
404 (if (and reftex-guess-label-type | |
405 (setq type (reftex-guess-label-type))) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
406 (setq cut (cdr type) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
407 type (car type)) |
25280 | 408 (setq type (reftex-query-label-type)))) |
409 | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
410 (let* ((refstyle |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
411 (cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
412 ((reftex-typekey-check type reftex-fref-is-default) "\\fref") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
413 (t "\\ref"))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
414 (reftex-format-ref-function reftex-format-ref-function) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
415 (form "\\ref{%s}") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
416 label labels sep sep1) |
25280 | 417 |
418 ;; Have the user select a label | |
419 (set-marker reftex-select-return-marker (point)) | |
420 (setq labels (save-excursion | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
421 (reftex-offer-label-menu type))) |
25280 | 422 (reftex-ensure-compiled-variables) |
423 (set-marker reftex-select-return-marker nil) | |
47050
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
424 ;; If the first entry is the symbol 'concat, concat all labels. |
25280 | 425 ;; We keep the cdr of the first label for typekey etc information. |
426 (if (eq (car labels) 'concat) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
427 (setq labels (list (list (mapconcat 'car (cdr labels) ",") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
428 (cdr (nth 1 labels)))))) |
25280 | 429 (setq type (nth 1 (car labels)) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
430 form (or (cdr (assoc type reftex-typekey-to-format-alist)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
431 form)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
432 |
25280 | 433 (cond |
434 (no-insert | |
435 ;; Just return the first label | |
436 (car (car labels))) | |
437 ((null labels) | |
438 (message "Quit") | |
439 nil) | |
440 (t | |
441 (while labels | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
442 (setq label (car (car labels)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
443 sep (nth 2 (car labels)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
444 sep1 (cdr (assoc sep reftex-multiref-punctuation)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
445 labels (cdr labels)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
446 (when cut |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
447 (backward-delete-char cut) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
448 (setq cut nil)) |
25280 | 449 |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
450 ;; remove ~ if we do already have a space |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
451 (when (and (= ?~ (string-to-char form)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
452 (member (preceding-char) '(?\ ?\t ?\n ?. ?~))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
453 (setq form (substring form 1))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
454 ;; do we have a special format? |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
455 (setq reftex-format-ref-function |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
456 (cond |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
457 ((string= refstyle "\\vref") 'reftex-format-vref) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
458 ((string= refstyle "\\fref") 'reftex-format-fref) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
459 ((string= refstyle "\\Fref") 'reftex-format-Fref) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
460 (t reftex-format-ref-function))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
461 ;; ok, insert the reference |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
462 (if sep1 (insert sep1)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
463 (insert |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
464 (if reftex-format-ref-function |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
465 (funcall reftex-format-ref-function label form) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
466 (format form label label))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
467 ;; take out the initial ~ for good |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
468 (and (= ?~ (string-to-char form)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
469 (setq form (substring form 1)))) |
25280 | 470 (message "") |
471 label)))) | |
472 | |
473 (defun reftex-guess-label-type () | |
474 ;; Examine context to guess what a \ref might want to reference. | |
475 (let ((words reftex-words-to-typekey-alist) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
476 (case-fold-search t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
477 (bound (max (point-min) (- (point) 35))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
478 matched cell) |
25280 | 479 (save-excursion |
480 (while (and (setq cell (pop words)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
481 (not (setq matched |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
482 (re-search-backward (car cell) bound t)))))) |
25280 | 483 (if matched |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
484 (cons (cdr cell) (- (match-end 0) (match-end 1))) |
25280 | 485 nil))) |
486 | |
487 (defvar reftex-select-label-map) | |
488 (defun reftex-offer-label-menu (typekey) | |
489 ;; Offer a menu with the appropriate labels. | |
490 (let* ((buf (current-buffer)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
491 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
492 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
493 (xr-index 0) |
25280 | 494 (here-I-am (car (reftex-where-am-I))) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
495 (here-I-am1 here-I-am) |
25280 | 496 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0)) |
497 (files (reftex-typekey-check typekey reftex-label-menu-flags 7)) | |
498 (context (not (reftex-typekey-check | |
499 typekey reftex-label-menu-flags 3))) | |
500 (counter (reftex-typekey-check | |
501 typekey reftex-label-menu-flags 2)) | |
502 (follow (reftex-typekey-check | |
503 typekey reftex-label-menu-flags 4)) | |
504 (commented (nth 5 reftex-label-menu-flags)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
505 (prefix "") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
506 selection-buffers |
25280 | 507 offset rtn key data last-data entries) |
508 | |
509 (unwind-protect | |
510 (catch 'exit | |
511 (while t | |
512 (save-window-excursion | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
513 (delete-other-windows) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
514 (setq reftex-call-back-to-this-buffer buf |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
515 reftex-latex-syntax-table (syntax-table)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
516 (let ((default-major-mode 'reftex-select-label-mode)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
517 (if reftex-use-multiple-selection-buffers |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
518 (switch-to-buffer-other-window |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
519 (save-excursion |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
520 (set-buffer buf) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
521 (reftex-make-selection-buffer-name typekey))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
522 (switch-to-buffer-other-window "*RefTeX Select*") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
523 (reftex-erase-buffer))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
524 (unless (eq major-mode 'reftex-select-label-mode) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
525 (reftex-select-label-mode)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
526 (add-to-list 'selection-buffers (current-buffer)) |
25280 | 527 (setq truncate-lines t) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
528 (setq mode-line-format |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
529 (list "---- " 'mode-line-buffer-identification |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
530 " " 'global-mode-string " (" mode-name ")" |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
531 " S<" 'refstyle ">" |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
532 " -%-")) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
533 (cond |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
534 ((= 0 (buffer-size)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
535 (let ((buffer-read-only nil)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
536 (message "Creating Selection Buffer...") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
537 (setq offset (reftex-insert-docstruct |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
538 buf |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
539 toc |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
540 typekey |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
541 nil ; index |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
542 files |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
543 context |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
544 counter |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
545 commented |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
546 (or here-I-am offset) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
547 prefix |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
548 nil ; no a toc buffer |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
549 )))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
550 (here-I-am |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
551 (setq offset (reftex-get-offset buf here-I-am typekey))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
552 (t (setq offset t))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
553 (setq buffer-read-only t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
554 (setq offset (or offset t)) |
25280 | 555 |
556 (setq here-I-am nil) ; turn off determination of offset | |
557 (setq rtn | |
558 (reftex-select-item | |
559 reftex-select-label-prompt | |
560 reftex-select-label-help | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
561 reftex-select-label-map |
25280 | 562 offset |
563 'reftex-show-label-location follow)) | |
564 (setq key (car rtn) | |
565 data (nth 1 rtn) | |
566 last-data (nth 2 rtn) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
567 offset t) |
25280 | 568 (unless key (throw 'exit nil)) |
569 (cond | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
570 ((eq key ?g) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
571 ;; update buffer |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
572 (reftex-erase-buffer)) |
25280 | 573 ((or (eq key ?r) |
574 (eq key ?R)) | |
575 ;; rescan buffer | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
576 (and current-prefix-arg (setq key ?R)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
577 (reftex-erase-buffer) |
25280 | 578 (reftex-reparse-document buf last-data key)) |
579 ((eq key ?c) | |
580 ;; toggle context mode | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
581 (reftex-erase-buffer) |
25280 | 582 (setq context (not context))) |
583 ((eq key ?s) | |
584 ;; switch type | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
585 (setq here-I-am here-I-am1) |
25280 | 586 (setq typekey (reftex-query-label-type))) |
587 ((eq key ?t) | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
588 ;; toggle table of contents display, or change depth |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
589 (reftex-erase-buffer) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
590 (if current-prefix-arg |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
591 (setq reftex-toc-max-level (prefix-numeric-value |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
592 current-prefix-arg)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
593 (setq toc (not toc)))) |
25280 | 594 ((eq key ?F) |
595 ;; toggle display of included file borders | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
596 (reftex-erase-buffer) |
25280 | 597 (setq files (not files))) |
598 ((eq key ?#) | |
599 ;; toggle counter display | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
600 (reftex-erase-buffer) |
25280 | 601 (setq counter (not counter))) |
602 ((eq key ?%) | |
603 ;; toggle display of commented labels | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
604 (reftex-erase-buffer) |
25280 | 605 (setq commented (not commented))) |
606 ((eq key ?l) | |
607 ;; reuse the last referenced label again | |
608 (setq entries reftex-last-used-reference) | |
609 (throw 'exit t)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
610 ((eq key ?x) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
611 ;; select an external document |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
612 (setq xr-index (reftex-select-external-document |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
613 xr-alist xr-index)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
614 (setq buf (or (reftex-get-file-buffer-force |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
615 (cdr (nth xr-index xr-alist))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
616 (error "Cannot switch document")) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
617 prefix (or (car (nth xr-index xr-alist)) "")) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
618 (set-buffer buf) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
619 (reftex-access-scan-info)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
620 ((stringp key) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
621 (setq entries |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
622 (list |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
623 (list |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
624 (or (assoc key (symbol-value reftex-docstruct-symbol)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
625 (list key typekey))))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
626 (throw 'exit t)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
627 ((memq key '(?a ?A return)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
628 (cond |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
629 (reftex-select-marked |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
630 (setq entries (nreverse reftex-select-marked))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
631 (data |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
632 (setq entries (list (list data)))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
633 (t (setq entries nil))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
634 (when entries |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
635 (if (equal key ?a) (push 'concat entries)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
636 (setq reftex-last-used-reference entries)) |
25280 | 637 (set-buffer buf) |
638 (throw 'exit t)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
639 (t (error "This should not happen (reftex-offer-label-menu)")))))) |
25280 | 640 (save-excursion |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
641 (while reftex-buffers-with-changed-invisibility |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
642 (set-buffer (car (car reftex-buffers-with-changed-invisibility))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
643 (setq buffer-invisibility-spec |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
644 (cdr (pop reftex-buffers-with-changed-invisibility))))) |
25280 | 645 (mapcar (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf))) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
646 selection-buffers) |
25280 | 647 (reftex-kill-temporary-buffers)) |
648 ;; Add the prefixes, put together the relevant information in the form | |
46683
060f433ebf11
Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents:
46612
diff
changeset
|
649 ;; (LABEL TYPEKEY SEPARATOR) and return a list of those. |
25280 | 650 (mapcar (lambda (x) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
651 (if (listp x) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
652 (list (concat prefix (car (car x))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
653 (nth 1 (car x)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
654 (nth 2 x)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
655 x)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
656 entries))) |
25280 | 657 |
658 (defun reftex-reparse-document (&optional buffer data key) | |
659 ;; Rescan the document. | |
660 (save-window-excursion | |
661 (save-excursion | |
662 (if buffer | |
663 (if (not (bufferp buffer)) | |
664 (error "No such buffer %s" (buffer-name buffer)) | |
665 (set-buffer buffer))) | |
666 (let ((arg (if (eq key ?R) '(16) '(4))) | |
667 (file (nth 3 data))) | |
668 (reftex-access-scan-info arg file))))) | |
669 | |
670 (defun reftex-query-label-type () | |
671 ;; Ask for label type | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
672 (let ((key (reftex-select-with-char |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
673 reftex-type-query-prompt reftex-type-query-help 3))) |
25280 | 674 (unless (member (char-to-string key) reftex-typekey-list) |
675 (error "No such label type: %s" (char-to-string key))) | |
676 (char-to-string key))) | |
677 | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
678 (defun reftex-show-label-location (data forward no-revisit |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
679 &optional stay error) |
25280 | 680 ;; View the definition site of a label in another window. |
681 ;; DATA is an entry from the docstruct list. | |
682 ;; FORWARD indicates if the label is likely forward from current point. | |
683 ;; NO-REVISIT means do not load a file to show this label. | |
684 ;; STAY means leave the new window selected. | |
685 ;; ERROR means throw an error exception when the label cannot be found. | |
686 ;; If ERROR is nil, the return value of this function indicates success. | |
687 (let* ((this-window (selected-window)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
688 (errorf (if error 'error 'message)) |
25280 | 689 label file buffer re found) |
690 | |
691 (catch 'exit | |
692 (setq label (nth 0 data) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
693 file (nth 3 data)) |
25280 | 694 |
695 (unless file | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
696 (funcall errorf "Unknown label - reparse might help") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
697 (throw 'exit nil)) |
25280 | 698 |
699 ;; Goto the file in another window | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
700 (setq buffer |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
701 (if no-revisit |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
702 (reftex-get-buffer-visiting file) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
703 (reftex-get-file-buffer-force |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
704 file (not reftex-keep-temporary-buffers)))) |
25280 | 705 (if buffer |
706 ;; good - the file is available | |
707 (switch-to-buffer-other-window buffer) | |
708 ;; we have got a problem here. The file does not exist. | |
709 ;; Let' get out of here.. | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
710 (funcall errorf "Label %s not found" label) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
711 (throw 'exit nil)) |
25280 | 712 |
713 ;; search for that label | |
714 (setq re (format reftex-find-label-regexp-format (regexp-quote label))) | |
715 (setq found | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
716 (if forward |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
717 (re-search-forward re nil t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
718 (re-search-backward re nil t))) |
25280 | 719 (unless found |
720 (goto-char (point-min)) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
721 (unless (setq found (re-search-forward re nil t)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
722 ;; Ooops. Must be in a macro with distributed args. |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
723 (setq found |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
724 (re-search-forward |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
725 (format reftex-find-label-regexp-format2 |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
726 (regexp-quote label)) nil t)))) |
25280 | 727 (if (match-end 3) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
728 (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
729 (reftex-highlight 0 (match-beginning 3) (match-end 3)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
730 (reftex-show-entry (match-beginning 3) (match-end 3)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
731 (recenter '(4)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
732 (unless stay (select-window this-window))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
733 (select-window this-window) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
734 (funcall errorf "Label %s not found" label)) |
25280 | 735 found))) |
736 | |
737 (defvar font-lock-mode) | |
738 (defun reftex-show-entry (beg-hlt end-hlt) | |
739 ;; Show entry if point is hidden | |
740 (let* ((n (/ (reftex-window-height) 2)) | |
741 (beg (save-excursion | |
742 (re-search-backward "[\n\r]" nil 1 n) (point))) | |
743 (end (save-excursion | |
744 (re-search-forward "[\n\r]" nil 1 n) (point)))) | |
745 (cond | |
746 ((and (boundp 'buffer-invisibility-spec) buffer-invisibility-spec | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
747 (get-char-property (1+ beg-hlt) 'invisible)) |
25280 | 748 ;; Invisible with text properties. That is easy to change. |
749 (push (cons (current-buffer) buffer-invisibility-spec) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
750 reftex-buffers-with-changed-invisibility) |
25280 | 751 (setq buffer-invisibility-spec nil)) |
752 ((string-match "\r" (buffer-substring beg end)) | |
753 ;; Invisible with selective display. We need to copy it. | |
754 (let ((string (buffer-substring-no-properties beg end))) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
755 (switch-to-buffer "*RefTeX Context Copy*") |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
756 (setq buffer-read-only nil) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
757 (erase-buffer) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
758 (insert string) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
759 (subst-char-in-region (point-min) (point-max) ?\r ?\n t) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
760 (goto-char (- beg-hlt beg)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
761 (reftex-highlight 0 (1+ (- beg-hlt beg)) (1+ (- end-hlt beg))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
762 (if (reftex-refontify) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
763 (when (or (not (eq major-mode 'latex-mode)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
764 (not font-lock-mode)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
765 (latex-mode) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
766 (run-hook-with-args |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
767 'reftex-pre-refontification-functions |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
768 reftex-call-back-to-this-buffer 'reftex-hidden) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
769 (turn-on-font-lock)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
770 (when (or (not (eq major-mode 'fundamental-mode)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
771 font-lock-mode) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
772 (fundamental-mode))) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
773 (run-hooks 'reftex-display-copied-context-hook) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
774 (setq buffer-read-only t)))))) |
25280 | 775 |
776 (defun reftex-varioref-vref () | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
777 "Insert a reference using the `\\vref' macro from the varioref package." |
25280 | 778 (interactive) |
779 (let ((reftex-format-ref-function 'reftex-format-vref)) | |
780 (reftex-reference))) | |
781 (defun reftex-fancyref-fref () | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
782 "Insert a reference using the `\\fref' macro from the fancyref package." |
25280 | 783 (interactive) |
784 (let ((reftex-format-ref-function 'reftex-format-fref) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
785 ;;(reftex-guess-label-type nil) ;FIXME do we want this???? |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
786 ) |
25280 | 787 (reftex-reference))) |
788 (defun reftex-fancyref-Fref () | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
789 "Insert a reference using the `\\Fref' macro from the fancyref package." |
25280 | 790 (interactive) |
791 (let ((reftex-format-ref-function 'reftex-format-Fref) | |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
792 ;;(reftex-guess-label-type nil) ;FIXME do we want this???? |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
793 ) |
25280 | 794 (reftex-reference))) |
795 | |
796 (defun reftex-format-vref (label fmt) | |
797 (while (string-match "\\\\ref{" fmt) | |
798 (setq fmt (replace-match "\\vref{" t t fmt))) | |
799 (format fmt label label)) | |
800 (defun reftex-format-Fref (label def-fmt) | |
801 (format "\\Fref{%s}" label)) | |
802 (defun reftex-format-fref (label def-fmt) | |
803 (format "\\fref{%s}" label)) | |
804 | |
47050
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
805 (defun reftex-goto-label (&optional other-window) |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
806 "Prompt for a label (with completion) and jump to the location of this label. |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
807 Optional prefix argument OTHER-WINDOW goes to the label in another window." |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
808 (interactive "P") |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
809 (reftex-access-scan-info) |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
810 (let* ((wcfg (current-window-configuration)) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
811 (docstruct (symbol-value reftex-docstruct-symbol)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
812 (label (completing-read "Label: " docstruct |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
813 (lambda (x) (stringp (car x))) t)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
814 (selection (assoc label docstruct)) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
815 (where (progn |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
816 (reftex-show-label-location selection t nil 'stay) |
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
817 (point-marker)))) |
47050
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
818 (unless other-window |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
819 (set-window-configuration wcfg) |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
820 (switch-to-buffer (marker-buffer where)) |
52170
27340819ef07
Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents:
50978
diff
changeset
|
821 (goto-char where)) |
47050
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
822 (reftex-unhighlight 0))) |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
823 |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
824 |
904fd28be439
Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents:
46683
diff
changeset
|
825 |
52401 | 826 ;;; arch-tag: 52f14032-fb76-4d31-954f-750c72415675 |
25280 | 827 ;;; reftex-ref.el ends here |