branch: externals/auctex
commit a55b66ddaeaf59590db6a1c3198cfbc56b6360d8
Author: Arash Esbati <[email protected]>
Commit: Arash Esbati <[email protected]>
Improve inserting arguments of \captionof macro
* style/caption.el (LaTeX-arg-caption-captionof): New function
improving query and insert of caption and label acc. to float
type.
("caption"): Use it.
---
style/caption.el | 50 ++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 42 insertions(+), 8 deletions(-)
diff --git a/style/caption.el b/style/caption.el
index d8699fa..f4b2ab0 100644
--- a/style/caption.el
+++ b/style/caption.el
@@ -270,6 +270,46 @@ caption, insert only a caption."
;; (cf. `paragraph-start').
(LaTeX-fill-paragraph))
+(defun LaTeX-arg-caption-captionof (optional &optional star)
+ "Query for the arguments of \"\\captionof\" macro and insert them.
+If OPTIONAL is non-nil, insert the arguments in brackets. If
+STAR is non-nil, do not query for a short-caption and a label."
+ (let* ((envtype (completing-read (TeX-argument-prompt optional nil "Float
type")
+ LaTeX-caption-supported-float-types))
+ (figtypes '("figure" "subfigure" "floatingfigure"
+ "figwindow" "SCfigure" "measuredfigure" "wrapfigure"))
+ (tabtypes '("table" "subtable" "floatingtable" "tabwindow" "SCtable"
+ "supertabular" "xtabular" "threeparttable" "wraptable"))
+ (caption (TeX-read-string
+ (TeX-argument-prompt optional nil "Caption")))
+ (short-caption
+ (when (and (not star)
+ (>= (length caption) LaTeX-short-caption-prompt-length))
+ (TeX-read-string
+ (TeX-argument-prompt t nil "Short caption")))))
+ (indent-according-to-mode)
+ (TeX-argument-insert envtype optional)
+ (when (and short-caption (not (string= short-caption "")))
+ (insert LaTeX-optop short-caption LaTeX-optcl))
+ (TeX-argument-insert caption optional)
+ (LaTeX-fill-paragraph)
+ (unless star
+ (LaTeX-newline)
+ (indent-according-to-mode)
+ ;; Check if `envtype' is a figure or a table, also consult
+ ;; `LaTeX-label-alist' for additions from user or newfloat.el,
+ ;; then run `LaTeX-label' w/ 'environment arg, otherwise w/o.
+ (if (or (member envtype figtypes)
+ (member envtype tabtypes)
+ (assoc envtype LaTeX-label-alist))
+ (LaTeX-label (cond ((member envtype figtypes)
+ "figure")
+ ((member envtype tabtypes)
+ "table")
+ (t envtype))
+ 'environment)
+ (LaTeX-label envtype)))))
+
(TeX-add-style-hook
"caption"
(lambda ()
@@ -305,15 +345,9 @@ caption, insert only a caption."
LaTeX-caption-supported-float-types]
t)
- '("captionof"
- (TeX-arg-eval completing-read (TeX-argument-prompt nil nil "Float type")
- LaTeX-caption-supported-float-types)
- ["Short caption"] t)
+ '("captionof" LaTeX-arg-caption-captionof)
- '("captionof*"
- (TeX-arg-eval completing-read (TeX-argument-prompt nil nil "Float type")
- LaTeX-caption-supported-float-types)
- t)
+ '("captionof*" (LaTeX-arg-caption-captionof t))
'("captionsetup"
(TeX-arg-conditional (member "bicaption" (TeX-style-list))