branch: externals/auctex commit d937d4035cc8754cc95a379cfba59cf88fd951f6 Author: Arash Esbati <ar...@gnu.org> Commit: Arash Esbati <ar...@gnu.org>
Simplify implementation of style/changelog.el * style/changelog.el (LaTeX-changelog-key-val-options): New function returning key=vals. The functionality used to be part of `LaTeX-env-changelog'. (LaTeX-env-changelog): Adjust in order to insert a label into optional argument. ("changelog"): Adjust function usage in the hook accordingly. --- style/changelog.el | 97 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/style/changelog.el b/style/changelog.el index a4ebb43cfa..227caa3c81 100644 --- a/style/changelog.el +++ b/style/changelog.el @@ -1,6 +1,6 @@ ;;; changelog.el --- AUCTeX style for `changelog.sty' (v2.0.0) -*- lexical-binding: t; -*- -;; Copyright (C) 2019, 2020 Free Software Foundation, Inc. +;; Copyright (C) 2019--2022 Free Software Foundation, Inc. ;; Author: Arash Esbati <ar...@gnu.org> ;; Maintainer: auctex-de...@gnu.org @@ -57,67 +57,72 @@ The keys sectioncmd and label are added in the function ("short" ("true" "false"))) "key=value options for version environment.") -(defun LaTeX-env-changelog (environment) - "Insert ENVIRONMENT, ask for optional argument and insert a label." - (let* ((seccmds (mapcar #'car LaTeX-section-list)) - ;; Collect the key=vals acc. to environment & documentclass - (opts (TeX-read-key-val - t - (if (string= environment "changelog") - (append - `(("sectioncmd" - ,(if (< (LaTeX-largest-level) 2) - (append - (mapcar (lambda (cmd) (concat TeX-esc cmd)) - seccmds) - (mapcar (lambda (cmd) (concat TeX-esc cmd "*")) - seccmds)) - (append - (mapcar (lambda (cmd) (concat TeX-esc cmd)) - (remove "chapter" seccmds)) - (mapcar (lambda (cmd) (concat TeX-esc cmd "*")) - (remove "chapter" seccmds)))))) - LaTeX-changelog-env-key-val-options - LaTeX-changelog-version-env-key-val-options) - LaTeX-changelog-version-env-key-val-options))) +(defun LaTeX-changelog-key-val-options () + "Return an updated list of key=vals from changelog package." + (let ((currenv (or LaTeX-current-environment + (LaTeX-current-environment))) + (seccmds (mapcar #'car LaTeX-section-list))) + (if (string= currenv "changelog") + (append + `(("sectioncmd" + ,(if (< (LaTeX-largest-level) 2) + (append (mapcar (lambda (cmd) (concat TeX-esc cmd)) + seccmds) + (mapcar (lambda (cmd) (concat TeX-esc cmd "*")) + seccmds)) + (append (mapcar (lambda (cmd) (concat TeX-esc cmd)) + (remove "chapter" seccmds)) + (mapcar (lambda (cmd) (concat TeX-esc cmd "*")) + (remove "chapter" seccmds)))))) + LaTeX-changelog-env-key-val-options + LaTeX-changelog-version-env-key-val-options) + LaTeX-changelog-version-env-key-val-options))) + +(defun LaTeX-env-changelog (_optional) + "Insert a label into the optional argument of changelog environment. +OPTIONAL is ignored." + (let* ((s (save-excursion + (LaTeX-find-matching-begin) + (point))) + (currenv LaTeX-current-environment) ;; Extract the chosen sectioning command - (sec (progn - (string-match "sectioncmd=\\\\\\([a-z]+\\)\\(\\*?\\)" opts) - (match-string-no-properties 1 opts))) + (sec (save-excursion + (re-search-backward + (concat "sectioncmd=\\\\\\([a-z]+\\)\\(\\*?\\)" + "\\|" + "\\<\\(section\\)\\(?:=true\\)?") + s t) + (or (match-string-no-properties 1) + (match-string-no-properties 3)))) ;; Temp. re-bind `LaTeX-label-alist' and pick the label ;; prefix from `LaTeX-section-label' (LaTeX-label-alist - (when (and (string= environment "changelog") - (match-string 2 opts) - (not (string= (match-string 2 opts) "*"))) - `(,(cons environment + (when (or (and (match-string 2) + (not (string= (match-string 2) "*"))) + (match-string 3)) + `(,(cons currenv (cdr (assoc sec LaTeX-section-label)))))) ;; Temp. re-bind `reftex-label-alist' as well and make ;; `reftex-label' DTRT: (reftex-label-alist (when (and (boundp 'reftex-label-alist) - LaTeX-label-alist - (string= environment "changelog")) - `((,environment ?s ,(cdr (assoc sec LaTeX-section-label)) nil t))))) - (LaTeX-insert-environment - environment - (when (and opts (not (string= opts ""))) - (concat LaTeX-optop opts LaTeX-optcl))) + LaTeX-label-alist) + `((,currenv ?s ,(cdr (assoc sec LaTeX-section-label)) nil t))))) ;; Add a label into the opt. argument - (when (string= environment "changelog") - (LaTeX-env-label-as-keyval nil "sectioncmd" nil environment)) - ;; Add an \item in version environment - (when (string= environment "version") - (TeX-insert-macro "item") - (indent-according-to-mode)))) + (when LaTeX-label-alist + (LaTeX-env-label-as-keyval nil "\\<section\\(?:cmd\\)?\\>" + nil currenv)))) (TeX-add-style-hook "changelog" (lambda () (LaTeX-add-environments - '("changelog" LaTeX-env-changelog) - '("version" LaTeX-env-changelog)) + '("changelog" LaTeX-env-args + [TeX-arg-key-val (LaTeX-changelog-key-val-options)] + LaTeX-env-changelog) + '("version" LaTeX-env-item-args + [TeX-arg-key-val (LaTeX-changelog-key-val-options)])) (TeX-add-symbols '("added" 0)