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