branch: master
commit 41546c5b912dfcc37c813b8113bb69ac84e9b55e
Author: Arash Esbati <ar...@gnu.org>
Commit: Arash Esbati <ar...@gnu.org>

    Adjust color macros support for in-buffer completion
    
    * style/color.el (LaTeX-color-used-model-regexp)
    (LaTeX-color-used-model, LaTeX-color-used-model-requires-spec-p)
    (LaTeX-color-available-models, LaTeX-color-available-colors): New
    variables and functions.
    (TeX-arg-color-definecolor, TeX-arg-color)
    (TeX-arg-color-fcolorbox): Query and insert only the color
    specification argument and not all arguments.
    ("color"): Use the new setup in the hook.
    
    * style/xcolor.el (LaTeX-xcolor-color-cmds-regexp)
    (LaTeX-xcolor-defcolor-cmds-regexp)
    (LaTeX-xcolor-used-type-model, LaTeX-xcolor-cmd-requires-spec-p):
    New variables and functions.
    (TeX-arg-xcolor): Query and insert only the color specification
    argument.
    (TeX-arg-xcolor-definecolor): Query and insert only the newly
    defined color name and not all arguments.
    ("xcolor"): Use the new setup in the hook.
    (LaTeX-xcolor-package-options): Comment out obsolete options.
    
    * style/changebar.el ("changebar"):
    * style/colortbl.el ("colortbl"):
    * style/paracol.el ("paracol"): Adjust hooks to the new setup.
---
 style/changebar.el |  21 ++-
 style/color.el     | 366 +++++++++++++++++++++++++++-----------------------
 style/colortbl.el  | 131 +++++++++++++-----
 style/paracol.el   | 128 ++++++++++++++----
 style/xcolor.el    | 386 ++++++++++++++++++++++++++++++++---------------------
 5 files changed, 656 insertions(+), 376 deletions(-)

diff --git a/style/changebar.el b/style/changebar.el
index b3020bd7..7783b94e 100644
--- a/style/changebar.el
+++ b/style/changebar.el
@@ -60,11 +60,26 @@
    ;; Options management:
    (when (LaTeX-provided-package-options-member "changebar" "color")
      (TeX-run-style-hooks "color")
-     (TeX-add-symbols '("cbcolor" TeX-arg-color)))
+     (TeX-add-symbols
+      '("cbcolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name"))))))
 
    (when (LaTeX-provided-package-options-member "changebar" "xcolor")
      (TeX-run-style-hooks "xcolor")
-     (TeX-add-symbols '("cbcolor" TeX-arg-xcolor)))
+     (TeX-add-symbols
+      '("cbcolor"
+        [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                          "Color model"
+                                          nil nil "/" "/"]
+        (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+            (TeX-arg-xcolor)
+          ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                    "Color name"))))))
 
    (when (or (LaTeX-provided-package-options-member "changebar" "xetex")
              (LaTeX-provided-package-options-member "changebar" "XeTeX"))
@@ -111,3 +126,5 @@
     "grey" "color" "xcolor")
   "Package options for the changebar package.
 This variable contains only the lowercase version of the options.")
+
+;;; changebar.el ends here
diff --git a/style/color.el b/style/color.el
index a98b01bd..76f80209 100644
--- a/style/color.el
+++ b/style/color.el
@@ -1,6 +1,6 @@
 ;;; color.el --- AUCTeX style for `color.sty' (v1.3d)  -*- lexical-binding: t; 
-*-
 
-;; Copyright (C) 2015--2022 Free Software Foundation, Inc.
+;; Copyright (C) 2015--2024 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <ar...@gnu.org>
 ;; Maintainer: auctex-devel@gnu.org
@@ -34,7 +34,7 @@
 
 ;;; Code:
 
-;; Needed for compiling `LaTeX-check-insert-macro-default-style':
+(require 'tex)
 (require 'latex)
 
 ;; Silence the compiler:
@@ -66,9 +66,6 @@
     "WildStrawberry" "Yellow"          "YellowGreen"  "YellowOrange")
   "List of colors defined by package option `dvipsnames' from `color.sty'.")
 
-;; Needed for auto-parsing.
-(require 'tex)
-
 ;; Plug \definecolor into the parser
 (TeX-auto-add-type "color-definecolor" "LaTeX")
 
@@ -83,167 +80,148 @@
 (add-hook 'TeX-auto-prepare-hook #'LaTeX-color-auto-prepare t)
 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
 
-(defun TeX-arg-color-definecolor (optional &optional prompt)
-  "Insert arguments of `\\definecolor' from `color.sty'."
+(defconst LaTeX-color-used-model-regexp
+  (concat (regexp-quote TeX-esc)
+          (regexp-opt '("color" "textcolor"
+                        "mathcolor" "pagecolor"
+                        "colorbox" "fcolorbox"
+                        ;; changebar.el
+                        "cbcolor"
+                        ;; colortbl.el
+                        "columncolor" "rowcolor" "cellcolor"
+                        "arrayrulecolor" "doublerulesepcolor"
+                        ;; paracol.el also provides a columncolor which
+                        ;; we don't repeat:
+                        "colseprulecolor"))
+          "\\(?:\\[\\([^]]+\\)\\]\\)?")
+  "Regexp for matching the optional argument of color macros.")
+
+(defvar-local LaTeX-color-used-model nil
+  "Variable containing the color model from last search.
+It is set by the function `LaTeX-color-used-model'.")
+
+(defun LaTeX-color-used-model-requires-spec-p ()
+  "Return non-nil if the used color model requires color specification."
+  (and (save-excursion
+         (re-search-backward LaTeX-color-used-model-regexp
+                             (line-beginning-position) t)
+         (setq LaTeX-color-used-model (match-string-no-properties 1)))
+       (not (string= LaTeX-color-used-model "named"))))
+
+(defun LaTeX-color-available-models ()
+  "Return a list of available color models."
+  (if (or (LaTeX-provided-package-options-member "color" "dvips")
+          (LaTeX-provided-package-options-member "color" "dvipsnames"))
+      LaTeX-color-colour-models
+    (remove "named" LaTeX-color-colour-models)))
+
+(defun LaTeX-color-available-colors ()
+  "Return a list of available colors."
+  (if (string= LaTeX-color-used-model "named")
+      LaTeX-color-dvipsnames-colors
+    (LaTeX-color-definecolor-list)))
+
+(defun TeX-arg-color-definecolor (optional)
+  "Insert <color spec> argument of \\definecolor from color.sty.
+If OPTIONAL is non-nil, insert the argument when non-empty and in
+brackets.  The \"named\" color model is handled inside the hook and not
+in this function."
   ;; \definecolor{<name>}{<model>}{<color spec>}
-  ;; Ask for <name>, add to our list and insert it
-  (let ((colorname (TeX-read-string "Color name: ")))
-    (LaTeX-add-color-definecolors colorname)
-    (TeX-argument-insert colorname optional))
-  ;; Ask and insert <model>
-  (let ((model (completing-read
-                (TeX-argument-prompt optional prompt "Color model")
-                (if (not (or (LaTeX-provided-package-options-member "color" 
"dvips")
-                             (LaTeX-provided-package-options-member "color" 
"dvipsnames")))
-                    (remove "named" LaTeX-color-colour-models)
-                  LaTeX-color-colour-models))))
-    (TeX-argument-insert model optional)
-    ;; Depending on <model>, ask for <color spec> and insert it
-    (cond (;; <cmyk> model
-           (string-equal model "cmyk")
-           (let ((cyan    (TeX-read-string "Value Cyan (between 0,1): "))
-                 (magenta (TeX-read-string "Value Magenta (between 0,1): "))
-                 (yellow  (TeX-read-string "Value Yellow (between 0,1): "))
-                 (black   (TeX-read-string "Value Black (between 0,1): ")))
+  ;; Depending on <model>, ask for <color spec> and insert it
+  (pcase LaTeX-color-used-model
+    ;; <cmyk> model
+    ("cmyk" (let ((cyan    (TeX-read-string "Value Cyan (between 0,1): "))
+                  (magenta (TeX-read-string "Value Magenta (between 0,1): "))
+                  (yellow  (TeX-read-string "Value Yellow (between 0,1): "))
+                  (black   (TeX-read-string "Value Black (between 0,1): ")))
+              (TeX-argument-insert
+               (mapconcat #'identity (list cyan magenta yellow black) ",")
+               optional)))
+    ;; <rgb> model
+    ("rgb" (let ((red   (TeX-read-string "Value Red (between 0,1): "))
+                 (green (TeX-read-string "Value Green (between 0,1): "))
+                 (blue  (TeX-read-string "Value Blue (between 0,1): ")))
              (TeX-argument-insert
-              (concat cyan "," magenta "," yellow "," black) optional)))
-          ;; <rgb> model
-          ((string-equal model "rgb")
-           (let ((red   (TeX-read-string "Value Red (between 0,1): "))
+              (mapconcat #'identity (list red green blue) ",")
+              optional)))
+    ;; <gray> model
+    ("gray" (TeX-argument-insert
+             (TeX-read-string "Value Gray (between 0,1): ")
+             optional))
+    (_ (error "%s" "Finding color model failed"))))
+
+(defun TeX-arg-color (optional)
+  "Insert <color spec> argument of various color commands from color.sty.
+If OPTIONAL is non-nil, insert the argument when non-empty and in
+brackets.  The \"named\" color model is handled inside the hook and not
+in this function."
+  ;; \color[<model>]{<color spec>}: Query for <color spec> based on
+  ;; `LaTeX-color-used-model':
+  (pcase LaTeX-color-used-model
+    ;; <cmyk> model
+    ("cmyk" (let ((cyan    (TeX-read-string "Value Cyan (between 0,1): "))
+                  (magenta (TeX-read-string "Value Magenta (between 0,1): "))
+                  (yellow  (TeX-read-string "Value Yellow (between 0,1): "))
+                  (black   (TeX-read-string "Value Black (between 0,1): ")))
+              (TeX-argument-insert
+               (mapconcat #'identity (list cyan magenta yellow black) ",")
+               optional)))
+    ;; <rgb> model
+    ("rgb" (let ((red   (TeX-read-string "Value Red (between 0,1): "))
                  (green (TeX-read-string "Value Green (between 0,1): "))
                  (blue  (TeX-read-string "Value Blue (between 0,1): ")))
              (TeX-argument-insert
-              (concat red "," green "," blue) optional)))
-          ;; <gray> model
-          ((string-equal model "gray")
-           (let ((grayness (TeX-read-string "Value Gray (between 0,1): ")))
-             (TeX-argument-insert grayness optional)))
-          ;; <named> model takes the dvipsnames
-          ((string-equal model "named")
-           (let ((color (completing-read "Named Color: "
-                                         LaTeX-color-dvipsnames-colors)))
-             (TeX-argument-insert color optional))))))
-
-(defun TeX-arg-color (optional &optional prompt)
-  "Insert arguments of various color commands from `color.sty'."
-  ;; \color{<name>} or \color[<model>]{<color spec>} First, ask for
-  ;; <model>.  This happens depending on the values of
-  ;; `TeX-insert-macro-default-style' and if `current-prefix-arg'.
-  ;; `named' is removed here from completion if package option is not
-  ;; given.
-  (let* ((TeX-last-optional-rejected nil)
-         (model (LaTeX-check-insert-macro-default-style
-                 (completing-read
-                  (TeX-argument-prompt t prompt "Color model")
-                  (if (not (or (LaTeX-provided-package-options-member "color" 
"dvips")
-                               (LaTeX-provided-package-options-member "color" 
"dvipsnames")))
-                      (remove "named" LaTeX-color-colour-models)
-                    LaTeX-color-colour-models)))))
-    ;; If <model> is non-nil because of 'mandatory-args-only and not
-    ;; an empty string, then insert it
-    (if (and model (not (string-equal model "")))
-        (progn
-          (insert (concat LaTeX-optop model LaTeX-optcl))
-          (cond (;; <cmyk> model
-                 (string-equal model "cmyk")
-                 (let ((cyan    (TeX-read-string "Value Cyan (between 0,1): "))
-                       (magenta (TeX-read-string "Value Magenta (between 0,1): 
"))
-                       (yellow  (TeX-read-string "Value Yellow (between 0,1): 
"))
-                       (black   (TeX-read-string "Value Black (between 0,1): 
")))
-                   (TeX-argument-insert
-                    (concat cyan "," magenta "," yellow "," black) optional)))
-                ;; <rgb> model
-                ((string-equal model "rgb")
-                 (let ((red   (TeX-read-string "Value Red (between 0,1): "))
-                       (green (TeX-read-string "Value Green (between 0,1): "))
-                       (blue  (TeX-read-string "Value Blue (between 0,1): ")))
-                   (TeX-argument-insert
-                    (concat red "," green "," blue) optional)))
-                ;; <gray> model
-                ((string-equal model "gray")
-                 (let ((grayness (TeX-read-string "Value Gray (between 0,1): 
")))
-                   (TeX-argument-insert grayness optional)))
-                ;; <named> model; allowed are dvipsnames.
-                ((string-equal model "named")
-                 (let ((color (completing-read "Named Color: "
-                                               LaTeX-color-dvipsnames-colors)))
-                   (TeX-argument-insert color optional)))))
-      ;; if empty, ask for <name> with completion
-      (let ((color (completing-read
-                    (TeX-argument-prompt optional prompt "Color name")
-                    (LaTeX-color-definecolor-list))))
-        (TeX-argument-insert color optional)))))
+              (mapconcat #'identity (list red green blue) ",")
+              optional)))
+    ;; <gray> model
+    ("gray" (TeX-argument-insert
+             (TeX-read-string "Value Gray (between 0,1): ")
+             optional))
+    (_ (error "%s" "Finding color model failed"))))
 
 (defun TeX-arg-color-fcolorbox (optional &optional prompt)
-  "Insert arguments of `\\fcolorbox' from `color.sty'. "
+  "Insert <color spec> argument of `\\fcolorbox' from `color.sty'.
+If OPTIONAL is non-nil, insert the argument when non-empty and in
+brackets.  PROMPT is only \"Box\" when non-nil.  The \"named\" color
+model is handled inside the hook and not in this function."
   ;; \fcolorbox{<frame color name>}{<box color name>}{<text>} or
   ;; \fcolorbox[<model>]{<frame color spec>}{<box color spec>}{<text>}
-  ;; First, ask for <model> depending on
-  ;; `TeX-insert-macro-default-style' and `current-prefix-arg'.
-  ;; Remove `named' if necessary.
-  (let* ((TeX-last-optional-rejected nil)
-         (model (LaTeX-check-insert-macro-default-style
-                 (completing-read
-                  (TeX-argument-prompt t prompt "Color model")
-                  (if (not (or (LaTeX-provided-package-options-member "color" 
"dvips")
-                               (LaTeX-provided-package-options-member "color" 
"dvipsnames")))
-                      (remove "named" LaTeX-color-colour-models)
-                    LaTeX-color-colour-models)))))
-    ;; If <model> is non-nil because of 'mandatory-args-only and not
-    ;; an empty string, then insert [<model>] and cater for 2
-    ;; mandatory args.
-    (if (and model (not (string-equal model "")))
-        (progn
-          (insert (concat LaTeX-optop model LaTeX-optcl))
-          (cond (;; <cmyk> model
-                 (string-equal model "cmyk")
-                 (let ((cyan    (TeX-read-string "Frame value Cyan (between 
0,1): "))
-                       (magenta (TeX-read-string "Frame value Magenta (between 
0,1): "))
-                       (yellow  (TeX-read-string "Frame value Yellow (between 
0,1): "))
-                       (black   (TeX-read-string "Frame value Black (between 
0,1): ")))
-                   (TeX-argument-insert
-                    (concat cyan "," magenta "," yellow "," black) optional))
-                 (let ((cyan    (TeX-read-string "Box value Cyan (between 
0,1): "))
-                       (magenta (TeX-read-string "Box value Magenta (between 
0,1): "))
-                       (yellow  (TeX-read-string "Box value Yellow (between 
0,1): "))
-                       (black   (TeX-read-string "Box value Black (between 
0,1): ")))
-                   (TeX-argument-insert
-                    (concat cyan "," magenta "," yellow "," black) optional)))
-                ;; <rgb> model
-                ((string-equal model "rgb")
-                 (let ((red   (TeX-read-string "Frame value Red (between 0,1): 
"))
-                       (green (TeX-read-string "Frame value Green (between 
0,1): "))
-                       (blue  (TeX-read-string "Frame value Blue (between 
0,1): ")))
-                   (TeX-argument-insert
-                    (concat red "," green "," blue) optional))
-                 (let ((red   (TeX-read-string "Box value Red (between 0,1): 
"))
-                       (green (TeX-read-string "Box value Green (between 0,1): 
"))
-                       (blue  (TeX-read-string "box value Blue (between 0,1): 
")))
-                   (TeX-argument-insert
-                    (concat red "," green "," blue) optional)))
-                ;; <gray> model
-                ((string-equal model "gray")
-                 (let ((grayness (TeX-read-string "Frame value Gray (between 
0,1): ")))
-                   (TeX-argument-insert grayness optional))
-                 (let ((grayness (TeX-read-string "Box value Gray (between 
0,1): ")))
-                   (TeX-argument-insert grayness optional)))
-                ;; <named> model; allowed are dvipsnames.
-                ((string-equal model "named")
-                 (let ((color (completing-read "Frame named Color: "
-                                               LaTeX-color-dvipsnames-colors)))
-                   (TeX-argument-insert color optional))
-                 (let ((color (completing-read "Box named Color: "
-                                               LaTeX-color-dvipsnames-colors)))
-                   (TeX-argument-insert color optional)))))
-      ;; if empty, ask for {<frame color spce>}{<box color name>} with 
completion
-      (let ((frame-color (completing-read
-                          (TeX-argument-prompt optional prompt "Frame color 
name")
-                          (LaTeX-color-definecolor-list)))
-            (box-color   (completing-read
-                          (TeX-argument-prompt optional prompt "Box color 
name")
-                          (LaTeX-color-definecolor-list))))
-        (TeX-argument-insert frame-color optional)
-        (TeX-argument-insert box-color   optional)))))
+  (pcase LaTeX-color-used-model
+    ;; <cmyk> model
+    ("cmyk" (let ((cyan    (TeX-read-string
+                            (concat (or prompt "Frame")
+                                    " value Cyan (between 0,1): ")))
+                  (magenta (TeX-read-string
+                            (concat (or prompt "Frame")
+                                    " value Magenta (between 0,1): ")))
+                  (yellow  (TeX-read-string
+                            (concat (or prompt "Frame")
+                                    " value Yellow (between 0,1): ")))
+                  (black   (TeX-read-string
+                            (concat (or prompt "Frame")
+                                    " value Black (between 0,1): "))))
+              (TeX-argument-insert
+               (mapconcat #'identity (list cyan magenta yellow black) ",")
+               optional)))
+    ;; <rgb> model
+    ("rgb" (let ((red   (TeX-read-string
+                         (concat (or prompt "Frame")
+                                 " value Red (between 0,1): ")))
+                 (green (TeX-read-string
+                         (concat (or prompt "Frame")
+                                 " value Green (between 0,1): ")))
+                 (blue  (TeX-read-string
+                         (concat (or prompt "Frame")
+                                 " value Blue (between 0,1): "))))
+             (TeX-argument-insert
+              (mapconcat #'identity (list red green blue) ",")
+              optional)))
+    ;; <gray> model
+    ("gray" (TeX-argument-insert (TeX-read-string
+                                  (concat (or prompt "Frame")
+                                          " value Gray (between 0,1): "))
+                                 optional))
+    (_ (error "%s" "Finding color model failed"))))
 
 (TeX-add-style-hook
  "color"
@@ -264,33 +242,93 @@
    (unless (member "xcolor" (TeX-style-list))
      (TeX-add-symbols
       ;; \definecolor{<name>}{<model>}{<color spec>}
-      '("definecolor" TeX-arg-color-definecolor)
+      '("definecolor"
+        (lambda (optional)
+          (let ((colorname (TeX-read-string
+                            (TeX-argument-prompt optional nil "Color name"))))
+            (LaTeX-add-color-definecolors colorname)
+            (TeX-argument-insert colorname optional)))
+        (TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model")
+        (TeX-arg-conditional
+            (and (save-excursion
+                   (re-search-backward "\\\\definecolor{[^}]+}{\\([^}]+\\)}"
+                                       (line-beginning-position) t)
+                   (setq LaTeX-color-used-model (match-string-no-properties 
1)))
+                 (not (string= LaTeX-color-used-model "named")))
+            (TeX-arg-color-definecolor)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name"))))
 
       ;; \color{<name>} or \color[<model>]{<color spec>}
-      '("color" TeX-arg-color)
+      '("color"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name"))))
 
       ;; \textcolor{<name>}{<text>} or
       ;; \textcolor[<model>]{<color spec>}{<text>}
-      '("textcolor" TeX-arg-color "Text")
+      '("textcolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name")))
+        "Text")
 
       ;; \mathcolor{<name>}{<math>} or
       ;; \mathcolor[<model>]{<color spec>}{<math>}
-      '("mathcolor" TeX-arg-color "Math")
+      '("mathcolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name")))
+        "Math")
 
       ;; \pagecolor{<name>} or
       ;; \pagecolor[<model>]{<color spec>}
-      '("pagecolor" TeX-arg-color)
+      '("pagecolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name"))))
 
       ;; \nopagecolor
       '("nopagecolor" 0)
 
       ;; \colorbox{<name>}{<text>} or
       ;; \colorbox[<model>]{<color spec>}{<text>}
-      '("colorbox" TeX-arg-color "Text")
+      '("colorbox"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name")))
+        "Text")
 
       ;; \fcolorbox{<frame color name>}{<box color name>}{<text>} or
       ;; \fcolorbox[<model>]{<frame color spec>}{<box color spec>}{<text>}
-      '("fcolorbox" TeX-arg-color-fcolorbox "Text"))
+      '("fcolorbox"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color-fcolorbox)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Frame color name")))
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            ((TeX-arg-color-fcolorbox "Box"))
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Box color name")))
+        "Text"))
 
      ;; Fontification
      (when (and (featurep 'font-latex)
diff --git a/style/colortbl.el b/style/colortbl.el
index 7bbab914..41131c83 100644
--- a/style/colortbl.el
+++ b/style/colortbl.el
@@ -1,6 +1,6 @@
 ;;; colortbl.el --- AUCTeX style for `colortbl.sty' (v1.0a)  -*- 
lexical-binding: t; -*-
 
-;; Copyright (C) 2015, 2016, 2018, 2020 Free Software Foundation, Inc.
+;; Copyright (C) 2015--2024 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <ar...@gnu.org>
 ;; Maintainer: auctex-devel@gnu.org
@@ -48,35 +48,102 @@
 
    ;; Load color.el only if xcolor.el is not already loaded.  This is
    ;; mainly for the option `table' from xcolor.sty which loads
-   ;; colortbl.sty, but we don't want to load color.el.
-   (unless (member "xcolor" (TeX-style-list))
-     (TeX-run-style-hooks "color"))
-
-   (TeX-add-symbols
-    ;; `TeX-arg-color' is provided by color.el,
-    ;; `TeX-arg-xcolor' is provided by xcolor.el.
-    '("columncolor" (TeX-arg-conditional (member "xcolor" (TeX-style-list))
-                                         (TeX-arg-xcolor)
-                                         (TeX-arg-color))
-      [ TeX-arg-length "Left overhang" ] [ TeX-arg-length "Right overhang" ] )
-
-    '("rowcolor"    (TeX-arg-conditional (member "xcolor" (TeX-style-list))
-                                         (TeX-arg-xcolor)
-                                         (TeX-arg-color))
-      [ TeX-arg-length "Left overhang" ] [ TeX-arg-length "Right overhang" ] )
-
-    '("cellcolor"   (TeX-arg-conditional (member "xcolor" (TeX-style-list))
-                                         (TeX-arg-xcolor)
-                                         (TeX-arg-color))
-      [ TeX-arg-length "Left overhang" ] [ TeX-arg-length "Right overhang" ] )
-
-    '("arrayrulecolor" (TeX-arg-conditional (member "xcolor" (TeX-style-list))
-                                            (TeX-arg-xcolor)
-                                            (TeX-arg-color)))
-
-    '("doublerulesepcolor" (TeX-arg-conditional (member "xcolor" 
(TeX-style-list))
-                                                (TeX-arg-xcolor)
-                                                (TeX-arg-color))))
+   ;; colortbl.sty where we don't want to load color.el:
+   (if (member "xcolor" (TeX-style-list))
+       ;; xcolor.sty
+       (TeX-add-symbols
+        '("columncolor"
+          [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                            "Color model"
+                                            nil nil "/" "/"]
+          (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+              (TeX-arg-xcolor)
+            ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                      "Color name")))
+          [TeX-arg-length "Left overhang"] [TeX-arg-length "Right overhang"] )
+
+        '("rowcolor"
+          [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                            "Color model"
+                                            nil nil "/" "/"]
+          (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+              (TeX-arg-xcolor)
+            ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                      "Color name")))
+          [TeX-arg-length "Left overhang"] [TeX-arg-length "Right overhang"] )
+
+        '("cellcolor"
+          [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                            "Color model"
+                                            nil nil "/" "/"]
+          (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+              (TeX-arg-xcolor)
+            ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                      "Color name")))
+          [TeX-arg-length "Left overhang"] [TeX-arg-length "Right overhang"] )
+
+        '("arrayrulecolor"
+          [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                            "Color model"
+                                            nil nil "/" "/"]
+          (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+              (TeX-arg-xcolor)
+            ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                      "Color name"))))
+
+        '("doublerulesepcolor"
+          [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                            "Color model"
+                                            nil nil "/" "/"]
+          (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+              (TeX-arg-xcolor)
+            ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                      "Color name")))))
+     ;; color.sty
+     (TeX-run-style-hooks "color")
+     (TeX-add-symbols
+      '("columncolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name")))
+        [TeX-arg-length "Left overhang"] [TeX-arg-length "Right overhang"])
+
+      '("rowcolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name")))
+        [TeX-arg-length "Left overhang"] [TeX-arg-length "Right overhang"])
+
+      '("cellcolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name")))
+        [TeX-arg-length "Left overhang"] [TeX-arg-length "Right overhang"] )
+
+      '("arrayrulecolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name"))))
+
+      '("doublerulesepcolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+            (TeX-arg-color)
+          ((TeX-arg-completing-read (LaTeX-color-available-colors)
+                                    "Color name"))))))
 
    (LaTeX-add-lengths "minrowclearance")
 
@@ -91,8 +158,8 @@
                               'function)))
  TeX-dialect)
 
-;; colortbl.sty has one option `debugshow'.  I ignore that since it
-;; would only take more time during insertation in a buffer and I
+;; colortbl.sty has one option `debugshow'.  We ignore that since it
+;; would only take more time during insertation in a buffer and we
 ;; presume that not many users use it anyway.
 (defvar LaTeX-colortbl-package-options nil
   "Package option for the colortbl package.")
diff --git a/style/paracol.el b/style/paracol.el
index 86a47a26..bc9b4ded 100644
--- a/style/paracol.el
+++ b/style/paracol.el
@@ -1,6 +1,6 @@
 ;;; paracol.el --- AUCTeX style for `paracol.sty' (v1.35)  -*- 
lexical-binding: t; -*-
 
-;; Copyright (C) 2016--2022 Free Software Foundation, Inc.
+;; Copyright (C) 2016--2024 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <ar...@gnu.org>
 ;; Maintainer: auctex-devel@gnu.org
@@ -64,6 +64,21 @@ If OPTIONAL is non-nil, insert the result in square 
brackets."
         (backward-char 1)
         (TeX-argument-insert col optional)))))
 
+(defun LaTeX-paracol--used-model (&optional xcolor)
+  "Seach for \\backgroundcolor and return the optional used color model.
+If XCOLOR is non-nil, store the returned value in the variable
+`LaTeX-xcolor-used-type-model', otherwise in the variable
+`LaTeX-color-used-model'."
+  (save-excursion
+    (and (re-search-backward (concat (regexp-quote TeX-esc)
+                                     "backgroundcolor"
+                                     "\\(?:{[^}]*}\\)"
+                                     "\\(?:\\[\\([^]]+\\)\\]\\)?")
+                             (line-beginning-position) t)
+         (set (if xcolor 'LaTeX-xcolor-used-type-model 'LaTeX-color-used-model)
+              (match-string-no-properties 1))
+         (not (string= "named" (match-string-no-properties 1))))))
+
 (TeX-add-style-hook
  "paracol"
  (lambda ()
@@ -176,47 +191,20 @@ If OPTIONAL is non-nil, insert the result in square 
brackets."
     '("nofncounteradjustment" 0)
 
     ;; 7.7 Commands for Coloring Texts and Column-Separating Rules
-    ;; \columncolor[mode]{color}[col]
-    ;;
-    ;; This clashes if colortbl.el is loaded since it provides a
-    ;; command with the same name but different arguments.  We add
-    ;; the command only here but not for fontification
-    '("columncolor" (TeX-arg-conditional (member "xcolor" (TeX-style-list))
-                                         (TeX-arg-xcolor)
-                                         (TeX-arg-color))
-      [ "Column" ] )
-
     ;; \normalcolumncolor[col]
     '("normalcolumncolor" [ "Column" ] )
     '("coloredwordhyphenated" 0)
     '("nocoloredwordhyphenated" 0)
 
-    ;; \colseprulecolor[mode]{color}[col]
     ;; \normalcolseprulecolor[col]
-    '("colseprulecolor" (TeX-arg-conditional (member "xcolor" (TeX-style-list))
-                                             (TeX-arg-xcolor)
-                                             (TeX-arg-color))
-      [ "Column" ] )
     '("normalcolseprulecolor" [ "Column" ] )
 
     ;; 7.8 Commands for Background Painting
-    ;; \backgroundcolor{region}[mode]{color}
-    ;; \backgroundcolor{region(x0,y0)}[mode]{color}
-    ;; \backgroundcolor{region(x0,y0)(x1,y1)}[mode]{color}
-    '("backgroundcolor"
-      (TeX-arg-completing-read ("c" "g" "s" "f" "n" "p" "t" "b" "l" "r"
-                                "C" "G" "S" "F" "N" "P" "T" "B" "L" "R")
-                               "Region")
-      (TeX-arg-conditional (member "xcolor" (TeX-style-list))
-                           (TeX-arg-xcolor)
-                           (TeX-arg-color)))
-
     ;; \nobackgroundcolor{region}
     '("nobackgroundcolor"
       (TeX-arg-completing-read ("c" "g" "s" "f" "n" "p" "t" "b" "l" "r"
                                 "C" "G" "S" "F" "N" "P" "T" "B" "L" "R")
                                "Region"))
-
     ;; \resetbackgroundcolor
     '("resetbackgroundcolor" 0)
 
@@ -229,6 +217,90 @@ If OPTIONAL is non-nil, insert the result in square 
brackets."
     ;; 7.10 Page Flushing Commands
     '("flushpage" 0))
 
+   ;; xcolor.el
+   (when (member "xcolor" (TeX-style-list))
+     ;; 7.7 Commands for Coloring Texts and Column-Separating Rules
+     ;; \columncolor[model]{color}[col]
+     ;;
+     ;; This clashes if colortbl.el is loaded since it provides a
+     ;; command with the same name but different arguments.  We add
+     ;; the command only here but not for fontification
+     (TeX-add-symbols
+      '("columncolor"
+        [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                          "Color model"
+                                          nil nil "/" "/"]
+        (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+                             (TeX-arg-xcolor)
+                             ((TeX-arg-completing-read 
(LaTeX-xcolor-definecolor-list)
+                                                       "Color name")))
+        [ "Column" ] )
+
+      ;; \colseprulecolor[model]{color}[col]
+      '("colseprulecolor"
+        [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                          "Color model"
+                                          nil nil "/" "/"]
+        (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+                             (TeX-arg-xcolor)
+                             ((TeX-arg-completing-read 
(LaTeX-xcolor-definecolor-list)
+                                                       "Color name")))
+        [ "Column" ] )
+
+      ;; 7.8 Commands for Background Painting
+      ;; \backgroundcolor{region}[mode]{color}
+      ;; \backgroundcolor{region(x0,y0)}[mode]{color}
+      ;; \backgroundcolor{region(x0,y0)(x1,y1)}[mode]{color}
+      '("backgroundcolor"
+        (TeX-arg-completing-read ("c" "g" "s" "f" "n" "p" "t" "b" "l" "r"
+                                  "C" "G" "S" "F" "N" "P" "T" "B" "L" "R")
+                                 "Region")
+        [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                          "Color model"
+                                          nil nil "/" "/"]
+        (TeX-arg-conditional (LaTeX-paracol--used-model t)
+                             (TeX-arg-xcolor)
+                             ((TeX-arg-completing-read 
(LaTeX-xcolor-definecolor-list)
+                                                       "Color name"))))))
+
+   ;; color.el: Always prefer xcolor.sty over color.sty
+   (when (and (member "color" (TeX-style-list))
+              (not (member "xcolor" TeX-active-styles)))
+     (TeX-add-symbols
+      '("columncolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+                             (TeX-arg-color)
+                             ((TeX-arg-completing-read 
(LaTeX-color-available-colors)
+                                                       "Color name")))
+        [ "Column" ] )
+
+      ;; \colseprulecolor[mode]{color}[col]
+      '("colseprulecolor"
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-color-used-model-requires-spec-p)
+                             (TeX-arg-color)
+                             ((TeX-arg-completing-read 
(LaTeX-color-available-colors)
+                                                       "Color name")))
+        [ "Column" ] )
+
+      ;; 7.8 Commands for Background Painting
+      ;; \backgroundcolor{region}[mode]{color}
+      ;; \backgroundcolor{region(x0,y0)}[mode]{color}
+      ;; \backgroundcolor{region(x0,y0)(x1,y1)}[mode]{color}
+      '("backgroundcolor"
+        (TeX-arg-completing-read ("c" "g" "s" "f" "n" "p" "t" "b" "l" "r"
+                                  "C" "G" "S" "F" "N" "P" "T" "B" "L" "R")
+                                 "Region")
+        [TeX-arg-completing-read (LaTeX-color-available-models)
+                                 "Color model"]
+        (TeX-arg-conditional (LaTeX-paracol--used-model)
+                             (TeX-arg-color)
+                             ((TeX-arg-completing-read 
(LaTeX-color-available-colors)
+                                                       "Color name"))))))
+
    ;; \belowfootnoteskip is a length:
    (LaTeX-add-lengths "belowfootnoteskip")
 
diff --git a/style/xcolor.el b/style/xcolor.el
index b0bc74fb..440d7d35 100644
--- a/style/xcolor.el
+++ b/style/xcolor.el
@@ -1,6 +1,6 @@
-;; xcolor.el --- AUCTeX style for `xcolor.sty' (v2.12)  -*- lexical-binding: 
t; -*-
+;; xcolor.el --- AUCTeX style for `xcolor.sty' (v3.01)  -*- lexical-binding: 
t; -*-
 
-;; Copyright (C) 2016--2023 Free Software Foundation, Inc.
+;; Copyright (C) 2016--2024 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <ar...@gnu.org>
 ;; Maintainer: auctex-devel@gnu.org
@@ -26,7 +26,7 @@
 
 ;;; Commentary:
 
-;; This file adds support for `xcolor.sty' (v2.13) from 2021/10/31.
+;; This file adds support for `xcolor.sty' (v3.01) from 2023/11/15.
 ;; `xcolor.sty' is part of TeXLive.
 
 ;; `xcolor.sty' and `color.sty' share many command namens, but the
@@ -44,7 +44,7 @@
 
 ;;; Code:
 
-;; Needed for compiling `LaTeX-check-insert-macro-default-style':
+(require 'tex)
 (require 'latex)
 
 ;; Silence the compiler:
@@ -52,22 +52,6 @@
                   "font-latex"
                   (keywords class))
 
-(defvar LaTeX-xcolor-core-color-models
-  '("rgb" "cmy" "cmyk" "hsb" "gray")
-  "List of core color models provided by xcolor.sty.")
-
-(defvar LaTeX-xcolor-num-color-models
-  '("RGB" "HTML" "HSB" "Gray" "HsB" "tHsB" "wave")
-  "List of integer and decimal color models provided by xcolor.sty.")
-
-(defvar LaTeX-xcolor-pseudo-color-models
-  '("named")
-  "List of pseudo color models provided by xcolor.sty.")
-
-(defvar LaTeX-xcolor-type-color-models
-  '("named" "ps")
-  "List of type color models provided by xcolor.sty.")
-
 (defvar LaTeX-xcolor-base-colors
   '("red"    "green" "blue"     "cyan"      "magenta" "yellow" "black"
     "gray"   "white" "darkgray" "lightgray" "brown"   "lime"   "olive"
@@ -218,11 +202,28 @@
     "DeepPink4"         "LightSteelBlue4" "RosyBrown4")
   "List of colors defined by package option x11names from xcolor.sty.")
 
+(defvar LaTeX-xcolor-core-color-models
+  '("rgb" "cmy" "cmyk" "hsb" "gray")
+  "List of core color models provided by xcolor.sty.")
+
+(defvar LaTeX-xcolor-num-color-models
+  '("RGB" "HTML" "HSB" "Gray" "HsB" "tHsB" "wave")
+  "List of integer and decimal color models provided by xcolor.sty.")
+
+(defvar LaTeX-xcolor-pseudo-color-models
+  '("named")
+  "List of pseudo color models provided by xcolor.sty.")
+
+(defvar LaTeX-xcolor-color-types
+  '("named" "ps")
+  "List of color types provided by xcolor.sty.")
+
 (defvar LaTeX-xcolor-color-models
   (append LaTeX-xcolor-core-color-models
           LaTeX-xcolor-num-color-models
           LaTeX-xcolor-pseudo-color-models)
-  "Combine three variables `LaTeX-xcolor-core-color-models',
+  "Combine three variables containing color model.
+These are `LaTeX-xcolor-core-color-models',
 `LaTeX-xcolor-num-color-models' and `LaTeX-xcolor-pseudo-color-models'.")
 
 (defun LaTeX-xcolor-color-models (&optional no-named)
@@ -233,9 +234,6 @@ remainder."
       (remove "named" LaTeX-xcolor-color-models)
     LaTeX-xcolor-color-models))
 
-;; Needed for auto-parsing.
-(require 'tex)
-
 ;; Setup AUCTeX parser for \definecolor(set):
 (TeX-auto-add-type "xcolor-definecolor" "LaTeX")
 (TeX-auto-add-type "xcolor-definecolorset" "LaTeX")
@@ -245,7 +243,7 @@ remainder."
     `(,(concat "\\\\"
                (regexp-opt '("definecolor"  "providecolor"
                              "preparecolor" "colorlet"))
-               "\\(?:\\[\\(?:[^]]*\\)\\]\\)?{\\([^}]+\\)}")
+               "\\(?:\\[[^]]*\\]\\)?{\\([^}]+\\)}")
       1 LaTeX-auto-xcolor-definecolor))
   "Match the argument of various color defining macros from xcolor package.")
 
@@ -281,106 +279,84 @@ xcolor package.")
 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-xcolor-auto-cleanup t)
 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
 
-(defun TeX-arg-xcolor-definecolor (optional)
-  "Insert arguments of \\definecolor and similar macros from xcolor.sty."
-  ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
-  (let* ((TeX-last-optional-rejected nil)
-         (xcoltype  (LaTeX-check-insert-macro-default-style
-                     (completing-read
-                      (TeX-argument-prompt t nil "Type")
-                      LaTeX-xcolor-type-color-models)))
-         (xcolname  (TeX-read-string
-                     (TeX-argument-prompt optional nil "Color name")))
-         (xcolmodel (completing-read
-                     (TeX-argument-prompt optional nil "Model (list)")
-                     (if (string= xcoltype "named")
-                         (LaTeX-xcolor-color-models t)
-                       LaTeX-xcolor-color-models)))
-         (xcolspec  (if (string= xcolmodel "named")
-                        (completing-read
-                         (TeX-argument-prompt optional nil "Color")
-                         (LaTeX-xcolor-definecolor-list))
-                      (TeX-read-string
-                       (TeX-argument-prompt optional nil (concat xcolmodel " 
spec (list)"))))))
-    (when (and xcoltype (not (string= xcoltype "")))
-      (insert (format "[%s]" xcoltype)))
-    (TeX-argument-insert xcolname optional)
-    (LaTeX-add-xcolor-definecolors xcolname)
-    (TeX-argument-insert xcolmodel optional)
-    (TeX-argument-insert xcolspec optional)))
-
-(defun TeX-arg-xcolor-definecolorset (optional)
-  "Insert arguments of \\definecolorset and similar macros from xcolor.sty."
-  (let* ((TeX-last-optional-rejected nil)
-         (xcoltype (LaTeX-check-insert-macro-default-style
-                    (completing-read
-                     (TeX-argument-prompt t nil "Type")
-                     LaTeX-xcolor-type-color-models)))
-         (xcolmodel (completing-read
-                     (TeX-argument-prompt optional nil "Model")
-                     (LaTeX-xcolor-color-models t))))
-    (when (and xcoltype (not (string= xcoltype "")))
-      (insert (format "[%s]" xcoltype)))
-    (TeX-argument-insert xcolmodel optional)))
+(defconst LaTeX-xcolor-color-cmds-regexp
+  (concat (regexp-quote TeX-esc)
+          (regexp-opt '("color" "textcolor"
+                        "mathcolor" "pagecolor"
+                        "colorbox" "fcolorbox"
+                        ;; changebar.el
+                        "cbcolor"
+                        ;; colortbl.el
+                        "columncolor" "rowcolor" "cellcolor"
+                        "arrayrulecolor" "doublerulesepcolor"
+                        ;; paracol.el also provides a columncolor which
+                        ;; we don't repeat:
+                        "colseprulecolor"))
+          "\\(?:\\[\\([^]]*\\)\\]\\)?")
+  "Regexp for matching the optional argument of color macros.")
+
+(defconst LaTeX-xcolor-defcolor-cmds-regexp
+  (concat (regexp-quote TeX-esc)
+          (regexp-opt '("definecolor" "providecolor" "colorlet"
+                        "preparecolor"))
+          "\\(?:\\[\\([^]]*\\)\\]\\)?"
+          "\\(?:{[^}]+}\\)?"
+          "\\(?:{\\([^}]+\\)}\\)?")
+  "Regexp matching the type and model argument of color defining macros.")
+
+(defvar-local LaTeX-xcolor-used-type-model nil
+  "Variable containing the color type or model from last search.
+It is set by the function `LaTeX-xcolor-cmd-requires-spec-p'.")
+
+(defun LaTeX-xcolor-cmd-requires-spec-p (what &optional which)
+  "Search backward for type or model of color commands.
+WHAT determines the regexp for color commands to search for where:
+WHAT      Variable
+-------   -----------------------------------
+\\='col      `LaTeX-xcolor-color-cmds-regexp'
+\\='defcol   `LaTeX-xcolor-defcolor-cmds-regexp'
+\\='colbox   Calculated inside this function.
+
+If WHICH is non-nil, the second grouped argument from the search is
+returned instead of the first."
+  (let ((regexp (pcase what
+                  ('col LaTeX-xcolor-color-cmds-regexp)
+                  ('defcol LaTeX-xcolor-defcolor-cmds-regexp)
+                  ('colbox "\\\\fcolorbox\\(?:\\[\\([^]]*\\)\\]\\)?")))
+        (regexp-add "{[^}]*}\\(?:\\[\\([^]]*\\)\\]\\)?"))
+    (when (and which (eq what 'colbox))
+      (setq regexp (concat regexp regexp-add)))
+    (save-excursion
+      (re-search-backward regexp (line-beginning-position) t))
+    (setq LaTeX-xcolor-used-type-model
+          (unless (string-empty-p (match-string-no-properties (if which 2 1)))
+            (match-string-no-properties (if which 2 1)))))
+  (if (and LaTeX-xcolor-used-type-model
+           (not (string= LaTeX-xcolor-used-type-model "named")))
+      t
+    nil))
 
 (defun TeX-arg-xcolor (optional)
-  "Insert arguments of various color commands from xcolor.sty."
+  "Insert mandatory argument of various color commands from xcolor.sty.
+If OPTIONAL is non-nil, insert the result only when non-empty and in
+brackets."
   ;; \color{<name>} or \color[<model-list>]{<spec-list>}
-  (let* ((TeX-last-optional-rejected nil)
-         (xcolmodel (LaTeX-check-insert-macro-default-style
-                     (completing-read
-                      (TeX-argument-prompt t nil "Model (list)")
-                      (LaTeX-xcolor-color-models t))))
-         (xcolor (if (and xcolmodel (not (string= xcolmodel "")))
-                     (TeX-read-string
-                      (TeX-argument-prompt optional nil (concat xcolmodel " 
spec (list)")))
-                   (completing-read
-                    (TeX-argument-prompt optional nil "Color")
-                    (LaTeX-xcolor-definecolor-list)))))
-    (when (and xcolmodel (not (string= xcolmodel "")))
-      (insert (format "[%s]" xcolmodel)))
-    (TeX-argument-insert xcolor optional)))
-
-(defun TeX-arg-xcolor-fcolorbox (optional)
-  "Insert arguments of \\fcolorbox from xcolor.sty."
-  ;;\fcolorbox[<frame model>]{<frame spec>}[<background model>]{<background 
spec>}{<text>}
-  (let* ((TeX-last-optional-rejected nil)
-         (xfrmodel (LaTeX-check-insert-macro-default-style
-                    (completing-read
-                     (TeX-argument-prompt t nil "(Frame) Color model")
-                     LaTeX-xcolor-color-models)))
-         ;; Set `TeX-last-optional-rejected' acc. to `xfrmodel'
-         (TeX-last-optional-rejected (or (not xfrmodel)
-                                         (and xfrmodel (string= xfrmodel ""))))
-         (xfrspec  (if (or (null xfrmodel)
-                           (string= xfrmodel "")
-                           (string= xfrmodel "named"))
-                       (completing-read
-                        (TeX-argument-prompt optional nil "Frame color spec")
-                        (LaTeX-xcolor-definecolor-list))
-                     (TeX-read-string
-                      (TeX-argument-prompt optional nil "Frame color spec"))))
-         (xbgmodel (LaTeX-check-insert-macro-default-style
-                    (completing-read
-                     (TeX-argument-prompt t nil "Background Color model")
-                     LaTeX-xcolor-color-models)))
-         (xbgspec  (if (or (null xfrmodel)
-                           (string= xfrmodel "")
-                           (string= xfrmodel "named")
-                           (null xbgmodel)
-                           (string= xbgmodel "")
-                           (string= xbgmodel "named"))
-                       (completing-read
-                        (TeX-argument-prompt optional nil "Background color 
spec")
-                        (LaTeX-xcolor-definecolor-list))
-                     (TeX-read-string
-                      (TeX-argument-prompt optional nil "Background color 
spec")))))
-    (when (and xfrmodel (not (string= xfrmodel "")))
-      (insert (format "[%s]" xfrmodel)))
-    (TeX-argument-insert xfrspec optional)
-    (when (and xbgmodel (not (string= xbgmodel "")))
-      (insert (format "[%s]" xbgmodel)))
-    (TeX-argument-insert xbgspec optional)))
+  (TeX-argument-insert
+   (TeX-read-string
+    (TeX-argument-prompt optional nil (concat LaTeX-xcolor-used-type-model
+                                              " spec (list)")))
+   optional))
+
+(defun TeX-arg-xcolor-definecolor (optional &optional prompt)
+  "Insert first mandatory argument of color defining macros.
+If OPTIONAL is non-nil, insert the result only when non-empty and in
+brackets.  PROMPT replaces the standard one."
+  ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
+  (let ((name-spec (TeX-read-string
+                    (TeX-argument-prompt optional prompt "Color name"))))
+    (unless (string-empty-p name-spec)
+      (LaTeX-add-xcolor-definecolors name-spec))
+    (TeX-argument-insert name-spec optional)))
 
 (TeX-add-style-hook
  "xcolor"
@@ -410,37 +386,84 @@ xcolor package.")
    (TeX-add-symbols
     ;; 2.5.2 Color definition in xcolor
     ;; \definecolor[<type>]{<name>}{<model-list>}{<spec-list>}
-    '("definecolor" TeX-arg-xcolor-definecolor)
+    '("definecolor"
+      [TeX-arg-completing-read LaTeX-xcolor-color-types
+                               "Type"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'defcol)
+          ((TeX-arg-xcolor-definecolor))
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name")))
+      (TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Model (list)" nil nil "/" "/")
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'defcol t)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name"))))
 
     ;; \providecolor[<type>]{<name>}{<model-list>}{<spec-list>}
-    '("providecolor" TeX-arg-xcolor-definecolor)
+    '("providecolor"
+      [TeX-arg-completing-read LaTeX-xcolor-color-types
+                               "Type"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'defcol)
+          ((TeX-arg-xcolor-definecolor))
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name")))
+      (TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Model (list)" nil nil "/" "/")
+      (TeX-arg-conditional (LaTeX-xcolor-used-type-model-requires-spec-p 
'model)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name"))))
 
     ;; \colorlet[<type>]{<name>}[<num model>]{<color>}
-    `("colorlet"
-      [TeX-arg-completing-read LaTeX-xcolor-type-color-models "Type"]
-      ,(lambda (optional)
-         (let ((xcolor (TeX-read-string
-                        (TeX-argument-prompt optional nil "Color"))))
-           (LaTeX-add-xcolor-definecolors xcolor)
-           (TeX-argument-insert xcolor optional)))
-      [TeX-arg-completing-read ,(lambda ()
-                                  (LaTeX-xcolor-color-models t))
+    '("colorlet"
+      [TeX-arg-completing-read LaTeX-xcolor-color-types "Type"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'defcol)
+          ((TeX-arg-xcolor-definecolor))
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name")))
+      [TeX-arg-completing-read (lambda ()
+                                 (LaTeX-xcolor-color-models t))
                                "Model"]
       (TeX-arg-completing-read (LaTeX-xcolor-definecolor-list) "Color"))
 
     ;; 2.5.3 Defining sets of colors
     ;; \definecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
-    '("definecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)
+    '("definecolorset"
+      [TeX-arg-completing-read LaTeX-xcolor-color-types "Type"]
+      (TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Model (list)" nil nil "/" "/")
+      "Head" "Tail" t)
 
     ;; \providecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
-    '("providecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)
+    '("providecolorset"
+      [TeX-arg-completing-read LaTeX-xcolor-color-types "Type"]
+      (TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Model (list)" nil nil "/" "/")
+      "Head" "Tail" t)
 
     ;; 2.5.4 Immediate and deferred definitions
     ;; \preparecolor[<type>]{<name>}{<model-list>}{<spec-list>}
-    '("preparecolor" TeX-arg-xcolor-definecolor)
+    '("preparecolor"
+      [TeX-arg-completing-read LaTeX-xcolor-color-types
+                               "Type"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'defcol)
+          ((TeX-arg-xcolor-definecolor))
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name")))
+      (TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Model (list)" nil nil "/" "/")
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'defcol t)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name"))))
 
     ;; \preparecolorset[<type>]{<model-list>}{<head>}{<tail>}{<set spec>}
-    '("preparecolorset" TeX-arg-xcolor-definecolorset "Head" "Tail" t)
+    '("preparecolorset"
+      [TeX-arg-completing-read LaTeX-xcolor-color-types "Type"]
+      (TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Model (list)" nil nil "/" "/")
+      "Head" "Tail" t)
 
     ;; \definecolors{<id-list>}
     '("definecolors" t)
@@ -452,19 +475,49 @@ xcolor package.")
     ;; 2.6.1 Standard color commands
 
     ;; \color{<name>} or \color[<model>]{<color spec>}
-    '("color" TeX-arg-xcolor)
+    '("color"
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name"))))
 
     ;; \textcolor{<name>}{<text>} or
     ;; \textcolor[<model>]{<color spec>}{<text>}
-    '("textcolor" TeX-arg-xcolor "Text")
+    '("textcolor"
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name")))
+      "Text")
 
     ;; \mathcolor{<name>}{<math>} or
     ;; \mathcolor[<model>]{<color spec>}{<math>}
-    '("mathcolor" TeX-arg-xcolor "Math")
+    '("mathcolor"
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name")))
+      "Math")
 
     ;; \pagecolor{<name>} or
     ;; \pagecolor[<model>]{<color spec>}
-    '("pagecolor" TeX-arg-xcolor)
+    '("pagecolor"
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name"))))
 
     ;; \nopagecolor
     '("nopagecolor" 0)
@@ -472,17 +525,47 @@ xcolor package.")
     ;; 2.6.2 Colored boxes
     ;; \colorbox{<name>}{<text>} or
     ;; \colorbox[<model>]{<color spec>}{<text>}
-    '("colorbox" TeX-arg-xcolor "Text")
+    '("colorbox"
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name")))
+      "Text")
 
     ;; \fcolorbox{<frame color>}{<box color>}{<text>} or
     ;; \fcolorbox[<model>]{<frame spec>}{<background spec>}{<text>} or
     ;; \fcolorbox[<frame model>]{<frame spec>}[<background model>]{<background 
spec>}{<text>}
-    '("fcolorbox" TeX-arg-xcolor-fcolorbox "Text")
+    '("fcolorbox"
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Frame color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'colbox)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Frame color name")))
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Background color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'colbox t)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Background color name")))
+      "Text")
 
     ;; 2.6.4 Color testing
     ;; \testcolor{<name>} or
     ;; \testcolor[<model>]{<color spec>}
-    '("testcolor" TeX-arg-xcolor)
+    '("testcolor"
+      [TeX-arg-completing-read-multiple (LaTeX-xcolor-color-models)
+                                        "Color model"
+                                        nil nil "/" "/"]
+      (TeX-arg-conditional (LaTeX-xcolor-cmd-requires-spec-p 'col)
+          (TeX-arg-xcolor)
+        ((TeX-arg-completing-read (LaTeX-xcolor-definecolor-list)
+                                  "Color name"))))
 
     ;; 2.7 Color blending
     '("blendcolors"
@@ -491,8 +574,8 @@ xcolor package.")
       (TeX-arg-completing-read (LaTeX-xcolor-definecolor-list) "Mix expr"))
 
     ;; 2.8 Color masks and separation
-    `("maskcolors"
-      [TeX-arg-completing-read ,(lambda () (LaTeX-xcolor-color-models t)) 
"Model"]
+    '("maskcolors"
+      [TeX-arg-completing-read (lambda () (LaTeX-xcolor-color-models t)) 
"Model"]
       (TeX-arg-completing-read (LaTeX-xcolor-definecolor-list) "Color"))
 
     ;; 2.9 Color series
@@ -522,10 +605,10 @@ xcolor package.")
 
     ;; 2.14 Color conversion
     ;; \convertcolorspec{<model>}{<spec>}{<target model>}{cmd>}
-    `("convertcolorspec"
+    '("convertcolorspec"
       (TeX-arg-completing-read (LaTeX-xcolor-color-models) "Model")
-      (TeX-arg-string "Spec")
-      (TeX-arg-completing-read ,(lambda () (LaTeX-xcolor-color-models t))
+      "Spec"
+      (TeX-arg-completing-read (lambda () (LaTeX-xcolor-color-models t))
                                "Target model")
       (TeX-arg-define-macro "Macro: \\")) ) ; close TeX-add-symbols
 
@@ -609,7 +692,10 @@ xcolor package.")
     "dvipsnames" "dvipsnames*" "svgnames" "svgnames*" "x11names" "x11names*"
 
     ;; options that determine which other packages to load
-    "table" "fixpdftex" "hyperref"
+    "table"
+
+    ;; obsolete options
+    ;; "fixpdftex" "hyperref"
 
     ;; options that influence the behaviour of other commands
     "prologue" "kernelfbox" "xcdraw" "noxcdraw" "fixinclude"

Reply via email to