Mercurial > emacs
annotate lisp/textmodes/reftex-sel.el @ 41571:2902b21d2034
(outline-version, outline-open-topic)
(outline-rebullet-heading, outline-insert-listified)
(outline-latex-verbatim-quote-curr-line)
(outline-latexify-one-item, outlineify-sticky): Use insert instead of
insert-string.
author | Pavel Janík <Pavel@Janik.cz> |
---|---|
date | Mon, 26 Nov 2001 16:23:06 +0000 |
parents | 7a94f1c588c4 |
children | 1d0fea9f9515 |
rev | line source |
---|---|
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37998
diff
changeset
|
1 ;;; reftex-sel.el --- the selection modes for 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 | 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 | 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-sel) |
30 (require 'reftex) | |
31 ;;; | |
32 | |
33 (defvar reftex-select-label-map nil | |
34 "Keymap used for *RefTeX Select* buffer, when selecting a label. | |
35 This keymap can be used to configure the label selection process which is | |
36 started with the command \\[reftex-reference].") | |
37 | |
38 (defun reftex-select-label-mode () | |
39 "Major mode for selecting a label in a LaTeX document. | |
40 This buffer was created with RefTeX. | |
41 It only has a meaningful keymap when you are in the middle of a | |
42 selection process. | |
43 To select a label, move the cursor to it and press RET. | |
44 Press `?' for a summary of important key bindings. | |
45 | |
46 During a selection process, these are the local bindings. | |
47 | |
48 \\{reftex-select-label-map}" | |
49 | |
50 (interactive) | |
51 (kill-all-local-variables) | |
52 (make-local-hook 'pre-command-hook) | |
53 (make-local-hook 'post-command-hook) | |
54 (setq major-mode 'reftex-select-label-mode | |
55 mode-name "LSelect") | |
56 (set (make-local-variable 'reftex-select-marked) nil) | |
57 (when (syntax-table-p reftex-latex-syntax-table) | |
58 (set-syntax-table reftex-latex-syntax-table)) | |
59 ;; We do not set a local map - reftex-select-item does this. | |
60 (run-hooks 'reftex-select-label-mode-hook)) | |
61 | |
62 (defvar reftex-select-bib-map nil | |
63 "Keymap used for *RefTeX Select* buffer, when selecting a BibTeX entry. | |
64 This keymap can be used to configure the BibTeX selection process which is | |
65 started with the command \\[reftex-citation].") | |
66 | |
67 (defun reftex-select-bib-mode () | |
68 "Major mode for selecting a citation key in a LaTeX document. | |
69 This buffer was created with RefTeX. | |
70 It only has a meaningful keymap when you are in the middle of a | |
71 selection process. | |
72 In order to select a citation, move the cursor to it and press RET. | |
73 Press `?' for a summary of important key bindings. | |
74 | |
75 During a selection process, these are the local bindings. | |
76 | |
77 \\{reftex-select-label-map}" | |
78 (interactive) | |
79 (kill-all-local-variables) | |
80 (make-local-hook 'pre-command-hook) | |
81 (make-local-hook 'post-command-hook) | |
82 (setq major-mode 'reftex-select-bib-mode | |
83 mode-name "BSelect") | |
84 (set (make-local-variable 'reftex-select-marked) nil) | |
85 ;; We do not set a local map - reftex-select-item does this. | |
86 (run-hooks 'reftex-select-bib-mode-hook)) | |
87 | |
88 (defun reftex-get-offset (buf here-am-I &optional typekey toc index file) | |
89 ;; Find the correct offset data, like insert-docstruct would, but faster. | |
90 ;; Buffer BUF knows the correct docstruct to use. | |
91 ;; Basically this finds the first docstruct entry after HERE-I-AM which | |
92 ;; is of allowed type. The optional arguments specify what is allowed. | |
93 (catch 'exit | |
94 (save-excursion | |
95 (set-buffer buf) | |
96 (reftex-access-scan-info) | |
97 (let* ((rest (memq here-am-I (symbol-value reftex-docstruct-symbol))) | |
98 entry) | |
99 (while (setq entry (pop rest)) | |
100 (if (or (and typekey | |
101 (stringp (car entry)) | |
102 (or (equal typekey " ") | |
103 (equal typekey (nth 1 entry)))) | |
104 (and toc (eq (car entry) 'toc)) | |
105 (and index (eq (car entry) 'index)) | |
106 (and file | |
107 (memq (car entry) '(bof eof file-error)))) | |
108 (throw 'exit entry))) | |
109 nil)))) | |
110 | |
111 (defun reftex-insert-docstruct | |
112 (buf toc labels index-entries files context counter show-commented | |
113 here-I-am xr-prefix toc-buffer) | |
114 ;; Insert an excerpt of the docstruct list. | |
115 ;; Return the data property of the entry corresponding to HERE-I-AM. | |
116 ;; BUF is the buffer which has the correct docstruct-symbol. | |
117 ;; LABELS non-nil means to include labels into the list. | |
118 ;; When a string, indicates the label type to include | |
34402
5eec8d1d09f0
Update to RefTeX 4.15, see ChangeLog for details
Carsten Dominik <dominik@science.uva.nl>
parents:
29775
diff
changeset
|
119 ;; FILES non-nil means to display file boundaries. |
25280 | 120 ;; CONTEXT non-nil means to include label context. |
121 ;; COUNTER means to count the labels. | |
122 ;; SHOW-COMMENTED means to include also labels which are commented out. | |
123 ;; HERE-I-AM is a member of the docstruct list. The function will return | |
124 ;; a used member near to this one, as a possible starting point. | |
125 ;; XR-PREFIX is the prefix to put in front of labels. | |
126 ;; TOC-BUFFER means this is to fill the toc buffer. | |
127 (let* ((font (reftex-use-fonts)) | |
128 (cnt 0) | |
129 (index -1) | |
130 (toc-indent " ") | |
131 (label-indent | |
132 (concat "> " | |
133 (if toc (make-string (* 7 reftex-level-indent) ?\ ) ""))) | |
134 (context-indent | |
135 (concat ". " | |
136 (if toc (make-string (* 7 reftex-level-indent) ?\ ) ""))) | |
137 (mouse-face | |
138 (if (memq reftex-highlight-selection '(mouse both)) | |
139 reftex-mouse-selected-face | |
140 nil)) | |
141 (label-face (reftex-verified-face reftex-label-face | |
142 'font-lock-constant-face | |
143 'font-lock-reference-face)) | |
144 (index-face (reftex-verified-face reftex-index-face | |
145 'font-lock-constant-face | |
146 'font-lock-reference-face)) | |
147 all cell text label typekey note comment master-dir-re | |
148 offset from to index-tag docstruct-symbol) | |
149 | |
150 ;; Pop to buffer buf to get the correct buffer-local variables | |
151 (save-excursion | |
152 (set-buffer buf) | |
153 | |
154 ;; Ensure access to scanning info | |
155 (reftex-access-scan-info) | |
156 | |
157 (setq docstruct-symbol reftex-docstruct-symbol | |
158 all (symbol-value reftex-docstruct-symbol) | |
159 reftex-active-toc nil | |
160 master-dir-re | |
161 (concat "\\`" (regexp-quote | |
162 (file-name-directory (reftex-TeX-master-file)))))) | |
163 | |
164 (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol) | |
165 (set (make-local-variable 'reftex-prefix) | |
166 (cdr (assoc labels reftex-typekey-to-prefix-alist))) | |
167 (if (equal reftex-prefix " ") (setq reftex-prefix nil)) | |
168 | |
169 ;; Walk the docstruct and insert the appropriate stuff | |
170 (while (setq cell (pop all)) | |
171 | |
172 (incf index) | |
173 (setq from (point)) | |
174 | |
175 (if (eq cell here-I-am) (setq offset 'attention)) | |
176 | |
177 (cond | |
178 | |
179 ((memq (car cell) '(bib thebib label-numbers appendix | |
180 master-dir bibview-cache is-multi xr xr-doc))) | |
181 ;; These are currently ignored | |
182 | |
183 ((memq (car cell) '(bof eof file-error)) | |
184 ;; Beginning or end of a file | |
185 (when files | |
186 (if (eq offset 'attention) (setq offset cell)) | |
187 (insert | |
188 " File " (if (string-match master-dir-re (nth 1 cell)) | |
189 (substring (nth 1 cell) (match-end 0)) | |
190 (nth 1 cell)) | |
191 (cond ((eq (car cell) 'bof) " starts here\n") | |
192 ((eq (car cell) 'eof) " ends here\n") | |
193 ((eq (car cell) 'file-error) " was not found\n"))) | |
194 (setq to (point)) | |
195 (when font | |
196 (put-text-property from to | |
197 'face reftex-file-boundary-face)) | |
198 (when toc-buffer | |
199 (if mouse-face | |
200 (put-text-property from (1- to) | |
201 'mouse-face mouse-face)) | |
202 (put-text-property from to :data cell)))) | |
203 | |
204 ((eq (car cell) 'toc) | |
205 ;; a table of contents entry | |
26910
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
206 (when (and toc |
489a5439b988
* reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents:
25806
diff
changeset
|
207 (<= (nth 5 cell) reftex-toc-max-level)) |
25280 | 208 (if (eq offset 'attention) (setq offset cell)) |
209 (setq reftex-active-toc cell) | |
210 (insert (concat toc-indent (nth 2 cell) "\n")) | |
211 (setq to (point)) | |
212 (when font | |
213 (put-text-property from to | |
214 'face reftex-section-heading-face)) | |
215 (when toc-buffer | |
216 (if mouse-face | |
217 (put-text-property from (1- to) | |
218 'mouse-face mouse-face)) | |
219 (put-text-property from to :data cell)) | |
220 (goto-char to))) | |
221 | |
222 ((stringp (car cell)) | |
223 ;; a label | |
224 (when (null (nth 2 cell)) | |
225 ;; No context yet. Quick update. | |
226 (setcdr cell (cdr (reftex-label-info-update cell))) | |
227 (put docstruct-symbol 'modified t)) | |
228 | |
229 (setq label (car cell) | |
230 typekey (nth 1 cell) | |
231 text (nth 2 cell) | |
232 comment (nth 4 cell) | |
233 note (nth 5 cell)) | |
234 | |
235 (when (and labels | |
236 (or (eq labels t) | |
237 (string= typekey labels) | |
238 (string= labels " ")) | |
239 (or show-commented (null comment))) | |
240 | |
241 ;; Yes we want this one | |
242 (incf cnt) | |
243 (if (eq offset 'attention) (setq offset cell)) | |
244 | |
245 (setq label (concat xr-prefix label)) | |
246 (when comment (setq label (concat "% " label))) | |
247 (insert label-indent label) | |
248 (when font | |
249 (setq to (point)) | |
250 (put-text-property | |
251 (- (point) (length label)) to | |
252 'face (if comment | |
253 'font-lock-comment-face | |
254 label-face)) | |
255 (goto-char to)) | |
256 | |
257 (insert (if counter (format " (%d) " cnt) "") | |
258 (if comment " LABEL IS COMMENTED OUT " "") | |
259 (if (stringp note) (concat " " note) "") | |
260 "\n") | |
261 (setq to (point)) | |
262 | |
263 (when context | |
264 (insert context-indent text "\n") | |
265 (setq to (point))) | |
266 (put-text-property from to :data cell) | |
267 (when mouse-face | |
268 (put-text-property from (1- to) | |
269 'mouse-face mouse-face)) | |
270 (goto-char to))) | |
271 | |
272 ((eq (car cell) 'index) | |
273 ;; index entry | |
274 (when (and index-entries | |
275 (or (eq t index-entries) | |
276 (string= index-entries (nth 1 cell)))) | |
277 (if (eq offset 'attention) (setq offset cell)) | |
278 (setq index-tag (format "<%s>" (nth 1 cell))) | |
279 (and font | |
280 (put-text-property 0 (length index-tag) | |
281 'face reftex-index-tag-face index-tag)) | |
282 (insert label-indent index-tag " " (nth 7 cell)) | |
283 | |
284 (when font | |
285 (setq to (point)) | |
286 (put-text-property | |
287 (- (point) (length (nth 7 cell))) to | |
288 'face index-face) | |
289 (goto-char to)) | |
290 (insert "\n") | |
291 (setq to (point)) | |
292 | |
293 (when context | |
294 (insert context-indent (nth 2 cell) "\n") | |
295 (setq to (point))) | |
296 (put-text-property from to :data cell) | |
297 (when mouse-face | |
298 (put-text-property from (1- to) | |
299 'mouse-face mouse-face)) | |
300 (goto-char to))))) | |
301 | |
302 (when (reftex-refontify) | |
303 ;; we need to fontify the buffer | |
304 (reftex-fontify-select-label-buffer buf)) | |
305 (run-hooks 'reftex-display-copied-context-hook) | |
306 offset)) | |
307 | |
308 (defun reftex-find-start-point (fallback &rest locations) | |
309 ;; Set point to the first available LOCATION. When a LOCATION is a list, | |
310 ;; search for such a :data text property. When it is an integer, | |
311 ;; use is as line number. FALLBACK is a buffer position used if everything | |
312 ;; else fails. | |
313 (catch 'exit | |
314 (goto-char (point-min)) | |
315 (let (loc pos) | |
316 (while locations | |
317 (setq loc (pop locations)) | |
318 (cond | |
319 ((null loc)) | |
320 ((listp loc) | |
321 (setq pos (text-property-any (point-min) (point-max) :data loc)) | |
322 (when pos | |
323 (goto-char pos) | |
324 (throw 'exit t))) | |
325 ((integerp loc) | |
326 (when (<= loc (count-lines (point-min) (point-max))) | |
327 (goto-line loc) | |
328 (throw 'exit t))))) | |
329 (goto-char fallback)))) | |
330 | |
331 (defvar reftex-last-data nil) | |
332 (defvar reftex-last-line nil) | |
333 (defvar reftex-select-marked nil) | |
334 | |
335 (defun reftex-select-item (prompt help-string keymap | |
336 &optional offset | |
337 call-back cb-flag) | |
338 ;; Select an item, using PROMPT. The function returns a key indicating | |
339 ;; an exit status, along with a data structure indicating which item was | |
340 ;; selected. | |
341 ;; HELP-STRING contains help. KEYMAP is a keymap with the available | |
342 ;; selection commands. | |
343 ;; OFFSET can be a label list item which will be selected at start. | |
344 ;; When it is t, point will start out at the beginning of the buffer. | |
345 ;; Any other value will cause restart where last selection left off. | |
346 ;; When CALL-BACK is given, it is a function which is called with the index | |
347 ;; of the element. | |
348 ;; CB-FLAG is the initial value of that flag. | |
349 | |
350 (let* (ev data last-data (selection-buffer (current-buffer))) | |
351 | |
352 (setq reftex-select-marked nil) | |
353 | |
354 (setq ev | |
355 (catch 'myexit | |
356 (save-window-excursion | |
357 (setq truncate-lines t) | |
358 | |
359 ;; Find a good starting point | |
360 (reftex-find-start-point | |
361 (point-min) offset reftex-last-data reftex-last-line) | |
362 (beginning-of-line 1) | |
363 (set (make-local-variable 'reftex-last-follow-point) (point)) | |
364 | |
365 (unwind-protect | |
366 (progn | |
367 (use-local-map keymap) | |
368 (add-hook 'pre-command-hook 'reftex-select-pre-command-hook nil t) | |
369 (add-hook 'post-command-hook 'reftex-select-post-command-hook nil t) | |
370 (princ prompt) | |
371 (set-marker reftex-recursive-edit-marker (point)) | |
372 ;; XEmacs does not run post-command-hook here | |
373 (and (featurep 'xemacs) (run-hooks 'post-command-hook)) | |
374 (recursive-edit)) | |
375 | |
376 (set-marker reftex-recursive-edit-marker nil) | |
377 (save-excursion | |
378 (set-buffer selection-buffer) | |
379 (use-local-map nil) | |
380 (remove-hook 'pre-command-hook 'reftex-select-pre-command-hook t) | |
381 (remove-hook 'post-command-hook | |
382 'reftex-select-post-command-hook t)) | |
383 ;; Kill the mark overlays | |
384 (mapcar (lambda (c) (delete-overlay (nth 1 c))) | |
385 reftex-select-marked))))) | |
386 | |
387 (set (make-local-variable 'reftex-last-line) | |
388 (+ (count-lines (point-min) (point)) (if (bolp) 1 0))) | |
389 (set (make-local-variable 'reftex-last-data) last-data) | |
390 (reftex-kill-buffer "*RefTeX Help*") | |
391 (setq reftex-callback-fwd (not reftex-callback-fwd)) ;; ;-))) | |
392 (message "") | |
393 (list ev data last-data))) | |
394 | |
395 ;; The following variables are all bound dynamically in `reftex-select-item'. | |
396 ;; The defvars are here only to silence the byte compiler. | |
397 | |
398 (defvar found-list) | |
399 (defvar cb-flag) | |
400 (defvar data) | |
401 (defvar prompt) | |
402 (defvar last-data) | |
403 (defvar call-back) | |
404 (defvar help-string) | |
405 (defvar refstyle) | |
406 | |
407 ;; The selection commands | |
408 | |
409 (defun reftex-select-pre-command-hook () | |
410 (reftex-unhighlight 1) | |
411 (reftex-unhighlight 0)) | |
412 | |
413 (defun reftex-select-post-command-hook () | |
414 (let (b e) | |
415 (setq data (get-text-property (point) :data)) | |
416 (setq last-data (or data last-data)) | |
417 | |
418 (when (and data cb-flag | |
419 (not (equal reftex-last-follow-point (point)))) | |
420 (setq reftex-last-follow-point (point)) | |
421 (funcall call-back data reftex-callback-fwd | |
422 (not reftex-revisit-to-follow))) | |
423 (if data | |
424 (setq b (or (previous-single-property-change | |
425 (1+ (point)) :data) | |
426 (point-min)) | |
427 e (or (next-single-property-change | |
428 (point) :data) | |
429 (point-max))) | |
430 (setq b (point) e (point))) | |
431 (and (memq reftex-highlight-selection '(cursor both)) | |
432 (reftex-highlight 1 b e)) | |
433 (if (or (not (pos-visible-in-window-p b)) | |
434 (not (pos-visible-in-window-p e))) | |
435 (recenter '(4))) | |
436 (unless (current-message) | |
437 (princ prompt)))) | |
438 | |
439 (defun reftex-select-next (&optional arg) | |
440 "Move to next selectable item." | |
441 (interactive "p") | |
442 (setq reftex-callback-fwd t) | |
443 (or (eobp) (forward-char 1)) | |
444 (re-search-forward "^[^. \t\n\r]" nil t arg) | |
445 (beginning-of-line 1)) | |
446 (defun reftex-select-previous (&optional arg) | |
447 "Move to previous selectable item." | |
448 (interactive "p") | |
449 (setq reftex-callback-fwd nil) | |
450 (re-search-backward "^[^. \t\n\r]" nil t arg)) | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
451 (defun reftex-select-jump (arg) |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
452 "Jump to a specific section. E.g. '3 z' jumps to section 3. |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
453 Useful for large TOC's." |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
454 (interactive "P") |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
455 (goto-char (point-min)) |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
456 (re-search-forward |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
457 (concat "^ *" (number-to-string (if (numberp arg) arg 1)) " ") |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
458 nil t) |
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
459 (beginning-of-line)) |
25280 | 460 (defun reftex-select-next-heading (&optional arg) |
461 "Move to next table of contentes line." | |
462 (interactive "p") | |
463 (end-of-line) | |
464 (re-search-forward "^ " nil t arg) | |
465 (beginning-of-line)) | |
466 (defun reftex-select-previous-heading (&optional arg) | |
467 "Move to previous table of contentes line." | |
468 (interactive "p") | |
469 (re-search-backward "^ " nil t arg)) | |
470 (defun reftex-select-quit () | |
471 "Abort selection process." | |
472 (interactive) | |
473 (throw 'myexit nil)) | |
474 (defun reftex-select-keyboard-quit () | |
475 "Abort selection process." | |
476 (interactive) | |
477 (throw 'exit t)) | |
478 (defun reftex-select-jump-to-previous () | |
479 "Jump back to where previous selection process left off." | |
480 (interactive) | |
481 (let (pos) | |
482 (cond | |
483 ((and (local-variable-p 'reftex-last-data (current-buffer)) | |
484 reftex-last-data | |
485 (setq pos (text-property-any (point-min) (point-max) | |
486 :data reftex-last-data))) | |
487 (goto-char pos)) | |
488 ((and (local-variable-p 'reftex-last-line (current-buffer)) | |
489 (integerp reftex-last-line)) | |
490 (goto-line reftex-last-line)) | |
491 (t (ding))))) | |
492 (defun reftex-select-toggle-follow () | |
493 "Toggle follow mode: Other window follows with full context." | |
494 (interactive) | |
495 (setq reftex-last-follow-point -1) | |
496 (setq cb-flag (not cb-flag))) | |
497 (defun reftex-select-toggle-varioref () | |
498 "Toggle the macro used for referencing the label between \\ref and \\vref." | |
499 (interactive) | |
500 (if (string= refstyle "\\ref") | |
501 (setq refstyle "\\vref") | |
502 (setq refstyle "\\ref")) | |
503 (force-mode-line-update)) | |
504 (defun reftex-select-toggle-fancyref () | |
505 "Toggle the macro used for referencing the label between \\ref and \\vref." | |
506 (interactive) | |
507 (setq refstyle | |
508 (cond ((string= refstyle "\\ref") "\\fref") | |
509 ((string= refstyle "\\fref") "\\Fref") | |
510 (t "\\ref"))) | |
511 (force-mode-line-update)) | |
512 (defun reftex-select-show-insertion-point () | |
513 "Show the point from where selection was started in another window." | |
514 (interactive) | |
515 (let ((this-window (selected-window))) | |
516 (unwind-protect | |
517 (progn | |
518 (switch-to-buffer-other-window | |
519 (marker-buffer reftex-select-return-marker)) | |
520 (goto-char (marker-position reftex-select-return-marker)) | |
521 (recenter '(4))) | |
522 (select-window this-window)))) | |
523 (defun reftex-select-callback () | |
524 "Show full context in another window." | |
525 (interactive) | |
526 (if data (funcall call-back data reftex-callback-fwd nil) (ding))) | |
527 (defun reftex-select-accept () | |
528 "Accept the currently selected item." | |
529 (interactive) | |
530 (throw 'myexit 'return)) | |
531 (defun reftex-select-mouse-accept (ev) | |
532 "Accept the item at the mouse click." | |
533 (interactive "e") | |
534 (mouse-set-point ev) | |
535 (setq data (get-text-property (point) :data)) | |
536 (setq last-data (or data last-data)) | |
537 (throw 'myexit 'return)) | |
538 (defun reftex-select-read-label () | |
539 "Use minibuffer to read a label to reference, with completion." | |
540 (interactive) | |
541 (let ((label (completing-read | |
542 "Label: " (symbol-value reftex-docstruct-symbol) | |
543 nil nil reftex-prefix))) | |
544 (unless (or (equal label "") (equal label reftex-prefix)) | |
545 (throw 'myexit label)))) | |
546 (defun reftex-select-read-cite () | |
547 "Use minibuffer to read a citation key with completion." | |
548 (interactive) | |
549 (let* ((key (completing-read "Citation key: " found-list)) | |
550 (entry (assoc key found-list))) | |
551 (cond | |
552 ((or (null key) (equal key ""))) | |
553 (entry | |
554 (setq data entry) | |
555 (setq last-data data) | |
556 (throw 'myexit 'return)) | |
557 (t (throw 'myexit key))))) | |
558 | |
559 (defun reftex-select-mark (&optional separator) | |
560 "Mark the entry." | |
561 (interactive) | |
562 (let* ((data (get-text-property (point) :data)) | |
563 boe eoe ovl) | |
564 (or data (error "No entry to mark at point")) | |
565 (if (assq data reftex-select-marked) | |
566 (error "Entry is already marked")) | |
567 (setq boe (or (previous-single-property-change (1+ (point)) :data) | |
568 (point-min)) | |
569 eoe (or (next-single-property-change (point) :data) (point-max))) | |
570 (setq ovl (make-overlay boe eoe)) | |
571 (push (list data ovl separator) reftex-select-marked) | |
572 (overlay-put ovl 'face reftex-select-mark-face) | |
573 (if (featurep 'xemacs) | |
574 ;; before-string property is broken in Emacs | |
575 (overlay-put ovl 'before-string | |
576 (if separator | |
577 (format "*%c%d* " separator | |
578 (length reftex-select-marked)) | |
579 (format "*%d* " (length reftex-select-marked))))) | |
580 (message "Entry has mark no. %d" (length reftex-select-marked)))) | |
581 | |
582 (defun reftex-select-mark-comma () | |
583 "Mark the entry and store the `comma' separator." | |
584 (interactive) | |
585 (reftex-select-mark ?,)) | |
586 (defun reftex-select-mark-to () | |
587 "Mark the entry and store the `to' separator." | |
588 (interactive) | |
589 (reftex-select-mark ?-)) | |
590 (defun reftex-select-mark-and () | |
591 "Mark the entry and store `and' to separator." | |
592 (interactive) | |
593 (reftex-select-mark ?+)) | |
594 | |
595 (defun reftex-select-unmark () | |
596 "Unmark the entry." | |
597 (interactive) | |
598 (let* ((data (get-text-property (point) :data)) | |
599 (cell (assq data reftex-select-marked)) | |
600 (ovl (nth 1 cell)) | |
601 (cnt 0) | |
602 sep) | |
603 (unless cell | |
604 (error "No marked entry at point")) | |
605 (and ovl (delete-overlay ovl)) | |
606 (setq reftex-select-marked (delq cell reftex-select-marked)) | |
607 (if (featurep 'xemacs) | |
608 ;; before-string property is broken in Emacs | |
609 (progn | |
610 (setq cnt (1+ (length reftex-select-marked))) | |
611 (mapcar (lambda (c) | |
612 (setq sep (nth 2 c)) | |
613 (overlay-put (nth 1 c) 'before-string | |
614 (if sep | |
615 (format "*%c%d* " sep (decf cnt)) | |
616 (format "*%d* " (decf cnt))))) | |
617 reftex-select-marked))) | |
618 (message "Entry no longer marked"))) | |
619 | |
620 (defun reftex-select-help () | |
621 "Display a summary of the special key bindings." | |
622 (interactive) | |
623 (with-output-to-temp-buffer "*RefTeX Help*" | |
624 (princ help-string)) | |
625 (reftex-enlarge-to-fit "*RefTeX Help*" t)) | |
626 | |
627 ;; Common bindings in reftex-select-label-map and reftex-select-bib-map | |
628 (let ((map (make-sparse-keymap))) | |
629 (substitute-key-definition | |
630 'next-line 'reftex-select-next map global-map) | |
631 (substitute-key-definition | |
632 'previous-line 'reftex-select-previous map global-map) | |
633 (substitute-key-definition | |
634 'keyboard-quit 'reftex-select-keyboard-quit map global-map) | |
635 (substitute-key-definition | |
636 'newline 'reftex-select-accept map global-map) | |
637 | |
638 (loop for x in | |
639 '((" " . reftex-select-callback) | |
640 ("n" . reftex-select-next) | |
641 ([(down)] . reftex-select-next) | |
642 ("p" . reftex-select-previous) | |
643 ([(up)] . reftex-select-previous) | |
644 ("f" . reftex-select-toggle-follow) | |
645 ("\C-m" . reftex-select-accept) | |
646 ([(return)] . reftex-select-accept) | |
647 ("q" . reftex-select-quit) | |
648 ("." . reftex-select-show-insertion-point) | |
649 ("?" . reftex-select-help)) | |
650 do (define-key map (car x) (cdr x))) | |
651 | |
652 ;; The mouse-2 binding | |
653 (if (featurep 'xemacs) | |
654 (define-key map [(button2)] 'reftex-select-mouse-accept) | |
655 (define-key map [(mouse-2)] 'reftex-select-mouse-accept)) | |
656 | |
657 ;; Digit arguments | |
658 (loop for key across "0123456789" do | |
659 (define-key map (vector (list key)) 'digit-argument)) | |
660 (define-key map "-" 'negative-argument) | |
661 | |
662 ;; Make two maps | |
663 (setq reftex-select-label-map map) | |
664 (setq reftex-select-bib-map (copy-keymap map))) | |
665 | |
666 ;; Specific bindings in reftex-select-label-map | |
667 (loop for key across "aAcgFlrRstx#%" do | |
668 (define-key reftex-select-label-map (vector (list key)) | |
669 (list 'lambda '() | |
670 "Press `?' during selection to find out about this key." | |
671 '(interactive) (list 'throw '(quote myexit) key)))) | |
672 | |
673 (loop for x in | |
674 '(("b" . reftex-select-jump-to-previous) | |
37998
706af946b1e7
* reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents:
34402
diff
changeset
|
675 ("z" . reftex-select-jump) |
25280 | 676 ("v" . reftex-select-toggle-varioref) |
677 ("V" . reftex-select-toggle-fancyref) | |
678 ("m" . reftex-select-mark) | |
679 ("u" . reftex-select-unmark) | |
680 ("," . reftex-select-mark-comma) | |
681 ("-" . reftex-select-mark-to) | |
682 ("+" . reftex-select-mark-and) | |
683 ([(tab)] . reftex-select-read-label) | |
684 ("\C-i" . reftex-select-read-label) | |
685 ("\C-c\C-n" . reftex-select-next-heading) | |
686 ("\C-c\C-p" . reftex-select-previous-heading)) | |
687 do | |
688 (define-key reftex-select-label-map (car x) (cdr x))) | |
689 | |
690 ;; Specific bindings in reftex-select-bib-map | |
691 (loop for key across "grRaA" do | |
692 (define-key reftex-select-bib-map (vector (list key)) | |
693 (list 'lambda '() | |
694 "Press `?' during selection to find out about this key." | |
695 '(interactive) (list 'throw '(quote myexit) key)))) | |
696 | |
697 (loop for x in | |
698 '(("\C-i" . reftex-select-read-cite) | |
699 ([(tab)] . reftex-select-read-cite) | |
700 ("m" . reftex-select-mark) | |
701 ("u" . reftex-select-unmark)) | |
702 do (define-key reftex-select-bib-map (car x) (cdr x))) | |
703 | |
704 | |
705 ;;; reftex-sel.el ends here |