branch: externals/auctex
commit 8d7fef32c4ca2adcef822e8b12e56e66fb1a10a4
Author: Arash Esbati <[email protected]>
Commit: Tassilo Horn <[email protected]>
Improve styles enumitem.el and caption.el.
* style/enumitem.el (LaTeX-enumitem-SetEnumitemKey-regexp): Delete
match for the second argument.
(LaTeX-enumitem-SetEnumitemValue-regexp): Delete match for the
third argument.
(LaTeX-arg-SetEnumitemValue): Replace the randomly generated
number with something human-readable.
* style/caption.el (LaTeX-caption-DeclareCaption-regexp): Delete
match for the second argument.
(LaTeX-arg-caption-DeclareCaption): Replace the randomly generated
number with something human-readable.
---
ChangeLog | 14 ++++++++++++++
style/caption.el | 13 ++++++++-----
style/enumitem.el | 19 ++++++++++++-------
3 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a53574a..7e88388 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2015-03-15 Arash Esbati <[email protected]>
+
+ * style/enumitem.el (LaTeX-enumitem-SetEnumitemKey-regexp): Delete
+ match for the second argument.
+ (LaTeX-enumitem-SetEnumitemValue-regexp): Delete match for the
+ third argument.
+ (LaTeX-arg-SetEnumitemValue): Replace the randomly generated
+ number with something human-readable.
+
+ * style/caption.el (LaTeX-caption-DeclareCaption-regexp): Delete
+ match for the second argument.
+ (LaTeX-arg-caption-DeclareCaption): Replace the randomly generated
+ number with something human-readable.
+
2015-03-10 Tassilo Horn <[email protected]>
* tex.el (TeX-style-path): Replace `pushnew' with equivalent code
diff --git a/style/caption.el b/style/caption.el
index f2ea856..c79f562 100644
--- a/style/caption.el
+++ b/style/caption.el
@@ -121,14 +121,16 @@ supported by `caption.sty'.")
;; Setup for various \DeclareCaption's:
(TeX-auto-add-type "caption-DeclareCaption" "LaTeX")
+;; The 2. argument to `DeclareCaption[A-Za-z]' contains (La)TeX code.
+;; We deliberately ignore that argument in our regex since it is not
+;; needed for this style and would pollute the auto generated
+;; `docname.el' file.
(defvar LaTeX-caption-DeclareCaption-regexp
`(,(concat "\\\\DeclareCaption\\(Font\\|Format\\|Justification"
"\\|LabelFormat\\|LabelSeparator\\|ListFormat"
"\\|Option\\|Style\\|TextFormat\\)"
"\\*?"
"[ \t\n\r%]*"
- "{\\([^}]+\\)}"
- "[ \t\n\r%]*"
"{\\([^}]+\\)}")
(0 1 2) LaTeX-auto-caption-DeclareCaption)
"Matches the arguments of different `\\DeclareCaption*' from
@@ -175,14 +177,15 @@ standard one."
;; In `LaTeX-caption-DeclareCaption-regexp', we match (0 1 2). When
;; adding a new `Name', we need something unique for `0'-match until
-;; the next `C-c C-n'. We use a random number for this purpose which
-;; will then disappear.
+;; the next `C-c C-n'. We mimic that regex-match bei concat'ing the
+;; elements. It will vanish upon next `C-c C-n'.
(defun LaTeX-arg-caption-DeclareCaption (format)
"Insert various `\\DeclareCaptionFORMAT' commands. FORMAT is
the suffix of the command."
(let ((name (TeX-read-string "Name: ")))
(LaTeX-add-caption-DeclareCaptions
- `(,(number-to-string (random)) ,format ,name))
+ (list (concat "\\DeclareCaption" format "{" name "}")
+ format name))
(format "%s" name)))
(TeX-add-style-hook
diff --git a/style/enumitem.el b/style/enumitem.el
index 760a145..e2fce50 100644
--- a/style/enumitem.el
+++ b/style/enumitem.el
@@ -137,7 +137,7 @@ package.")
(TeX-auto-add-type "enumitem-SetEnumitemKey" "LaTeX")
(defvar LaTeX-enumitem-SetEnumitemKey-regexp
- '("\\\\SetEnumitemKey{\\([^}]+\\)}{\\([^}]+\\)}"
+ '("\\\\SetEnumitemKey{\\([^}]+\\)}"
1 LaTeX-auto-enumitem-SetEnumitemKey)
"Matches the arguments of `\\SetEnumitemKey' from `enumitem'
package.")
@@ -150,9 +150,12 @@ package.")
;; Upon Tassilo's recommendation, we include also `0' so that we can
;; use the function `LaTeX-enumitem-SetEnumitemValue-list' while we
;; make sure that `TeX-auto-list-information' doesn't remove multiple
-;; defined values to a specific key.
+;; defined values to a specific key. For this reason, we also ignore
+;; the 3. argument to the `\SetEnumitemValue' macro (i.e., a third
+;; {\\([^}]+\\)} in regex) so that we don't pollute the generated
+;; `docname.el' with unnecessary (La)TeX code.
(defvar LaTeX-enumitem-SetEnumitemValue-regexp
- '("\\\\SetEnumitemValue{\\([^}]+\\)}{\\([^}]+\\)}{\\([^}]+\\)}"
+ '("\\\\SetEnumitemValue{\\([^}]+\\)}{\\([^}]+\\)}"
(0 1 2) LaTeX-auto-enumitem-SetEnumitemValue)
"Matches the arguments of `\\SetEnumitemValue' from `enumitem'
package.")
@@ -229,11 +232,12 @@ key-val and the first item."
(add-to-list 'LaTeX-enumitem-key-val-options-local (list key))
(LaTeX-add-enumitem-SetEnumitemKeys key)))
-
;; In `LaTeX-enumitem-SetEnumitemValue-regexp', we match (0 1 2).
;; When adding a new `key=val', we need something unique for `0'-match
-;; until the next `C-c C-n'. We use a random number for this purpose
-;; which will then disappear.
+;; until the next `C-c C-n'. We mimic that regex-match bei concat'ing
+;; the elements and pass the result to
+;; `LaTeX-add-enumitem-SetEnumitemValues'. It will vanish upon next
+;; invocation of `C-c C-n'.
(defun LaTeX-arg-SetEnumitemValue (optional &optional prompt)
"Ask for a new value added to an existing key incl. the final
replacement of the value."
@@ -252,7 +256,8 @@ replacement of the value."
(TeX-argument-insert key optional)
(TeX-argument-insert val optional)
(LaTeX-add-enumitem-SetEnumitemValues
- `(,(number-to-string (random)) ,key ,val))))
+ (list (concat "\\SetEnumitemValue{" key "}{" val "}")
+ key val))))
(defun LaTeX-enumitem-update-key-val-options ()
"Update the buffer-local key-val options before offering them