Merge from trunk.
[bpt/emacs.git] / lisp / textmodes / reftex-ref.el
index 655d69b..b47f2f6 100644 (file)
@@ -1,7 +1,6 @@
 ;;; reftex-ref.el --- code to create labels and references with RefTeX
 
-;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1997-2011 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
 ;; Maintainer: auctex-devel@gnu.org
@@ -237,9 +236,9 @@ This function is controlled by the settings of reftex-insert-label-flags."
         (setq label default))
 
       ;; Insert the label into the label list
-      (let* ((here-I-am-info 
+      (let* ((here-I-am-info
               (save-excursion
-                (if (and (or naked no-insert) 
+                (if (and (or naked no-insert)
                          (integerp (cdr macro-cell)))
                     (goto-char (cdr macro-cell)))
                 (reftex-where-am-I)))
@@ -830,8 +829,16 @@ Optional prefix argument OTHER-WINDOW goes to the label in another window."
   (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))
+        ;; If point is inside a \ref{} or \pageref{}, use that as
+        ;; default value.
+        (default (when (looking-back "\\\\\\(?:page\\)?ref{[-a-zA-Z0-9_*.:]*")
+                   (reftex-this-word "-a-zA-Z0-9_*.:")))
+         (label (completing-read (if default
+                                    (format "Label (default %s): " default)
+                                  "Label: ")
+                                docstruct
+                                 (lambda (x) (stringp (car x))) t nil nil
+                                default))
          (selection (assoc label docstruct))
          (where (progn
                   (reftex-show-label-location selection t nil 'stay)