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