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