Hi,
following up on the discussion about the support for \autoref on the
`auctex' mailing list I've tried to come up with something more flexible
than the current approach where you are limited to fancyref and varioref
(through customizing `reftex-{vref,fref}-is-default'). The idea is that
there is a list of styles which can be cycled through when selecting the
reference for insertion. This list includes all reference styles,
i.e. the macros \ref, \vref, \fref, etc. If RefTeX has information
about the LaTeX packages used in the document, the list can be limited
to the macros made available by the packages.
Attached you may find a patch which demonstrates the idea. The code is
not finished yet. For example the logic for restricting the available
macros is not there yet, the chosen style is not remembered yet and it
does not honor `reftex-{vref,fref}-is-default' for backwards
compatibility. An interesting part of the patch is likely the variable
`reftex-ref-style-alist' which can be adapted by the user to include
more referencing macros and information on the LaTeX package they are
defined in.
If people think this is an approach worth pursuing I'll try to develop
it further.
--
Ralf
Index: lisp/reftex-base.el
===================================================================
RCS file: /sources/auctex/reftex/lisp/reftex-base.el,v
retrieving revision 1.6
diff -u -r1.6 reftex-base.el
--- lisp/reftex-base.el 23 Aug 2007 21:36:03 -0000 1.6
+++ lisp/reftex-base.el 2 Jan 2008 20:29:58 -0000
@@ -2300,21 +2300,17 @@
:style radio :selected (eq reftex-auto-view-crossref 'window)]
"--"
"MISC"
- ["AUC TeX Interface" reftex-toggle-plug-into-AUCTeX
+ ["AUCTeX Interface" reftex-toggle-plug-into-AUCTeX
:style toggle :selected reftex-plug-into-AUCTeX]
["isearch whole document" reftex-isearch-minor-mode
:style toggle :selected reftex-isearch-minor-mode])
("Reference Style"
- ["Default" (setq reftex-vref-is-default nil
- reftex-fref-is-default nil)
- :style radio :selected (not (or reftex-vref-is-default
- reftex-fref-is-default))]
- ["Varioref" (setq reftex-vref-is-default t
- reftex-fref-is-default nil)
- :style radio :selected reftex-vref-is-default]
- ["Fancyref" (setq reftex-fref-is-default t
- reftex-vref-is-default nil)
- :style radio :selected reftex-fref-is-default])
+ ,@(mapcar (lambda (elt)
+ (let ((elt (car elt)))
+ (vector elt `(setq reftex-ref-style-default ,elt)
+ :style 'radio
+ :selected `(equal reftex-ref-style-default ,elt))))
+ reftex-ref-style-alist))
("Citation Style"
,@(mapcar
(lambda (x)
Index: lisp/reftex-ref.el
===================================================================
RCS file: /sources/auctex/reftex/lisp/reftex-ref.el,v
retrieving revision 1.32
diff -u -r1.32 reftex-ref.el
--- lisp/reftex-ref.el 23 Aug 2007 21:36:02 -0000 1.32
+++ lisp/reftex-ref.el 2 Jan 2008 20:29:59 -0000
@@ -431,10 +431,13 @@
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")))
+ (let* ((refstyle
+ (let ((default (caar reftex-ref-style-alist)))
+ (if (or (equal reftex-ref-style-default default)
+ (not (reftex-typekey-check
+ type reftex-ref-style-label-types)))
+ default
+ reftex-ref-style-default)))
(reftex-format-ref-function reftex-format-ref-function)
(form "\\ref{%s}")
label labels sep sep1)
Index: lisp/reftex-sel.el
===================================================================
RCS file: /sources/auctex/reftex/lisp/reftex-sel.el,v
retrieving revision 1.33
diff -u -r1.33 reftex-sel.el
--- lisp/reftex-sel.el 23 Aug 2007 21:36:02 -0000 1.33
+++ lisp/reftex-sel.el 2 Jan 2008 20:30:01 -0000
@@ -533,21 +533,23 @@
(interactive)
(setq reftex-last-follow-point -1)
(setq cb-flag (not cb-flag)))
-(defun reftex-select-toggle-varioref ()
- "Toggle the macro used for referencing the label between \\ref and \\vref."
+
+(defun reftex-select-switch-ref-style-forward ()
+ "Switch forward the macro used for referencing."
(interactive)
- (if (string= refstyle "\\ref")
- (setq refstyle "\\vref")
- (setq refstyle "\\ref"))
+ (let ((list reftex-ref-style-alist))
+ (setq refstyle (or (car (cadr (member (assoc refstyle list) list)))
+ (caar list))))
(force-mode-line-update))
-(defun reftex-select-toggle-fancyref ()
- "Toggle the macro used for referencing the label between \\ref and \\vref."
+
+(defun reftex-select-switch-ref-style-backward ()
+ "Switch backward the macro used for referencing."
(interactive)
- (setq refstyle
- (cond ((string= refstyle "\\ref") "\\fref")
- ((string= refstyle "\\fref") "\\Fref")
- (t "\\ref")))
+ (let ((list (reverse reftex-ref-style-alist)))
+ (setq refstyle (or (car (cadr (member (assoc refstyle list) list)))
+ (caar list))))
(force-mode-line-update))
+
(defun reftex-select-show-insertion-point ()
"Show the point from where selection was started in another window."
(interactive)
@@ -709,8 +711,8 @@
(loop for x in
'(("b" . reftex-select-jump-to-previous)
("z" . reftex-select-jump)
- ("v" . reftex-select-toggle-varioref)
- ("V" . reftex-select-toggle-fancyref)
+ ("v" . reftex-select-switch-ref-style-forward)
+ ("V" . reftex-select-switch-ref-style-backward)
("m" . reftex-select-mark)
("u" . reftex-select-unmark)
("," . reftex-select-mark-comma)
Index: lisp/reftex-vars.el
===================================================================
RCS file: /sources/auctex/reftex/lisp/reftex-vars.el,v
retrieving revision 1.44
diff -u -r1.44 reftex-vars.el
--- lisp/reftex-vars.el 10 Oct 2007 20:07:15 -0000 1.44
+++ lisp/reftex-vars.el 2 Jan 2008 20:30:04 -0000
@@ -945,6 +945,47 @@
:group 'reftex-referencing-labels
:type '(repeat (cons (character) (string))))
+(defcustom reftex-ref-style-alist
+ '(("\\ref" t)
+ ("\\vref" "varioref")
+ ("\\fref" "fancyref")
+ ("\\Fref" "fancyref")
+ ("\\autoref" "hyperref")
+ ("\\hyperref" "hyperref"))
+ "Alist of reference styles.
+Each element is a list of the string to be inserted as reference
+macro and the LaTeX package providing the macro. The first
+element will be used as a fallback if the label type does not
+match those specified in `reftex-ref-style-label-types'."
+ :group 'reftex-referencing-labels
+ :type '(alist :key-type (string :tag "Macro")
+ :value-type (group (choice :tag "Package"
+ (const :tag "Any package" t)
+ (string :tag "Name")))))
+
+(defcustom reftex-ref-style-default (caar reftex-ref-style-alist)
+ "Macro to be used as default for references.
+This has to be a string and one of the macros specified in the
+variable `reftex-ref-style-alist'. The default value is the
+first macro defined in the latter variable, usually \\ref."
+ :group 'reftex-referencing-labels
+ :type `(choice ,@(mapcar (lambda (elt) (list 'const (car elt)))
+ reftex-ref-style-alist)))
+
+(defcustom reftex-ref-style-label-types t
+ "Label types the special referencing macro should be used for.
+The special macro is defined by `reftex-ref-style-default'. If
+the latter is set to nil, setting this variable has no effect.
+If this variable is set to t, the special macro will be used for
+all references. If set to a string, the string will be
+interpreted as a list of label type specifiers the macro should
+be applied to. For example \"ef\" means to apply the special
+macro to equations and figures. For all other label types \\ref
+will be used."
+ :group 'reftex-referencing-labels
+ :type '(choice (const :tag "Any label type" t)
+ (string :tag "List of label types")))
+
(defcustom reftex-vref-is-default nil
"*Non-nil means, the varioref macro \\vref is used as default.
In the selection buffer, the `v' key toggles the reference macro between
_______________________________________________
auctex-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/auctex-devel