Function: tex-validate-buffer

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

Signature

(tex-validate-buffer)

Documentation

Check current buffer for paragraphs containing mismatched braces or $s.

Their positions are recorded in the buffer *Occur*. To find a particular invalidity from *Occur*, switch to that buffer and type C-c C-c or click with mouse-2 on the line for the invalidity you want to see.

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-buffer ()
  "Check current buffer for paragraphs containing mismatched braces or $s.
Their positions are recorded in the buffer `*Occur*'.
To find a particular invalidity from `*Occur*', switch to that buffer
and type C-c C-c or click with mouse-2
on the line for the invalidity you want to see."
  (interactive)
  (let ((buffer (current-buffer))
	(prevpos (point-min))
	(linenum nil)
	(num-matches 0))
    (with-output-to-temp-buffer "*Occur*"
      (princ "Mismatches:\n")
      (with-current-buffer standard-output
	(occur-mode)
	;; This won't actually work...Really, this whole thing should
	;; be rewritten instead of being a hack on top of occur.
	(setq occur-revert-arguments (list nil 0 (list buffer))))
      (save-excursion
	(goto-char (point-max))
	;; Do a little shimmy to place point at the end of the last
	;; "real" paragraph. Need to avoid validating across an \end,
	;; because that blows up latex-forward-sexp.
	(backward-paragraph)
	(forward-paragraph)
	(while (not (bobp))
	    ;; Scan the previous paragraph for invalidities.
	  (backward-paragraph)
	  (save-excursion
	    (or (tex-validate-region (point) (save-excursion
					       (forward-paragraph)
					       (point)))
		(let ((end (line-beginning-position 2))
		       start tem)
		  (beginning-of-line)
		  (setq start (point))
		  ;; Keep track of line number as we scan,
		  ;; in a cumulative fashion.
		  (if linenum
		      (setq linenum (- linenum
				       (count-lines prevpos (point))))
		    (setq linenum (1+ (count-lines 1 start))))
		  (setq prevpos (point))
		  ;; Mention this mismatch in *Occur*.
		  ;; Since we scan from end of buffer to beginning,
		  ;; add each mismatch at the beginning of *Occur*.
		  (save-excursion
		    (setq tem (point-marker))
		    (set-buffer standard-output)
		    (goto-char (point-min))
		    ;; Skip "Mismatches:" header line.
		    (forward-line 1)
		    (setq num-matches (1+ num-matches))
                    (let ((inhibit-read-only t))
		      (insert-buffer-substring buffer start end)
		      (let ((text-end (point-marker))
                            text-beg)
                        (forward-char (- start end))
                        (setq text-beg (point-marker))
                        (insert (format "%3d: " linenum))
                        (add-text-properties
                         text-beg (- text-end 1)
                         '(mouse-face highlight
				      help-echo
				      "mouse-2: go to this invalidity"))
                        (put-text-property (point) (- text-end 1)
					   'occur-match t)
                        (put-text-property text-beg text-end
					   'occur-target tem)))))))))
      (with-current-buffer standard-output
	(let ((no-matches (zerop num-matches))
              (inhibit-read-only t))
	  (if no-matches
	      (insert "None!\n"))
	  (if (called-interactively-p 'interactive)
	      (message (cond (no-matches "No mismatches found")
			     ((= num-matches 1) "1 mismatch found")
			     (t "%d mismatches found"))
		       num-matches)))))))