diff --git a/latex.el b/latex.el index d855b5c5..c7331173 100644 --- a/latex.el +++ b/latex.el @@ -4058,6 +4058,11 @@ value." :group 'LaTeX-indentation :type 'regexp) +(defcustom LaTeX-indent-always-align-end-with-begin t + "If non-nil, always indent \\end{foo} aligned with \\begin{foo}." + :group 'LaTeX-indentation + :type 'boolean) + (defvar docTeX-indent-inner-fixed `((,(concat (regexp-quote TeX-esc) "\\(begin\\|end\\)[ \t]*{macrocode\\*?}") @@ -4310,8 +4315,12 @@ outer indentation in case of a commented line. The symbols "\\(" LaTeX-end-regexp "\\)")) - ;; Backindent at \end. - (- (LaTeX-indent-calculate-last force-type) LaTeX-indent-level)) + (if LaTeX-indent-always-align-end-with-begin + (save-excursion + (LaTeX-find-matching-begin) + (LaTeX-current-indentation force-type)) + ;; Backindent at \end. + (- (LaTeX-indent-calculate-last force-type) LaTeX-indent-level))) ((looking-at (concat (regexp-quote TeX-esc) "right\\b")) ;; Backindent at \right. (- (LaTeX-indent-calculate-last force-type) @@ -8935,8 +8944,11 @@ COL for efficiency." LaTeX-indent-environment-list) out))))) (cond ((looking-at tabular-like-end-regex) - beg-col) - + (if LaTeX-indent-always-align-end-with-begin + beg-col + (save-excursion + (goto-char beg-pos) + (LaTeX-current-indentation)))) ((looking-at "\\\\\\\\") (+ 2 beg-col))