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