From d79d37bd136542193dc61ac2e0163245058c4a13 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Thu, 25 Apr 2013 14:01:09 +0200 Subject: [PATCH] * textmodes/reftex-vars.el (reftex-label-ignored-macros-and-environments): New defcustom. * textmodes/reftex-parse.el (reftex-parse-from-file): Use it. --- lisp/ChangeLog | 7 +++++++ lisp/textmodes/reftex-parse.el | 14 ++++++++++++-- lisp/textmodes/reftex-vars.el | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7bce53d7caf..e8933ee7c83 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-04-25 Tassilo Horn + + * textmodes/reftex-vars.el + (reftex-label-ignored-macros-and-environments): New defcustom. + + * textmodes/reftex-parse.el (reftex-parse-from-file): Use it. + 2013-04-25 Stefan Monnier * emacs-lisp/smie.el (smie-indent--hanging-p): Don't burp at EOB. diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el index a86b10e21cc..6bfc70c5d44 100644 --- a/lisp/textmodes/reftex-parse.el +++ b/lisp/textmodes/reftex-parse.el @@ -234,8 +234,18 @@ of master file." ((match-end 1) ;; It is a label - (push (reftex-label-info (reftex-match-string 1) file bound) - docstruct)) + (when (or (null reftex-label-ignored-macros-and-environments) + ;; \label{} defs should always be honored, + ;; just no keyval style [label=foo] defs. + (string-equal "\label{" (substring (reftex-match-string 0) 0 7)) + (not (fboundp 'TeX-current-macro)) + (not (fboundp 'LaTeX-current-environment)) + (not (or (member (save-match-data (TeX-current-macro)) + reftex-label-ignored-macros-and-environments) + (member (save-match-data (LaTeX-current-environment)) + reftex-label-ignored-macros-and-environments)))) + (push (reftex-label-info (reftex-match-string 1) file bound) + docstruct))) ((match-end 3) ;; It is a section diff --git a/lisp/textmodes/reftex-vars.el b/lisp/textmodes/reftex-vars.el index 7343d86b06f..ab085a3085a 100644 --- a/lisp/textmodes/reftex-vars.el +++ b/lisp/textmodes/reftex-vars.el @@ -885,6 +885,25 @@ effective." :group 'reftex-defining-label-environments :type '(repeat (regexp :tag "Regular Expression"))) +(defcustom reftex-label-ignored-macros-and-environments nil + "List of macros and environments to be ignored when searching for labels. +The purpose is to ignore environments and macros that use keyval +style label=foo arguments, but the label has a different meaning +than a \\label{foo}. Standard \\label{...} definitions are never +ignored. + +E.g., TikZ defines several macros/environments where [label=foo] +defines the label to be printed at some node or edge, but it's +not a label used for referencing. + +Note that this feature is only supported if you are using AUCTeX +and the functions `TeX-current-macro' and +`LaTeX-current-environment' are bound. Also note that this +feature might slow down the reftex parsing process for large TeX +files." + :group 'reftex-defining-label-environments + :type '(repeat string)) + (defcustom reftex-label-illegal-re "[^-a-zA-Z0-9_+=:;,.]" "Regexp matching characters not valid in labels." :group 'reftex-making-and-inserting-labels -- 2.39.2