diff --git a/doc/auctex.texi b/doc/auctex.texi index 682e4ed8..8e3f8d51 100644 --- a/doc/auctex.texi +++ b/doc/auctex.texi @@ -5650,6 +5650,19 @@ Following is a list of available hooks for @item LaTeX-env-item Insert the given environment and the first item. +@item LaTeX-env-item-args +Insert the given environment, the first item and further arguments to the +environment. You can use this as a hook in case you want to specify +multiple complex arguments just like in elements of +@code{TeX-add-symbols}. Here is an example from @file{enumitem.el} in +order to prompt for a @samp{key=value} list to be inserted as an optional +argument to the @samp{itemize} environment: +@lisp +(LaTeX-add-environments + '("itemize" LaTeX-env-item-args + [TeX-arg-key-val (LaTeX-enumitem-key-val-options)])) +@end lisp + @item LaTeX-env-figure Insert the given figure-like environment with a caption and a label. @@ -5660,6 +5673,10 @@ specifications. @item LaTeX-env-label Insert the given environment with a label. +@item LaTeX-env-label-args +Insert the given environment with a label and further arguments to the +environment. + @item LaTeX-env-list Insert the given list-like environment, a specifier for the label and the first item. diff --git a/latex.el b/latex.el index e096603b..d87c69fa 100644 --- a/latex.el +++ b/latex.el @@ -1061,6 +1061,15 @@ If nil, act like the empty string is given, but do not prompt." :group 'LaTeX-label :type 'string) +(defun LaTeX--env-parse-args (args) + "Helper function to insert arguments defined by ARGS." + (save-excursion + (LaTeX-find-matching-begin) + (end-of-line) + (let ((TeX-exit-mark (or TeX-exit-mark + (make-marker)))) + (TeX-parse-arguments args)))) + (defun LaTeX-env-item (environment) "Insert ENVIRONMENT and the first item." (LaTeX-insert-environment environment) @@ -1088,6 +1097,11 @@ If nil, act like the empty string is given, but do not prompt." (current-fill-column))) (LaTeX-fill-paragraph nil))) +(defun LaTeX-env-item-args (environment &rest args) + "Run `LaTeX-env-item' on ENVIRONMENT and insert ARGS." + (LaTeX-env-item environment) + (LaTeX--env-parse-args args)) + (defcustom LaTeX-label-alist '(("figure" . LaTeX-figure-label) ("table" . LaTeX-table-label) @@ -1296,6 +1310,11 @@ Just like array and tabular." ;; Restore the positions of point and mark. (exchange-point-and-mark))) +(defun LaTeX-env-label-args (environment &rest args) + "Run `LaTeX-env-label' on ENVIRONMENT and insert ARGS." + (LaTeX-env-label environment) + (LaTeX--env-parse-args args)) + (defun LaTeX-env-list (environment) "Insert ENVIRONMENT and the first item." (let ((label (TeX-read-string "Default Label: "))) @@ -1422,12 +1441,7 @@ Just like array and tabular." (defun LaTeX-env-args (environment &rest args) "Insert ENVIRONMENT and arguments defined by ARGS." (LaTeX-insert-environment environment) - (save-excursion - (LaTeX-find-matching-begin) - (end-of-line) - (let ((TeX-exit-mark (or TeX-exit-mark - (make-marker)))) - (TeX-parse-arguments args)))) + (LaTeX--env-parse-args args)) (defun LaTeX-env-label-as-keyval (_optional &optional keyword keyvals environment) "Query for a label and insert it in the optional argument of an environment. @@ -7458,10 +7472,12 @@ or `LaTeX-environment-list' and returns it." (TeX-symbol-list) (LaTeX-environment-list))))) - ;; Check if there is a `LaTeX-env-args' in the `arg-list' and + ;; Check if there is a `LaTeX-env-*-args' in the `arg-list' and ;; remove it: (when (and (eq mac-or-env 'env) - (eq (car arg-list) #'LaTeX-env-args)) + (memq (car arg-list) '(LaTeX-env-args + LaTeX-env-item-args + LaTeX-env-label-args))) (pop arg-list)) ;; Check for `TeX-arg-conditional' here and change `arg-list'