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