* 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
* bug#34629: 27.0.50; Wrong parsing of key-val labels
2019-02-23 13:17 27.0.50; Wrong parsing of key-val labels Arash Esbati
@ 2019-02-27 17:26 ` Tassilo Horn
[not found] ` <87fts9ta61.fsf@gnu.org>
1 sibling, 0 replies; 4+ messages in thread
From: Tassilo Horn @ 2019-02-27 17:26 UTC (permalink / raw)
To: Arash Esbati; +Cc: auctex-devel, 34629-close
Arash Esbati <arash@gnu.org> writes:
Hi Arash,
> The is due to the second regexp in `reftex-label-regexps'. Please
> find attached a patch fixing this issue. Any comments welcome.
Pushed to emacs master. Thanks a lot!
Bye,
Tassilo
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <87fts9ta61.fsf@gnu.org>]
* bug#34629: 27.0.50; Wrong parsing of key-val labels
[not found] ` <87fts9ta61.fsf@gnu.org>
@ 2019-03-08 21:12 ` Arash Esbati
[not found] ` <867ed9hxzc.fsf@gnu.org>
1 sibling, 0 replies; 4+ messages in thread
From: Arash Esbati @ 2019-03-08 21:12 UTC (permalink / raw)
To: Tassilo Horn; +Cc: auctex-devel, 34629
[-- Attachment #1: Type: text/plain, Size: 720 bytes --]
Tassilo Horn <tsdh@gnu.org> writes:
> Arash Esbati <arash@gnu.org> writes:
>
>> The is due to the second regexp in `reftex-label-regexps'. Please
>> find attached a patch fixing this issue. Any comments welcome.
>
> Pushed to emacs master. Thanks a lot!
Hi Tassilo,
many thanks for installing the patch. Unfortunately, my last patch
wasn't good enough since I forgot that the ctable package provides a
macro and not an environment. The patch attached fixes this issue.
This patch hardcodes the search to the environments/macro provided by
the packages "listings", "breqn" and "ctable". I think this change is
acceptable; any other envs/macros can be added easily by the user and/or
AUCTeX styles.
Best, Arash
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-matching-of-key-val-labels-yet-more-bug-3462.patch --]
[-- Type: text/x-patch, Size: 3255 bytes --]
From 557490e4bd37b794133fca128710f2918d4d005f Mon Sep 17 00:00:00 2001
From: Arash Esbati <arash@gnu.org>
Date: Fri, 8 Mar 2019 22:01:01 +0100
Subject: [PATCH] ; Improve matching of key-val labels yet more (bug#34629)
* lisp/textmodes/reftex-vars.el (reftex-label-regexps): Match
explicitly for key-val labels in optional arguments of
environments provided by "listings" and "breqn" packages and the
macro "\ctable" from the package of the same name.
Update docstring.
---
lisp/textmodes/reftex-vars.el | 33 ++++++++++++++++++++++++++-------
1 file changed, 26 insertions(+), 7 deletions(-)
diff --git a/lisp/textmodes/reftex-vars.el b/lisp/textmodes/reftex-vars.el
index eb1dfc50a3..88ad4478b0 100644
--- a/lisp/textmodes/reftex-vars.el
+++ b/lisp/textmodes/reftex-vars.el
@@ -894,11 +894,25 @@ reftex-derive-label-parameters
`(;; Normal \\label{foo} labels
"\\\\label{\\(?1:[^}]*\\)}"
;; keyvals [..., label = {foo}, ...] forms used by ctable,
- ;; listings, minted, ...
+ ;; listings, breqn, ...
,(concat
;; Make sure we search only for optional arguments of
- ;; environments and don't match any other [
- "\\\\begin[[:space:]]*{\\(?:[^}]+\\)}[[:space:]]*"
+ ;; environments/macros and don't match any other [. ctable
+ ;; provides a macro called \ctable, listings/breqn have
+ ;; environments. Start with a backslash and a group for names
+ "\\\\\\(?:"
+ ;; begin, optional spaces and opening brace
+ "begin[[:space:]]*{"
+ ;; Build a regexp for env names
+ (regexp-opt '("lstlisting" "dmath" "dseries" "dgroup" "darray"))
+ ;; closing brace, optional spaces
+ "}[[:space:]]*"
+ ;; Now for macros
+ "\\|"
+ ;; Build a regexp for macro names; currently only \ctable
+ (regexp-opt '("ctable"))
+ ;; Close the group for names
+ "\\)"
;; Match the opening [ and the following chars
"\\[[^][]*"
;; Allow nested levels of chars enclosed in braces
@@ -912,13 +926,18 @@ reftex-derive-label-parameters
;; Match the label value; braces around the value are
;; optional.
"{?\\(?1:[^] ,}\r\n\t%]+\\)}?"
- ;; We are done. Such search until the next closing bracket
+ ;; We are done. Just 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
-assumed that the regexp group 1 matches the label text, so you
-have to define it using \\(?1:...\\) when adding new regexps.
+keyval style [..., label = {...}, ...] label definitions. The
+regexp for keyval style explicitly looks for environments
+provided by the packages \"listings\" (\"lstlisting\"),
+\"breqn\" (\"dmath\", \"dseries\", \"dgroup\", \"darray\") and
+the macro \"\\ctable\" provided by the package of the same name.
+
+It is assumed that the regexp group 1 matches the label text, so
+you have to define it using \\(?1:...\\) when adding new regexps.
When changed from Lisp, make sure to call
`reftex-compile-variables' afterwards to make the change
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
[parent not found: <867ed9hxzc.fsf@gnu.org>]
* bug#34629: 27.0.50; Wrong parsing of key-val labels
[not found] ` <867ed9hxzc.fsf@gnu.org>
@ 2019-03-09 6:50 ` Tassilo Horn
0 siblings, 0 replies; 4+ messages in thread
From: Tassilo Horn @ 2019-03-09 6:50 UTC (permalink / raw)
To: Arash Esbati; +Cc: auctex-devel, 34629
Arash Esbati <arash@gnu.org> writes:
Hi Arash,
>> Pushed to emacs master. Thanks a lot!
>
> Hi Tassilo,
>
> many thanks for installing the patch. Unfortunately, my last patch
> wasn't good enough since I forgot that the ctable package provides a
> macro and not an environment. The patch attached fixes this issue.
> This patch hardcodes the search to the environments/macro provided by
> the packages "listings", "breqn" and "ctable". I think this change is
> acceptable; any other envs/macros can be added easily by the user
> and/or AUCTeX styles.
Pushed! Thanks a lot!
Tassilo
^ permalink raw reply [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).