- (save-excursion
- (skip-chars-forward " \t")
- (or
- ;; Stick the first line at column 0.
- (and (= (point-min) (line-beginning-position)) 0)
- ;; Trust the current indentation, if such info is applicable.
- (and virtual (save-excursion (skip-chars-backward " \t&") (bolp))
- (current-column))
- ;; Stick verbatim environments to the left margin.
- (and (looking-at "\\\\\\(begin\\|end\\) *{\\([^\n}]+\\)")
- (member (match-string 2) tex-verbatim-environments)
- 0)
- ;; Put leading close-paren where the matching open paren would be.
- (and (or (eq (latex-syntax-after) ?\))
- ;; Try to handle escaped close parens.
- (and (looking-at "\\\\\\([])}]\\)")
- (goto-char (match-beginning 1))))
- (ignore-errors
- (save-excursion
- (latex-skip-close-parens)
- (latex-backward-sexp-1)
- (latex-find-indent 'virtual))))
- ;; Default (maybe an argument)
- (let ((pos (point))
- ;; Outdent \item if necessary.
- (indent (if (looking-at tex-indent-item-re) (- tex-indent-item) 0))
- up-list-pos)
- ;; Find the previous point which determines our current indentation.
- (condition-case err
- (progn
- (latex-backward-sexp-1)
- (while (> (current-column) (current-indentation))
- (latex-backward-sexp-1)))
- (scan-error
- (setq up-list-pos (nth 2 err))))
- (cond
- ((= (point-min) pos) 0) ; We're really just indenting the first line.
- ((integerp up-list-pos)
- ;; Have to indent relative to the open-paren.
- (goto-char up-list-pos)
- (if (and (not tex-indent-allhanging)
- (save-excursion
- ;; Make sure we're an argument to a macro and
- ;; that the macro is at the beginning of a line.
- (condition-case nil
- (progn
- (while (eq (char-syntax (char-after)) ?\()
- (forward-sexp -1))
- (and (eq (char-syntax (char-after)) ?/)
- (progn (skip-chars-backward " \t&")
- (bolp))))
- (scan-error nil)))
- (> pos (progn (latex-down-list)
- (forward-comment (point-max))
- (point))))
- ;; Align with the first element after the open-paren.
- (current-column)
- ;; We're the first element after a hanging brace.
+ (let ((latex-handle-escaped-parens latex-indent-within-escaped-parens))
+ (save-excursion
+ (skip-chars-forward " \t")
+ (or
+ ;; Stick the first line at column 0.
+ (and (= (point-min) (line-beginning-position)) 0)
+ ;; Trust the current indentation, if such info is applicable.
+ (and virtual (save-excursion (skip-chars-backward " \t&") (bolp))
+ (current-column))
+ ;; Stick verbatim environments to the left margin.
+ (and (looking-at "\\\\\\(begin\\|end\\) *{\\([^\n}]+\\)")
+ (member (match-string 2) tex-verbatim-environments)
+ 0)
+ ;; Put leading close-paren where the matching open paren would be.
+ (let (escaped)
+ (and (or (eq (latex-syntax-after) ?\))
+ ;; Try to handle escaped close parens but keep
+ ;; original position if it doesn't work out.
+ (and latex-handle-escaped-parens
+ (setq escaped (looking-at "\\\\\\([])}]\\)"))))
+ (ignore-errors
+ (save-excursion
+ (when escaped
+ (goto-char (match-beginning 1)))
+ (latex-skip-close-parens)
+ (latex-backward-sexp-1)
+ (latex-find-indent 'virtual)))))
+ ;; Default (maybe an argument)
+ (let ((pos (point))
+ ;; Outdent \item if necessary.
+ (indent (if (looking-at tex-indent-item-re) (- tex-indent-item) 0))
+ up-list-pos)
+ ;; Find the previous point which determines our current indentation.
+ (condition-case err
+ (progn
+ (latex-backward-sexp-1)
+ (while (> (current-column) (current-indentation))
+ (latex-backward-sexp-1)))
+ (scan-error
+ (setq up-list-pos (nth 2 err))))
+ (cond
+ ((= (point-min) pos) 0) ; We're really just indenting the first line.
+ ((integerp up-list-pos)
+ ;; Have to indent relative to the open-paren.