auctex-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-diffs] GNU AUCTeX branch, master, updated. 1b3f6e813326b65eb753c


From: Arash Esbati
Subject: [AUCTeX-diffs] GNU AUCTeX branch, master, updated. 1b3f6e813326b65eb753c4be00bd74f7ae15963b
Date: Sun, 29 Jan 2017 14:18:01 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
       via  1b3f6e813326b65eb753c4be00bd74f7ae15963b (commit)
      from  85c46564d4b5d98d56bd128d349be25db1c9e51b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1b3f6e813326b65eb753c4be00bd74f7ae15963b
Author: Arash Esbati <address@hidden>
Date:   Sun Jan 29 15:17:00 2017 +0100

    Update style/listings.el to use `LaTeX-env-label-as-keyval'
    
    * style/listings.el (LaTeX-listings-key-val-options): Comment the
    "label" key.
    (LaTeX-listings-key-val-label-extract):
    (LaTeX-listings-key-val-label-regexp): New variable.
    (LaTeX-listings-auto-cleanup): Use `LaTeX-add-environments'
    instead of adding new enviroments to `LaTeX-auto-environment'.
    Use the function `LaTeX-env-label-as-keyval' to insert labels.
    Add parsed enviroments to AUCTeX parser with `TeX-auto-add-regexp'.
    ("listings"): Add `LaTeX-listings-key-val-label-regexp' to the
    parser.
    Use `LaTeX-env-label-as-keyval' for "lstlisting".

diff --git a/style/listings.el b/style/listings.el
index b2b8f90..e36af7a 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-2016 Free Software Foundation, Inc.
+;; Copyright (C) 2004, 2005, 2009, 2013-2017 Free Software Foundation, Inc.
 
 ;; Author: Ralf Angeli <address@hidden>
 ;; Maintainer: address@hidden
@@ -34,6 +34,8 @@
 ;; October 2015: The style detects new "styles" defined with
 ;; `\lstdefinestyle' and offers them during key-value query.
 ;;
+;; January 2017: Put label in opt. argument of environment.
+;;
 ;; FIXME: Please make me more sophisticated!
 
 ;;; Code:
@@ -108,7 +110,9 @@
     ;; Captions
     ("title")
     ("caption") ; Insert braces?
-    ("label")
+    ;; Label is inserted as part of environment insertion; see below
+    ;; for "lstlisting" in style hook
+    ;; ("label")
     ("nolol" ("true" "false"))
     ("numberbychapter" ("true" "false"))
     ("captionpos" ("t" "b")) ; Can be a subset of tb.
@@ -252,6 +256,27 @@ from `listings' package.")
   "Matches the argument of \"\\lstdefinestyle\" from
 \"listings\" package.")
 
+;; Setup for parsing the labels inside optional arguments:
+
+(defvar LaTeX-listings-key-val-label-extract
+  (concat
+   "\\(?:\\[[^][]*"
+     "\\(?:{[^}{]*"
+       "\\(?:{[^}{]*"
+         "\\(?:{[^}{]*}[^}{]*\\)*"
+       "}[^}{]*\\)*"
+     "}[^][]*\\)*"
+   "label[ \t]*=[ \t]*{\\([^}]+\\)}"
+   "\\(?:[^]]*\\)*"
+   "\\]\\)")
+  "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)
+    1 LaTeX-auto-label)
+  "Matches the label inside an optional argument after \\begin{lstlisting}.")
+
 (defun LaTeX-listings-update-style-key ()
   "Update the \"style\" key from `LaTeX-listings-key-val-options-local'
 with user-defined values via the \"lstdefinestyle\" macro."
@@ -280,18 +305,36 @@ with user-defined values via the \"lstdefinestyle\" 
macro."
       (cond (;; opt. 1st argument and mandatory argument(s)
             (and args (not (string-equal args ""))
                  opt  (not (string-equal opt  "")))
-            (add-to-list 'LaTeX-auto-environment
-                         (list env 'LaTeX-env-args (vector "argument")
-                               (1- (string-to-number args)))))
+            (LaTeX-add-environments
+             `(,env
+               LaTeX-env-args
+               [TeX-arg-key-val LaTeX-listings-key-val-options-local]
+               (LaTeX-env-label-as-keyval "caption")
+               ,(1- (string-to-number args)))))
            (;; mandatory argument(s) only
             (and args (not (string-equal args ""))
                  (string-equal opt ""))
-            (add-to-list 'LaTeX-auto-environment
-                         (list env (string-to-number args))))
+            (LaTeX-add-environments
+             (list env (string-to-number args))))
            (t ; No args
-            (add-to-list 'LaTeX-auto-environment (list env))))
+            (LaTeX-add-environments (list env))))
       (add-to-list 'LaTeX-indent-environment-list `(,env current-indentation) 
t)
-      (add-to-list 'LaTeX-verbatim-environments-local env)
+      (add-to-list 'LaTeX-verbatim-environments-local env t)
+      (add-to-list 'LaTeX-label-alist (cons 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)
+                            1 LaTeX-auto-label))
+      ;; Tell RefTeX
+      (when (fboundp 'reftex-add-label-environments)
+       (reftex-add-label-environments
+        `((,env ?l "lst:" "~\\ref{%s}" nil (regexp "[Ll]isting")))))
+      ;; Fontification
+      (when (and (fboundp 'font-latex-add-keywords)
+                (fboundp 'font-latex-update-font-lock)
+                (eq TeX-install-font-lock 'font-latex-setup))
+       ;; Tell font-lock about the update.
+       (font-latex-update-font-lock t))
       ;; Add new env's to `ispell-tex-skip-alist': skip the entire env
       (TeX-ispell-skip-setcdr `(,(cons env (concat "\\\\end{" env "}"))))))
   (when (LaTeX-listings-lstdefinestyle-list)
@@ -308,6 +351,7 @@ with user-defined values via the \"lstdefinestyle\" macro."
    ;; Add to parser:
    (TeX-auto-add-regexp LaTeX-listings-lstnewenvironment-regexp)
    (TeX-auto-add-regexp LaTeX-listings-lstdefinestyle-regexp)
+   (TeX-auto-add-regexp LaTeX-listings-key-val-label-regexp)
 
    ;; Local version of key-val options:
    (setq LaTeX-listings-key-val-options-local
@@ -342,7 +386,9 @@ with user-defined values via the \"lstdefinestyle\" macro."
    ;; New environments
    (LaTeX-add-environments
     '("lstlisting" LaTeX-env-args
-      [TeX-arg-key-val LaTeX-listings-key-val-options-local]))
+      [TeX-arg-key-val LaTeX-listings-key-val-options-local]
+      (LaTeX-env-label-as-keyval "caption")))
+
    ;; Filling
    (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
                '("lstlisting" current-indentation) t)

-----------------------------------------------------------------------

Summary of changes:
 style/listings.el |   66 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 56 insertions(+), 10 deletions(-)


hooks/post-receive
-- 
GNU AUCTeX



reply via email to

[Prev in Thread] Current Thread [Next in Thread]