Function: LaTeX-modify-environment

LaTeX-modify-environment is a byte-compiled function defined in latex.el.

Signature

(LaTeX-modify-environment ENVIRONMENT)

Documentation

Modify current environment to new ENVIRONMENT.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-modify-environment (environment)
  "Modify current environment to new ENVIRONMENT."
  (let ((goto-end (lambda ()
                    (LaTeX-find-matching-end)
                    (re-search-backward (concat (regexp-quote TeX-esc)
                                                "end"
                                                (regexp-quote TeX-grop)
                                                (LaTeX-environment-name-regexp)
                                                (regexp-quote TeX-grcl))
                                        (line-beginning-position))))
        (goto-begin (lambda ()
                      (LaTeX-find-matching-begin)
                      (prog1 (point)
                        (re-search-forward (concat (regexp-quote TeX-esc)
                                                   "begin"
                                                   (regexp-quote TeX-grop)
                                                   (LaTeX-environment-name-regexp)
                                                   (regexp-quote TeX-grcl))
                                           (line-end-position))))))
    (save-excursion
      (funcall goto-end)
      (let ((old-env (match-string-no-properties 1))
            beg-pos)
        (replace-match environment t t nil 1)
        ;; This failed when \begin and \end lie on the same line. (bug#58689)
        ;; (beginning-of-line 1)
        (setq beg-pos (funcall goto-begin))
        (replace-match environment t t nil 1)
        ;; (end-of-line 1)
        (run-hook-with-args 'LaTeX-after-modify-env-hook
                            environment old-env
                            beg-pos
                            (funcall goto-end))))))