Function: latex-forward-sexp-1
latex-forward-sexp-1 is a byte-compiled function defined in
tex-mode.el.gz.
Signature
(latex-forward-sexp-1)
Documentation
Like (forward-sexp 1) but aware of multi-char elements and escaped parens.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/tex-mode.el.gz
;; Note this does not handle things like mismatched brackets inside
;; begin/end blocks.
;; Needs to handle escaped parens for tex-validate-*.
;; https://lists.gnu.org/r/bug-gnu-emacs/2007-09/msg00038.html
;; Does not handle escaped parens when latex-handle-escaped-parens is nil.
(defun latex-forward-sexp-1 ()
"Like (forward-sexp 1) but aware of multi-char elements and escaped parens."
(let ((pos (point))
(forward-sexp-function))
(forward-sexp 1)
(let ((newpos (point)))
(skip-syntax-backward "/w")
(cond
((looking-at "\\\\end\\>")
(signal 'scan-error
(list "Containing expression ends prematurely"
(point)
(prog1
(progn (ignore-errors (forward-sexp 2)) (point))
(goto-char pos)))))
((looking-at "\\\\begin\\>")
(goto-char (match-end 0))
(tex-next-unmatched-end))
;; A better way to handle this, \( .. \) etc, is probably to
;; temporarily change the syntax of the \ in \( to punctuation.
((and latex-handle-escaped-parens
(looking-back "\\\\[])}]" (- (point) 2)))
(signal 'scan-error
(list "Containing expression ends prematurely"
(- (point) 2) (prog1 (point)
(goto-char pos)))))
((and latex-handle-escaped-parens
(looking-back "\\\\\\([({[]\\)" (- (point) 2)))
(tex-next-unmatched-eparen (match-string 1)))
(t (goto-char newpos))))))