Function: LaTeX-backward-up-environment

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

Signature

(LaTeX-backward-up-environment &optional ARG)

Documentation

Move backward out of the enclosing environment.

Helper function of LaTeX-current-environment(var)/LaTeX-current-environment(fun) and LaTeX-find-matching-begin. With optional ARG>=1, find that outer level. Return non-nil if the operation succeeded.

Assume the current point is on neither "begin{foo}" nor "end{foo}".

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-backward-up-environment (&optional arg)
  "Move backward out of the enclosing environment.
Helper function of `LaTeX-current-environment' and
`LaTeX-find-matching-begin'.
With optional ARG>=1, find that outer level.
Return non-nil if the operation succeeded.

Assume the current point is on neither \"begin{foo}\" nor \"end{foo}\"."
  (setq arg (if arg (if (< arg 1) 1 arg) 1))
  (let* ((in-comment (TeX-in-commented-line))
         (comment-prefix (and in-comment (TeX-comment-prefix)))
         (case-fold-search nil))
    (while (and (/= arg 0)
                (re-search-backward
                 (concat (regexp-quote TeX-esc) "\\(begin\\|end\\)\\b") nil t))
      (when (or (and LaTeX-syntactic-comments
                     (eq in-comment (TeX-in-commented-line))
                     (or (not in-comment)
                         ;; Consider only matching prefixes in the
                         ;; commented case.
                         (string= comment-prefix (TeX-comment-prefix))))
                (and (not LaTeX-syntactic-comments)
                     (not (TeX-in-commented-line)))
                ;; macrocode*? in docTeX-mode is special since we have
                ;; also regular code lines not starting with a
                ;; comment-prefix.  Hence, the next check just looks
                ;; if we're inside such a group and returns non-nil to
                ;; recognize such a situation.
                (and (eq major-mode 'docTeX-mode)
                     (looking-at-p (concat (regexp-quote TeX-esc)
                                   "\\(?:begin\\|end\\) *{macrocode\\*?}"))))
        (setq arg (if (= (char-after (match-beginning 1)) ?e)
                      (1+ arg)
                    (1- arg)))))
    (= arg 0)))