--- latex.el 13 Oct 2005 00:56:32 +0200 5.387 +++ latex.el 14 Oct 2005 04:55:52 +0200 @@ -572,9 +572,10 @@ (t (apply (nth 1 entry) environment (nthcdr 2 entry)))))) -(defun LaTeX-close-environment () - "Create an \\end{...} to match the current environment." - (interactive "*") +(defun LaTeX-close-environment (&optional reopen) + "Create an \\end{...} to match the current environment. +With prefix-argument, reopen environment afterwards." + (interactive "*P") (if (> (point) (save-excursion (beginning-of-line) @@ -584,17 +585,25 @@ (skip-chars-forward " \t") (point))) (LaTeX-newline)) - (insert "\\end{" (LaTeX-current-environment 1) "}") - (indent-according-to-mode) - (if (or (not (looking-at "[ \t]*$")) - (and (TeX-in-commented-line) - (save-excursion (beginning-of-line 2) - (not (TeX-in-commented-line))))) - (LaTeX-newline) - (let ((next-line-add-newlines t)) - (next-line 1) - (beginning-of-line))) - (indent-according-to-mode)) + (let ((environment (LaTeX-current-environment 1)) marker) + (insert "\\end{" environment "}") + (indent-according-to-mode) + (if (or (not (looking-at "[ \t]*$")) + (and (TeX-in-commented-line) + (save-excursion (beginning-of-line 2) + (not (TeX-in-commented-line))))) + (LaTeX-newline) + (let ((next-line-add-newlines t)) + (next-line 1) + (beginning-of-line))) + (indent-according-to-mode) + (when reopen + (save-excursion + (setq marker (point-marker)) + (set-marker-insertion-type marker t) + (LaTeX-environment-menu environment) + (delete-region (point) marker) + (move-marker marker nil))))) (defun LaTeX-insert-environment (environment &optional extra) "Insert LaTeX ENVIRONMENT with optional argument EXTRA."