branch: externals/auctex commit 8e3137f641654655c76f869ebf2be5dd5480d462 Author: Arash Esbati <ar...@gnu.org> Commit: Arash Esbati <ar...@gnu.org>
Simplify implementation of style/titlesec.el * style/titlesec.el (LaTeX-titlesec-section-command-list): Delete unnecessary `symbol-value'. (LaTeX-titlesec-titlespec-key-val-options): New function replacing `LaTeX-arg-titlesec-titlespec'. The new function returns only key=vals and doesn't insert them into buffer. ("titlesec"): Use the new function in the style hook. --- style/titlesec.el | 59 +++++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/style/titlesec.el b/style/titlesec.el index 3c232b0f18..bc1faf13d8 100644 --- a/style/titlesec.el +++ b/style/titlesec.el @@ -75,34 +75,29 @@ Removal is based on the return value of function `TeX-esc'." (mapcar (lambda (elt) (concat TeX-esc elt)) (if (< (LaTeX-largest-level) 2) - (symbol-value 'LaTeX-titlesec-section-command-list) + LaTeX-titlesec-section-command-list (remove "chapter" LaTeX-titlesec-section-command-list)))) -(defun LaTeX-arg-titlesec-titlespec (optional) - "Insert the first argument of \"\\titleformat\" and \"\\titlespacing\". -Depending on returned value of function `LaTeX-largest-level', -append a \"name\" key with corresponding values to -`LaTeX-titlesec-key-val-options'. The values are retrieved from -`LaTeX-titlesec-section-command-list'. The values of this list -are also added stand-alone as keys. If OPTIONAL is non-nil, -insert the argument in brackets." - (let ((keyvals - (TeX-read-key-val - optional - (append - `(("name" - ,(mapcar (lambda (elt) (concat TeX-esc elt)) - (if (< (LaTeX-largest-level) 2) - (symbol-value 'LaTeX-titlesec-section-command-list) - (remove "chapter" LaTeX-titlesec-section-command-list))))) - (mapcar #'list - (mapcar (lambda (elt) (concat TeX-esc elt)) - (if (< (LaTeX-largest-level) 2) - (symbol-value 'LaTeX-titlesec-section-command-list) - (remove "chapter" LaTeX-titlesec-section-command-list)))) - LaTeX-titlesec-key-val-options) - "Sectioning command"))) - (TeX-argument-insert keyvals optional))) +(defun LaTeX-titlesec-titlespec-key-val-options () + "Return key=val's for the 1st arg of \"\\titleformat\" and \"\\titlespacing\". +Depending on the returned value of the function +`LaTeX-largest-level', append a \"name\" key with corresponding +values to `LaTeX-titlesec-key-val-options'. The values are +retrieved from `LaTeX-titlesec-section-command-list'. The values +of this list are also added stand-alone as keys." + (append + `(("name" + ,(mapcar (lambda (elt) (concat TeX-esc elt)) + (if (< (LaTeX-largest-level) 2) + LaTeX-titlesec-section-command-list + (remove "chapter" LaTeX-titlesec-section-command-list))))) + (mapcar #'list + (mapcar (lambda (elt) (concat TeX-esc elt)) + (if (< (LaTeX-largest-level) 2) + LaTeX-titlesec-section-command-list + (remove "chapter" LaTeX-titlesec-section-command-list)))) + LaTeX-titlesec-key-val-options)) + (TeX-add-style-hook "titlesec" @@ -117,30 +112,30 @@ insert the argument in brackets." '("titlelabel" t) ;; \titleformat*{<command>}{<format>} - '("titleformat*" (LaTeX-arg-titlesec-titlespec) t) + '("titleformat*" (TeX-arg-key-val (LaTeX-titlesec-titlespec-key-val-options)) t) ;; 3. Advanced Interface ;; \titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>] '("titleformat" - (LaTeX-arg-titlesec-titlespec) + (TeX-arg-key-val (LaTeX-titlesec-titlespec-key-val-options)) [TeX-arg-completing-read LaTeX-titlesec-section-shape-list "Shape"] (TeX-arg-conditional (y-or-n-p "With optional after-code? ") - (4 [nil]) - (4))) + (4 [nil]) + (4))) '("chaptertitlename" 0) ;; 3.2. Spacing ;; \titlespacing{<command>}{<left>}{<before-sep>}{<after-sep>}[<right-sep>] '("titlespacing" - (LaTeX-arg-titlesec-titlespec) + (TeX-arg-key-val (LaTeX-titlesec-titlespec-key-val-options)) (TeX-arg-length "Left margin") (TeX-arg-length "Before vertical space") (TeX-arg-length "Space between title and text") [TeX-arg-length "Right margin"]) '("titlespacing*" - (LaTeX-arg-titlesec-titlespec) + (TeX-arg-key-val (LaTeX-titlesec-titlespec-key-val-options)) (TeX-arg-length "Left margin") (TeX-arg-length "Before vertical space") (TeX-arg-length "Space between title and text")