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