branch: externals/auctex commit 0b24e363f829f381415fe7cc34f6386baafa9921 Author: Arash Esbati <ar...@gnu.org> Commit: Arash Esbati <ar...@gnu.org>
Improve indentation after '\end{macrocode}' in docTeX mode * latex.el (LaTeX-indent-calculate-last): Improve indentation after '\end{macrocode}' if still inside a description environment like 'macro' or 'environment'. * tests/latex/doctex-indent-in.dtx: * tests/latex/doctex-indent-out.dtx: New test files. * tests/latex/latex-test.el (docTeX-indentation): New test. --- latex.el | 17 ++++++++-- tests/latex/doctex-indent-in.dtx | 68 +++++++++++++++++++++++++++++++++++++++ tests/latex/doctex-indent-out.dtx | 68 +++++++++++++++++++++++++++++++++++++++ tests/latex/latex-test.el | 21 +++++++++++- 4 files changed, 170 insertions(+), 4 deletions(-) diff --git a/latex.el b/latex.el index 4527fbafb7..85c290ec50 100644 --- a/latex.el +++ b/latex.el @@ -4156,9 +4156,20 @@ outer indentation in case of a commented line. The symbols "end[ \t]*{macrocode\\*?}")) fill-prefix (TeX-in-line-comment)) - ;; Reset indentation to zero after a macrocode - ;; environment. - 0) + ;; Reset indentation to zero after a macrocode environment + ;; only when we're not still inside a describing + ;; environment like "macro" or "environment" etc. Text + ;; inside these environments after '\end{macrocode}' is + ;; indented with `LaTeX-indent-level': + (let ((outer-env (LaTeX-current-environment 2))) + (cond ((member outer-env '("macro" "environment")) + LaTeX-indent-level) + ((and (fboundp 'LaTeX-doc-NewDocElement-list) + (LaTeX-doc-NewDocElement-list) + (member outer-env + (mapcar #'cadr (LaTeX-doc-NewDocElement-list)))) + LaTeX-indent-level) + (t 0)))) ((looking-at (concat (regexp-quote TeX-esc) "begin *{" ;; Don't give optional argument here diff --git a/tests/latex/doctex-indent-in.dtx b/tests/latex/doctex-indent-in.dtx new file mode 100644 index 0000000000..4f439588a7 --- /dev/null +++ b/tests/latex/doctex-indent-in.dtx @@ -0,0 +1,68 @@ +% \iffalse meta-comment +% +% This file may be distributed and/or modified under the conditions +% of the LaTeX Project Public License, either version 1.3 of this +% license or (at your option) any later version. The latest version +% of this license is in: +% +% http://www.latex-project.org/lppl.txt +% +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% \fi +% +% \iffalse +%<*driver> +\documentclass{ltxdoc} +\usepackage{package} +\EnableCrossrefs +\CodelineIndex +\RecordChanges +\begin{document} +\DocInput{package.dtx} +\end{document} +%</driver> +% \fi +% +% \section{Usage} +% +% \DescribeMacro{\YOURMACRO} +% Put description of |\YOURMACRO| here. +% +% \DescribeEnv{YOURENV} +% Put description of |YOURENV| here. +% +% \StopEventually{\PrintIndex} +% +% \section{Implementation} +% +% \begin{macro}{\YOURMACRO} +% Put explanation of |\YOURMACRO|'s implementation here. +% \begin{macrocode} + \newcommand{\YOURMACRO}{% + code goes here% +} +% \end{macrocode} +% Some more text afterwards. +% \end{macro} +% +%\begin{environment}{YOURENV} +%Put explanation of |YOURENV|'s implementation here. +%\begin{macrocode} +\newenvironment{YOURENV}{% +code before environment% +}{% +code after environment% +} +%\end{macrocode} +%Some more text afterwards. +%\end{environment} +% +% \Finale +% +% \endinput +% Local Variables: +% mode: doctex +% TeX-master: t +% End: diff --git a/tests/latex/doctex-indent-out.dtx b/tests/latex/doctex-indent-out.dtx new file mode 100644 index 0000000000..2bdcf40cbe --- /dev/null +++ b/tests/latex/doctex-indent-out.dtx @@ -0,0 +1,68 @@ +% \iffalse meta-comment +% +% This file may be distributed and/or modified under the conditions +% of the LaTeX Project Public License, either version 1.3 of this +% license or (at your option) any later version. The latest version +% of this license is in: +% +% http://www.latex-project.org/lppl.txt +% +% and version 1.3 or later is part of all distributions of LaTeX +% version 2005/12/01 or later. +% +% \fi +% +% \iffalse +%<*driver> +\documentclass{ltxdoc} +\usepackage{package} +\EnableCrossrefs +\CodelineIndex +\RecordChanges +\begin{document} +\DocInput{package.dtx} +\end{document} +%</driver> +% \fi +% +% \section{Usage} +% +% \DescribeMacro{\YOURMACRO} +% Put description of |\YOURMACRO| here. +% +% \DescribeEnv{YOURENV} +% Put description of |YOURENV| here. +% +% \StopEventually{\PrintIndex} +% +% \section{Implementation} +% +% \begin{macro}{\YOURMACRO} +% Put explanation of |\YOURMACRO|'s implementation here. +% \begin{macrocode} +\newcommand{\YOURMACRO}{% + code goes here% +} +% \end{macrocode} +% Some more text afterwards. +% \end{macro} +% +% \begin{environment}{YOURENV} +% Put explanation of |YOURENV|'s implementation here. +% \begin{macrocode} +\newenvironment{YOURENV}{% + code before environment% +}{% + code after environment% +} +% \end{macrocode} +% Some more text afterwards. +% \end{environment} +% +% \Finale +% +% \endinput +% Local Variables: +% mode: doctex +% TeX-master: t +% End: diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el index d10b98a6e1..d5f267e418 100644 --- a/tests/latex/latex-test.el +++ b/tests/latex/latex-test.el @@ -54,7 +54,11 @@ 'LaTeX-conditionals-indent/in "conditionals-indent-in.tex" 'LaTeX-conditionals-indent/out - "conditionals-indent-out.tex") + "conditionals-indent-out.tex" + 'docTeX/in + "doctex-indent-in.dtx" + 'docTeX/out + "doctex-indent-out.dtx") ;; Test for detecting \& in a table cell added; see ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26010 @@ -672,4 +676,19 @@ check the indentation for optional argument of \\usepackage." (insert-file-contents LaTeX-conditionals-indent/out) (buffer-string))))) +(ert-deftest docTeX-indentation () + "Test if content in docTeX-mode is indented correctly." + (should (string= + (with-temp-buffer + (insert-file-contents docTeX/in) + (docTeX-mode) + (let ((TeX-parse-self t)) + (TeX-update-style t) + (indent-region (point-min) (point-max)) + (whitespace-cleanup) + (buffer-string))) + (with-temp-buffer + (insert-file-contents docTeX/out) + (buffer-string))))) + ;;; latex-test.el ends here