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