- (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 type (reftex-query-label-type))))
-
- (let* ((reftex-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 ((reftex-refstyle (when (and (boundp 'reftex-refstyle) reftex-refstyle)
+ reftex-refstyle))
+ (reftex-format-ref-function reftex-format-ref-function)
+ (form "\\ref{%s}")
+ label labels sep sep1 style-alist)
+
+ (unless reftex-refstyle
+ (if reftex-ref-macro-prompt
+ (progn
+ ;; Build a temporary list which handles more easily.
+ (dolist (elt reftex-ref-style-alist)
+ (when (member (car elt) (reftex-ref-style-list))
+ (mapc (lambda (x)
+ (add-to-list 'style-alist (cons (cadr x) (car x)) t))
+ (nth 2 elt))))
+ ;; Prompt the user for the macro.
+ (let ((key (reftex-select-with-char
+ "" (concat "SELECT A REFERENCE FORMAT\n\n"
+ (mapconcat
+ (lambda (x)
+ (format "[%c] %s %s" (car x)
+ (if (> (car x) 31) " " "")
+ (cdr x)))
+ style-alist "\n")))))
+ (setq reftex-refstyle (cdr (assoc key style-alist)))
+ (unless reftex-refstyle
+ (error "No reference macro associated with key `%c'" key))))
+ ;; Get the first macro from `reftex-ref-style-alist' which
+ ;; matches the first entry in the list of active styles.
+ (setq reftex-refstyle
+ (or (caar (nth 2 (assoc (car (reftex-ref-style-list))
+ reftex-ref-style-alist)))
+ ;; Use the first entry in r-r-s-a as a last resort.
+ (caar (nth 2 (car reftex-ref-style-alist)))))))
+
+ (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 type (reftex-query-label-type))))