Function: tex-validate-region

tex-validate-region is an interactive and byte-compiled function defined in tex-mode.el.gz.

Signature

(tex-validate-region START END)

Documentation

Check for mismatched braces or $'s in region.

Returns t if no mismatches. Returns nil and moves point to suspect area if a mismatch is found.

View in manual

Probably introduced at or before Emacs version 20.4.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/tex-mode.el.gz
(defun tex-validate-region (start end)
  "Check for mismatched braces or $'s in region.
Returns t if no mismatches.  Returns nil and moves point to suspect
area if a mismatch is found."
  (interactive "r")
  (let ((failure-point nil) (max-possible-sexps (- end start)))
    (save-excursion
      (condition-case ()
	  (save-restriction
	    (narrow-to-region start end)
	    ;; First check that the open and close parens balance in numbers.
	    (goto-char start)
	    (while (and (not (eobp))
			(<= 0 (setq max-possible-sexps
				    (1- max-possible-sexps))))
	      (forward-sexp 1))
	    ;; Now check that like matches like.
	    (goto-char start)
	    (while (re-search-forward "\\s(" nil t)
	      (save-excursion
		(let ((pos (match-beginning 0)))
		  (goto-char pos)
		  (skip-chars-backward "\\\\") ; escaped parens
		  (forward-sexp 1)
		  (or (eq (preceding-char) (cdr (syntax-after pos)))
		      (eq (char-after pos) (cdr (syntax-after (1- (point)))))
		      (error "Mismatched parentheses"))))))
	(error
	 (skip-syntax-forward " .>")
	 (setq failure-point (point)))))
    (if failure-point (goto-char failure-point))
    (not failure-point)))