Subject: bug#20820: 25.0.50; [PATCH] Default for reftex-label-regexps is too loose

From: Nils Ackermann <[email-masked]>
Date: Mon, 15 Jun 2015 14:02:34 -0500

The following valid latex test file shows the problem:

====
\documentclass{article}
\usepackage{enumitem}

\begin{document}
\section{A}
 [
\section{B}
  \begin{enumerate}[label=a]
  \item 
  \end{enumerate}
\end{document}
====

After loading `reftex', calling `reftex-toc' in the buffer with above
test file results in the following output:

====
TABLE-OF-CONTENTS on /path/to/test.tex
SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
------------------------------------------------------------------------------
     1 A

====

while the following would be expected:

====
TABLE-OF-CONTENTS on /path/to/test.tex
SPC=view TAB=goto RET=goto+hide [q]uit [r]escan [l]abels [f]ollow [x]r [?]Help
------------------------------------------------------------------------------
     1 A
     2 B

====

The default regexp in reftex-label-regexps consumes everything from the
first opening `[' until the `label=' clause, hiding relevant material in
between.

This is a problem because in mathematics texts unbalanced brackets
appear commonly.  The gobbled up text is then not accessible from reftex
anymore.

Proposed fix:

---
 lisp/textmodes/reftex-vars.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/textmodes/reftex-vars.el b/lisp/textmodes/reftex-vars.el
index 7f050e9..4eb0432 100644
--- a/lisp/textmodes/reftex-vars.el
+++ b/lisp/textmodes/reftex-vars.el
@@ -876,7 +876,7 @@ DOWNCASE    t:   Downcase words before using them."
       "\\\\label{\\(?1:[^}]*\\)}"
       ;; keyvals [..., label = {foo}, ...] forms used by ctable,
       ;; listings, minted, ...
-      "\\[[^]]*\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^],}]+\\)}?")
+      "\\[[^[]]*\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^],}]+\\)}?")
     "List of regexps matching \\label definitions.
 The default value matches usual \\label{...} definitions and
 keyval style [..., label = {...}, ...] label definitions.  It is
-- 
1.9.1

In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu)
 of 2015-06-15 on aphrodite
Repository revision: f0f216eaa1ebc84457812f66a5e714721245ef9d
System Description:	Ubuntu 14.04.1 LTS

Configured using:
 `configure --without-x'

Configured features:
JPEG SOUND DBUS NOTIFY ACL GNUTLS ZLIB

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Info

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
Composing main Info directory...done
Found `--debug-init' in Option Index.  (26 total; use `,' for next)
Found `debug_print' in Command Index.  (26 total; use `,' for next)

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message dired format-spec
rfc822 mml mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail regexp-opt rfc2047 rfc2045
ietf-drums mm-util help-fns mail-prsvr mail-utils info tool-bar easymenu
term/xterm xterm byte-opt gv bytecomp byte-compile cl-extra seq
cl-loaddefs pcase cl-lib cconv time-date mule-util tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type tabulated-list
newcomment elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow timer select mouse jit-lock font-lock syntax facemenu
font-core frame cl-generic cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind gfilenotify
multi-tty make-network-process emacs)

Memory information:
((conses 16 199619 6741)
 (symbols 48 18902 0)
 (miscs 40 68 248)
 (strings 32 24335 7161)
 (string-bytes 1 682421)
 (vectors 16 9830)
 (vector-slots 8 365902 7860)
 (floats 8 114 255)
 (intervals 56 34479 187)
 (buffers 976 12)
 (heap 1024 42239 918))