1 ;;; reftex-ref.el --- code to create labels and references with RefTeX
2 ;; Copyright (c) 1997, 1998, 1999, 2000, 2003, 2004, 2005
3 ;; Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <dominik@science.uva.nl>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
34 (defun reftex-label-location (&optional bound)
35 "Return the environment or macro which determines the label type at point.
36 If optional BOUND is an integer, limit backward searches to that point."
38 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
39 (loc2 (reftex-what-environment reftex-label-env-list bound))
40 (loc3 (reftex-what-special-env 1 bound))
41 (p1 (or (cdr loc1) 0))
42 (p2 (or (cdr loc2) 0))
43 (p3 (or (cdr loc3) 0))
44 (pmax (max p1 p2 p3)))
46 (setq reftex-location-start pmax)
49 ;; A macro. Default context after macro name.
50 (setq reftex-default-context-position (+ p1 (length (car loc1))))
51 (or (car loc1) "section"))
53 ;; An environment. Default context after \begin{name}.
54 (setq reftex-default-context-position (+ p2 8 (length (car loc2))))
55 (or (car loc2) "section"))
57 ;; A special. Default context right there.
58 (setq reftex-default-context-position p3)
59 (setq loc3 (car loc3))
60 (cond ((null loc3) "section")
61 ((symbolp loc3) (symbol-name loc3))
64 (t ;; This should not happen, I think?
67 (defun reftex-label-info-update (cell)
68 ;; Update information about just one label in a different file.
69 ;; CELL contains the old info list
70 (let* ((label (nth 0 cell))
71 (typekey (nth 1 cell))
72 ;; (text (nth 2 cell))
74 (comment (nth 4 cell))
76 (buf (reftex-get-file-buffer-force
77 file (not (eq t reftex-keep-temporary-buffers)))))
79 (list label typekey "" file comment "LOST LABEL. RESCAN TO FIX.")
86 (if (or (re-search-forward
87 (format reftex-find-label-regexp-format
88 (regexp-quote label)) nil t)
90 (format reftex-find-label-regexp-format2
91 (regexp-quote label)) nil t))
95 (append (reftex-label-info label file) (list note)))
96 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")))))))
98 (defun reftex-label-info (label &optional file bound derive env-or-mac)
99 ;; Return info list on LABEL at point.
100 (let* ((prefix (if (string-match "^[a-zA-Z0-9]+:" label)
101 (match-string 0 label)))
102 (typekey (cdr (assoc prefix reftex-prefix-to-typekey-alist)))
103 (file (or file (buffer-file-name)))
104 (trust reftex-trust-label-prefix)
105 (in-comment (reftex-in-comment)))
107 (cond ((eq trust t) t)
109 ((stringp trust) (string-match trust typekey))
110 ((listp trust) (member typekey trust))
113 (reftex-nicify-text (reftex-context-substring))
115 (let* ((env-or-mac (or env-or-mac (reftex-label-location bound)))
116 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist)))
117 (parse (nth 2 (assoc env-or-mac reftex-env-or-mac-alist)))
118 (text (reftex-short-context env-or-mac parse reftex-location-start
120 (list label typekey text file in-comment)))))
122 ;;; Creating labels ---------------------------------------------------------
124 (defun reftex-label (&optional environment no-insert)
125 "Insert a unique label. Return the label.
126 If ENVIRONMENT is given, don't bother to find out yourself.
127 If NO-INSERT is non-nil, do not insert label into buffer.
128 With prefix arg, force to rescan document first.
129 When you are prompted to enter or confirm a label, and you reply with
130 just the prefix or an empty string, no label at all will be inserted.
131 A new label is also recorded into the label list.
132 This function is controlled by the settings of reftex-insert-label-flags."
136 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4).
137 (reftex-access-scan-info current-prefix-arg)
139 ;; Find out what kind of environment this is and abort if necessary.
140 (if (or (not environment)
141 (not (assoc environment reftex-env-or-mac-alist)))
142 (setq environment (reftex-label-location)))
144 (error "Can't figure out what kind of label should be inserted"))
148 (let* ((entry (assoc environment reftex-env-or-mac-alist))
149 (typekey (nth 1 entry))
150 (format (nth 3 entry))
151 (macro-cell (reftex-what-macro 1))
152 (entry1 (assoc (car macro-cell) reftex-env-or-mac-alist))
153 label naked prefix valid default force-prompt rescan-is-useful)
154 (when (and (or (nth 5 entry) (nth 5 entry1))
155 (memq (preceding-char) '(?\[ ?\{)))
156 ;; This is an argument of a label macro. Insert naked label.
157 (setq naked t format "%s"))
159 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
160 (concat typekey "-")))
161 ;; Replace any escapes in the prefix
162 (setq prefix (reftex-replace-prefix-escapes prefix))
164 ;; Make a default label.
167 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
168 ;; Derive a label from context.
169 (setq reftex-active-toc (reftex-last-assoc-before-elt
170 'toc (car (reftex-where-am-I))
171 (symbol-value reftex-docstruct-symbol)))
172 (setq default (reftex-no-props
173 (nth 2 (reftex-label-info " " nil nil t))))
174 ;; Catch the cases where the is actually no context available.
175 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
176 (string-match "INVALID VALUE OF PARSE" default)
177 (string-match "SECTION HEADING NOT FOUND" default)
178 (string-match "HOOK ERROR" default)
179 (string-match "^[ \t]*$" default))
181 force-prompt t) ; need to prompt
184 (funcall reftex-string-to-label-function default)))
187 (setq default (reftex-uniquify-label default nil "-"))))
189 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags))
190 ;; Minimal default: the user will be prompted.
191 (setq default prefix))
194 ;; Make an automatic label.
195 (setq default (reftex-uniquify-label prefix t))))
197 ;; Should we ask the user?
198 (if (or (reftex-typekey-check typekey
199 (nth 1 reftex-insert-label-flags)) ; prompt
203 ;; iterate until we get a legal label
205 (setq label (read-string
206 (if naked "Naked Label: " "Label: ")
209 ;; Lets make sure that this is a legal label
212 ((string-match (concat "\\`\\(" (regexp-quote prefix)
215 ;; No label at all, please
216 (message "No label inserted.")
219 ;; Test if label contains strange characters
220 ((string-match reftex-label-illegal-re label)
221 (message "Label \"%s\" contains invalid characters" label)
225 ;; Look it up in the label list
226 ((setq entry (assoc label
227 (symbol-value reftex-docstruct-symbol)))
230 (format "Label '%s' exists. Use anyway? " label))
236 (setq label default))
238 ;; Insert the label into the label list
239 (let* ((here-I-am-info
241 (if (and (or naked no-insert)
242 (integerp (cdr macro-cell)))
243 (goto-char (cdr macro-cell)))
244 (reftex-where-am-I)))
245 (here-I-am (car here-I-am-info))
246 (note (if (cdr here-I-am-info)
248 "POSITION UNCERTAIN. RESCAN TO FIX."))
249 (file (buffer-file-name))
251 (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
253 (or (cdr here-I-am-info) (setq rescan-is-useful t))
256 (push (list label typekey text file nil note) (cdr tail))
257 (put reftex-docstruct-symbol 'modified t)))
259 ;; Insert the label into the buffer
262 (if reftex-format-label-function
263 (funcall reftex-format-label-function label format)
264 (format format label)))
265 (if (and reftex-plug-into-AUCTeX
266 (fboundp 'LaTeX-add-labels))
267 ;; Tell AUCTeX about this
268 (LaTeX-add-labels label)))
270 ;; Delete the corresponding selection buffers to force update on next use.
271 (when reftex-auto-update-selection-buffers
272 (reftex-erase-buffer (reftex-make-selection-buffer-name typekey))
273 (reftex-erase-buffer (reftex-make-selection-buffer-name " ")))
275 (when (and rescan-is-useful reftex-allow-automatic-rescan)
278 ;; return value of the function is the label
281 (defun reftex-string-to-label (string)
282 "Convert a string (a sentence) to a label.
283 Uses `reftex-derive-label-parameters' and `reftex-label-illegal-re'. It
284 also applies `reftex-translate-to-ascii-function' to the string."
285 (when (and reftex-translate-to-ascii-function
286 (fboundp reftex-translate-to-ascii-function))
287 (setq string (funcall reftex-translate-to-ascii-function string)))
288 (apply 'reftex-convert-string string
289 "[-~ \t\n\r,;]+" reftex-label-illegal-re nil nil
290 reftex-derive-label-parameters))
292 (defun reftex-latin1-to-ascii (string)
293 ;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents
294 (let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy")
295 (emacsp (not (featurep 'xemacs))))
298 (cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1
299 (char-to-string (aref tab (- c 128))))
300 ((and emacsp ; Not for XEmacs
301 (> c 2175) (< c 2304)) ; Mule Latin-1
302 (char-to-string (aref tab (- c 2176))))
303 (t (char-to-string c))))
306 (defun reftex-replace-prefix-escapes (prefix)
307 ;; Replace %escapes in a label prefix
309 (let (letter (num 0) replace)
310 (while (string-match "\\%\\([a-zA-Z]\\)" prefix num)
311 (setq letter (match-string 1 prefix))
316 (file-name-sans-extension
317 (file-name-nondirectory (buffer-file-name))))
319 (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
320 (file (file-name-sans-extension (buffer-file-name))))
321 (if (string-match (concat "\\`" (regexp-quote masterdir))
323 (substring file (length masterdir))
326 (file-name-sans-extension
327 (file-name-nondirectory (reftex-TeX-master-file))))
329 (file-name-nondirectory
330 (substring (file-name-directory (reftex-TeX-master-file))
333 (or (user-login-name) ""))
335 (let* (macro level-exp level)
338 (when (re-search-backward reftex-section-regexp nil t)
339 (setq macro (reftex-match-string 2)
340 level-exp (cdr (assoc macro reftex-section-levels-all))
341 level (if (symbolp level-exp)
342 (abs (save-match-data
343 (funcall level-exp)))
345 (cdr (or (assoc macro reftex-section-prefixes)
346 (assoc level reftex-section-prefixes)
347 (assq t reftex-section-prefixes)
348 (list t "sec:")))))))
350 (setq num (1- (+ (match-beginning 1) (length replace)))
351 prefix (replace-match replace nil nil prefix)))
354 (defun reftex-uniquify-label (label &optional force separator)
355 ;; Make label unique by appending a number.
356 ;; Optional FORCE means, force appending a number, even if label is unique.
357 ;; Optional SEPARATOR is a string to stick between label and number.
359 ;; Ensure access to scanning info
360 (reftex-access-scan-info)
364 (not (assoc label (symbol-value reftex-docstruct-symbol))))
367 (let* ((label-numbers (assq 'label-numbers
368 (symbol-value reftex-docstruct-symbol)))
369 (label-numbers-alist (cdr label-numbers))
370 (cell (or (assoc label label-numbers-alist)
371 (car (setcdr label-numbers
373 label-numbers-alist)))))
374 (num (1+ (cdr cell)))
375 (sep (or separator "")))
376 (while (assoc (concat label sep (int-to-string num))
377 (symbol-value reftex-docstruct-symbol))
380 (concat label sep (int-to-string num))))))
382 ;;; Referencing labels ------------------------------------------------------
384 ;; Help string for the reference label menu
385 (defconst reftex-select-label-prompt
386 "Select: [n]ext [p]revious [r]escan [ ]context e[x]tern [q]uit RET [?]HELP+more")
388 (defconst reftex-select-label-help
389 " n / p Go to next/previous label (Cursor motion works as well)
390 C-c C-n/p Go to next/previous section heading.
391 b / l Jump back to previous selection / Reuse last referenced label.
392 z Jump to a specific section, e.g. '3 z' jumps to section 3.
393 g / s Update menu / Switch label type.
394 r / C-u r Reparse document / Reparse entire document.
395 x Switch to label menu of external document (with LaTeX package `xr').
396 F t c Toggle: [F]ile borders, [t]able of contents, [c]ontext
397 # % Toggle: [#] label counters, [%] labels in comments
398 SPC / f Show full context in other window / Toggle follow mode.
399 . Show insertion point in other window.
400 v / V Toggle \\ref <-> \\vref / Rotate \\ref <=> \\fref <=> \\Fref
401 TAB Enter a label with completion.
402 m , - + Mark entry. `,-+' also assign a separator.
403 a / A Put all marked entries into one/many \\ref commands.
404 q / RET Quit without referencing / Accept current label (also on mouse-2).")
406 (defun reftex-reference (&optional type no-insert cut)
407 "Make a LaTeX reference. Look only for labels of a certain TYPE.
408 With prefix arg, force to rescan buffer for labels. This should only be
409 necessary if you have recently entered labels yourself without using
410 reftex-label. Rescanning of the buffer can also be requested from the
411 label selection menu.
412 The function returns the selected label or nil.
413 If NO-INSERT is non-nil, do not insert \\ref command, just return label.
414 When called with 2 C-u prefix args, disable magic word recognition."
418 ;; check for active recursive edits
419 (reftex-check-recursive-edit)
421 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
422 (reftex-access-scan-info current-prefix-arg)
425 ;; guess type from context
426 (if (and reftex-guess-label-type
427 (setq type (reftex-guess-label-type)))
430 (setq type (reftex-query-label-type))))
433 (cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref")
434 ((reftex-typekey-check type reftex-fref-is-default) "\\fref")
436 (reftex-format-ref-function reftex-format-ref-function)
438 label labels sep sep1)
440 ;; Have the user select a label
441 (set-marker reftex-select-return-marker (point))
442 (setq labels (save-excursion
443 (reftex-offer-label-menu type)))
444 (reftex-ensure-compiled-variables)
445 (set-marker reftex-select-return-marker nil)
446 ;; If the first entry is the symbol 'concat, concat all labels.
447 ;; We keep the cdr of the first label for typekey etc information.
448 (if (eq (car labels) 'concat)
449 (setq labels (list (list (mapconcat 'car (cdr labels) ",")
450 (cdr (nth 1 labels))))))
451 (setq type (nth 1 (car labels))
452 form (or (cdr (assoc type reftex-typekey-to-format-alist))
457 ;; Just return the first label
464 (setq label (car (car labels))
465 sep (nth 2 (car labels))
466 sep1 (cdr (assoc sep reftex-multiref-punctuation))
469 (backward-delete-char cut)
472 ;; remove ~ if we do already have a space
473 (when (and (= ?~ (string-to-char form))
474 (member (preceding-char) '(?\ ?\t ?\n ?~)))
475 (setq form (substring form 1)))
476 ;; do we have a special format?
477 (setq reftex-format-ref-function
479 ((string= refstyle "\\vref") 'reftex-format-vref)
480 ((string= refstyle "\\fref") 'reftex-format-fref)
481 ((string= refstyle "\\Fref") 'reftex-format-Fref)
482 (t reftex-format-ref-function)))
483 ;; ok, insert the reference
484 (if sep1 (insert sep1))
486 (if reftex-format-ref-function
487 (funcall reftex-format-ref-function label form)
488 (format form label label)))
489 ;; take out the initial ~ for good
490 (and (= ?~ (string-to-char form))
491 (setq form (substring form 1))))
495 (defun reftex-guess-label-type ()
496 ;; Examine context to guess what a \ref might want to reference.
497 (let ((words reftex-words-to-typekey-alist)
499 (bound (max (point-min) (- (point) 35)))
502 (while (and (setq cell (pop words))
504 (re-search-backward (car cell) bound t))))))
506 (cons (cdr cell) (- (match-end 0) (match-end 1)))
509 (defvar reftex-select-label-map)
510 (defun reftex-offer-label-menu (typekey)
511 ;; Offer a menu with the appropriate labels.
512 (let* ((buf (current-buffer))
513 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
514 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
516 (here-I-am (car (reftex-where-am-I)))
517 (here-I-am1 here-I-am)
518 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
519 (files (reftex-typekey-check typekey reftex-label-menu-flags 7))
520 (context (not (reftex-typekey-check
521 typekey reftex-label-menu-flags 3)))
522 (counter (reftex-typekey-check
523 typekey reftex-label-menu-flags 2))
524 (follow (reftex-typekey-check
525 typekey reftex-label-menu-flags 4))
526 (commented (nth 5 reftex-label-menu-flags))
529 offset rtn key data last-data entries)
534 (save-window-excursion
535 (delete-other-windows)
536 (setq reftex-call-back-to-this-buffer buf
537 reftex-latex-syntax-table (syntax-table))
538 (let ((default-major-mode 'reftex-select-label-mode))
539 (if reftex-use-multiple-selection-buffers
540 (switch-to-buffer-other-window
543 (reftex-make-selection-buffer-name typekey)))
544 (switch-to-buffer-other-window "*RefTeX Select*")
545 (reftex-erase-buffer)))
546 (unless (eq major-mode 'reftex-select-label-mode)
547 (reftex-select-label-mode))
548 (add-to-list 'selection-buffers (current-buffer))
549 (setq truncate-lines t)
550 (setq mode-line-format
551 (list "---- " 'mode-line-buffer-identification
552 " " 'global-mode-string " (" mode-name ")"
557 (let ((buffer-read-only nil))
558 (message "Creating Selection Buffer...")
559 (setq offset (reftex-insert-docstruct
568 (or here-I-am offset)
570 nil ; no a toc buffer
573 (setq offset (reftex-get-offset buf here-I-am typekey)))
575 (setq buffer-read-only t)
576 (setq offset (or offset t))
578 (setq here-I-am nil) ; turn off determination of offset
581 reftex-select-label-prompt
582 reftex-select-label-help
583 reftex-select-label-map
585 'reftex-show-label-location follow))
588 last-data (nth 2 rtn)
590 (unless key (throw 'exit nil))
594 (reftex-erase-buffer))
598 (and current-prefix-arg (setq key ?R))
599 (reftex-erase-buffer)
600 (reftex-reparse-document buf last-data key))
602 ;; toggle context mode
603 (reftex-erase-buffer)
604 (setq context (not context)))
607 (setq here-I-am here-I-am1)
608 (setq typekey (reftex-query-label-type)))
610 ;; toggle table of contents display, or change depth
611 (reftex-erase-buffer)
612 (if current-prefix-arg
613 (setq reftex-toc-max-level (prefix-numeric-value
615 (setq toc (not toc))))
617 ;; toggle display of included file borders
618 (reftex-erase-buffer)
619 (setq files (not files)))
621 ;; toggle counter display
622 (reftex-erase-buffer)
623 (setq counter (not counter)))
625 ;; toggle display of commented labels
626 (reftex-erase-buffer)
627 (setq commented (not commented)))
629 ;; reuse the last referenced label again
630 (setq entries reftex-last-used-reference)
633 ;; select an external document
634 (setq xr-index (reftex-select-external-document
636 (setq buf (or (reftex-get-file-buffer-force
637 (cdr (nth xr-index xr-alist)))
638 (error "Cannot switch document"))
639 prefix (or (car (nth xr-index xr-alist)) ""))
641 (reftex-access-scan-info))
646 (or (assoc key (symbol-value reftex-docstruct-symbol))
647 (list key typekey)))))
649 ((memq key '(?a ?A return))
651 (reftex-select-marked
652 (setq entries (nreverse reftex-select-marked)))
654 (setq entries (list (list data))))
655 (t (setq entries nil)))
657 (if (equal key ?a) (push 'concat entries))
658 (setq reftex-last-used-reference entries))
661 (t (error "This should not happen (reftex-offer-label-menu)"))))))
663 (while reftex-buffers-with-changed-invisibility
664 (set-buffer (car (car reftex-buffers-with-changed-invisibility)))
665 (setq buffer-invisibility-spec
666 (cdr (pop reftex-buffers-with-changed-invisibility)))))
667 (mapcar (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf)))
669 (reftex-kill-temporary-buffers))
670 ;; Add the prefixes, put together the relevant information in the form
671 ;; (LABEL TYPEKEY SEPARATOR) and return a list of those.
674 (list (concat prefix (car (car x)))
680 (defun reftex-reparse-document (&optional buffer data key)
681 ;; Rescan the document.
682 (save-window-excursion
685 (if (not (bufferp buffer))
686 (error "No such buffer %s" (buffer-name buffer))
687 (set-buffer buffer)))
688 (let ((arg (if (eq key ?R) '(16) '(4)))
690 (reftex-access-scan-info arg file)))))
692 (defun reftex-query-label-type ()
693 ;; Ask for label type
694 (let ((key (reftex-select-with-char
695 reftex-type-query-prompt reftex-type-query-help 3)))
696 (unless (member (char-to-string key) reftex-typekey-list)
697 (error "No such label type: %s" (char-to-string key)))
698 (char-to-string key)))
700 (defun reftex-show-label-location (data forward no-revisit
701 &optional stay error)
702 ;; View the definition site of a label in another window.
703 ;; DATA is an entry from the docstruct list.
704 ;; FORWARD indicates if the label is likely forward from current point.
705 ;; NO-REVISIT means do not load a file to show this label.
706 ;; STAY means leave the new window selected.
707 ;; ERROR means throw an error exception when the label cannot be found.
708 ;; If ERROR is nil, the return value of this function indicates success.
709 (let* ((this-window (selected-window))
710 (errorf (if error 'error 'message))
711 label file buffer re found)
714 (setq label (nth 0 data)
718 (funcall errorf "Unknown label - reparse might help")
721 ;; Goto the file in another window
724 (reftex-get-buffer-visiting file)
725 (reftex-get-file-buffer-force
726 file (not reftex-keep-temporary-buffers))))
728 ;; good - the file is available
729 (switch-to-buffer-other-window buffer)
730 ;; we have got a problem here. The file does not exist.
731 ;; Let' get out of here..
732 (funcall errorf "Label %s not found" label)
735 ;; search for that label
736 (setq re (format reftex-find-label-regexp-format (regexp-quote label)))
739 (re-search-forward re nil t)
740 (re-search-backward re nil t)))
742 (goto-char (point-min))
743 (unless (setq found (re-search-forward re nil t))
744 ;; Ooops. Must be in a macro with distributed args.
747 (format reftex-find-label-regexp-format2
748 (regexp-quote label)) nil t))))
751 (reftex-highlight 0 (match-beginning 3) (match-end 3))
752 (reftex-show-entry (match-beginning 3) (match-end 3))
754 (unless stay (select-window this-window)))
755 (select-window this-window)
756 (funcall errorf "Label %s not found" label))
759 (defvar font-lock-mode)
760 (defun reftex-show-entry (beg-hlt end-hlt)
761 ;; Show entry if point is hidden
762 (let* ((n (/ (reftex-window-height) 2))
764 (re-search-backward "[\n\r]" nil 1 n) (point)))
766 (re-search-forward "[\n\r]" nil 1 n) (point))))
768 ((and (boundp 'buffer-invisibility-spec) buffer-invisibility-spec
769 (get-char-property (1+ beg-hlt) 'invisible))
770 ;; Invisible with text properties. That is easy to change.
771 (push (cons (current-buffer) buffer-invisibility-spec)
772 reftex-buffers-with-changed-invisibility)
773 (setq buffer-invisibility-spec nil))
774 ((string-match "\r" (buffer-substring beg end))
775 ;; Invisible with selective display. We need to copy it.
776 (let ((string (buffer-substring-no-properties beg end)))
777 (switch-to-buffer "*RefTeX Context Copy*")
778 (setq buffer-read-only nil)
781 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
782 (goto-char (- beg-hlt beg))
783 (reftex-highlight 0 (1+ (- beg-hlt beg)) (1+ (- end-hlt beg)))
784 (if (reftex-refontify)
785 (when (or (not (eq major-mode 'latex-mode))
786 (not font-lock-mode))
789 'reftex-pre-refontification-functions
790 reftex-call-back-to-this-buffer 'reftex-hidden)
792 (when (or (not (eq major-mode 'fundamental-mode))
795 (run-hooks 'reftex-display-copied-context-hook)
796 (setq buffer-read-only t))))))
798 (defun reftex-varioref-vref ()
799 "Insert a reference using the `\\vref' macro from the varioref package."
801 (let ((reftex-format-ref-function 'reftex-format-vref))
803 (defun reftex-fancyref-fref ()
804 "Insert a reference using the `\\fref' macro from the fancyref package."
806 (let ((reftex-format-ref-function 'reftex-format-fref)
807 ;;(reftex-guess-label-type nil) ;FIXME do we want this????
810 (defun reftex-fancyref-Fref ()
811 "Insert a reference using the `\\Fref' macro from the fancyref package."
813 (let ((reftex-format-ref-function 'reftex-format-Fref)
814 ;;(reftex-guess-label-type nil) ;FIXME do we want this????
818 (defun reftex-format-vref (label fmt)
819 (while (string-match "\\\\ref{" fmt)
820 (setq fmt (replace-match "\\vref{" t t fmt)))
821 (format fmt label label))
822 (defun reftex-format-Fref (label def-fmt)
823 (format "\\Fref{%s}" label))
824 (defun reftex-format-fref (label def-fmt)
825 (format "\\fref{%s}" label))
827 (defun reftex-goto-label (&optional other-window)
828 "Prompt for a label (with completion) and jump to the location of this label.
829 Optional prefix argument OTHER-WINDOW goes to the label in another window."
831 (reftex-access-scan-info)
832 (let* ((wcfg (current-window-configuration))
833 (docstruct (symbol-value reftex-docstruct-symbol))
834 (label (completing-read "Label: " docstruct
835 (lambda (x) (stringp (car x))) t))
836 (selection (assoc label docstruct))
838 (reftex-show-label-location selection t nil 'stay)
841 (set-window-configuration wcfg)
842 (switch-to-buffer (marker-buffer where))
844 (reftex-unhighlight 0)))
848 ;;; arch-tag: 52f14032-fb76-4d31-954f-750c72415675
849 ;;; reftex-ref.el ends here