X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/5725bd2cc0e691dadc31bd958f210b1bbcf17c49..c9a75a4030a556d700fd95222ec0bf4c1a9f67b5:/lisp/textmodes/reftex-ref.el diff --git a/lisp/textmodes/reftex-ref.el b/lisp/textmodes/reftex-ref.el index 1882e7dde5..d0e09bff88 100644 --- a/lisp/textmodes/reftex-ref.el +++ b/lisp/textmodes/reftex-ref.el @@ -1,11 +1,9 @@ ;;; reftex-ref.el --- code to create labels and references with RefTeX -;; Copyright (C) 1997-2012 Free Software Foundation, Inc. +;; Copyright (C) 1997-2015 Free Software Foundation, Inc. ;; Author: Carsten Dominik ;; Maintainer: auctex-devel@gnu.org -;; Version: 4.31 -;; Package: reftex ;; This file is part of GNU Emacs. @@ -27,11 +25,11 @@ ;;; Code: (eval-when-compile (require 'cl)) -(provide 'reftex-ref) + (require 'reftex) (require 'reftex-parse) -;;; +;;;###autoload (defun reftex-label-location (&optional bound) "Return the environment or macro which determines the label type at point. If optional BOUND is an integer, limit backward searches to that point." @@ -65,6 +63,7 @@ If optional BOUND is an integer, limit backward searches to that point." (t ;; This should not happen, I think? "section")))) +;;;###autoload (defun reftex-label-info-update (cell) ;; Update information about just one label in a different file. ;; CELL contains the old info list @@ -95,6 +94,7 @@ If optional BOUND is an integer, limit backward searches to that point." (append (reftex-label-info label file) (list note))) (list label typekey "" file "LOST LABEL. RESCAN TO FIX."))))))) +;;;###autoload (defun reftex-label-info (label &optional file bound derive env-or-mac) ;; Return info list on LABEL at point. (let* ((prefix (if (string-match "^[a-zA-Z0-9]+:" label) @@ -121,6 +121,7 @@ If optional BOUND is an integer, limit backward searches to that point." ;;; Creating labels --------------------------------------------------------- +;;;###autoload (defun reftex-label (&optional environment no-insert) "Insert a unique label. Return the label. If ENVIRONMENT is given, don't bother to find out yourself. @@ -401,6 +402,7 @@ also applies `reftex-translate-to-ascii-function' to the string." a / A Put all marked entries into one/many \\ref commands. q / RET Quit without referencing / Accept current label (also on mouse-2).") +;;;###autoload (defun reftex-reference (&optional type no-insert cut) "Make a LaTeX reference. Look only for labels of a certain TYPE. With prefix arg, force to rescan buffer for labels. This should only be @@ -413,27 +415,54 @@ When called with 2 C-u prefix args, disable magic word recognition." (interactive) - ;; check for active recursive edits + ;; 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 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 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)))) ;; Have the user select a label (set-marker reftex-select-return-marker (point)) @@ -472,17 +501,13 @@ When called with 2 C-u prefix args, disable magic word recognition." (member (preceding-char) '(?\ ?\t ?\n ?~))) (setq form (substring form 1))) ;; do we have a special format? - (setq reftex-format-ref-function - (cond - ((string= reftex-refstyle "\\vref") 'reftex-format-vref) - ((string= reftex-refstyle "\\fref") 'reftex-format-fref) - ((string= reftex-refstyle "\\Fref") 'reftex-format-Fref) - (t reftex-format-ref-function))) + (unless (string= reftex-refstyle "\\ref") + (setq reftex-format-ref-function 'reftex-format-special)) ;; ok, insert the reference (if sep1 (insert sep1)) (insert (if reftex-format-ref-function - (funcall reftex-format-ref-function label form) + (funcall reftex-format-ref-function label form reftex-refstyle) (format form label label))) ;; take out the initial ~ for good (and (= ?~ (string-to-char form)) @@ -685,6 +710,7 @@ When called with 2 C-u prefix args, disable magic word recognition." (file (nth 3 data))) (reftex-access-scan-info arg file))))) +;;;###autoload (defun reftex-query-label-type () ;; Ask for label type (let ((key (reftex-select-with-char @@ -693,6 +719,7 @@ When called with 2 C-u prefix args, disable magic word recognition." (error "No such label type: %s" (char-to-string key))) (char-to-string key))) +;;;###autoload (defun reftex-show-label-location (data forward no-revisit &optional stay error) ;; View the definition site of a label in another window. @@ -791,35 +818,36 @@ When called with 2 C-u prefix args, disable magic word recognition." (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." - (interactive) - (let ((reftex-format-ref-function 'reftex-format-vref)) - (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-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-reference))) - -(defun reftex-format-vref (label fmt) - (while (string-match "\\\\ref{" fmt) - (setq fmt (replace-match "\\vref{" t t fmt))) - (format fmt label label)) -(defun reftex-format-Fref (label def-fmt) - (format "\\Fref{%s}" label)) -(defun reftex-format-fref (label def-fmt) - (format "\\fref{%s}" label)) +;; Generate functions for direct insertion of specific referencing +;; macros. The functions are named `reftex--', +;; e.g. `reftex-varioref-vref'. +(dolist (elt reftex-ref-style-alist) + (when (stringp (nth 1 elt)) + (dolist (item (nth 2 elt)) + (let ((macro (car item)) + (package (nth 1 elt))) + (eval `(defun ,(intern (format "reftex-%s-%s" package + (substring macro 1 (length macro)))) () + ,(format "Insert a reference using the `%s' macro from the %s \ +package.\n\nThis is a generated function." + macro package) + (interactive) + (let ((reftex-refstyle ,macro)) + (reftex-reference)))))))) + +(defun reftex-format-special (label fmt refstyle) + "Apply selected reference style to format FMT and add LABEL. +Replace any occurrences of \"\\ref\" with REFSTYLE." + ;; Replace instances of \ref in `fmt' with the special reference + ;; style selected by the user. + (cond + ((while (string-match "\\(\\\\ref\\)[ \t]*{" fmt) + (setq fmt (replace-match refstyle t t fmt 1)))) + ((string-match "\\(\\\\[[:alpha:]]+\\)[ \t]*{" fmt) + (setq fmt (replace-match refstyle t t fmt 1)))) + (format fmt label)) +;;;###autoload (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." @@ -829,7 +857,8 @@ Optional prefix argument OTHER-WINDOW goes to the label in another window." (docstruct (symbol-value reftex-docstruct-symbol)) ;; If point is inside a \ref{} or \pageref{}, use that as ;; default value. - (default (when (looking-back "\\\\\\(?:page\\)?ref{[-a-zA-Z0-9_*.:]*") + (default (when (looking-back "\\\\\\(?:page\\)?ref{[-a-zA-Z0-9_*.:]*" + (line-beginning-position)) (reftex-this-word "-a-zA-Z0-9_*.:"))) (label (completing-read (if default (format "Label (default %s): " default) @@ -847,5 +876,10 @@ Optional prefix argument OTHER-WINDOW goes to the label in another window." (goto-char where)) (reftex-unhighlight 0))) +(provide 'reftex-ref) ;;; reftex-ref.el ends here + +;; Local Variables: +;; generated-autoload-file: "reftex.el" +;; End: