emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/auctex 7c4147b 57/71: Improve handling of key=vals in s


From: Tassilo Horn
Subject: [elpa] externals/auctex 7c4147b 57/71: Improve handling of key=vals in style/tcolorbox.el
Date: Fri, 17 Dec 2021 15:00:36 -0500 (EST)

branch: externals/auctex
commit 7c4147b2965c3e82db1cc1a0a8bf55ae4de7ad47
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>

    Improve handling of key=vals in style/tcolorbox.el
    
    * style/tcolorbox.el (LaTeX-tcolorbox-keyval-options-local)
    (LaTeX-tcolorbox-update-style-key): Remove now unused variable and
    function.
    (LaTeX-tcolorbox-keyval-options): New function returning key=vals.
    (LaTeX-tcolorbox-keyval-options-full): Change the content of the
    variable.  It now holds a list of symbols.
    (LaTeX-tcolorbox-keyval-options-full): New function returning
    key=vals from symbols in the variable
    `LaTeX-tcolorbox-keyval-options-full'.
    ("tcolorbox-tcbuselibrary"): Add the missing prefix to plural
    argument.
    (LaTeX-tcolorbox-auto-cleanup): Don't call
    `LaTeX-tcolorbox-update-style-key' anymore.
    ("tcolorbox"): Use new function `LaTeX-tcolorbox-keyval-options'
    in the hook.
    Process the library names read in by \tcbuselibrary directly.
    
    * style/tcolorboxlib-raster.el
    (LaTeX-tcolorbox-lib-raster-env-item): Use the new function
    `LaTeX-tcolorbox-keyval-options'.
    ("tcolorboxlib-raster"): Register library variable
    `LaTeX-tcolorbox-lib-raster-keyval-options' in
    `LaTeX-tcolorbox-keyval-options-full'.
    Use the function `LaTeX-tcolorbox-keyval-options' in the hook.
---
 style/tcolorbox.el           | 131 +++++++++++++++++++++++--------------------
 style/tcolorboxlib-raster.el |  24 ++++----
 2 files changed, 81 insertions(+), 74 deletions(-)

diff --git a/style/tcolorbox.el b/style/tcolorbox.el
index 0a4445b..5ba44bb 100644
--- a/style/tcolorbox.el
+++ b/style/tcolorbox.el
@@ -1,6 +1,6 @@
 ;;; tcolorbox.el --- AUCTeX style for `tcolorbox.sty' (v4.00)  -*- 
lexical-binding: t; -*-
 
-;; Copyright (C) 2015, 2016, 2018, 2020 Free Software Foundation, Inc.
+;; Copyright (C) 2015--2021 Free Software Foundation, Inc.
 
 ;; Author: Tassilo Horn <tsdh@gnu.org>
 ;; Maintainer: auctex-devel@gnu.org
@@ -34,9 +34,10 @@
 ;; file is prefixed with `tcolorboxlib-',
 ;; e.g. `tcolorboxlib-raster.el'.
 
-;; Libraries should also append their key=val option to variable
-;; `LaTeX-tcolorbox-keyval-options-full'.  This variable is called
-;; with macro `\tcbset'.
+;; Libraries should also prepend a symbol containing their key=val
+;; options to the variable `LaTeX-tcolorbox-keyval-options-full'.
+;; This variable is used by the function of the same name called when
+;; inserting `\tcbset' macro.
 
 ;;; Code:
 
@@ -343,14 +344,46 @@
     ("no recording"))
   "Key=value options for tcolorbox macros and environments.")
 
-(defvar LaTeX-tcolorbox-keyval-options-local nil
-   "Buffer-local key=value options for tcolorbox macros and environments.")
-(make-variable-buffer-local 'LaTeX-tcolorbox-keyval-options-local)
-
-(defvar LaTeX-tcolorbox-keyval-options-full nil
-  "Key=value options of tcolorbox core and all loaded libraries.")
+(defun LaTeX-tcolorbox-keyval-options ()
+  "Return an updated list of key=vals from tcolorbox package."
+  (append
+   ;; This style runs `xcolor.el', so we use
+   ;; `LaTeX-xcolor-definecolor-list' right away:
+   (let ((colors (mapcar #'car (LaTeX-xcolor-definecolor-list)))
+         (keys '("colframe"
+                 "colback"
+                 "colbacktitle"
+                 "colupper"
+                 "collower"
+                 "coltext"
+                 "coltitle"))
+         result)
+     (dolist (key keys result)
+       (cl-pushnew (list key colors) result :test #'equal)))
+   LaTeX-tcolorbox-keyval-options))
+
+(defvar LaTeX-tcolorbox-keyval-options-full
+  '(LaTeX-tcolorbox-keyval-options)
+  "Buffer-local list of symbols containing key=val options.
+tcolorbox libraries should add their key=val options to this
+list.  Key=val options might be a variable or a function.  This
+variable is initialized with the function
+`LaTeX-tcolorbox-keyval-options'.  Please add entries on top of
+this list so that this item always comes last.")
 (make-variable-buffer-local 'LaTeX-tcolorbox-keyval-options-full)
 
+(defun LaTeX-tcolorbox-keyval-options-full ()
+  "Return an updated list of full key=vals for tcolorbox and libraries.
+Each symbol is a variable or a function.  If a symbol name
+contains a function and a variable value, the function is
+preferred.  This function processes symbols in the variable
+`LaTeX-tcolorbox-keyval-options-full'."
+  (let (result)
+    (dolist (elt (reverse LaTeX-tcolorbox-keyval-options-full) result)
+      (if (functionp elt)
+          (setq result (append (funcall elt) result))
+        (setq result (append (symbol-value elt) result))))))
+
 (defvar LaTeX-tcolorbox-tcbox-options
   '(;; 4.20 \tcbox Specials
     ("tcbox raise")
@@ -437,7 +470,8 @@
   "Matches the arguments of \\newtcbox from tcolorbox package.")
 
 ;; Setup for \tcbuselibrary:
-(TeX-auto-add-type "tcolorbox-tcbuselibrary" "LaTeX" "tcbuselibraries")
+(TeX-auto-add-type "tcolorbox-tcbuselibrary"
+                   "LaTeX" "tcolorbox-tcbuselibraries")
 
 (defvar LaTeX-tcolorbox-tcbuselibrary-regexp
   '("\\\\tcbuselibrary{\\([^}]+\\)}"
@@ -464,25 +498,6 @@ for example \"tcolorboxlib-raster.el\"."
         (when (member x LaTeX-tcolorbox-library-list)
           (TeX-run-style-hooks (concat "tcolorboxlib-" x)))))))
 
-(defun LaTeX-tcolorbox-update-style-key ()
-  "Update some key=values in `LaTeX-tcolorbox-keyval-options-local'."
-  ;; Update the key=values for coloring.
-  (let* ((keys '("colframe"
-                 "colback"
-                 "colbacktitle"
-                 "colupper"
-                 "collower"
-                 "coltext"
-                 "coltitle"))
-         (tmp (copy-alist LaTeX-tcolorbox-keyval-options-local)))
-    (dolist (key keys)
-      (setq tmp (assq-delete-all (car (assoc key tmp)) tmp))
-      (cl-pushnew
-       (list key (mapcar #'car (LaTeX-xcolor-definecolor-list))) tmp :test 
#'equal))
-    (setq LaTeX-tcolorbox-keyval-options-local (copy-alist tmp)))
-  (setq LaTeX-tcolorbox-keyval-options-full
-        (copy-alist LaTeX-tcolorbox-keyval-options-local)))
-
 (defun LaTeX-tcolorbox-auto-prepare ()
   "Clear various LaTeX-tcolorbox-* variables before parsing."
   (setq LaTeX-auto-tcolorbox-newtcolorbox  nil
@@ -511,7 +526,7 @@ for example \"tcolorboxlib-raster.el\"."
              (LaTeX-add-environments
               (list box
                     #'LaTeX-env-args
-                    [TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local]
+                    [TeX-arg-key-val (LaTeX-tcolorbox-keyval-options)]
                     (1- (string-to-number arg)))))
             (;; mandatory argument(s) only
              (and arg (not (string= arg ""))
@@ -539,8 +554,8 @@ for example \"tcolorboxlib-raster.el\"."
              (and arg (not (string= arg ""))
                   opt (not (string= opt  "")))
              (TeX-add-symbols (list box
-                               [TeX-arg-key-val 
LaTeX-tcolorbox-keyval-options-local]
-                               (1- (string-to-number arg)))))
+                                    [TeX-arg-key-val 
(LaTeX-tcolorbox-keyval-options)]
+                                    (1- (string-to-number arg)))))
             (;; mandatory argument(s) only
              (and arg (not (string= arg ""))
                   (string-equal opt ""))
@@ -548,9 +563,6 @@ for example \"tcolorboxlib-raster.el\"."
             (t ; No args -- in pratice, this will probably never happen
              (TeX-add-symbols (list box))))))
   ;;
-  ;; Update key=vals
-  (LaTeX-tcolorbox-update-style-key)
-  ;;
   ;; Load style hooks for libraries, if any.
   (LaTeX-tcolorbox-load-used-libraries))
 
@@ -562,15 +574,6 @@ for example \"tcolorboxlib-raster.el\"."
  "tcolorbox"
  (lambda ()
 
-   ;; Activate the buffer-local version of key-vals.
-   (setq LaTeX-tcolorbox-keyval-options-local
-         (copy-alist LaTeX-tcolorbox-keyval-options))
-
-   ;; Collect key=val's from libraries in
-   ;; `LaTeX-tcolorbox-keyval-options-full'; \tcbset needs this:
-   (setq LaTeX-tcolorbox-keyval-options-full
-         (copy-alist LaTeX-tcolorbox-keyval-options-local))
-
    ;; Add tcolorbox to the parser.
    (TeX-auto-add-regexp LaTeX-tcolorbox-newtcolorbox-regexp)
    (TeX-auto-add-regexp LaTeX-tcolorbox-newtcbox-regexp)
@@ -584,32 +587,38 @@ for example \"tcolorboxlib-raster.el\"."
 
     ;; 1.3 Libraries
     '("tcbuselibrary"
-      (TeX-arg-eval mapconcat #'identity
-                    (TeX-completing-read-multiple
-                     (TeX-argument-prompt nil nil "Libraries")
-                     LaTeX-tcolorbox-library-list) ","))
+      (TeX-arg-eval
+       (lambda ()
+         (let ((libs (mapconcat #'identity
+                                (TeX-completing-read-multiple
+                                 (TeX-argument-prompt nil nil "Libraries")
+                                 LaTeX-tcolorbox-library-list)
+                                ",")))
+           (LaTeX-add-tcolorbox-tcbuselibraries libs)
+           (LaTeX-tcolorbox-load-used-libraries)
+           (format "%s" libs)))))
 
     ;; 3 Macros for Box Creation
     '("tcblower" 0)
 
     '("tcbset"
-      (TeX-arg-key-val LaTeX-tcolorbox-keyval-options-full))
+      (TeX-arg-key-val (LaTeX-tcolorbox-keyval-options-full)))
 
     '("tcbsetforeverylayer"
-      (TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local))
+      (TeX-arg-key-val (LaTeX-tcolorbox-keyval-options)))
 
     '("tcbox"
-      [ TeX-arg-eval TeX-read-key-val t
-        (append
-         LaTeX-tcolorbox-tcbox-options
-         LaTeX-tcolorbox-keyval-options-local) ]
+      [TeX-arg-eval TeX-read-key-val t
+                    (append
+                     LaTeX-tcolorbox-tcbox-options
+                     (LaTeX-tcolorbox-keyval-options))]
       t)
 
     '("newtcolorbox"
       [ TeX-arg-key-val LaTeX-tcolorbox-init-options ]
       "Name"
       [ TeX-arg-define-macro-arguments ]
-      (TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local))
+      (TeX-arg-key-val (LaTeX-tcolorbox-keyval-options)))
 
     '("renewtcolorbox"
       [ TeX-arg-key-val LaTeX-tcolorbox-init-options ]
@@ -617,13 +626,13 @@ for example \"tcolorboxlib-raster.el\"."
                     (TeX-argument-prompt nil nil "Color box")
                     (LaTeX-tcolorbox-newtcolorbox-list))
       [ TeX-arg-define-macro-arguments ]
-      (TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local))
+      (TeX-arg-key-val (LaTeX-tcolorbox-keyval-options)))
 
     '("newtcbox"
       [ TeX-arg-key-val LaTeX-tcolorbox-init-options ]
       TeX-arg-macro
       [ TeX-arg-define-macro-arguments ]
-      (TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local))
+      (TeX-arg-key-val (LaTeX-tcolorbox-keyval-options)))
 
     '("renewtcbox"
       [ TeX-arg-key-val LaTeX-tcolorbox-init-options ]
@@ -634,11 +643,11 @@ for example \"tcolorboxlib-raster.el\"."
                        (LaTeX-tcolorbox-newtcbox-list))))
            (concat TeX-esc macro))))
       [ TeX-arg-define-macro-arguments ]
-      (TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local))
+      (TeX-arg-key-val (LaTeX-tcolorbox-keyval-options)))
 
     '("tcolorboxenvironment"
       TeX-arg-environment
-      (TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local))
+      (TeX-arg-key-val (LaTeX-tcolorbox-keyval-options)))
 
     ;; 4.16 Layered Boxes and Every Box Settings
     '("tcbsetmanagedlayer" "Number")
@@ -670,7 +679,7 @@ for example \"tcolorboxlib-raster.el\"."
    (LaTeX-add-environments
     ;; 3 Macros for Box Creation: Main env
     '("tcolorbox" LaTeX-env-args
-      [ TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local ])
+      [ TeX-arg-key-val (LaTeX-tcolorbox-keyval-options) ])
 
     ;; 7 Saving and Loading of Verbatim Texts
     '("tcbverbatimwrite" "File name")
diff --git a/style/tcolorboxlib-raster.el b/style/tcolorboxlib-raster.el
index 912f3c2..db61a03 100644
--- a/style/tcolorboxlib-raster.el
+++ b/style/tcolorboxlib-raster.el
@@ -1,6 +1,6 @@
 ;;; tcolorboxlib-raster.el --- AUCTeX style for `raster' library from 
tcolorbox  -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2016, 2018, 2020 Free Software Foundation, Inc.
+;; Copyright (C) 2016--2021 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <arash@gnu.org>
 ;; Maintainer: auctex-devel@gnu.org
@@ -36,8 +36,7 @@
 (declare-function font-latex-add-keywords
                   "font-latex"
                   (keywords class))
-
-(defvar LaTeX-tcolorbox-keyval-options-local)
+(declare-function LaTeX-tcolorbox-keyval-options "tcolorbox" ())
 (defvar LaTeX-tcolorbox-keyval-options-full)
 
 (defvar LaTeX-tcolorbox-lib-raster-keyval-options
@@ -91,11 +90,11 @@
    environment
    (let ((opts (TeX-read-key-val t (append
                                     LaTeX-tcolorbox-lib-raster-keyval-options
-                                    LaTeX-tcolorbox-keyval-options-local)
+                                    (LaTeX-tcolorbox-keyval-options))
                                  (when (string= environment "tcboxeditemize")
                                    "Raster options (k=v)")))
          (box-opts (when (string= environment "tcboxeditemize")
-                     (TeX-read-key-val nil LaTeX-tcolorbox-keyval-options-local
+                     (TeX-read-key-val nil (LaTeX-tcolorbox-keyval-options)
                                        "Box options (k=v)"))))
      (concat
       (when (and opts (not (string= opts "")))
@@ -134,15 +133,14 @@
  "tcolorboxlib-raster"
  (lambda ()
 
-   ;; Append key-vals from library to `LaTeX-tcolorbox-keyval-options-full':
-   (setq LaTeX-tcolorbox-keyval-options-full
-         (append LaTeX-tcolorbox-lib-raster-keyval-options
-                 LaTeX-tcolorbox-keyval-options-full))
+   ;; Register key-vals from library to `LaTeX-tcolorbox-keyval-options-full':
+   (add-to-list 'LaTeX-tcolorbox-keyval-options-full
+                'LaTeX-tcolorbox-lib-raster-keyval-options)
 
    (TeX-add-symbols
     ;; 14.2 Macros of the Library
     '("tcbitem"
-      [ TeX-arg-key-val LaTeX-tcolorbox-keyval-options-local "Item options 
(k=v)" ]
+      [TeX-arg-key-val (LaTeX-tcolorbox-keyval-options) "Item options (k=v)" ]
       (TeX-arg-literal " ")))
 
    (LaTeX-add-environments
@@ -154,7 +152,7 @@
          (let ((raster-opts
                 (TeX-read-key-val t (append
                                      LaTeX-tcolorbox-lib-raster-keyval-options
-                                     LaTeX-tcolorbox-keyval-options-local))))
+                                     (LaTeX-tcolorbox-keyval-options)))))
            (when (and raster-opts (not (string= raster-opts "")))
              (concat LaTeX-optop raster-opts LaTeX-optcl))))))
 
@@ -167,10 +165,10 @@
          (let ((raster-opts
                 (TeX-read-key-val t (append
                                      LaTeX-tcolorbox-lib-raster-keyval-options
-                                     LaTeX-tcolorbox-keyval-options-local)
+                                     (LaTeX-tcolorbox-keyval-options))
                                   "Raster options (k=v)"))
                (box-opts
-                (TeX-read-key-val nil LaTeX-tcolorbox-keyval-options-local
+                (TeX-read-key-val nil (LaTeX-tcolorbox-keyval-options)
                                   "Box options (k=v)")))
            (concat
             (when (and raster-opts (not (string= raster-opts "")))



reply via email to

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