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