1 |
;;; reftex-ref.el --- code to create labels and references with RefTeX |
;;; reftex-ref.el --- code to create labels and references with 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 |
|
|
165 |
(string-match "^[ \t]*$" default)) |
(string-match "^[ \t]*$" default)) |
166 |
(setq default prefix |
(setq default prefix |
167 |
force-prompt t) ; need to prompt |
force-prompt t) ; need to prompt |
168 |
(setq default |
(setq default |
169 |
(concat prefix |
(concat prefix |
170 |
(funcall reftex-string-to-label-function default))) |
(funcall reftex-string-to-label-function default))) |
171 |
|
|
172 |
;; Make it unique. |
;; Make it unique. |
212 |
((setq entry (assoc label |
((setq entry (assoc label |
213 |
(symbol-value reftex-docstruct-symbol))) |
(symbol-value reftex-docstruct-symbol))) |
214 |
(ding) |
(ding) |
215 |
(if (y-or-n-p |
(if (y-or-n-p |
216 |
(format "Label '%s' exists. Use anyway? " label)) |
(format "Label '%s' exists. Use anyway? " label)) |
217 |
(setq valid t))) |
(setq valid t))) |
218 |
|
|
222 |
(setq label default)) |
(setq label default)) |
223 |
|
|
224 |
;; Insert the label into the label list |
;; Insert the label into the label list |
225 |
(let* ((here-I-am-info |
(let* ((here-I-am-info |
226 |
(save-excursion |
(save-excursion |
227 |
(if (and (or naked no-insert) |
(if (and (or naked no-insert) |
228 |
(integerp (cdr macro-cell))) |
(integerp (cdr macro-cell))) |
229 |
(goto-char (cdr macro-cell))) |
(goto-char (cdr macro-cell))) |
230 |
(reftex-where-am-I))) |
(reftex-where-am-I))) |
279 |
;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents |
;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents |
280 |
(let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy") |
(let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy") |
281 |
(emacsp (not (featurep 'xemacs)))) |
(emacsp (not (featurep 'xemacs)))) |
282 |
(mapconcat |
(mapconcat |
283 |
(lambda (c) |
(lambda (c) |
284 |
(cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1 |
(cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1 |
285 |
(char-to-string (aref tab (- c 128)))) |
(char-to-string (aref tab (- c 128)))) |
407 |
type (car type)) |
type (car type)) |
408 |
(setq type (reftex-query-label-type)))) |
(setq type (reftex-query-label-type)))) |
409 |
|
|
410 |
(let* ((refstyle |
(let* ((refstyle |
411 |
(cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref") |
(cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref") |
412 |
((reftex-typekey-check type reftex-fref-is-default) "\\fref") |
((reftex-typekey-check type reftex-fref-is-default) "\\fref") |
413 |
(t "\\ref"))) |
(t "\\ref"))) |
421 |
(reftex-offer-label-menu type))) |
(reftex-offer-label-menu type))) |
422 |
(reftex-ensure-compiled-variables) |
(reftex-ensure-compiled-variables) |
423 |
(set-marker reftex-select-return-marker nil) |
(set-marker reftex-select-return-marker nil) |
424 |
;; If the first entry is the symbol 'concat, concat all all labels. |
;; If the first entry is the symbol 'concat, concat all labels. |
425 |
;; We keep the cdr of the first label for typekey etc information. |
;; We keep the cdr of the first label for typekey etc information. |
426 |
(if (eq (car labels) 'concat) |
(if (eq (car labels) 'concat) |
427 |
(setq labels (list (list (mapconcat 'car (cdr labels) ",") |
(setq labels (list (list (mapconcat 'car (cdr labels) ",") |
429 |
(setq type (nth 1 (car labels)) |
(setq type (nth 1 (car labels)) |
430 |
form (or (cdr (assoc type reftex-typekey-to-format-alist)) |
form (or (cdr (assoc type reftex-typekey-to-format-alist)) |
431 |
form)) |
form)) |
432 |
|
|
433 |
(cond |
(cond |
434 |
(no-insert |
(no-insert |
435 |
;; Just return the first label |
;; Just return the first label |
443 |
sep (nth 2 (car labels)) |
sep (nth 2 (car labels)) |
444 |
sep1 (cdr (assoc sep reftex-multiref-punctuation)) |
sep1 (cdr (assoc sep reftex-multiref-punctuation)) |
445 |
labels (cdr labels)) |
labels (cdr labels)) |
446 |
(when cut |
(when cut |
447 |
(backward-delete-char cut) |
(backward-delete-char cut) |
448 |
(setq cut nil)) |
(setq cut nil)) |
449 |
|
|
450 |
;; remove ~ if we do already have a space |
;; remove ~ if we do already have a space |
451 |
(when (and (= ?~ (string-to-char form)) |
(when (and (= ?~ (string-to-char form)) |
452 |
(member (preceding-char) '(?\ ?\t ?\n))) |
(member (preceding-char) '(?\ ?\t ?\n))) |
453 |
(setq form (substring form 1))) |
(setq form (substring form 1))) |
454 |
;; do we have a special format? |
;; do we have a special format? |
455 |
(setq reftex-format-ref-function |
(setq reftex-format-ref-function |
478 |
matched cell) |
matched cell) |
479 |
(save-excursion |
(save-excursion |
480 |
(while (and (setq cell (pop words)) |
(while (and (setq cell (pop words)) |
481 |
(not (setq matched |
(not (setq matched |
482 |
(re-search-backward (car cell) bound t)))))) |
(re-search-backward (car cell) bound t)))))) |
483 |
(if matched |
(if matched |
484 |
(cons (cdr cell) (- (match-end 0) (match-end 1))) |
(cons (cdr cell) (- (match-end 0) (match-end 1))) |
543 |
context |
context |
544 |
counter |
counter |
545 |
commented |
commented |
546 |
(or here-I-am offset) |
(or here-I-am offset) |
547 |
prefix |
prefix |
548 |
nil ; no a toc buffer |
nil ; no a toc buffer |
549 |
)))) |
)))) |
550 |
(here-I-am |
(here-I-am |
551 |
(setq offset (reftex-get-offset buf here-I-am typekey))) |
(setq offset (reftex-get-offset buf here-I-am typekey))) |
640 |
(save-excursion |
(save-excursion |
641 |
(while reftex-buffers-with-changed-invisibility |
(while reftex-buffers-with-changed-invisibility |
642 |
(set-buffer (car (car reftex-buffers-with-changed-invisibility))) |
(set-buffer (car (car reftex-buffers-with-changed-invisibility))) |
643 |
(setq buffer-invisibility-spec |
(setq buffer-invisibility-spec |
644 |
(cdr (pop reftex-buffers-with-changed-invisibility))))) |
(cdr (pop reftex-buffers-with-changed-invisibility))))) |
645 |
(mapcar (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf))) |
(mapcar (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf))) |
646 |
selection-buffers) |
selection-buffers) |
647 |
(reftex-kill-temporary-buffers)) |
(reftex-kill-temporary-buffers)) |
648 |
;; Add the prefixes, put together the relevant information in the form |
;; Add the prefixes, put together the relevant information in the form |
649 |
;; (LABEL TYPEKEY SEPERATOR) and return a list of those. |
;; (LABEL TYPEKEY SEPARATOR) and return a list of those. |
650 |
(mapcar (lambda (x) |
(mapcar (lambda (x) |
651 |
(if (listp x) |
(if (listp x) |
652 |
(list (concat prefix (car (car x))) |
(list (concat prefix (car (car x))) |
669 |
|
|
670 |
(defun reftex-query-label-type () |
(defun reftex-query-label-type () |
671 |
;; Ask for label type |
;; Ask for label type |
672 |
(let ((key (reftex-select-with-char |
(let ((key (reftex-select-with-char |
673 |
reftex-type-query-prompt reftex-type-query-help 3))) |
reftex-type-query-prompt reftex-type-query-help 3))) |
674 |
(unless (member (char-to-string key) reftex-typekey-list) |
(unless (member (char-to-string key) reftex-typekey-list) |
675 |
(error "No such label type: %s" (char-to-string key))) |
(error "No such label type: %s" (char-to-string key))) |
676 |
(char-to-string key))) |
(char-to-string key))) |
677 |
|
|
678 |
(defun reftex-show-label-location (data forward no-revisit |
(defun reftex-show-label-location (data forward no-revisit |
679 |
&optional stay error) |
&optional stay error) |
680 |
;; View the definition site of a label in another window. |
;; View the definition site of a label in another window. |
681 |
;; DATA is an entry from the docstruct list. |
;; DATA is an entry from the docstruct list. |
697 |
(throw 'exit nil)) |
(throw 'exit nil)) |
698 |
|
|
699 |
;; Goto the file in another window |
;; Goto the file in another window |
700 |
(setq buffer |
(setq buffer |
701 |
(if no-revisit |
(if no-revisit |
702 |
(reftex-get-buffer-visiting file) |
(reftex-get-buffer-visiting file) |
703 |
(reftex-get-file-buffer-force |
(reftex-get-file-buffer-force |
763 |
(when (or (not (eq major-mode 'latex-mode)) |
(when (or (not (eq major-mode 'latex-mode)) |
764 |
(not font-lock-mode)) |
(not font-lock-mode)) |
765 |
(latex-mode) |
(latex-mode) |
766 |
(run-hook-with-args |
(run-hook-with-args |
767 |
'reftex-pre-refontification-functions |
'reftex-pre-refontification-functions |
768 |
reftex-call-back-to-this-buffer 'reftex-hidden) |
reftex-call-back-to-this-buffer 'reftex-hidden) |
769 |
(turn-on-font-lock)) |
(turn-on-font-lock)) |
802 |
(defun reftex-format-fref (label def-fmt) |
(defun reftex-format-fref (label def-fmt) |
803 |
(format "\\fref{%s}" label)) |
(format "\\fref{%s}" label)) |
804 |
|
|
805 |
|
|
806 |
|
;(defun reftex-goto-label () |
807 |
|
; (interactive) |
808 |
|
; (reftex-access-scan-info) |
809 |
|
; (let* ((docstruct (symbol-value reftex-docstruct-symbol)) |
810 |
|
; (label (completing-read "Label: " docstruct |
811 |
|
; (lambda (x) (stringp (car x))) t)) |
812 |
|
; (selection (assoc label docstruct))) |
813 |
|
; (reftex-show-label-location selection t nil 'stay) |
814 |
|
; (reftex-unhighlight 0))) |
815 |
|
|
816 |
|
(defun reftex-goto-label (&optional other-window) |
817 |
|
"Prompt for a label (with completion) and jump to the location of this label. |
818 |
|
Optional prefix argument OTHER-WINDOW goes to the label in another window." |
819 |
|
(interactive "P") |
820 |
|
(reftex-access-scan-info) |
821 |
|
(let* ((wcfg (current-window-configuration)) |
822 |
|
(docstruct (symbol-value reftex-docstruct-symbol)) |
823 |
|
(label (completing-read "Label: " docstruct |
824 |
|
(lambda (x) (stringp (car x))) t)) |
825 |
|
(selection (assoc label docstruct)) |
826 |
|
(where (progn |
827 |
|
(reftex-show-label-location selection t nil 'stay) |
828 |
|
(point-marker)))) |
829 |
|
(unless other-window |
830 |
|
(set-window-configuration wcfg) |
831 |
|
(switch-to-buffer (marker-buffer where)) |
832 |
|
(goto-char where)) |
833 |
|
(reftex-unhighlight 0))) |
834 |
|
|
835 |
|
|
836 |
|
|
837 |
;;; reftex-ref.el ends here |
;;; reftex-ref.el ends here |