auctex-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/auctex 1792a41446 29/30: Move support for xparse macros


From: Tassilo Horn
Subject: [elpa] externals/auctex 1792a41446 29/30: Move support for xparse macros into core
Date: Thu, 7 Dec 2023 03:51:10 -0500 (EST)

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

    Move support for xparse macros into core
    
    * style/xparse.el: Move content from here ...
    
    * latex.el: ... to here.
    (LaTeX-auto-xparse-macro, LaTeX-auto-xparse-environment): New
    variables needed for parsing.
    (LaTeX-auto-regexp-list): Add regexp's for new macros.
    (LaTeX-auto-prepare): Reset newly defined variables.
    (LaTeX-arg-xparse-embellishment): Rename.
    (LaTeX-xparse-macro-parse): Adjust to use the new variables.
    (LaTeX-auto-cleanup): Use `LaTeX-xparse-macro-parse' to cleanup.
    (LaTeX-common-initialization): Add macro entries.
    
    * font-latex.el: ... and to here.
    (font-latex-built-in-keyword-classes): Support fontification.
    
    * doc/changes.texi: Mention the change.
---
 doc/changes.texi |   6 ++
 font-latex.el    |  14 ++-
 latex.el         | 255 ++++++++++++++++++++++++++++++++++++++++++-
 style/xparse.el  | 323 +------------------------------------------------------
 4 files changed, 277 insertions(+), 321 deletions(-)

diff --git a/doc/changes.texi b/doc/changes.texi
index cbb341c62e..3489318aaa 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -16,6 +16,12 @@
 
 @item
 Now @LaTeX{} abbrevs are available in doc@TeX{} mode buffers.
+
+@item
+Macros provided by the @file{xparse} package are part of @LaTeX{} kernel
+since October 2020.  @AUCTeX{} tracks this change and the content of
+@file{xparse.el} is moved into @file{latex.el} and @file{font-latex.el}
+respectively.
 @end itemize
 
 @heading News in 13.2
diff --git a/font-latex.el b/font-latex.el
index ae922b5bcf..7deb9ec6f3 100644
--- a/font-latex.el
+++ b/font-latex.el
@@ -365,7 +365,19 @@ variable `font-latex-fontify-sectioning'." ',num)
       ("labelformat" "{{") ("linespread" "{")
       ("AddToHook" "{[{") ("RemoveFromHook" "{[") ("AddToHookNext" "{{")
       ("ProvidesClass" "{[") ("ProvidesPackage" "{[") ("ProvidesFile" "{[")
-      ("NewMarkClass" "{"))
+      ("NewMarkClass" "{")
+      ("DeclareDocumentCommand" "|{\\{{")
+      ("NewDocumentCommand"     "|{\\{{")
+      ("ProvideDocumentCommand" "|{\\{{")
+      ("RenewDocumentCommand"   "|{\\{{")
+      ("DeclareExpandableDocumentCommand" "|{\\{{")
+      ("NewExpandableDocumentCommand"     "|{\\{{")
+      ("ProvideExpandableDocumentCommand" "|{\\{{")
+      ("RenewExpandableDocumentCommand"   "|{\\{{")
+      ("DeclareDocumentEnvironment" "{{{{")
+      ("NewDocumentEnvironment"     "{{{{")
+      ("ProvideDocumentEnvironment" "{{{{")
+      ("RenewDocumentEnvironment"   "{{{{"))
      font-lock-function-name-face 2 command)
     ("function-noarg"
      ("enspace" "enskip" "quad" "qquad" "nonumber"
diff --git a/latex.el b/latex.el
index a18592d3ce..c7ff151cda 100644
--- a/latex.el
+++ b/latex.el
@@ -1721,6 +1721,12 @@ right number."
 (defvar LaTeX-auto-optional nil)
 (defvar LaTeX-auto-env-args nil)
 (defvar LaTeX-auto-env-args-with-opt nil)
+(defvar LaTeX-auto-xparse-macro nil
+  "Information about user defined macros in the current buffer.
+This variable contains information after parsing the buffer.")
+(defvar LaTeX-auto-xparse-environment nil
+  "Information about user defined enviroments in the current buffer.
+This variable contains information after parsing the buffer.")
 
 (TeX-auto-add-type "label" "LaTeX")
 (TeX-auto-add-type "bibitem" "LaTeX")
@@ -1827,12 +1833,33 @@ This is necessary since index entries may contain 
commands and stuff.")
         (2 3 1) LaTeX-auto-arguments)
        (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token 
"+\\)}?")
         1 TeX-auto-symbol)
+       (,(concat
+          "\\\\\\(New\\|Renew\\|Provide\\|Declare\\)"
+          "\\(?:Expandable\\)?"
+          "DocumentCommand"
+          "[ \t\n\r]*"
+          "{?"
+          "[ \t\n\r]*"
+          "\\\\\\(" token "+\\)"
+          "[ \t\n\r]*"
+          "}?"
+          "[ \t\n\r]*"
+          
"{\\([^}{]*\\(?:{[^}{]*\\(?:{[^}{]*\\(?:{[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}")
+        (0 2 3 1) LaTeX-auto-xparse-macro)
        ("\\\\\\(re\\)?newenvironment\\*?{\\([^}]+\\)}\\[\\([0-9]+\\)\\]\\["
         (2 3 1) LaTeX-auto-env-args-with-opt)
        ("\\\\\\(re\\)?newenvironment\\*?{\\([^}]+\\)}\\[\\([0-9]+\\)\\]"
         (2 3 1) LaTeX-auto-env-args)
        ("\\\\newenvironment\\*?{\\([^}]+\\)}"
         1 LaTeX-auto-environment)
+       (,(concat
+          "\\\\\\(New\\|Renew\\|Provide\\|Declare\\)"
+          "DocumentEnvironment"
+          "[ \t\n\r]*"
+          "{\\([^}]+\\)}"
+          "[ \t\n\r]*"
+          
"{\\([^}{]*\\(?:{[^}{]*\\(?:{[^}{]*\\(?:{[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}")
+        (0 2 3 1) LaTeX-auto-xparse-environment)
        (,(concat "\\\\newtheorem{\\(" token "+\\)}") 1 LaTeX-auto-environment)
        ("\\\\input{\"?\\([^#}%\"\\\n\r]+?\\)\\(?:\\.[^#}%/\"\\.\n\r]+\\)?\"?}"
         1 TeX-auto-file)
@@ -1876,7 +1903,9 @@ Split the string at commas and remove Biber file 
extensions."
         LaTeX-auto-optional nil
         LaTeX-auto-env-args nil
         LaTeX-auto-style nil
-        LaTeX-auto-end-symbol nil))
+        LaTeX-auto-end-symbol nil
+        LaTeX-auto-xparse-macro nil
+        LaTeX-auto-xparse-environment nil))
 
 (add-hook 'TeX-auto-prepare-hook #'LaTeX-auto-prepare)
 
@@ -1962,6 +1991,165 @@ See also `LaTeX-provided-class-options'.")
 The value is actually the tail of the list of options given to PACKAGE."
   (member option (cdr (assoc package LaTeX-provided-package-options))))
 
+(defun LaTeX-arg-xparse-embellishment (_optional embellish)
+  "Special insert function for embellishments.
+Compatibility argument OPTIONAL is ignored.  EMBELLISH is a
+string with parsed elements inserted in the buffer.  This
+function also sets the value of `TeX-exit-mark' where the point
+will be once the insertion is completed."
+  (let (p)
+    (just-one-space)
+    (setq p (point))
+    (insert embellish)
+    (set-marker TeX-exit-mark (1+ p))))
+
+(defun LaTeX-xparse-macro-parse (type)
+  "Process parsed macro and environment definitions.
+TYPE is one of the symbols mac or env."
+  (dolist (xcmd (if (eq type 'mac)
+                    LaTeX-auto-xparse-macro
+                  LaTeX-auto-xparse-environment))
+    (let ((name (string-trim (nth 1 xcmd) "[ \t\r\n%]+" "[ \t\r\n%]+"))
+          (spec (nth 2 xcmd))
+          (what (nth 3 xcmd))
+          (case-fold-search nil)
+          (syntax (TeX-search-syntax-table ?\{ ?\}))
+          args opt-star opt-token)
+      (with-temp-buffer
+        (set-syntax-table LaTeX-mode-syntax-table)
+        (insert (replace-regexp-in-string "[ \t\r\n%]" "" spec))
+        (goto-char (point-min))
+        (while (looking-at-p "[+!>=bmrRvodODsteE]")
+          (cond ((looking-at-p "[+!b]")
+                 ;; + or !: Long argument or space aware: Move over
+                 ;; them.  b is special; only available for
+                 ;; enviroments
+                 (forward-char 1))
+                ;; Argument processors and key-val modifier: Move
+                ;; over [>=] and a balanced {}
+                ((looking-at-p "[>=]")
+                 (forward-char 1)
+                 (with-syntax-table syntax (forward-sexp)))
+                ;; Mandatory arguments:
+                ;; m: Ask for input with "Text" as prompt
+                ((looking-at-p "m")
+                 (forward-char 1)
+                 (push "Text" args))
+                ;; r<token1><token2>
+                ((looking-at-p "r")
+                 (re-search-forward "r\\(.\\)\\(.\\)" (+ (point) 3) t)
+                 (push `(TeX-arg-string nil nil nil nil
+                                        ,(match-string-no-properties 1)
+                                        ,(match-string-no-properties 2))
+                       args))
+                ;; R<token1><token2>{default}
+                ((looking-at-p "R")
+                 (re-search-forward "R\\(.\\)\\(.\\)" (+ (point) 3) t)
+                 (with-syntax-table syntax (forward-sexp))
+                 (push `(TeX-arg-string nil nil nil nil
+                                        ,(match-string-no-properties 1)
+                                        ,(match-string-no-properties 2))
+                       args))
+                ;; v: Use `TeX-arg-verb-delim-or-brace'
+                ((looking-at-p "v")
+                 (forward-char 1)
+                 (push #'TeX-arg-verb-delim-or-brace args))
+                ;; Optional arguments:
+                ;; o standard LaTeX optional in square brackets
+                ((looking-at-p "o")
+                 (forward-char 1)
+                 (push (vector "Text") args))
+                ;; d<token1><token2>
+                ((looking-at-p "d")
+                 (re-search-forward "d\\(.\\)\\(.\\)" (+ (point) 3) t)
+                 (push (vector #'TeX-arg-string nil nil nil nil
+                               (match-string-no-properties 1)
+                               (match-string-no-properties 2))
+                       args))
+                ;; O{default}
+                ((looking-at-p "O")
+                 (forward-char 1)
+                 (with-syntax-table syntax (forward-sexp))
+                 (push (vector "Text") args))
+                ;; D<token1><token2>{default}
+                ((looking-at-p "D")
+                 (re-search-forward "D\\(.\\)\\(.\\)" (+ (point) 3) t)
+                 (with-syntax-table syntax (forward-sexp))
+                 (push (vector #'TeX-arg-string nil nil nil nil
+                               (match-string-no-properties 1)
+                               (match-string-no-properties 2))
+                       args))
+                ;; s: optional star
+                ((looking-at-p "s")
+                 (forward-char 1)
+                 (setq opt-star t))
+                ;; t: optional <token>
+                ((looking-at-p "t")
+                 (re-search-forward "t\\(.\\)" (+ (point) 2) t)
+                 (setq opt-token (match-string-no-properties 1)))
+                ;; e{tokes} a set of optional embellishments
+                ((looking-at-p "e")
+                 (forward-char)
+                 (if (looking-at-p TeX-grop)
+                     (re-search-forward "{\\([^}]+\\)}" nil t)
+                   (re-search-forward "\\(.\\)" (1+ (point)) t))
+                 (push `(LaTeX-arg-xparse-embellishment
+                         ,(match-string-no-properties 1))
+                       args))
+                ;; E{tokes}{defaults}
+                ((looking-at-p "E")
+                 (forward-char)
+                 (if (looking-at-p TeX-grop)
+                     (re-search-forward "{\\([^}]+\\)}" nil t)
+                   (re-search-forward "\\(.\\)" (1+ (point)) t))
+                 (push `(LaTeX-arg-xparse-embellishment
+                         ,(match-string-no-properties 1))
+                       args)
+                 (when (looking-at-p TeX-grop)
+                   (with-syntax-table syntax (forward-sexp))))
+                ;; Finished:
+                (t nil))))
+      (if (eq type 'env)
+          ;; Parsed enviroments: If we are Renew'ing or Delare'ing, we
+          ;; delete the enviroment first from `LaTeX-environment-list'
+          ;; before adding the new one.  We have to sort the value of
+          ;; `LaTeX-environment-list' by running the function of the
+          ;; same name:
+          (progn
+            (when (member what '("Renew" "Declare"))
+              (setq LaTeX-auto-environment
+                    (assq-delete-all (car (assoc name LaTeX-auto-environment))
+                                     LaTeX-auto-environment)))
+            (add-to-list 'LaTeX-auto-environment
+                         (if args
+                             `(,name LaTeX-env-args ,@(reverse args))
+                           (list name))))
+        ;; Parsed macros: If we are Renew'ing or Delare'ing, we delete
+        ;; the macros first from `TeX-symbol-list' before adding the
+        ;; new ones.  We have to sort the value of `TeX-symbol-list'
+        ;; by running the function of the same name:
+        (when (member what '("Renew" "Declare"))
+          (setq TeX-auto-symbol
+                (assq-delete-all (car (assoc name TeX-auto-symbol))
+                                 TeX-auto-symbol))
+          (when opt-star
+            (setq TeX-auto-symbol
+                  (assq-delete-all (car (assoc (concat name "*")
+                                               TeX-auto-symbol))
+                                   TeX-auto-symbol)))
+          (when opt-token
+            (setq TeX-auto-symbol
+                  (assq-delete-all (car (assoc (concat name opt-token)
+                                               TeX-auto-symbol))
+                                   TeX-auto-symbol))))
+        (add-to-list 'TeX-auto-symbol (cons name (reverse args)))
+        (when opt-star
+          (add-to-list 'TeX-auto-symbol (cons (concat name "*")
+                                              (reverse args))))
+        (when opt-token
+          (add-to-list 'TeX-auto-symbol (cons (concat name opt-token)
+                                              (reverse args))))))))
+
 (defun LaTeX-auto-cleanup ()
   "Cleanup after LaTeX parsing."
 
@@ -2057,6 +2245,9 @@ The value is actually the tail of the list of options 
given to PACKAGE."
                              (string-to-number (nth 1 entry)))))
         LaTeX-auto-arguments)
 
+  ;; Cleanup for marcos defined with former xparse commands:
+  (LaTeX-xparse-macro-parse 'mac)
+
   ;; Cleanup default optional arguments
   (mapc (lambda (entry)
           ;; If we're renewcommand-ing and there is already an entry
@@ -2103,6 +2294,9 @@ The value is actually the tail of the list of options 
given to PACKAGE."
                              (1- (string-to-number (nth 1 entry))))))
         LaTeX-auto-env-args-with-opt)
 
+  ;; Cleanup for enviroments defined with former xparse commands:
+  (LaTeX-xparse-macro-parse 'env)
+
   ;; Cleanup use of def to add environments
   ;; NOTE: This uses an O(N^2) algorithm, while an O(N log N)
   ;; algorithm is possible.
@@ -8708,6 +8902,65 @@ function would return non-nil and `(match-string 1)' 
would return
 
      '("linespread" "Factor")
 
+     ;; Macros for document-command parser, aka xparse added to LaTeX
+     ;; kernel with 2020-10-01 release:
+     '("DeclareDocumentCommand"
+       TeX-arg-define-macro "Argument specification" t)
+     '("NewDocumentCommand"
+       TeX-arg-define-macro "Argument specification" t)
+     '("RenewDocumentCommand"
+       TeX-arg-macro "Argument specification" t)
+     '("ProvideDocumentCommand"
+       TeX-arg-define-macro "Argument specification" t)
+
+     ;; Declaring environments
+     '("DeclareDocumentEnvironment" TeX-arg-define-environment
+       "Argument specification" t t)
+     '("NewDocumentEnvironment" TeX-arg-define-environment
+       "Argument specification" t t)
+     '("RenewDocumentEnvironment" TeX-arg-environment
+       "Argument specification" t t)
+     '("ProvideDocumentEnvironment" TeX-arg-define-environment
+       "Argument specification" t t)
+
+     ;; Fully-expandable document commands
+     '("DeclareExpandableDocumentCommand"
+       TeX-arg-define-macro "Argument specification" t)
+     '("NewExpandableDocumentCommand"
+       TeX-arg-define-macro "Argument specification" t)
+     '("RenewExpandableDocumentCommand"
+       TeX-arg-macro "Argument specification" t)
+     '("ProvideExpandableDocumentCommand"
+       TeX-arg-define-macro "Argument specification" t)
+
+     ;; Testing special values
+     '("IfBooleanTF" 3)
+     '("IfBooleanT" 2)
+     '("IfBooleanF" 2)
+     '("IfNoValueTF" 3)
+     '("IfNoValueT" 2)
+     '("IfNoValueF" 2)
+     '("IfValueTF" 3)
+     '("IfValueT" 2)
+     '("IfValueF" 2)
+     '("IfBlankTF" 3)
+     '("IfBlankT" 2)
+     '("IfBlankF" 2)
+     "BooleanTrue"
+     "BooleanFalse"
+     ;; Argument processors
+     "ProcessedArgument"
+     "ReverseBoolean"
+     '("SplitArgument" "Number" "Token")
+     '("SplitList" "Token")
+     "TrimSpaces"
+     '("ProcessList" "List" "Function")
+     ;; Access to the argument specification
+     '("GetDocumentCommandArgSpec" TeX-arg-macro)
+     '("GetDocumentEnvironmmentArgSpec" TeX-arg-environment)
+     '("ShowDocumentCommandArgSpec" TeX-arg-macro)
+     '("ShowDocumentEnvironmentArgSpec" TeX-arg-environment)
+
      ;; LaTeX hook macros:
      '("AddToHook"      TeX-arg-hook [ "Label" ] t)
      '("RemoveFromHook" TeX-arg-hook [ "Label" ])
diff --git a/style/xparse.el b/style/xparse.el
index f3feaa56f0..ed136702df 100644
--- a/style/xparse.el
+++ b/style/xparse.el
@@ -1,6 +1,6 @@
 ;;; xparse.el --- AUCTeX style for `xparse.sty' version 2022-07-05  -*- 
lexical-binding: t; -*-
 
-;; Copyright (C) 2013, 2020--2023 Free Software Foundation, Inc.
+;; Copyright (C) 2013--2023 Free Software Foundation, Inc.
 
 ;; Maintainer: auctex-devel@gnu.org
 ;; Author: Mosè Giordano <mose@gnu.org>
@@ -25,332 +25,17 @@
 
 ;;; Commentary:
 
-;; This file adds basic support for `xparse.sty' version 2022-07-05.
-;; It parses argument specification of macros and environments.
+;; The content of this file is now (December 2023) part of latex.el
+;; and font-latex.el.  This style provides only completion for xparse
+;; package options.
 
 ;; The "yet not more supported" specifiers `l', `u', `g' and `G' are
 ;; ignored completely and may lead to wrong parsing results.
 
 ;;; Code:
 
-(require 'tex)
 (require 'latex)
 
-;; Silence the compiler:
-(declare-function font-latex-add-keywords
-                  "font-latex"
-                  (keywords class))
-
-(TeX-auto-add-type "xparse-macro" "LaTeX")
-
-(defvar LaTeX-xparse-macro-regexp
-  `(,(concat
-      (regexp-quote TeX-esc)
-      "\\(New\\|Renew\\|Provide\\|Declare\\)"
-      "\\(?:Expandable\\)?"
-      "DocumentCommand"
-      "[ \t\n\r]*"
-      "{?"
-      "[ \t\n\r]*"
-      (regexp-quote TeX-esc)
-      "\\([A-Za-z]+\\)"
-      "[ \t\n\r]*"
-      "}?"
-      "[ \t\n\r]*"
-      
"{\\([^}{]*\\(?:{[^}{]*\\(?:{[^}{]*\\(?:{[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}")
-    (0 2 3 1) LaTeX-auto-xparse-macro)
-  "Matches macros by xparse package.")
-
-(TeX-auto-add-type "xparse-environment" "LaTeX")
-
-(defvar LaTeX-xparse-environment-regexp
-  `(,(concat
-      (regexp-quote TeX-esc)
-      "\\(New\\|Renew\\|Provide\\|Declare\\)"
-      "DocumentEnvironment"
-      "[ \t\n\r]*"
-      "{"
-      "[ \t\n\r]*"
-      "\\([A-Za-z]+\\)"
-      "[ \t\n\r]*"
-      "}"
-      "[ \t\n\r]*"
-      
"{\\([^}{]*\\(?:{[^}{]*\\(?:{[^}{]*\\(?:{[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}")
-    (0 2 3 1) LaTeX-auto-xparse-environment)
-  "Matches environments by xparse package.")
-
-(defun LaTeX-arg-xparse-query (optional op-brace cl-brace &optional prompt)
-  "Special query function for parsed elements from xparse package.
-If OPTIONAL is non-nil, indicate it in minibuffer.  OP-BRACE sets
-the opening brace, CL-BRACE sets the closing one.  PROMPT
-replaces the standard one."
-  (let ((TeX-arg-opening-brace op-brace)
-        (TeX-arg-closing-brace cl-brace))
-    (TeX-argument-insert
-     (TeX-read-string (TeX-argument-prompt optional prompt "Text"))
-     optional)))
-
-(defun LaTeX-arg-xparse-embellishment-query (_optional embellish)
-  "Special insert function for embellishments from xparse package.
-Compatibility argument OPTIONAL is ignored.  EMBELLISH is a
-string with parsed elements inserted in the buffer.  This
-function also sets the value of `TeX-exit-mark' where the point
-will be once the insertion is completed."
-  (let (p)
-    (just-one-space)
-    (setq p (point))
-    (insert embellish)
-    (set-marker TeX-exit-mark (1+ p))))
-
-(defun LaTeX-xparse-macro-parse (type)
-  "Process parsed macro and environment definitions.
-TYPE is one of the symbols mac or env."
-  (dolist (xcmd (if (eq type 'mac)
-                    (LaTeX-xparse-macro-list)
-                  (LaTeX-xparse-environment-list)))
-    (let ((name (nth 1 xcmd))
-          (spec (nth 2 xcmd))
-          (what (nth 3 xcmd))
-          (case-fold-search nil)
-          (syntax (TeX-search-syntax-table ?\{ ?\}))
-          args opt-star opt-token)
-      (with-temp-buffer
-        (set-syntax-table LaTeX-mode-syntax-table)
-        ;; This one is probably not really needed?
-        (goto-char (point-min))
-        (insert (replace-regexp-in-string "[ \t\r\n%]" "" spec))
-        (goto-char (point-min))
-        (while (looking-at-p "[+!>=bmrRvodODsteE]")
-          (cond ((looking-at-p "[+!b]")
-                 ;; + or !: Long argument or space aware: Move over
-                 ;; them.  b is special; only available for
-                 ;; enviroments
-                 (forward-char 1))
-                ;; Argument processors and key-val modifier: Move
-                ;; over [>=] and a balanced {}
-                ((looking-at-p "[>=]")
-                 (forward-char 1)
-                 (with-syntax-table syntax (forward-sexp)))
-                ;; Mandatory arguments:
-                ;; m: Ask for input with "Text" as prompt
-                ((looking-at-p "m")
-                 (forward-char 1)
-                 (push "Text" args))
-                ;; r<token1><token2>
-                ((looking-at-p "r")
-                 (re-search-forward "r\\(.\\)\\(.\\)" (+ (point) 3) t)
-                 (push `(LaTeX-arg-xparse-query
-                         ,(match-string-no-properties 1)
-                         ,(match-string-no-properties 2))
-                       args))
-                ;; R<token1><token2>{default}
-                ((looking-at-p "R")
-                 (re-search-forward "R\\(.\\)\\(.\\)" (+ (point) 3) t)
-                 (with-syntax-table syntax (forward-sexp))
-                 (push `(LaTeX-arg-xparse-query
-                         ,(match-string-no-properties 1)
-                         ,(match-string-no-properties 2))
-                       args))
-                ;; v: Use `TeX-arg-verb-delim-or-brace'
-                ((looking-at-p "v")
-                 (forward-char 1)
-                 (push #'TeX-arg-verb-delim-or-brace args))
-                ;; Optional arguments:
-                ;; o standard LaTeX optional in square brackets
-                ((looking-at-p "o")
-                 (forward-char 1)
-                 (push (vector "Text") args))
-                ;; d<token1><token2>
-                ((looking-at-p "d")
-                 (re-search-forward "d\\(.\\)\\(.\\)" (+ (point) 3) t)
-                 (push (vector #'LaTeX-arg-xparse-query
-                               (match-string-no-properties 1)
-                               (match-string-no-properties 2))
-                       args))
-                ;; O{default}
-                ((looking-at-p "O")
-                 (forward-char 1)
-                 (with-syntax-table syntax (forward-sexp))
-                 (push (vector "Text") args))
-                ;; D<token1><token2>{default}
-                ((looking-at-p "D")
-                 (re-search-forward "D\\(.\\)\\(.\\)" (+ (point) 3) t)
-                 (with-syntax-table syntax (forward-sexp))
-                 (push (vector #'LaTeX-arg-xparse-query
-                               (match-string-no-properties 1)
-                               (match-string-no-properties 2))
-                       args))
-                ;; s: optional star
-                ((looking-at-p "s")
-                 (forward-char 1)
-                 (setq opt-star t))
-                ;; t: optional <token>
-                ((looking-at-p "t")
-                 (re-search-forward "t\\(.\\)" (+ (point) 2) t)
-                 (setq opt-token (match-string-no-properties 1)))
-                ;; e{tokes} a set of optional embellishments
-                ((looking-at-p "e")
-                 (forward-char)
-                 (if (looking-at-p TeX-grop)
-                     (re-search-forward "{\\([^}]+\\)}" nil t)
-                   (re-search-forward "\\(.\\)" (1+ (point)) t))
-                 (push `(LaTeX-arg-xparse-embellishment-query
-                         ,(match-string-no-properties 1))
-                       args))
-                ;; E{tokes}{defaults}
-                ((looking-at-p "E")
-                 (forward-char)
-                 (if (looking-at-p TeX-grop)
-                     (re-search-forward "{\\([^}]+\\)}" nil t)
-                   (re-search-forward "\\(.\\)" (1+ (point)) t))
-                 (push `(LaTeX-arg-xparse-embellishment-query
-                         ,(match-string-no-properties 1))
-                       args)
-                 (when (looking-at-p TeX-grop)
-                   (with-syntax-table syntax (forward-sexp))))
-                ;; Finished:
-                (t nil))))
-      (if (eq type 'env)
-          ;; Parsed enviroments: If we are Renew'ing or Delare'ing, we
-          ;; delete the enviroment first from `LaTeX-environment-list'
-          ;; before adding the new one.  We have to sort the value of
-          ;; `LaTeX-environment-list' by running the function of the
-          ;; same name:
-          (progn
-            (when (member what '("Renew" "Declare"))
-              (LaTeX-environment-list)
-              (setq LaTeX-environment-list
-                    (assq-delete-all (car (assoc name LaTeX-environment-list))
-                                     LaTeX-environment-list)))
-            (LaTeX-add-environments `(,name
-                                      LaTeX-env-args
-                                      ,@(reverse args))))
-        ;; Parsed macros: If we are Renew'ing or Delare'ing, we delete
-        ;; the macros first from `TeX-symbol-list' before adding the
-        ;; new ones.  We have to sort the value of `TeX-symbol-list'
-        ;; by running the function of the same name:
-        (when (member what '("Renew" "Declare"))
-          (TeX-symbol-list)
-          (setq TeX-symbol-list
-                (assq-delete-all (car (assoc name TeX-symbol-list))
-                                 TeX-symbol-list))
-          (when opt-star
-            (setq TeX-symbol-list
-                  (assq-delete-all (car (assoc (concat name "*") 
TeX-symbol-list))
-                                   TeX-symbol-list)))
-          (when opt-token
-            (setq TeX-symbol-list
-                  (assq-delete-all (car (assoc (concat name opt-token) 
TeX-symbol-list))
-                                   TeX-symbol-list))))
-        (TeX-add-symbols (cons name
-                               (reverse args)))
-        (when opt-star
-          (TeX-add-symbols (cons (concat name "*")
-                                 (reverse args))))
-        (when opt-token
-          (TeX-add-symbols (cons (concat name opt-token)
-                                 (reverse args))))))))
-
-(defun LaTeX-xparse-auto-prepare ()
-  "Clear various `LaTeX-auto-xparse-*' variables before parsing."
-  (setq LaTeX-auto-xparse-macro nil
-        LaTeX-auto-xparse-environment nil))
-
-(defun LaTeX-xparse-auto-cleanup ()
-  "Process parsed elements for xparse package."
-  (LaTeX-xparse-macro-parse 'mac)
-  (LaTeX-xparse-macro-parse 'env))
-
-(add-hook 'TeX-auto-prepare-hook #'LaTeX-xparse-auto-prepare t)
-(add-hook 'TeX-auto-cleanup-hook #'LaTeX-xparse-auto-cleanup t)
-(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
-
-(TeX-add-style-hook
- "xparse"
- (lambda ()
-   (TeX-auto-add-regexp LaTeX-xparse-macro-regexp)
-   (TeX-auto-add-regexp LaTeX-xparse-environment-regexp)
-   (TeX-run-style-hooks
-    "expl3")
-   (TeX-add-symbols
-    ;; Declaring commands
-    '("DeclareDocumentCommand"
-      TeX-arg-define-macro "Argument specification" t)
-    '("NewDocumentCommand"
-      TeX-arg-define-macro "Argument specification" t)
-    '("RenewDocumentCommand"
-      TeX-arg-macro "Argument specification" t)
-    '("ProvideDocumentCommand"
-      TeX-arg-define-macro "Argument specification" t)
-
-    ;; Declaring commands and environments
-    '("DeclareDocumentEnvironment" TeX-arg-define-environment
-      "Argument specification" t t)
-    '("NewDocumentEnvironment" TeX-arg-define-environment
-      "Argument specification" t t)
-    '("RenewDocumentEnvironment" TeX-arg-environment
-      "Argument specification" t t)
-    '("ProvideDocumentEnvironment" TeX-arg-define-environment
-      "Argument specification" t t)
-
-    ;; Fully-expandable document commands
-    '("DeclareExpandableDocumentCommand"
-      TeX-arg-define-macro "Argument specification" t)
-    '("NewExpandableDocumentCommand"
-      TeX-arg-define-macro "Argument specification" t)
-    '("RenewExpandableDocumentCommand"
-      TeX-arg-macro "Argument specification" t)
-    '("ProvideExpandableDocumentCommand"
-      TeX-arg-define-macro "Argument specification" t)
-
-    ;; Testing special values
-    '("IfBooleanTF" 3)
-    '("IfBooleanT" 2)
-    '("IfBooleanF" 2)
-    '("IfNoValueTF" 3)
-    '("IfNoValueT" 2)
-    '("IfNoValueF" 2)
-    '("IfValueTF" 3)
-    '("IfValueT" 2)
-    '("IfValueF" 2)
-    '("IfBlankTF" 3)
-    '("IfBlankT" 2)
-    '("IfBlankF" 2)
-    "BooleanTrue"
-    "BooleanFalse"
-    ;; Argument processors
-    "ProcessedArgument"
-    "ReverseBoolean"
-    '("SplitArgument" "Number" "Token")
-    '("SplitList" "Token")
-    "TrimSpaces"
-    '("ProcessList" "List" "Function")
-    ;; Access to the argument specification
-    '("GetDocumentCommandArgSpec" TeX-arg-macro)
-    '("GetDocumentEnvironmmentArgSpec" TeX-arg-environment)
-    '("ShowDocumentCommandArgSpec" TeX-arg-macro)
-    '("ShowDocumentEnvironmentArgSpec" TeX-arg-environment))
-
-   ;; Fontification
-   (when (and (featurep 'font-latex)
-              (eq TeX-install-font-lock 'font-latex-setup))
-     (font-latex-add-keywords '(("DeclareDocumentCommand" "|{\\{{")
-                                ("NewDocumentCommand"     "|{\\{{")
-                                ("ProvideDocumentCommand" "|{\\{{")
-                                ("RenewDocumentCommand"   "|{\\{{")
-                                ;;
-                                ("DeclareExpandableDocumentCommand" "|{\\{{")
-                                ("NewExpandableDocumentCommand"     "|{\\{{")
-                                ("ProvideExpandableDocumentCommand" "|{\\{{")
-                                ("RenewExpandableDocumentCommand"   "|{\\{{")
-                                ;;
-                                ("DeclareDocumentEnvironment" "{{{{")
-                                ("NewDocumentEnvironment"     "{{{{")
-                                ("ProvideDocumentEnvironment" "{{{{")
-                                ("RenewDocumentEnvironment"   "{{{{"))
-                              'function)))
- TeX-dialect)
-
 (defvar LaTeX-xparse-package-options-list
   '(("log-declarations" ("true" "false")))
   "Package options for the xparse package.")




reply via email to

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