Function: LaTeX-close-environment

LaTeX-close-environment is an interactive and byte-compiled function defined in latex.el.

Signature

(LaTeX-close-environment &optional REOPEN)

Documentation

Create an \end{...} to match the current environment.

With prefix argument REOPEN, reopen environment afterwards.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-close-environment (&optional reopen)
  "Create an \\end{...} to match the current environment.
With prefix argument REOPEN, reopen environment afterwards."
  (declare (modes LaTeX-mode))
  (interactive "*P")
  (if (> (point)
         (save-excursion
           (beginning-of-line)
           (when LaTeX-insert-into-comments
             (if (looking-at comment-start-skip)
                 (goto-char (match-end 0))))
           (skip-chars-forward " \t")
           (point)))
      (LaTeX-newline))
  (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)
      (unless (= (forward-line 1) 0)
        (insert "\n")))
    (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)
                       (if (save-excursion (goto-char marker)
                                           (bolp))
                           (1- marker)
                         marker))
        (move-marker marker nil)))))