branch: externals/auctex commit ab57cb076d148321ef859422dd1b158fc7652c74 Author: Arash Esbati <ar...@gnu.org> Commit: Arash Esbati <ar...@gnu.org>
Add new function `LaTeX-extract-key-value-label' * latex.el (LaTeX-extract-key-value-label): Add new utility function to return a regexp string to extract label value in an optional key=val argument. * style/breqn.el (LaTeX-breqn-key-val-label-regexp): * style/listings.el (LaTeX-listings-key-val-label-regexp) (LaTeX-listings-auto-cleanup): Use `LaTeX-extract-key-value-label'. Delete now unused variable `LaTeX-listings-key-val-label-extract'. --- latex.el | 36 ++++++++++++++++++++++++++++++++++++ style/breqn.el | 14 ++++---------- style/listings.el | 20 ++++---------------- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/latex.el b/latex.el index 6a96cb4..f5f186d 100644 --- a/latex.el +++ b/latex.el @@ -6664,6 +6664,42 @@ functions `TeX-arg-color' (style/color.el) or last-optional-rejected)) ,@body)) +(defun LaTeX-extract-key-value-label (&optional key) + "Return a regexp string to match a label in an optional argument. +The optional KEY is a string which is the name of the key in the +key=value, default is \"label\". + +As an extra feature, the key can be the symbol none where the +entire matching for the key=value is skipped. The regexp then is +useful for skipping complex optional arguments. It should be +wrapped in \(?:...\)? then." + ;; The regexp produced here is ideally in sync with the complex one + ;; in `reftex-label-regexps'. + (concat + ;; Match the opening [ and the following chars + "\[[^][]*" + ;; Allow nested levels of chars enclosed in braces + "\(?:{[^}{]*" + "\(?:{[^}{]*" + "\(?:{[^}{]*}[^}{]*\)*" + "}[^}{]*\)*" + "}[^][]*\)*" + ;; If KEY is the symbol none, don't look for any key=val: + (unless (eq key 'none) + (concat "\<" + ;; Match the key, default is label + (or key "label") + ;; Optional spaces + "[[:space:]]*=[[:space:]]*" + ;; Match the value; braces around the value are optional + "{?\(" + ;; One of these chars terminates the value + "[^] ,} %]+" + ;; Close the group + "\)}?")) + ;; We are done. Just search until the next closing bracket + "[^]]*\]")) + (provide 'latex) ;;; latex.el ends here diff --git a/style/breqn.el b/style/breqn.el index 63821f2..f22696c 100644 --- a/style/breqn.el +++ b/style/breqn.el @@ -1,6 +1,6 @@ ;;; breqn.el --- AUCTeX style for `breqn.sty' (v0.98e) -;; Copyright (C) 2017 Free Software Foundation, Inc. +;; Copyright (C) 2017--2019 Free Software Foundation, Inc. ;; Author: Arash Esbati <ar...@gnu.org> ;; Maintainer: auctex-devel@gnu.org @@ -48,6 +48,8 @@ ;;; Code: +(require 'latex) + ;; Silence the compiler: (declare-function LaTeX-color-definecolor-list "color" ()) (declare-function LaTeX-xcolor-definecolor-list "xcolor" ()) @@ -77,15 +79,7 @@ The keys \"label\" and \"labelprefix\" are omitted.") "\\begin{" (regexp-opt '("dmath" "dseries" "dgroup" "darray")) "}" - "\(?:\[[^][]*" - "\(?:{[^}{]*" - "\(?:{[^}{]*" - "\(?:{[^}{]*}[^}{]*\)*" - "}[^}{]*\)*" - "}[^][]*\)*" - "label[ ]*=[ ]*{\([^}]+\)}" - "\(?:[^]]*\)*" - "\]\)") + (LaTeX-extract-key-value-label)) 1 LaTeX-auto-label) "Matches the label inside an optional argument after \begin{<breqn-env's>}.") diff --git a/style/listings.el b/style/listings.el index 598574c..5c20308 100644 --- a/style/listings.el +++ b/style/listings.el @@ -1,6 +1,6 @@ ;;; listings.el --- AUCTeX style for `listings.sty' -;; Copyright (C) 2004, 2005, 2009, 2013-2018 Free Software Foundation, Inc. +;; Copyright (C) 2004, 2005, 2009, 2013--2019 Free Software Foundation, Inc. ;; Author: Ralf Angeli <ang...@iwi.uni-sb.de> ;; Maintainer: auctex-devel@gnu.org @@ -48,6 +48,7 @@ ;; Needed for auto-parsing: (require 'tex) +(require 'latex) ;; Silence the compiler: (declare-function font-latex-add-keywords @@ -273,22 +274,9 @@ from `listings' package.") ;; Setup for parsing the labels inside optional arguments: -(defvar LaTeX-listings-key-val-label-extract - (concat - "\(?:\[[^][]*" - "\(?:{[^}{]*" - "\(?:{[^}{]*" - "\(?:{[^}{]*}[^}{]*\)*" - "}[^}{]*\)*" - "}[^][]*\)*" - "label[ ]*=[ ]*{\([^}]+\)}" - "\(?:[^]]*\)*" - "\]\)") - "Helper regexp to extract the label out of optional argument.") - (defvar LaTeX-listings-key-val-label-regexp `(,(concat - "\\begin{lstlisting}" LaTeX-listings-key-val-label-extract) + "\\begin{lstlisting}" (LaTeX-extract-key-value-label)) 1 LaTeX-auto-label) "Matches the label inside an optional argument after \begin{lstlisting}.") @@ -338,7 +326,7 @@ with user-defined values via the \"lstdefinestyle\" macro." (add-to-list 'LaTeX-label-alist `(,env . LaTeX-listing-label) t) ;; Add new env to parser for labels in opt. argument: (TeX-auto-add-regexp `(,(concat "\\begin{" env "}" - LaTeX-listings-key-val-label-extract) + (LaTeX-extract-key-value-label)) 1 LaTeX-auto-label)) ;; Tell RefTeX (when (fboundp 'reftex-add-label-environments) _______________________________________________ auctex-diffs mailing list auctex-di...@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-diffs