summaryrefslogtreecommitdiff
path: root/lisp/textmodes/reftex-ref.el
diff options
context:
space:
mode:
authorKenichi Handa <handa@m17n.org>2003-09-08 11:56:09 +0000
committerKenichi Handa <handa@m17n.org>2003-09-08 11:56:09 +0000
commit463f5630a5e7cbe7f042bc1175d1fa1c4e98860f (patch)
tree3287d0c628fea2249abf4635b3a4f45bedd6f8c4 /lisp/textmodes/reftex-ref.el
parent4256310de631bd57c78b88b5131caa073315b3d7 (diff)
downloademacs-463f5630a5e7cbe7f042bc1175d1fa1c4e98860f.tar.gz
emacs-463f5630a5e7cbe7f042bc1175d1fa1c4e98860f.tar.bz2
emacs-463f5630a5e7cbe7f042bc1175d1fa1c4e98860f.zip
New directory
Diffstat (limited to 'lisp/textmodes/reftex-ref.el')
-rw-r--r--lisp/textmodes/reftex-ref.el728
1 files changed, 369 insertions, 359 deletions
diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el
index 2d4935aedde..9991c0b2f77 100644
--- a/lisp/textmodes/reftex-ref.el
+++ b/lisp/textmodes/reftex-ref.el
@@ -1,8 +1,8 @@
;;; reftex-ref.el --- code to create labels and references with RefTeX
-;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
+;; Copyright (c) 1997, 1998, 1999, 2000, 2003 Free Software Foundation, Inc.
;; Author: Carsten Dominik <dominik@science.uva.nl>
-;; Version: 4.21
+;; Version: 4.18
;; This file is part of GNU Emacs.
@@ -36,11 +36,11 @@ If optional BOUND is an integer, limit backward searches to that point."
(let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
(loc2 (reftex-what-environment reftex-label-env-list bound))
- (loc3 (reftex-what-special-env 1 bound))
+ (loc3 (reftex-what-special-env 1 bound))
(p1 (or (cdr loc1) 0))
(p2 (or (cdr loc2) 0))
- (p3 (or (cdr loc3) 0))
- (pmax (max p1 p2 p3)))
+ (p3 (or (cdr loc3) 0))
+ (pmax (max p1 p2 p3)))
(setq reftex-location-start pmax)
(cond
@@ -57,9 +57,9 @@ If optional BOUND is an integer, limit backward searches to that point."
(setq reftex-default-context-position p3)
(setq loc3 (car loc3))
(cond ((null loc3) "section")
- ((symbolp loc3) (symbol-name loc3))
- ((stringp loc3) loc3)
- (t "section")))
+ ((symbolp loc3) (symbol-name loc3))
+ ((stringp loc3) loc3)
+ (t "section")))
(t ;; This should not happen, I think?
"section"))))
@@ -83,11 +83,11 @@ If optional BOUND is an integer, limit backward searches to that point."
(goto-char 1)
(if (or (re-search-forward
- (format reftex-find-label-regexp-format
- (regexp-quote label)) nil t)
- (re-search-forward
- (format reftex-find-label-regexp-format2
- (regexp-quote label)) nil t))
+ (format reftex-find-label-regexp-format
+ (regexp-quote label)) nil t)
+ (re-search-forward
+ (format reftex-find-label-regexp-format2
+ (regexp-quote label)) nil t))
(progn
(backward-char 1)
@@ -102,7 +102,7 @@ If optional BOUND is an integer, limit backward searches to that point."
(parse (nth 2 (assoc env-or-mac reftex-env-or-mac-alist)))
(text (reftex-short-context env-or-mac parse reftex-location-start
derive))
- (in-comment (reftex-in-comment)))
+ (in-comment (reftex-in-comment)))
(list label typekey text file in-comment)))
;;; Creating labels ---------------------------------------------------------
@@ -132,18 +132,18 @@ This function is controlled by the settings of reftex-insert-label-flags."
;; Ok, go ahead.
(catch 'exit
(let* ((entry (assoc environment reftex-env-or-mac-alist))
- (typekey (nth 1 entry))
- (format (nth 3 entry))
- (macro-cell (reftex-what-macro 1))
- (entry1 (assoc (car macro-cell) reftex-env-or-mac-alist))
- label naked prefix valid default force-prompt rescan-is-useful)
+ (typekey (nth 1 entry))
+ (format (nth 3 entry))
+ (macro-cell (reftex-what-macro 1))
+ (entry1 (assoc (car macro-cell) reftex-env-or-mac-alist))
+ label naked prefix valid default force-prompt rescan-is-useful)
(when (and (or (nth 5 entry) (nth 5 entry1))
- (memq (preceding-char) '(?\[ ?\{)))
- ;; This is an argument of a label macro. Insert naked label.
- (setq naked t format "%s"))
+ (memq (preceding-char) '(?\[ ?\{)))
+ ;; This is an argument of a label macro. Insert naked label.
+ (setq naked t format "%s"))
(setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
- (concat typekey "-")))
+ (concat typekey "-")))
;; Replace any escapes in the prefix
(setq prefix (reftex-replace-prefix-escapes prefix))
@@ -151,115 +151,115 @@ This function is controlled by the settings of reftex-insert-label-flags."
(cond
((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
- ;; Derive a label from context.
- (setq reftex-active-toc (reftex-last-assoc-before-elt
- 'toc (car (reftex-where-am-I))
- (symbol-value reftex-docstruct-symbol)))
- (setq default (reftex-no-props
- (nth 2 (reftex-label-info " " nil nil t))))
- ;; Catch the cases where the is actually no context available.
- (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
- (string-match "ILLEGAL VALUE OF PARSE" default)
- (string-match "SECTION HEADING NOT FOUND" default)
- (string-match "HOOK ERROR" default)
- (string-match "^[ \t]*$" default))
- (setq default prefix
- force-prompt t) ; need to prompt
- (setq default
- (concat prefix
- (funcall reftex-string-to-label-function default)))
-
- ;; Make it unique.
- (setq default (reftex-uniquify-label default nil "-"))))
+ ;; Derive a label from context.
+ (setq reftex-active-toc (reftex-last-assoc-before-elt
+ 'toc (car (reftex-where-am-I))
+ (symbol-value reftex-docstruct-symbol)))
+ (setq default (reftex-no-props
+ (nth 2 (reftex-label-info " " nil nil t))))
+ ;; Catch the cases where the is actually no context available.
+ (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
+ (string-match "ILLEGAL VALUE OF PARSE" default)
+ (string-match "SECTION HEADING NOT FOUND" default)
+ (string-match "HOOK ERROR" default)
+ (string-match "^[ \t]*$" default))
+ (setq default prefix
+ force-prompt t) ; need to prompt
+ (setq default
+ (concat prefix
+ (funcall reftex-string-to-label-function default)))
+
+ ;; Make it unique.
+ (setq default (reftex-uniquify-label default nil "-"))))
((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags))
- ;; Minimal default: the user will be prompted.
- (setq default prefix))
+ ;; Minimal default: the user will be prompted.
+ (setq default prefix))
(t
- ;; Make an automatic label.
- (setq default (reftex-uniquify-label prefix t))))
+ ;; Make an automatic label.
+ (setq default (reftex-uniquify-label prefix t))))
;; Should we ask the user?
(if (or (reftex-typekey-check typekey
- (nth 1 reftex-insert-label-flags)) ; prompt
- force-prompt)
-
- (while (not valid)
- ;; iterate until we get a legal label
-
- (setq label (read-string
- (if naked "Naked Label: " "Label: ")
- default))
-
- ;; Lets make sure that this is a legal label
- (cond
-
- ((string-match (concat "\\`\\(" (regexp-quote prefix)
- "\\)?[ \t]*\\'")
- label)
- ;; No label at all, please
- (message "No label inserted.")
- (throw 'exit nil))
-
- ;; Test if label contains strange characters
- ((string-match reftex-label-illegal-re label)
- (message "Label \"%s\" contains illegal characters" label)
- (ding)
- (sit-for 2))
-
- ;; Look it up in the label list
- ((setq entry (assoc label
- (symbol-value reftex-docstruct-symbol)))
- (ding)
- (if (y-or-n-p
- (format "Label '%s' exists. Use anyway? " label))
- (setq valid t)))
-
- ;; Label is ok
- (t
- (setq valid t))))
- (setq label default))
+ (nth 1 reftex-insert-label-flags)) ; prompt
+ force-prompt)
+
+ (while (not valid)
+ ;; iterate until we get a legal label
+
+ (setq label (read-string
+ (if naked "Naked Label: " "Label: ")
+ default))
+
+ ;; Lets make sure that this is a legal label
+ (cond
+
+ ((string-match (concat "\\`\\(" (regexp-quote prefix)
+ "\\)?[ \t]*\\'")
+ label)
+ ;; No label at all, please
+ (message "No label inserted.")
+ (throw 'exit nil))
+
+ ;; Test if label contains strange characters
+ ((string-match reftex-label-illegal-re label)
+ (message "Label \"%s\" contains illegal characters" label)
+ (ding)
+ (sit-for 2))
+
+ ;; Look it up in the label list
+ ((setq entry (assoc label
+ (symbol-value reftex-docstruct-symbol)))
+ (ding)
+ (if (y-or-n-p
+ (format "Label '%s' exists. Use anyway? " label))
+ (setq valid t)))
+
+ ;; Label is ok
+ (t
+ (setq valid t))))
+ (setq label default))
;; Insert the label into the label list
- (let* ((here-I-am-info
- (save-excursion
- (if (and (or naked no-insert)
- (integerp (cdr macro-cell)))
- (goto-char (cdr macro-cell)))
- (reftex-where-am-I)))
- (here-I-am (car here-I-am-info))
- (note (if (cdr here-I-am-info)
- ""
- "POSITION UNCERTAIN. RESCAN TO FIX."))
- (file (buffer-file-name))
- (text nil)
- (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
-
- (or (cdr here-I-am-info) (setq rescan-is-useful t))
-
- (when tail
- (push (list label typekey text file nil note) (cdr tail))
- (put reftex-docstruct-symbol 'modified t)))
+ (let* ((here-I-am-info
+ (save-excursion
+ (if (and (or naked no-insert)
+ (integerp (cdr macro-cell)))
+ (goto-char (cdr macro-cell)))
+ (reftex-where-am-I)))
+ (here-I-am (car here-I-am-info))
+ (note (if (cdr here-I-am-info)
+ ""
+ "POSITION UNCERTAIN. RESCAN TO FIX."))
+ (file (buffer-file-name))
+ (text nil)
+ (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
+
+ (or (cdr here-I-am-info) (setq rescan-is-useful t))
+
+ (when tail
+ (push (list label typekey text file nil note) (cdr tail))
+ (put reftex-docstruct-symbol 'modified t)))
;; Insert the label into the buffer
(unless no-insert
- (insert
- (if reftex-format-label-function
- (funcall reftex-format-label-function label format)
- (format format label)))
- (if (and reftex-plug-into-AUCTeX
- (fboundp 'LaTeX-add-labels))
- ;; Tell AUCTeX about this
- (LaTeX-add-labels label)))
+ (insert
+ (if reftex-format-label-function
+ (funcall reftex-format-label-function label format)
+ (format format label)))
+ (if (and reftex-plug-into-AUCTeX
+ (fboundp 'LaTeX-add-labels))
+ ;; Tell AUCTeX about this
+ (LaTeX-add-labels label)))
;; Delete the corresponding selection buffers to force update on next use.
(when reftex-auto-update-selection-buffers
- (reftex-erase-buffer (reftex-make-selection-buffer-name typekey))
- (reftex-erase-buffer (reftex-make-selection-buffer-name " ")))
+ (reftex-erase-buffer (reftex-make-selection-buffer-name typekey))
+ (reftex-erase-buffer (reftex-make-selection-buffer-name " ")))
(when (and rescan-is-useful reftex-allow-automatic-rescan)
- (reftex-parse-one))
+ (reftex-parse-one))
;; return value of the function is the label
label)))
@@ -269,24 +269,24 @@ This function is controlled by the settings of reftex-insert-label-flags."
Uses `reftex-derive-label-parameters' and `reftex-label-illegal-re'. It
also applies `reftex-translate-to-ascii-function' to the string."
(when (and reftex-translate-to-ascii-function
- (fboundp reftex-translate-to-ascii-function))
+ (fboundp reftex-translate-to-ascii-function))
(setq string (funcall reftex-translate-to-ascii-function string)))
(apply 'reftex-convert-string string
- "[-~ \t\n\r,;]+" reftex-label-illegal-re nil nil
- reftex-derive-label-parameters))
+ "[-~ \t\n\r,;]+" reftex-label-illegal-re nil nil
+ reftex-derive-label-parameters))
(defun reftex-latin1-to-ascii (string)
;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents
(let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy")
- (emacsp (not (featurep 'xemacs))))
- (mapconcat
+ (emacsp (not (featurep 'xemacs))))
+ (mapconcat
(lambda (c)
(cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1
- (char-to-string (aref tab (- c 128))))
- ((and emacsp ; Not for XEmacs
- (> c 2175) (< c 2304)) ; Mule Latin-1
- (char-to-string (aref tab (- c 2176))))
- (t (char-to-string c))))
+ (char-to-string (aref tab (- c 128))))
+ ((and emacsp ; Not for XEmacs
+ (> c 2175) (< c 2304)) ; Mule Latin-1
+ (char-to-string (aref tab (- c 2176))))
+ (t (char-to-string c))))
string "")))
(defun reftex-replace-prefix-escapes (prefix)
@@ -309,21 +309,21 @@ also applies `reftex-translate-to-ascii-function' to the string."
file)))
((equal letter "u")
(or (user-login-name) ""))
- ((equal letter "S")
- (let* (macro level-exp level)
- (save-excursion
- (save-match-data
- (when (re-search-backward reftex-section-regexp nil t)
- (setq macro (reftex-match-string 2)
- level-exp (cdr (assoc macro reftex-section-levels-all))
- level (if (symbolp level-exp)
- (abs (save-match-data
- (funcall level-exp)))
- (abs level-exp))))
- (cdr (or (assoc macro reftex-section-prefixes)
- (assoc level reftex-section-prefixes)
- (assq t reftex-section-prefixes)
- (list t "sec:")))))))
+ ((equal letter "S")
+ (let* (macro level-exp level)
+ (save-excursion
+ (save-match-data
+ (when (re-search-backward reftex-section-regexp nil t)
+ (setq macro (reftex-match-string 2)
+ level-exp (cdr (assoc macro reftex-section-levels-all))
+ level (if (symbolp level-exp)
+ (abs (save-match-data
+ (funcall level-exp)))
+ (abs level-exp))))
+ (cdr (or (assoc macro reftex-section-prefixes)
+ (assoc level reftex-section-prefixes)
+ (assq t reftex-section-prefixes)
+ (list t "sec:")))))))
(t "")))
(setq num (1- (+ (match-beginning 1) (length replace)))
prefix (replace-match replace nil nil prefix)))
@@ -396,40 +396,40 @@ When called with 2 C-u prefix args, disable magic word recognition."
;; check for active recursive edits
(reftex-check-recursive-edit)
- ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
+ ;; Ensure access to scanning info and rescan buffer if prefix arg is '(4)
(reftex-access-scan-info current-prefix-arg)
(unless type
;; guess type from context
(if (and reftex-guess-label-type
(setq type (reftex-guess-label-type)))
- (setq cut (cdr type)
- type (car type))
+ (setq cut (cdr type)
+ type (car type))
(setq type (reftex-query-label-type))))
- (let* ((refstyle
- (cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref")
- ((reftex-typekey-check type reftex-fref-is-default) "\\fref")
- (t "\\ref")))
- (reftex-format-ref-function reftex-format-ref-function)
- (form "\\ref{%s}")
- label labels sep sep1)
+ (let* ((refstyle
+ (cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref")
+ ((reftex-typekey-check type reftex-fref-is-default) "\\fref")
+ (t "\\ref")))
+ (reftex-format-ref-function reftex-format-ref-function)
+ (form "\\ref{%s}")
+ label labels sep sep1)
;; Have the user select a label
(set-marker reftex-select-return-marker (point))
(setq labels (save-excursion
- (reftex-offer-label-menu type)))
+ (reftex-offer-label-menu type)))
(reftex-ensure-compiled-variables)
(set-marker reftex-select-return-marker nil)
;; If the first entry is the symbol 'concat, concat all labels.
;; We keep the cdr of the first label for typekey etc information.
(if (eq (car labels) 'concat)
- (setq labels (list (list (mapconcat 'car (cdr labels) ",")
- (cdr (nth 1 labels))))))
+ (setq labels (list (list (mapconcat 'car (cdr labels) ",")
+ (cdr (nth 1 labels))))))
(setq type (nth 1 (car labels))
- form (or (cdr (assoc type reftex-typekey-to-format-alist))
- form))
-
+ form (or (cdr (assoc type reftex-typekey-to-format-alist))
+ form))
+
(cond
(no-insert
;; Just return the first label
@@ -439,60 +439,60 @@ When called with 2 C-u prefix args, disable magic word recognition."
nil)
(t
(while labels
- (setq label (car (car labels))
- sep (nth 2 (car labels))
- sep1 (cdr (assoc sep reftex-multiref-punctuation))
- labels (cdr labels))
- (when cut
- (backward-delete-char cut)
- (setq cut nil))
-
- ;; remove ~ if we do already have a space
- (when (and (= ?~ (string-to-char form))
- (member (preceding-char) '(?\ ?\t ?\n ?. ?~)))
- (setq form (substring form 1)))
- ;; do we have a special format?
- (setq reftex-format-ref-function
- (cond
- ((string= refstyle "\\vref") 'reftex-format-vref)
- ((string= refstyle "\\fref") 'reftex-format-fref)
- ((string= refstyle "\\Fref") 'reftex-format-Fref)
- (t reftex-format-ref-function)))
- ;; ok, insert the reference
- (if sep1 (insert sep1))
- (insert
- (if reftex-format-ref-function
- (funcall reftex-format-ref-function label form)
- (format form label label)))
- ;; take out the initial ~ for good
- (and (= ?~ (string-to-char form))
- (setq form (substring form 1))))
+ (setq label (car (car labels))
+ sep (nth 2 (car labels))
+ sep1 (cdr (assoc sep reftex-multiref-punctuation))
+ labels (cdr labels))
+ (when cut
+ (backward-delete-char cut)
+ (setq cut nil))
+
+ ;; remove ~ if we do already have a space
+ (when (and (= ?~ (string-to-char form))
+ (member (preceding-char) '(?\ ?\t ?\n)))
+ (setq form (substring form 1)))
+ ;; do we have a special format?
+ (setq reftex-format-ref-function
+ (cond
+ ((string= refstyle "\\vref") 'reftex-format-vref)
+ ((string= refstyle "\\fref") 'reftex-format-fref)
+ ((string= refstyle "\\Fref") 'reftex-format-Fref)
+ (t reftex-format-ref-function)))
+ ;; ok, insert the reference
+ (if sep1 (insert sep1))
+ (insert
+ (if reftex-format-ref-function
+ (funcall reftex-format-ref-function label form)
+ (format form label label)))
+ ;; take out the initial ~ for good
+ (and (= ?~ (string-to-char form))
+ (setq form (substring form 1))))
(message "")
label))))
(defun reftex-guess-label-type ()
;; Examine context to guess what a \ref might want to reference.
(let ((words reftex-words-to-typekey-alist)
- (case-fold-search t)
- (bound (max (point-min) (- (point) 35)))
- matched cell)
+ (case-fold-search t)
+ (bound (max (point-min) (- (point) 35)))
+ matched cell)
(save-excursion
(while (and (setq cell (pop words))
- (not (setq matched
- (re-search-backward (car cell) bound t))))))
+ (not (setq matched
+ (re-search-backward (car cell) bound t))))))
(if matched
- (cons (cdr cell) (- (match-end 0) (match-end 1)))
+ (cons (cdr cell) (- (match-end 0) (match-end 1)))
nil)))
(defvar reftex-select-label-map)
(defun reftex-offer-label-menu (typekey)
;; Offer a menu with the appropriate labels.
(let* ((buf (current-buffer))
- (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
- (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
- (xr-index 0)
+ (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
+ (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
+ (xr-index 0)
(here-I-am (car (reftex-where-am-I)))
- (here-I-am1 here-I-am)
+ (here-I-am1 here-I-am)
(toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
(files (reftex-typekey-check typekey reftex-label-menu-flags 7))
(context (not (reftex-typekey-check
@@ -502,158 +502,158 @@ When called with 2 C-u prefix args, disable magic word recognition."
(follow (reftex-typekey-check
typekey reftex-label-menu-flags 4))
(commented (nth 5 reftex-label-menu-flags))
- (prefix "")
- selection-buffers
+ (prefix "")
+ selection-buffers
offset rtn key data last-data entries)
(unwind-protect
(catch 'exit
(while t
(save-window-excursion
- (delete-other-windows)
- (setq reftex-call-back-to-this-buffer buf
- reftex-latex-syntax-table (syntax-table))
- (let ((default-major-mode 'reftex-select-label-mode))
- (if reftex-use-multiple-selection-buffers
- (switch-to-buffer-other-window
- (save-excursion
- (set-buffer buf)
- (reftex-make-selection-buffer-name typekey)))
- (switch-to-buffer-other-window "*RefTeX Select*")
- (reftex-erase-buffer)))
- (unless (eq major-mode 'reftex-select-label-mode)
- (reftex-select-label-mode))
- (add-to-list 'selection-buffers (current-buffer))
+ (delete-other-windows)
+ (setq reftex-call-back-to-this-buffer buf
+ reftex-latex-syntax-table (syntax-table))
+ (let ((default-major-mode 'reftex-select-label-mode))
+ (if reftex-use-multiple-selection-buffers
+ (switch-to-buffer-other-window
+ (save-excursion
+ (set-buffer buf)
+ (reftex-make-selection-buffer-name typekey)))
+ (switch-to-buffer-other-window "*RefTeX Select*")
+ (reftex-erase-buffer)))
+ (unless (eq major-mode 'reftex-select-label-mode)
+ (reftex-select-label-mode))
+ (add-to-list 'selection-buffers (current-buffer))
(setq truncate-lines t)
- (setq mode-line-format
- (list "---- " 'mode-line-buffer-identification
- " " 'global-mode-string " (" mode-name ")"
- " S<" 'refstyle ">"
- " -%-"))
- (cond
- ((= 0 (buffer-size))
- (let ((buffer-read-only nil))
- (message "Creating Selection Buffer...")
- (setq offset (reftex-insert-docstruct
- buf
- toc
- typekey
- nil ; index
- files
- context
- counter
- commented
- (or here-I-am offset)
- prefix
- nil ; no a toc buffer
- ))))
- (here-I-am
- (setq offset (reftex-get-offset buf here-I-am typekey)))
- (t (setq offset t)))
- (setq buffer-read-only t)
- (setq offset (or offset t))
+ (setq mode-line-format
+ (list "---- " 'mode-line-buffer-identification
+ " " 'global-mode-string " (" mode-name ")"
+ " S<" 'refstyle ">"
+ " -%-"))
+ (cond
+ ((= 0 (buffer-size))
+ (let ((buffer-read-only nil))
+ (message "Creating Selection Buffer...")
+ (setq offset (reftex-insert-docstruct
+ buf
+ toc
+ typekey
+ nil ; index
+ files
+ context
+ counter
+ commented
+ (or here-I-am offset)
+ prefix
+ nil ; no a toc buffer
+ ))))
+ (here-I-am
+ (setq offset (reftex-get-offset buf here-I-am typekey)))
+ (t (setq offset t)))
+ (setq buffer-read-only t)
+ (setq offset (or offset t))
(setq here-I-am nil) ; turn off determination of offset
(setq rtn
(reftex-select-item
reftex-select-label-prompt
reftex-select-label-help
- reftex-select-label-map
+ reftex-select-label-map
offset
'reftex-show-label-location follow))
(setq key (car rtn)
data (nth 1 rtn)
last-data (nth 2 rtn)
- offset t)
+ offset t)
(unless key (throw 'exit nil))
(cond
- ((eq key ?g)
- ;; update buffer
- (reftex-erase-buffer))
+ ((eq key ?g)
+ ;; update buffer
+ (reftex-erase-buffer))
((or (eq key ?r)
(eq key ?R))
;; rescan buffer
- (and current-prefix-arg (setq key ?R))
- (reftex-erase-buffer)
+ (and current-prefix-arg (setq key ?R))
+ (reftex-erase-buffer)
(reftex-reparse-document buf last-data key))
((eq key ?c)
;; toggle context mode
- (reftex-erase-buffer)
+ (reftex-erase-buffer)
(setq context (not context)))
((eq key ?s)
;; switch type
- (setq here-I-am here-I-am1)
+ (setq here-I-am here-I-am1)
(setq typekey (reftex-query-label-type)))
((eq key ?t)
;; toggle table of contents display, or change depth
- (reftex-erase-buffer)
- (if current-prefix-arg
- (setq reftex-toc-max-level (prefix-numeric-value
- current-prefix-arg))
- (setq toc (not toc))))
+ (reftex-erase-buffer)
+ (if current-prefix-arg
+ (setq reftex-toc-max-level (prefix-numeric-value
+ current-prefix-arg))
+ (setq toc (not toc))))
((eq key ?F)
;; toggle display of included file borders
- (reftex-erase-buffer)
+ (reftex-erase-buffer)
(setq files (not files)))
((eq key ?#)
;; toggle counter display
- (reftex-erase-buffer)
+ (reftex-erase-buffer)
(setq counter (not counter)))
((eq key ?%)
;; toggle display of commented labels
- (reftex-erase-buffer)
+ (reftex-erase-buffer)
(setq commented (not commented)))
((eq key ?l)
;; reuse the last referenced label again
(setq entries reftex-last-used-reference)
(throw 'exit t))
- ((eq key ?x)
- ;; select an external document
- (setq xr-index (reftex-select-external-document
- xr-alist xr-index))
- (setq buf (or (reftex-get-file-buffer-force
- (cdr (nth xr-index xr-alist)))
- (error "Cannot switch document"))
- prefix (or (car (nth xr-index xr-alist)) ""))
+ ((eq key ?x)
+ ;; select an external document
+ (setq xr-index (reftex-select-external-document
+ xr-alist xr-index))
+ (setq buf (or (reftex-get-file-buffer-force
+ (cdr (nth xr-index xr-alist)))
+ (error "Cannot switch document"))
+ prefix (or (car (nth xr-index xr-alist)) ""))
+ (set-buffer buf)
+ (reftex-access-scan-info))
+ ((stringp key)
+ (setq entries
+ (list
+ (list
+ (or (assoc key (symbol-value reftex-docstruct-symbol))
+ (list key typekey)))))
+ (throw 'exit t))
+ ((memq key '(?a ?A return))
+ (cond
+ (reftex-select-marked
+ (setq entries (nreverse reftex-select-marked)))
+ (data
+ (setq entries (list (list data))))
+ (t (setq entries nil)))
+ (when entries
+ (if (equal key ?a) (push 'concat entries))
+ (setq reftex-last-used-reference entries))
(set-buffer buf)
- (reftex-access-scan-info))
- ((stringp key)
- (setq entries
- (list
- (list
- (or (assoc key (symbol-value reftex-docstruct-symbol))
- (list key typekey)))))
(throw 'exit t))
- ((memq key '(?a ?A return))
- (cond
- (reftex-select-marked
- (setq entries (nreverse reftex-select-marked)))
- (data
- (setq entries (list (list data))))
- (t (setq entries nil)))
- (when entries
- (if (equal key ?a) (push 'concat entries))
- (setq reftex-last-used-reference entries))
- (set-buffer buf)
- (throw 'exit t))
- (t (error "This should not happen (reftex-offer-label-menu)"))))))
+ (t (error "This should not happen (reftex-offer-label-menu)"))))))
(save-excursion
- (while reftex-buffers-with-changed-invisibility
- (set-buffer (car (car reftex-buffers-with-changed-invisibility)))
- (setq buffer-invisibility-spec
- (cdr (pop reftex-buffers-with-changed-invisibility)))))
+ (while reftex-buffers-with-changed-invisibility
+ (set-buffer (car (car reftex-buffers-with-changed-invisibility)))
+ (setq buffer-invisibility-spec
+ (cdr (pop reftex-buffers-with-changed-invisibility)))))
(mapcar (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf)))
- selection-buffers)
+ selection-buffers)
(reftex-kill-temporary-buffers))
;; Add the prefixes, put together the relevant information in the form
;; (LABEL TYPEKEY SEPARATOR) and return a list of those.
(mapcar (lambda (x)
- (if (listp x)
- (list (concat prefix (car (car x)))
- (nth 1 (car x))
- (nth 2 x))
- x))
- entries)))
+ (if (listp x)
+ (list (concat prefix (car (car x)))
+ (nth 1 (car x))
+ (nth 2 x))
+ x))
+ entries)))
(defun reftex-reparse-document (&optional buffer data key)
;; Rescan the document.
@@ -669,14 +669,14 @@ When called with 2 C-u prefix args, disable magic word recognition."
(defun reftex-query-label-type ()
;; Ask for label type
- (let ((key (reftex-select-with-char
- reftex-type-query-prompt reftex-type-query-help 3)))
+ (let ((key (reftex-select-with-char
+ reftex-type-query-prompt reftex-type-query-help 3)))
(unless (member (char-to-string key) reftex-typekey-list)
(error "No such label type: %s" (char-to-string key)))
(char-to-string key)))
-(defun reftex-show-label-location (data forward no-revisit
- &optional stay error)
+(defun reftex-show-label-location (data forward no-revisit
+ &optional stay error)
;; View the definition site of a label in another window.
;; DATA is an entry from the docstruct list.
;; FORWARD indicates if the label is likely forward from current point.
@@ -685,53 +685,53 @@ When called with 2 C-u prefix args, disable magic word recognition."
;; ERROR means throw an error exception when the label cannot be found.
;; If ERROR is nil, the return value of this function indicates success.
(let* ((this-window (selected-window))
- (errorf (if error 'error 'message))
+ (errorf (if error 'error 'message))
label file buffer re found)
(catch 'exit
(setq label (nth 0 data)
- file (nth 3 data))
+ file (nth 3 data))
(unless file
- (funcall errorf "Unknown label - reparse might help")
- (throw 'exit nil))
+ (funcall errorf "Unknown label - reparse might help")
+ (throw 'exit nil))
;; Goto the file in another window
- (setq buffer
- (if no-revisit
- (reftex-get-buffer-visiting file)
- (reftex-get-file-buffer-force
- file (not reftex-keep-temporary-buffers))))
+ (setq buffer
+ (if no-revisit
+ (reftex-get-buffer-visiting file)
+ (reftex-get-file-buffer-force
+ file (not reftex-keep-temporary-buffers))))
(if buffer
;; good - the file is available
(switch-to-buffer-other-window buffer)
;; we have got a problem here. The file does not exist.
;; Let' get out of here..
- (funcall errorf "Label %s not found" label)
- (throw 'exit nil))
+ (funcall errorf "Label %s not found" label)
+ (throw 'exit nil))
;; search for that label
(setq re (format reftex-find-label-regexp-format (regexp-quote label)))
(setq found
- (if forward
- (re-search-forward re nil t)
- (re-search-backward re nil t)))
+ (if forward
+ (re-search-forward re nil t)
+ (re-search-backward re nil t)))
(unless found
(goto-char (point-min))
- (unless (setq found (re-search-forward re nil t))
- ;; Ooops. Must be in a macro with distributed args.
- (setq found
- (re-search-forward
- (format reftex-find-label-regexp-format2
- (regexp-quote label)) nil t))))
+ (unless (setq found (re-search-forward re nil t))
+ ;; Ooops. Must be in a macro with distributed args.
+ (setq found
+ (re-search-forward
+ (format reftex-find-label-regexp-format2
+ (regexp-quote label)) nil t))))
(if (match-end 3)
- (progn
- (reftex-highlight 0 (match-beginning 3) (match-end 3))
- (reftex-show-entry (match-beginning 3) (match-end 3))
- (recenter '(4))
- (unless stay (select-window this-window)))
- (select-window this-window)
- (funcall errorf "Label %s not found" label))
+ (progn
+ (reftex-highlight 0 (match-beginning 3) (match-end 3))
+ (reftex-show-entry (match-beginning 3) (match-end 3))
+ (recenter '(4))
+ (unless stay (select-window this-window)))
+ (select-window this-window)
+ (funcall errorf "Label %s not found" label))
found)))
(defvar font-lock-mode)
@@ -744,34 +744,34 @@ When called with 2 C-u prefix args, disable magic word recognition."
(re-search-forward "[\n\r]" nil 1 n) (point))))
(cond
((and (boundp 'buffer-invisibility-spec) buffer-invisibility-spec
- (get-char-property (1+ beg-hlt) 'invisible))
+ (get-char-property (1+ beg-hlt) 'invisible))
;; Invisible with text properties. That is easy to change.
(push (cons (current-buffer) buffer-invisibility-spec)
- reftex-buffers-with-changed-invisibility)
+ reftex-buffers-with-changed-invisibility)
(setq buffer-invisibility-spec nil))
((string-match "\r" (buffer-substring beg end))
;; Invisible with selective display. We need to copy it.
(let ((string (buffer-substring-no-properties beg end)))
- (switch-to-buffer "*RefTeX Context Copy*")
- (setq buffer-read-only nil)
- (erase-buffer)
- (insert string)
- (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
- (goto-char (- beg-hlt beg))
- (reftex-highlight 0 (1+ (- beg-hlt beg)) (1+ (- end-hlt beg)))
- (if (reftex-refontify)
- (when (or (not (eq major-mode 'latex-mode))
- (not font-lock-mode))
- (latex-mode)
- (run-hook-with-args
- 'reftex-pre-refontification-functions
- reftex-call-back-to-this-buffer 'reftex-hidden)
- (turn-on-font-lock))
- (when (or (not (eq major-mode 'fundamental-mode))
- font-lock-mode)
- (fundamental-mode)))
- (run-hooks 'reftex-display-copied-context-hook)
- (setq buffer-read-only t))))))
+ (switch-to-buffer "*RefTeX Context Copy*")
+ (setq buffer-read-only nil)
+ (erase-buffer)
+ (insert string)
+ (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
+ (goto-char (- beg-hlt beg))
+ (reftex-highlight 0 (1+ (- beg-hlt beg)) (1+ (- end-hlt beg)))
+ (if (reftex-refontify)
+ (when (or (not (eq major-mode 'latex-mode))
+ (not font-lock-mode))
+ (latex-mode)
+ (run-hook-with-args
+ 'reftex-pre-refontification-functions
+ reftex-call-back-to-this-buffer 'reftex-hidden)
+ (turn-on-font-lock))
+ (when (or (not (eq major-mode 'fundamental-mode))
+ font-lock-mode)
+ (fundamental-mode)))
+ (run-hooks 'reftex-display-copied-context-hook)
+ (setq buffer-read-only t))))))
(defun reftex-varioref-vref ()
"Insert a reference using the `\\vref' macro from the varioref package."
@@ -782,15 +782,15 @@ When called with 2 C-u prefix args, disable magic word recognition."
"Insert a reference using the `\\fref' macro from the fancyref package."
(interactive)
(let ((reftex-format-ref-function 'reftex-format-fref)
- ;;(reftex-guess-label-type nil) ;FIXME do we want this????
- )
+ ;;(reftex-guess-label-type nil) ;FIXME do we want this????
+ )
(reftex-reference)))
(defun reftex-fancyref-Fref ()
"Insert a reference using the `\\Fref' macro from the fancyref package."
(interactive)
(let ((reftex-format-ref-function 'reftex-format-Fref)
- ;;(reftex-guess-label-type nil) ;FIXME do we want this????
- )
+ ;;(reftex-guess-label-type nil) ;FIXME do we want this????
+ )
(reftex-reference)))
(defun reftex-format-vref (label fmt)
@@ -802,26 +802,36 @@ When called with 2 C-u prefix args, disable magic word recognition."
(defun reftex-format-fref (label def-fmt)
(format "\\fref{%s}" label))
+
+;(defun reftex-goto-label ()
+; (interactive)
+; (reftex-access-scan-info)
+; (let* ((docstruct (symbol-value reftex-docstruct-symbol))
+; (label (completing-read "Label: " docstruct
+; (lambda (x) (stringp (car x))) t))
+; (selection (assoc label docstruct)))
+; (reftex-show-label-location selection t nil 'stay)
+; (reftex-unhighlight 0)))
+
(defun reftex-goto-label (&optional other-window)
"Prompt for a label (with completion) and jump to the location of this label.
Optional prefix argument OTHER-WINDOW goes to the label in another window."
(interactive "P")
(reftex-access-scan-info)
(let* ((wcfg (current-window-configuration))
- (docstruct (symbol-value reftex-docstruct-symbol))
- (label (completing-read "Label: " docstruct
- (lambda (x) (stringp (car x))) t))
- (selection (assoc label docstruct))
- (where (progn
- (reftex-show-label-location selection t nil 'stay)
- (point-marker))))
+ (docstruct (symbol-value reftex-docstruct-symbol))
+ (label (completing-read "Label: " docstruct
+ (lambda (x) (stringp (car x))) t))
+ (selection (assoc label docstruct))
+ (where (progn
+ (reftex-show-label-location selection t nil 'stay)
+ (point-marker))))
(unless other-window
(set-window-configuration wcfg)
(switch-to-buffer (marker-buffer where))
- (goto-char where))
+ (goto-char where))
(reftex-unhighlight 0)))
-;;; arch-tag: 52f14032-fb76-4d31-954f-750c72415675
;;; reftex-ref.el ends here