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