[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex 380bc4a 06/71: Handle optional embellishment arg
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex 380bc4a 06/71: Handle optional embellishment arguments correctly |
Date: |
Fri, 17 Dec 2021 15:00:25 -0500 (EST) |
branch: externals/auctex
commit 380bc4a2ef1eceb3e8536bc3e0c7ddcc978e63e9
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>
Handle optional embellishment arguments correctly
* style/xparse.el (LaTeX-xparse-macro-regexp)
(LaTeX-xparse-environment-regexp): Include the entire match text
to avoid ambiguity.
(LaTeX-arg-xparse-embellishment-query): New function.
(LaTeX-xparse-macro-parse): Handle embellishments (e/E argument
type) correctly.
---
style/xparse.el | 94 ++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 66 insertions(+), 28 deletions(-)
diff --git a/style/xparse.el b/style/xparse.el
index 2a9dff4..314938e 100644
--- a/style/xparse.el
+++ b/style/xparse.el
@@ -1,6 +1,6 @@
;;; xparse.el --- AUCTeX style for `xparse.sty' version 2020-03-06 -*-
lexical-binding: t; -*-
-;; Copyright (C) 2013, 2020 Free Software Foundation, Inc.
+;; Copyright (C) 2013, 2020, 2021 Free Software Foundation, Inc.
;; Maintainer: auctex-devel@gnu.org
;; Author: Mosè Giordano <mose@gnu.org>
@@ -28,10 +28,8 @@
;; This file adds basic support for `xparse.sty' version 2020-03-06.
;; It parses argument specification of macros and environments.
-;; Currently, this style doesn't parse the embellishments specifiers
-;; `e' and `E'. The "yet not more supported" specifiers `l', `u', `g'
-;; and `G' are ignored completely and may lead to wrong parsing
-;; results.
+;; The "yet not more supported" specifiers `l', `u', `g' and `G' are
+;; ignored completely and may lead to wrong parsing results.
;;; Code:
@@ -48,7 +46,7 @@
(defvar LaTeX-xparse-macro-regexp
`(,(concat
(regexp-quote TeX-esc)
- "\\(?:New\\|Renew\\|Provide\\|Declare\\)"
+ "\\(New\\|Renew\\|Provide\\|Declare\\)"
"\\(?:Expandable\\)?"
"DocumentCommand"
"[ \t\n\r]*"
@@ -60,7 +58,7 @@
"}?"
"[ \t\n\r]*"
"{\\([^}{]*\\({[^}{]*\\({[^}{]*\\({[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}")
- (1 2) LaTeX-auto-xparse-macro)
+ (0 2 3 1) LaTeX-auto-xparse-macro)
"Matches macros by xparse package.")
(TeX-auto-add-type "xparse-environment" "LaTeX")
@@ -68,7 +66,7 @@
(defvar LaTeX-xparse-environment-regexp
`(,(concat
(regexp-quote TeX-esc)
- "\\(?:New\\|Renew\\|Provide\\|Declare\\)"
+ "\\(New\\|Renew\\|Provide\\|Declare\\)"
"DocumentEnvironment"
"[ \t\n\r]*"
"{"
@@ -78,7 +76,7 @@
"}"
"[ \t\n\r]*"
"{\\([^}{]*\\({[^}{]*\\({[^}{]*\\({[^}{]*}[^}{]*\\)*}[^}{]*\\)*}[^}{]*\\)*\\)}")
- (1 2) LaTeX-auto-xparse-environment)
+ (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)
@@ -92,14 +90,27 @@ replaces the standard one."
(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 symobols mac or env."
+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 (car xcmd))
- (spec (cadr xcmd))
+ (let ((name (nth 1 xcmd))
+ (spec (nth 2 xcmd))
+ (what (nth 3 xcmd))
args opt-star opt-token)
(with-temp-buffer
(set-syntax-table LaTeX-mode-syntax-table)
@@ -175,29 +186,56 @@ TYPE is one of the symobols mac or env."
((looking-at-p "t")
(re-search-forward "t\\(.\\)" (+ (point) 2) t)
(setq opt-token (match-string-no-properties 1)))
- ;; e & E are currently ignored. e: If looking at a
- ;; {, move one balanced expression, otherwise only
- ;; one character.
+ ;; e{tokes} a set of optional embellishments
((looking-at-p "e")
(forward-char)
(if (looking-at-p TeX-grop)
- (forward-sexp)
- (forward-char)))
- ;; E
+ (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)
- (forward-sexp)
- (forward-char))
- (if (looking-at-p TeX-grop)
- (forward-sexp)
- (forward-char)))
+ (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)
+ (forward-sexp)))
;; Finished:
(t nil))))
(if (eq type 'env)
- (LaTeX-add-environments `(,name
- LaTeX-env-args
- ,@(reverse (copy-sequence args))))
+ ;; 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
+ (assoc-delete-all name LaTeX-environment-list)))
+ (LaTeX-add-environments `(,name
+ LaTeX-env-args
+ ,@(reverse (copy-sequence 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
+ (assoc-delete-all name TeX-symbol-list))
+ (when opt-star
+ (setq TeX-symbol-list
+ (assoc-delete-all (concat name "*" TeX-symbol-list))))
+ (when opt-token
+ (setq TeX-symbol-list
+ (assoc-delete-all (concat name opt-token TeX-symbol-list)))))
(TeX-add-symbols (cons name
(reverse (copy-sequence args))))
(when opt-star
@@ -275,9 +313,9 @@ TYPE is one of the symobols mac or env."
"ProcessedArgument"
"ReverseBoolean"
'("SplitArgument" "Number" "Token")
- "SplitList"
+ '("SplitList" "Token")
"TrimSpaces"
- '("ProcessList" "List" "Functiom")
+ '("ProcessList" "List" "Function")
;; Access to the argument specification
'("GetDocumentCommandArgSpec" TeX-arg-macro)
'("GetDocumentEnvironmmentArgSpec" TeX-arg-environment)
- [elpa] externals/auctex 7fa094f 14/71: ; * style/tabulary.el ("tabulary"): Really append the entry., (continued)
- [elpa] externals/auctex 7fa094f 14/71: ; * style/tabulary.el ("tabulary"): Really append the entry., Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 464fd34 20/71: * tests/latex/latex-test.el (LaTeX-flush-left-indent): New test., Tassilo Horn, 2021/12/17
- [elpa] externals/auctex ae2d7ef 23/71: Silence compiler warning, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex f6dd4a4 25/71: ; Silence the compiler, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex df0d719 52/71: Improve handling of key=vals in style/hologo.el, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 08f5c9e 51/71: Improve handling of key=vals in style/floatrow.el, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 9fa3859 38/71: ; Remove duplicates, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 7b632c6 43/71: * doc/todo.texi (Mid-term Goals): Add TODO about tool bar., Tassilo Horn, 2021/12/17
- [elpa] externals/auctex b379da7 18/71: Don't indent begin/end of comment env, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 483f6e9 05/71: ; * style/hyperref.el ("hyperref"): Fix other link to testform.tex., Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 380bc4a 06/71: Handle optional embellishment arguments correctly,
Tassilo Horn <=
- [elpa] externals/auctex bd723c7 24/71: Cater for corner case when dealing with TeX error, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 6433dc3 30/71: Extend `TeX-read-key-val' to accept a function call, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex df69443 26/71: ; Silence the compiler, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 8e0fb65 47/71: Improve handling of key=vals in style/listings.el, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 0419539 37/71: Improve style/babel.el, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex d62d8f3 34/71: Update style/fontspec.el to package version 2.7i, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex b9545c8 45/71: Improve handling of key=vals in style/fancyvrb.el, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 9e97edc 49/71: Fix wrong logic of the previous commit, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 8c50665 62/71: Add new style/unicodefonttable.el, Tassilo Horn, 2021/12/17
- [elpa] externals/auctex 8e13306 66/71: Update style/url.el to package version 3.4, Tassilo Horn, 2021/12/17