Hi all,

please find attached 4 patches improving some styles I touched recently.
My apologies for not getting it right last time.

* style/enumitem.el (LaTeX-enumitem-newlist-list)
(LaTeX-enumitem-newlist-list-item-arg)
(LaTeX-auto-enumitem-newlist): Remove variables.
(LaTeX-enumitem-newlist-list-local): Fix docstring.
(LaTeX-enumitem-auto-cleanup): Plug \newlist into AUCTeX parser.
("enumitem"): Offer only enumerated environments as completion for
\restartlist.

* style/theorem.el (LaTeX-theorem-fontdecl): Do not prefix the
elements with `TeX-esc'.
(LaTeX-arg-theorem-fontdecl): New function.
("theorem"): Use `LaTeX-arg-theorem-fontdecl' for font related
queries.

* style/ntheorem.el (LaTeX-ntheorem-fontdecl): Do not prefix the
elements with `TeX-esc'.
(LaTeX-arg-ntheorem-fontdecl): New function.
("ntheorem"): Use `LaTeX-arg-ntheorem-fontdecl' for font related
queries.

* style/amsthm.el (LaTeX-amsthm-fontdecl): Do not prefix the
elements with `TeX-esc'.
(LaTeX-arg-amsthm-fontdecl): New function.
("amsthm"): Use `LaTeX-arg-amsthm-fontdecl' for font related
queries.

Best, Arash

>From e313d690b13d83a3b9e0d2290758af6e3f061a3c Mon Sep 17 00:00:00 2001
From: Arash Esbati <esb...@gmx.de>
Date: Sat, 23 Jan 2016 17:05:12 +0100
Subject: [PATCH 1/4] Improve font related queries

* style/amsthm.el (LaTeX-amsthm-fontdecl): Do not prefix the
elements with `TeX-esc'.
(LaTeX-arg-amsthm-fontdecl): New function.
("amsthm"): Use `LaTeX-arg-amsthm-fontdecl' for font related
queries.
---
 style/amsthm.el | 50 ++++++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/style/amsthm.el b/style/amsthm.el
index a01cfe3..5c83724 100644
--- a/style/amsthm.el
+++ b/style/amsthm.el
@@ -40,21 +40,34 @@
 defined with \"\\newtheoremstyle\".")
 
 (defvar LaTeX-amsthm-fontdecl
-  (mapcar (lambda (elt) (concat TeX-esc elt))
-	  '(;; family
-	    "rmfamily" "sffamily" "ttfamily"
-	    ;; series
-	    "mdseries" "bfseries"
-	    ;; shape
-	    "upshape" "itshape" "slshape" "scshape"
-	    ;; size
-	    "tiny"  "scriptsize" "footnotesize"
-	    "small" "normalsize" "large"
-	    "Large" "LARGE" "huge" "Huge"
-	    ;; reset macro
-	    "normalfont"))
+  '(;; family
+    "rmfamily" "sffamily" "ttfamily"
+    ;; series
+    "mdseries" "bfseries"
+    ;; shape
+    "upshape" "itshape" "slshape" "scshape"
+    ;; size
+    "tiny"  "scriptsize" "footnotesize"
+    "small" "normalsize" "large"
+    "Large" "LARGE" "huge" "Huge"
+    ;; reset macro
+    "normalfont")
   "List of font declaration commands for \"\\newtheoremstyle\".")
 
+(defun LaTeX-arg-amsthm-fontdecl (optional &optional prompt)
+  "Prompt for font declaration commands in \"\\newtheoremstyle\".
+If OPTIONAL is non-nil, insert the resulting value as an optional
+argument.  Use PROMPT as the prompt string."
+  ;; `INITIAL-INPUT' (5th argument to `TeX-completing-read-multiple')
+  ;; is hard-coded to `TeX-esc'.
+  (let* ((crm-separator (regexp-quote TeX-esc))
+	 (fontdecl (mapconcat 'identity
+			      (TeX-completing-read-multiple
+			       (TeX-argument-prompt optional prompt "Font")
+			       LaTeX-amsthm-fontdecl nil nil TeX-esc)
+			      TeX-esc)))
+    (TeX-argument-insert fontdecl optional)))
+
 (defun LaTeX-amsthm-env-label (environment)
   "Insert ENVIRONMENT, query for an optional argument and prompt
 for label.  AUCTeX users should add ENVIRONMENT to
@@ -161,16 +174,9 @@ make them available as new environments.  Update
 	   (format "%s" nthmstyle))))
       (TeX-arg-length "Space above")
       (TeX-arg-length "Space below")
-      (TeX-arg-eval mapconcat 'identity
-		    (TeX-completing-read-multiple
-		     "Body font: "
-		     LaTeX-amsthm-fontdecl) "")
+      (LaTeX-arg-amsthm-fontdecl "Body font")
       "Indent amount"
-      (TeX-arg-eval mapconcat 'identity
-		    (TeX-completing-read-multiple
-		     "Theorem head font: "
-		     LaTeX-amsthm-fontdecl) "")
-
+      (LaTeX-arg-amsthm-fontdecl "Theorem head font")
       "Punctuation after head"
       (TeX-arg-length "Space after head")
       "Theorem head spec"))
-- 
2.7.0

>From 74a74a7e7bb03e23178759cb849daf1e64d13259 Mon Sep 17 00:00:00 2001
From: Arash Esbati <esb...@gmx.de>
Date: Sat, 23 Jan 2016 17:07:52 +0100
Subject: [PATCH 2/4] Improve font related queries

* style/ntheorem.el (LaTeX-ntheorem-fontdecl): Do not prefix the
elements with `TeX-esc'.
(LaTeX-arg-ntheorem-fontdecl): New function.
("ntheorem"): Use `LaTeX-arg-ntheorem-fontdecl' for font related
queries.
---
 style/ntheorem.el | 49 ++++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/style/ntheorem.el b/style/ntheorem.el
index cedc5a8..630c09b 100644
--- a/style/ntheorem.el
+++ b/style/ntheorem.el
@@ -49,21 +49,34 @@ defined with \"\\newtheoremstyle\".")
 defined with \"\\newtheoremlisttype\".")
 
 (defvar LaTeX-ntheorem-fontdecl
-  (mapcar (lambda (elt) (concat TeX-esc elt))
-	  '(;; family
-	    "rmfamily" "sffamily" "ttfamily"
-	    ;; series
-	    "mdseries" "bfseries"
-	    ;; shape
-	    "upshape" "itshape" "slshape" "scshape"
-	    ;; size
-	    "tiny"  "scriptsize" "footnotesize"
-	    "small" "normalsize" "large"
-	    "Large" "LARGE" "huge" "Huge"
-	    ;; reset macro
-	    "normalfont"))
+  '(;; family
+    "rmfamily" "sffamily" "ttfamily"
+    ;; series
+    "mdseries" "bfseries"
+    ;; shape
+    "upshape" "itshape" "slshape" "scshape"
+    ;; size
+    "tiny"  "scriptsize" "footnotesize"
+    "small" "normalsize" "large"
+    "Large" "LARGE" "huge" "Huge"
+    ;; reset macro
+    "normalfont")
   "List of font declaration commands for \"\\newtheoremstyle\".")
 
+(defun LaTeX-arg-ntheorem-fontdecl (optional &optional prompt)
+  "Prompt for font declaration commands in \"\\theorem(body\|header)font\".
+If OPTIONAL is non-nil, insert the resulting value as an optional
+argument.  Use PROMPT as the prompt string."
+  ;; `INITIAL-INPUT' (5th argument to `TeX-completing-read-multiple')
+  ;; is hard-coded to `TeX-esc'.
+  (let* ((crm-separator (regexp-quote TeX-esc))
+	 (fontdecl (mapconcat 'identity
+			      (TeX-completing-read-multiple
+			       (TeX-argument-prompt optional prompt "Font declaration")
+			       LaTeX-ntheorem-fontdecl nil nil TeX-esc)
+			      TeX-esc)))
+    (TeX-argument-insert fontdecl optional)))
+
 (defun LaTeX-ntheorem-env-label (environment)
   "Insert ENVIRONMENT, query for an optional argument and prompt
 for label.  AUCTeX users should add ENVIRONMENT to
@@ -190,16 +203,10 @@ make them available as new environments.  Update
 		    LaTeX-ntheorem-theoremstyle-list))
 
     '("theorembodyfont"
-      (TeX-arg-eval mapconcat 'identity
-		    (TeX-completing-read-multiple
-		     "Body font: "
-		     LaTeX-ntheorem-fontdecl) ""))
+      (LaTeX-arg-ntheorem-fontdecl "Body font"))
 
     '("theoremheaderfont"
-      (TeX-arg-eval mapconcat 'identity
-		    (TeX-completing-read-multiple
-		     "Header font: "
-		     LaTeX-ntheorem-fontdecl) ""))
+      (LaTeX-arg-ntheorem-fontdecl "Header font"))
 
     '("theoremnumbering"
       (TeX-arg-eval completing-read
-- 
2.7.0

>From e061f5a0a5777a61706c3c346c6b21da0dc0f635 Mon Sep 17 00:00:00 2001
From: Arash Esbati <esb...@gmx.de>
Date: Sat, 23 Jan 2016 17:09:58 +0100
Subject: [PATCH 3/4] Improve font related queries

* style/theorem.el (LaTeX-theorem-fontdecl): Do not prefix the
elements with `TeX-esc'.
(LaTeX-arg-theorem-fontdecl): New function.
("theorem"): Use `LaTeX-arg-theorem-fontdecl' for font related
queries.
---
 style/theorem.el | 49 ++++++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/style/theorem.el b/style/theorem.el
index 7d8bffd..d8466f1 100644
--- a/style/theorem.el
+++ b/style/theorem.el
@@ -42,21 +42,34 @@
   "List of theorem styles provided by `theorem.sty'.")
 
 (defvar LaTeX-theorem-fontdecl
-  (mapcar (lambda (elt) (concat TeX-esc elt))
-	  '(;; family
-	    "rmfamily" "sffamily" "ttfamily"
-	    ;; series
-	    "mdseries" "bfseries"
-	    ;; shape
-	    "upshape" "itshape" "slshape" "scshape"
-	    ;; size
-	    "tiny"  "scriptsize" "footnotesize"
-	    "small" "normalsize" "large"
-	    "Large" "LARGE" "huge" "Huge"
-	    ;; reset macro
-	    "normalfont"))
+  '(;; family
+    "rmfamily" "sffamily" "ttfamily"
+    ;; series
+    "mdseries" "bfseries"
+    ;; shape
+    "upshape" "itshape" "slshape" "scshape"
+    ;; size
+    "tiny"  "scriptsize" "footnotesize"
+    "small" "normalsize" "large"
+    "Large" "LARGE" "huge" "Huge"
+    ;; reset macro
+    "normalfont")
   "List of font declaration commands for \"\\theorem(body\|header)font\".")
 
+(defun LaTeX-arg-theorem-fontdecl (optional &optional prompt)
+  "Prompt for font declaration commands in \"\\theorem(body\|header)font\".
+If OPTIONAL is non-nil, insert the resulting value as an optional
+argument.  Use PROMPT as the prompt string."
+  ;; `INITIAL-INPUT' (5th argument to `TeX-completing-read-multiple')
+  ;; is hard-coded to `TeX-esc'.
+  (let* ((crm-separator (regexp-quote TeX-esc))
+	 (fontdecl (mapconcat 'identity
+			      (TeX-completing-read-multiple
+			       (TeX-argument-prompt optional prompt "Font")
+			       LaTeX-theorem-fontdecl nil nil TeX-esc)
+			      TeX-esc)))
+    (TeX-argument-insert fontdecl optional)))
+
 (defun LaTeX-theorem-env-label (environment)
   "Insert ENVIRONMENT, query for an optional argument and prompt
 for label.  AUCTeX users should add ENVIRONMENT to
@@ -133,16 +146,10 @@ make them available as new environments."
 		    LaTeX-theorem-theoremstyle-list))
 
     '("theorembodyfont"
-      (TeX-arg-eval mapconcat 'identity
-		    (TeX-completing-read-multiple
-		     "Body font: "
-		     LaTeX-theorem-fontdecl) ""))
+      (LaTeX-arg-theorem-fontdecl "Body font"))
 
     '("theoremheaderfont"
-      (TeX-arg-eval mapconcat 'identity
-		    (TeX-completing-read-multiple
-		     "Header font: "
-		     LaTeX-theorem-fontdecl) ""))
+      (LaTeX-arg-theorem-fontdecl "Header font"))
 
     '("theorempreskipamount"
       (TeX-arg-length "Skip before theorem"))
-- 
2.7.0

>From bdf5ba19c9ccbd4ef33a2b0c20cb4a7744ab0ad4 Mon Sep 17 00:00:00 2001
From: Arash Esbati <esb...@gmx.de>
Date: Sat, 23 Jan 2016 17:20:49 +0100
Subject: [PATCH 4/4] Improve style/enumitem

* style/enumitem.el (LaTeX-enumitem-newlist-list)
(LaTeX-enumitem-newlist-list-item-arg)
(LaTeX-auto-enumitem-newlist): Remove variables.
(LaTeX-enumitem-newlist-list-local): Fix docstring.
(LaTeX-enumitem-auto-cleanup): Plug \newlist into AUCTeX parser.
("enumitem"): Offer only enumerated environments as completion for
\restartlist.
---
 style/enumitem.el | 69 +++++++++++++++++++++++--------------------------------
 1 file changed, 29 insertions(+), 40 deletions(-)

diff --git a/style/enumitem.el b/style/enumitem.el
index a527c86..bbbfe79 100644
--- a/style/enumitem.el
+++ b/style/enumitem.el
@@ -100,25 +100,14 @@
   "Buffer-local key=value options for enumitem macros and environments.")
 (make-variable-buffer-local 'LaTeX-enumitem-key-val-options-local)
 
-;; Variables needed for \newlist: This command is not hooked into
-;; the parser via `TeX-auto-add-type', we mimic that behaviour.
-
-(defvar LaTeX-enumitem-newlist-list nil
-  "List of environments defined by command `\\newlist' from
-`enumitem' package.")
-
 (defvar LaTeX-enumitem-newlist-list-local nil
-  "Local list of all environments definded with `\\newlist'
-plus available through `enumitem' package.")
+  "Local list of all environments definded with `\\newlist' plus
+the ones initially available through `enumitem' package.")
 (make-variable-buffer-local 'LaTeX-enumitem-newlist-list-local)
 
-(defvar LaTeX-enumitem-newlist-list-item-arg nil
-  "List of description like environments defined by command
-`\\newlist' from `enumitem' package.")
+;; Setup for \newlist:
 
-(defvar LaTeX-auto-enumitem-newlist nil
-  "Temporary for parsing the arguments of `\\newlist' from
-`enumitem' package.")
+(TeX-auto-add-type "enumitem-newlist" "LaTeX")
 
 (defvar LaTeX-enumitem-newlist-regexp
   '("\\\\newlist{\\([^}]+\\)}{\\([^}]+\\)}"
@@ -126,7 +115,6 @@ plus available through `enumitem' package.")
   "Matches the arguments of `\\newlist' from `enumitem'
 package.")
 
-
 ;; Setup for \SetEnumitemKey:
 
 (TeX-auto-add-type "enumitem-SetEnumitemKey" "LaTeX")
@@ -137,7 +125,6 @@ package.")
   "Matches the arguments of `\\SetEnumitemKey' from `enumitem'
 package.")
 
-
 ;; Setup for \SetEnumitemValue:
 
 (TeX-auto-add-type "enumitem-SetEnumitemValue" "LaTeX")
@@ -158,9 +145,7 @@ package.")
 ;; Plug them into the machinery.
 (defun LaTeX-enumitem-auto-prepare ()
   "Clear various `LaTeX-enumitem-*' before parsing."
-  (setq	LaTeX-auto-enumitem-newlist          nil
-	LaTeX-enumitem-newlist-list          nil
-	LaTeX-enumitem-newlist-list-item-arg nil
+  (setq LaTeX-auto-enumitem-newlist          nil
 	LaTeX-auto-enumitem-SetEnumitemKey   nil
 	LaTeX-auto-enumitem-SetEnumitemValue nil))
 
@@ -168,26 +153,19 @@ package.")
   "Move parsing results into right places for further usage."
   ;; \newlist{<name>}{<type>}{<max-depth>}
   ;; env=<name>, type=<type>, ignored=<max-depth>
-  (dolist (env-type LaTeX-auto-enumitem-newlist)
+  (dolist (env-type (LaTeX-enumitem-newlist-list))
     (let* ((env  (car env-type))
 	   (type (cadr env-type)))
-      (add-to-list 'LaTeX-auto-environment
-		   (list env 'LaTeX-enumitem-env-with-opts))
-      (add-to-list 'LaTeX-enumitem-newlist-list
-		   (list env))
+      (LaTeX-add-environments (list env 'LaTeX-enumitem-env-with-opts))
+      ;; Tell AUCTeX about parsed description like environments.
       (when (or (string-equal type "description")
 		(string-equal type "description*"))
-	(add-to-list 'LaTeX-enumitem-newlist-list-item-arg
-		     (list env)))))
+	(add-to-list 'LaTeX-item-list `(,env . LaTeX-item-argument)))))
   ;; Now add the parsed env's to the local list.
-  (when LaTeX-enumitem-newlist-list
+  (when (LaTeX-enumitem-newlist-list)
     (setq LaTeX-enumitem-newlist-list-local
-	  (append LaTeX-enumitem-newlist-list
-		  LaTeX-enumitem-newlist-list-local)))
-  ;; Tell AUCTeX about parsed description like environments.
-  (when LaTeX-enumitem-newlist-list-item-arg
-    (dolist (env LaTeX-enumitem-newlist-list-item-arg)
-      (add-to-list 'LaTeX-item-list `(,(car env) . LaTeX-item-argument)))))
+	  (append (mapcar 'list (mapcar 'car (LaTeX-enumitem-newlist-list)))
+		  LaTeX-enumitem-newlist-list-local))))
 
 (add-hook 'TeX-auto-prepare-hook #'LaTeX-enumitem-auto-prepare t)
 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-enumitem-auto-cleanup t)
@@ -282,7 +260,6 @@ in `enumitem'-completions."
 	(pushnew (list key (list val)) opts :test #'equal))
       (setq LaTeX-enumitem-key-val-options-local (copy-alist opts)))))
 
-
 (TeX-add-style-hook
  "enumitem"
  (lambda ()
@@ -347,6 +324,7 @@ in `enumitem'-completions."
 		     (string-equal type "description*"))
 	     (add-to-list 'LaTeX-item-list `(,name . LaTeX-item-argument)))
 	   (LaTeX-add-environments `(,name LaTeX-enumitem-env-with-opts))
+	   (LaTeX-add-enumitem-newlists (list name type))
 	   (insert (format "{%s}" name)
 		   (format "{%s}" type))
 	    (format "%s" depth)))))
@@ -396,12 +374,23 @@ in `enumitem'-completions."
     '("AddEnumerateCounter" 3)
     '("AddEnumerateCounter*" 3)
 
-    ;; This command only makes sense for enumerate type environments.
-    ;; Currently, we offer all defined env's -- to be improved
-    ;; sometimes.
+    ;; "\restartlist" only works for lists defined with "resume" key.
+    ;; We will not extract that information and leave that to users.
+    ;; For completion, extract enumerated environments from
+    ;; `LaTeX-enumitem-newlist-list' and add "enumerate" to them.
     '("restartlist"
-      (TeX-arg-eval completing-read "List name: "
-		    LaTeX-enumitem-newlist-list-local))
+      (TeX-arg-eval
+       (lambda ()
+	 (let ((enums '("enumerate")))
+	   (when (LaTeX-provided-package-options-member "enumitem" "inline")
+	     (pushnew "enumerate*" enums :test #'equal))
+	   (dolist (env-type (LaTeX-enumitem-newlist-list))
+	     (let ((env   (car env-type))
+		   (type  (cadr env-type)))
+	       (when (or (string-equal type "enumerate")
+			 (string-equal type "enumerate*"))
+		 (pushnew env enums :test #'equal))))
+	   (completing-read "List name: " enums)))))
 
     ;; "Key" will be parsed and added to key-val list.
     '("SetEnumitemKey" LaTeX-arg-SetEnumitemKey)
-- 
2.7.0

_______________________________________________
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to