1 |
;;; reftex-sel.el --- the selection modes for RefTeX |
;;; reftex-sel.el --- the selection modes for RefTeX |
2 |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
;; Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
3 |
|
|
4 |
;; Author: Carsten Dominik <dominik@strw.LeidenUniv.nl> |
;; Author: Carsten Dominik <dominik@science.uva.nl> |
5 |
;; Version: 4.16 |
;; Version: 4.18 |
6 |
|
|
7 |
;; This file is part of GNU Emacs. |
;; This file is part of GNU Emacs. |
8 |
|
|
38 |
(defun reftex-select-label-mode () |
(defun reftex-select-label-mode () |
39 |
"Major mode for selecting a label in a LaTeX document. |
"Major mode for selecting a label in a LaTeX document. |
40 |
This buffer was created with RefTeX. |
This buffer was created with RefTeX. |
41 |
It only has a meaningful keymap when you are in the middle of a |
It only has a meaningful keymap when you are in the middle of a |
42 |
selection process. |
selection process. |
43 |
To select a label, move the cursor to it and press RET. |
To select a label, move the cursor to it and press RET. |
44 |
Press `?' for a summary of important key bindings. |
Press `?' for a summary of important key bindings. |
49 |
|
|
50 |
(interactive) |
(interactive) |
51 |
(kill-all-local-variables) |
(kill-all-local-variables) |
52 |
|
(when (featurep 'xemacs) |
53 |
|
;; XEmacs needs the call to make-local-hook |
54 |
|
(make-local-hook 'pre-command-hook) |
55 |
|
(make-local-hook 'post-command-hook)) |
56 |
(setq major-mode 'reftex-select-label-mode |
(setq major-mode 'reftex-select-label-mode |
57 |
mode-name "LSelect") |
mode-name "LSelect") |
58 |
(set (make-local-variable 'reftex-select-marked) nil) |
(set (make-local-variable 'reftex-select-marked) nil) |
69 |
(defun reftex-select-bib-mode () |
(defun reftex-select-bib-mode () |
70 |
"Major mode for selecting a citation key in a LaTeX document. |
"Major mode for selecting a citation key in a LaTeX document. |
71 |
This buffer was created with RefTeX. |
This buffer was created with RefTeX. |
72 |
It only has a meaningful keymap when you are in the middle of a |
It only has a meaningful keymap when you are in the middle of a |
73 |
selection process. |
selection process. |
74 |
In order to select a citation, move the cursor to it and press RET. |
In order to select a citation, move the cursor to it and press RET. |
75 |
Press `?' for a summary of important key bindings. |
Press `?' for a summary of important key bindings. |
79 |
\\{reftex-select-label-map}" |
\\{reftex-select-label-map}" |
80 |
(interactive) |
(interactive) |
81 |
(kill-all-local-variables) |
(kill-all-local-variables) |
82 |
|
(when (featurep 'xemacs) |
83 |
|
;; XEmacs needs the call to make-local-hook |
84 |
|
(make-local-hook 'pre-command-hook) |
85 |
|
(make-local-hook 'post-command-hook)) |
86 |
(setq major-mode 'reftex-select-bib-mode |
(setq major-mode 'reftex-select-bib-mode |
87 |
mode-name "BSelect") |
mode-name "BSelect") |
88 |
(set (make-local-variable 'reftex-select-marked) nil) |
(set (make-local-variable 'reftex-select-marked) nil) |
89 |
;; We do not set a local map - reftex-select-item does this. |
;; We do not set a local map - reftex-select-item does this. |
90 |
(run-hooks 'reftex-select-bib-mode-hook)) |
(run-hooks 'reftex-select-bib-mode-hook)) |
91 |
|
|
92 |
|
;;; (defun reftex-get-offset (buf here-am-I &optional typekey toc index file) |
93 |
|
;;; ;; Find the correct offset data, like insert-docstruct would, but faster. |
94 |
|
;;; ;; Buffer BUF knows the correct docstruct to use. |
95 |
|
;;; ;; Basically this finds the first docstruct entry after HERE-I-AM which |
96 |
|
;;; ;; is of allowed type. The optional arguments specify what is allowed. |
97 |
|
;;; (catch 'exit |
98 |
|
;;; (save-excursion |
99 |
|
;;; (set-buffer buf) |
100 |
|
;;; (reftex-access-scan-info) |
101 |
|
;;; (let* ((rest (memq here-am-I (symbol-value reftex-docstruct-symbol))) |
102 |
|
;;; entry) |
103 |
|
;;; (while (setq entry (pop rest)) |
104 |
|
;;; (if (or (and typekey |
105 |
|
;;; (stringp (car entry)) |
106 |
|
;;; (or (equal typekey " ") |
107 |
|
;;; (equal typekey (nth 1 entry)))) |
108 |
|
;;; (and toc (eq (car entry) 'toc)) |
109 |
|
;;; (and index (eq (car entry) 'index)) |
110 |
|
;;; (and file |
111 |
|
;;; (memq (car entry) '(bof eof file-error)))) |
112 |
|
;;; (throw 'exit entry))) |
113 |
|
;;; nil)))) |
114 |
|
|
115 |
(defun reftex-get-offset (buf here-am-I &optional typekey toc index file) |
(defun reftex-get-offset (buf here-am-I &optional typekey toc index file) |
116 |
;; Find the correct offset data, like insert-docstruct would, but faster. |
;; Find the correct offset data, like insert-docstruct would, but faster. |
117 |
;; Buffer BUF knows the correct docstruct to use. |
;; Buffer BUF knows the correct docstruct to use. |
118 |
;; Basically this finds the first docstruct entry after HERE-I-AM which |
;; Basically this finds the first docstruct entry before HERE-I-AM which |
119 |
;; is of allowed type. The optional arguments specify what is allowed. |
;; is of allowed type. The optional arguments specify what is allowed. |
120 |
(catch 'exit |
(catch 'exit |
121 |
(save-excursion |
(save-excursion |
122 |
(set-buffer buf) |
(set-buffer buf) |
123 |
(reftex-access-scan-info) |
(reftex-access-scan-info) |
124 |
(let* ((rest (memq here-am-I (symbol-value reftex-docstruct-symbol))) |
(let* ((rest (symbol-value reftex-docstruct-symbol)) |
125 |
entry) |
lastentry entry) |
126 |
(while (setq entry (pop rest)) |
(while (setq entry (pop rest)) |
127 |
(if (or (and typekey |
(if (or (and typekey |
128 |
(stringp (car entry)) |
(stringp (car entry)) |
132 |
(and index (eq (car entry) 'index)) |
(and index (eq (car entry) 'index)) |
133 |
(and file |
(and file |
134 |
(memq (car entry) '(bof eof file-error)))) |
(memq (car entry) '(bof eof file-error)))) |
135 |
(throw 'exit entry))) |
(setq lastentry entry)) |
136 |
|
(if (eq entry here-am-I) |
137 |
|
(throw 'exit (or lastentry entry)))) |
138 |
nil)))) |
nil)))) |
139 |
|
|
140 |
(defun reftex-insert-docstruct |
(defun reftex-insert-docstruct |
174 |
'font-lock-constant-face |
'font-lock-constant-face |
175 |
'font-lock-reference-face)) |
'font-lock-reference-face)) |
176 |
all cell text label typekey note comment master-dir-re |
all cell text label typekey note comment master-dir-re |
177 |
offset from to index-tag docstruct-symbol) |
prev-inserted offset from to index-tag docstruct-symbol) |
178 |
|
|
179 |
;; Pop to buffer buf to get the correct buffer-local variables |
;; Pop to buffer buf to get the correct buffer-local variables |
180 |
(save-excursion |
(save-excursion |
201 |
(incf index) |
(incf index) |
202 |
(setq from (point)) |
(setq from (point)) |
203 |
|
|
|
(if (eq cell here-I-am) (setq offset 'attention)) |
|
|
|
|
204 |
(cond |
(cond |
205 |
|
|
206 |
((memq (car cell) '(bib thebib label-numbers appendix |
((memq (car cell) '(bib thebib label-numbers appendix |
210 |
((memq (car cell) '(bof eof file-error)) |
((memq (car cell) '(bof eof file-error)) |
211 |
;; Beginning or end of a file |
;; Beginning or end of a file |
212 |
(when files |
(when files |
213 |
(if (eq offset 'attention) (setq offset cell)) |
(setq prev-inserted cell) |
214 |
|
; (if (eq offset 'attention) (setq offset cell)) |
215 |
(insert |
(insert |
216 |
" File " (if (string-match master-dir-re (nth 1 cell)) |
" File " (if (string-match master-dir-re (nth 1 cell)) |
217 |
(substring (nth 1 cell) (match-end 0)) |
(substring (nth 1 cell) (match-end 0)) |
233 |
;; a table of contents entry |
;; a table of contents entry |
234 |
(when (and toc |
(when (and toc |
235 |
(<= (nth 5 cell) reftex-toc-max-level)) |
(<= (nth 5 cell) reftex-toc-max-level)) |
236 |
(if (eq offset 'attention) (setq offset cell)) |
(setq prev-inserted cell) |
237 |
|
; (if (eq offset 'attention) (setq offset cell)) |
238 |
(setq reftex-active-toc cell) |
(setq reftex-active-toc cell) |
239 |
(insert (concat toc-indent (nth 2 cell) "\n")) |
(insert (concat toc-indent (nth 2 cell) "\n")) |
240 |
(setq to (point)) |
(setq to (point)) |
262 |
note (nth 5 cell)) |
note (nth 5 cell)) |
263 |
|
|
264 |
(when (and labels |
(when (and labels |
265 |
(or (eq labels t) |
(or (eq labels t) |
266 |
(string= typekey labels) |
(string= typekey labels) |
267 |
(string= labels " ")) |
(string= labels " ")) |
268 |
(or show-commented (null comment))) |
(or show-commented (null comment))) |
269 |
|
|
270 |
;; Yes we want this one |
;; Yes we want this one |
271 |
(incf cnt) |
(incf cnt) |
272 |
(if (eq offset 'attention) (setq offset cell)) |
(setq prev-inserted cell) |
273 |
|
; (if (eq offset 'attention) (setq offset cell)) |
274 |
|
|
275 |
(setq label (concat xr-prefix label)) |
(setq label (concat xr-prefix label)) |
276 |
(when comment (setq label (concat "% " label))) |
(when comment (setq label (concat "% " label))) |
296 |
(put-text-property from to :data cell) |
(put-text-property from to :data cell) |
297 |
(when mouse-face |
(when mouse-face |
298 |
(put-text-property from (1- to) |
(put-text-property from (1- to) |
299 |
'mouse-face mouse-face)) |
'mouse-face mouse-face)) |
300 |
(goto-char to))) |
(goto-char to))) |
301 |
|
|
302 |
((eq (car cell) 'index) |
((eq (car cell) 'index) |
304 |
(when (and index-entries |
(when (and index-entries |
305 |
(or (eq t index-entries) |
(or (eq t index-entries) |
306 |
(string= index-entries (nth 1 cell)))) |
(string= index-entries (nth 1 cell)))) |
307 |
(if (eq offset 'attention) (setq offset cell)) |
(setq prev-inserted cell) |
308 |
|
; (if (eq offset 'attention) (setq offset cell)) |
309 |
(setq index-tag (format "<%s>" (nth 1 cell))) |
(setq index-tag (format "<%s>" (nth 1 cell))) |
310 |
(and font |
(and font |
311 |
(put-text-property 0 (length index-tag) |
(put-text-property 0 (length index-tag) |
314 |
|
|
315 |
(when font |
(when font |
316 |
(setq to (point)) |
(setq to (point)) |
317 |
(put-text-property |
(put-text-property |
318 |
(- (point) (length (nth 7 cell))) to |
(- (point) (length (nth 7 cell))) to |
319 |
'face index-face) |
'face index-face) |
320 |
(goto-char to)) |
(goto-char to)) |
327 |
(put-text-property from to :data cell) |
(put-text-property from to :data cell) |
328 |
(when mouse-face |
(when mouse-face |
329 |
(put-text-property from (1- to) |
(put-text-property from (1- to) |
330 |
'mouse-face mouse-face)) |
'mouse-face mouse-face)) |
331 |
(goto-char to))))) |
(goto-char to)))) |
332 |
|
|
333 |
|
(if (eq cell here-I-am) |
334 |
|
(setq offset 'attention)) |
335 |
|
(if (and prev-inserted (eq offset 'attention)) |
336 |
|
(setq offset prev-inserted)) |
337 |
|
) |
338 |
|
|
339 |
(when (reftex-refontify) |
(when (reftex-refontify) |
340 |
;; we need to fontify the buffer |
;; we need to fontify the buffer |
357 |
((listp loc) |
((listp loc) |
358 |
(setq pos (text-property-any (point-min) (point-max) :data loc)) |
(setq pos (text-property-any (point-min) (point-max) :data loc)) |
359 |
(when pos |
(when pos |
360 |
(goto-char pos) |
(goto-char pos) |
361 |
(throw 'exit t))) |
(throw 'exit t))) |
362 |
((integerp loc) |
((integerp loc) |
363 |
(when (<= loc (count-lines (point-min) (point-max))) |
(when (<= loc (count-lines (point-min) (point-max))) |
394 |
(setq truncate-lines t) |
(setq truncate-lines t) |
395 |
|
|
396 |
;; Find a good starting point |
;; Find a good starting point |
397 |
(reftex-find-start-point |
(reftex-find-start-point |
398 |
(point-min) offset reftex-last-data reftex-last-line) |
(point-min) offset reftex-last-data reftex-last-line) |
399 |
(beginning-of-line 1) |
(beginning-of-line 1) |
400 |
(set (make-local-variable 'reftex-last-follow-point) (point)) |
(set (make-local-variable 'reftex-last-follow-point) (point)) |
415 |
(set-buffer selection-buffer) |
(set-buffer selection-buffer) |
416 |
(use-local-map nil) |
(use-local-map nil) |
417 |
(remove-hook 'pre-command-hook 'reftex-select-pre-command-hook t) |
(remove-hook 'pre-command-hook 'reftex-select-pre-command-hook t) |
418 |
(remove-hook 'post-command-hook |
(remove-hook 'post-command-hook |
419 |
'reftex-select-post-command-hook t)) |
'reftex-select-post-command-hook t)) |
420 |
;; Kill the mark overlays |
;; Kill the mark overlays |
421 |
(mapcar (lambda (c) (delete-overlay (nth 1 c))) |
(mapcar (lambda (c) (delete-overlay (nth 1 c))) |
451 |
(let (b e) |
(let (b e) |
452 |
(setq data (get-text-property (point) :data)) |
(setq data (get-text-property (point) :data)) |
453 |
(setq last-data (or data last-data)) |
(setq last-data (or data last-data)) |
454 |
|
|
455 |
(when (and data cb-flag |
(when (and data cb-flag |
456 |
(not (equal reftex-last-follow-point (point)))) |
(not (equal reftex-last-follow-point (point)))) |
457 |
(setq reftex-last-follow-point (point)) |
(setq reftex-last-follow-point (point)) |
458 |
(funcall call-back data reftex-callback-fwd |
(funcall call-back data reftex-callback-fwd |
459 |
(not reftex-revisit-to-follow))) |
(not reftex-revisit-to-follow))) |
460 |
(if data |
(if data |
461 |
(setq b (or (previous-single-property-change |
(setq b (or (previous-single-property-change |
575 |
(defun reftex-select-read-label () |
(defun reftex-select-read-label () |
576 |
"Use minibuffer to read a label to reference, with completion." |
"Use minibuffer to read a label to reference, with completion." |
577 |
(interactive) |
(interactive) |
578 |
(let ((label (completing-read |
(let ((label (completing-read |
579 |
"Label: " (symbol-value reftex-docstruct-symbol) |
"Label: " (symbol-value reftex-docstruct-symbol) |
580 |
nil nil reftex-prefix))) |
nil nil reftex-prefix))) |
581 |
(unless (or (equal label "") (equal label reftex-prefix)) |
(unless (or (equal label "") (equal label reftex-prefix)) |
680 |
([(up)] . reftex-select-previous) |
([(up)] . reftex-select-previous) |
681 |
("f" . reftex-select-toggle-follow) |
("f" . reftex-select-toggle-follow) |
682 |
("\C-m" . reftex-select-accept) |
("\C-m" . reftex-select-accept) |
683 |
([(return)] . reftex-select-accept) |
([(return)] . reftex-select-accept) |
684 |
("q" . reftex-select-quit) |
("q" . reftex-select-quit) |
685 |
("." . reftex-select-show-insertion-point) |
("." . reftex-select-show-insertion-point) |
686 |
("?" . reftex-select-help)) |
("?" . reftex-select-help)) |
703 |
;; Specific bindings in reftex-select-label-map |
;; Specific bindings in reftex-select-label-map |
704 |
(loop for key across "aAcgFlrRstx#%" do |
(loop for key across "aAcgFlrRstx#%" do |
705 |
(define-key reftex-select-label-map (vector (list key)) |
(define-key reftex-select-label-map (vector (list key)) |
706 |
(list 'lambda '() |
(list 'lambda '() |
707 |
"Press `?' during selection to find out about this key." |
"Press `?' during selection to find out about this key." |
708 |
'(interactive) (list 'throw '(quote myexit) key)))) |
'(interactive) (list 'throw '(quote myexit) key)))) |
709 |
|
|
727 |
;; Specific bindings in reftex-select-bib-map |
;; Specific bindings in reftex-select-bib-map |
728 |
(loop for key across "grRaA" do |
(loop for key across "grRaA" do |
729 |
(define-key reftex-select-bib-map (vector (list key)) |
(define-key reftex-select-bib-map (vector (list key)) |
730 |
(list 'lambda '() |
(list 'lambda '() |
731 |
"Press `?' during selection to find out about this key." |
"Press `?' during selection to find out about this key." |
732 |
'(interactive) (list 'throw '(quote myexit) key)))) |
'(interactive) (list 'throw '(quote myexit) key)))) |
733 |
|
|
737 |
("m" . reftex-select-mark) |
("m" . reftex-select-mark) |
738 |
("u" . reftex-select-unmark)) |
("u" . reftex-select-unmark)) |
739 |
do (define-key reftex-select-bib-map (car x) (cdr x))) |
do (define-key reftex-select-bib-map (car x) (cdr x))) |
740 |
|
|
741 |
|
|
742 |
;;; reftex-sel.el ends here |
;;; reftex-sel.el ends here |