unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* 27.0.50; Wrong parsing of key-val labels
@ 2019-02-23 13:17 Arash Esbati
  2019-02-27 17:26 ` bug#34629: " Tassilo Horn
       [not found] ` <87fts9ta61.fsf@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Arash Esbati @ 2019-02-23 13:17 UTC (permalink / raw)
  To: bug-gnu-emacs; +Cc: auctex-devel

[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]

Hi all,

Please consider the following LaTeX code in a buffer where RefTeX is
enabled:

--8<---------------cut here---------------start------------->8---
\documentclass{article}
\usepackage{listings}
\begin{document}

\begin{lstlisting}[
caption = Some caption ,
label   = lst:1        %
]
foo
\end{lstlisting}

\begin{lstlisting}[
caption = {[Short caption]Long caption},
label   = lst:2          
]
bar
\end{lstlisting}

\begin{lstlisting}[
language  = {[LaTeX]TeX}                           ,
frame     = single                                 ,
caption   = {[Short caption]\textit{L\textbf{o}ng} caption} ,
label     = lst:3     ]
foobar
\end{lstlisting}

\end{document}
--8<---------------cut here---------------end--------------->8---

When hitting `C-u C-c )' in order to add a \ref, RefTeX fails to see the
last 2 labels.  For the first one, it inserts

\ref{lst:1        %
}

The is due to the second regexp in `reftex-label-regexps'.  Please find
attached a patch fixing this issue.  Any comments welcome.

Best, Arash


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-matching-of-key-val-labels.patch --]
[-- Type: text/x-patch, Size: 2382 bytes --]

From f6e3a84824f5597ab4f1641edf957b8af4b51564 Mon Sep 17 00:00:00 2001
From: Arash Esbati <arash@gnu.org>
Date: Sat, 23 Feb 2019 14:02:05 +0100
Subject: [PATCH] Improve matching of key-val labels

* lisp/textmodes/reftex-vars.el (reftex-label-regexps): Improve
regexp for key-val labels in order to skip over content in braces.
---
 lisp/textmodes/reftex-vars.el | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/lisp/textmodes/reftex-vars.el b/lisp/textmodes/reftex-vars.el
index 9147de6e01..eb1dfc50a3 100644
--- a/lisp/textmodes/reftex-vars.el
+++ b/lisp/textmodes/reftex-vars.el
@@ -891,11 +891,29 @@ reftex-derive-label-parameters
     ;; so this list mustn't get any more items.
     (defconst reftex-label-regexps '("\\\\label{\\([^}]*\\)}"))
   (defcustom reftex-label-regexps
-    '(;; Normal \\label{foo} labels
+    `(;; Normal \\label{foo} labels
       "\\\\label{\\(?1:[^}]*\\)}"
       ;; keyvals [..., label = {foo}, ...] forms used by ctable,
       ;; listings, minted, ...
-      "\\[[^][]\\{0,2000\\}\\<label[[:space:]]*=[[:space:]]*{?\\(?1:[^],}]+\\)}?")
+      ,(concat
+        ;; Make sure we search only for optional arguments of
+        ;; environments and don't match any other [
+        "\\\\begin[[:space:]]*{\\(?:[^}]+\\)}[[:space:]]*"
+        ;; Match the opening [ and the following chars
+        "\\[[^][]*"
+        ;; Allow nested levels of chars enclosed in braces
+        "\\(?:{[^}{]*"
+          "\\(?:{[^}{]*"
+            "\\(?:{[^}{]*}[^}{]*\\)*"
+          "}[^}{]*\\)*"
+        "}[^][]*\\)*"
+        ;; Match the label key
+        "\\<label[[:space:]]*=[[:space:]]*"
+        ;; Match the label value; braces around the value are
+        ;; optional.
+        "{?\\(?1:[^] ,}\r\n\t%]+\\)}?"
+        ;; We are done.  Such search until the next closing bracket
+        "[^]]*\\]"))
     "List of regexps matching \\label definitions.
 The default value matches usual \\label{...} definitions and
 keyval style [..., label = {...}, ...] label definitions.  It is
@@ -905,7 +923,7 @@ reftex-derive-label-parameters
 When changed from Lisp, make sure to call
 `reftex-compile-variables' afterwards to make the change
 effective."
-    :version "25.1"
+    :version "27.1"
     :set (lambda (symbol value)
 	   (set symbol value)
 	   (when (fboundp 'reftex-compile-variables)
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 147 bytes --]

_______________________________________________
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-09  6:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-23 13:17 27.0.50; Wrong parsing of key-val labels Arash Esbati
2019-02-27 17:26 ` bug#34629: " Tassilo Horn
     [not found] ` <87fts9ta61.fsf@gnu.org>
2019-03-08 21:12   ` Arash Esbati
     [not found]   ` <867ed9hxzc.fsf@gnu.org>
2019-03-09  6:50     ` Tassilo Horn

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).