]> git.eshelyaron.com Git - emacs.git/commitdiff
(validate-tex-buffer): Record mismatches in *Occur*.
authorRichard M. Stallman <rms@gnu.org>
Sat, 31 Jul 1993 07:33:02 +0000 (07:33 +0000)
committerRichard M. Stallman <rms@gnu.org>
Sat, 31 Jul 1993 07:33:02 +0000 (07:33 +0000)
lisp/textmodes/tex-mode.el

index e6db1dafcdfa10700e2bc65e489e1192e980d825..edf48c17d651f0c4d6ad5266cb3da98795104b6b 100644 (file)
@@ -506,23 +506,59 @@ inserts \" characters."
 
 (defun validate-tex-buffer ()
   "Check current buffer for paragraphs containing mismatched $s.
-As each such paragraph is found, a mark is pushed at its beginning,
-and the location is displayed for a few seconds."
+Their positions are recorded in the buffer `*Occur*'.
+To find a particular invalidity from `*Occur*',
+switch to to that buffer and type C-c C-c on the line
+for the invalidity you want to see."
   (interactive)
-  (let ((opoint (point)))
-    (goto-char (point-max))
-    ;; Does not use save-excursion
-    ;; because we do not want to save the mark.
-    (unwind-protect
+  (let ((buffer (current-buffer))
+       (prevpos (point-min))
+       (linenum nil))
+    (with-output-to-temp-buffer "*Occur*"
+      (princ "Mismatches:\n")
+      (save-excursion
+       (set-buffer standard-output)
+       (occur-mode)
+       (setq occur-buffer buffer)
+       (setq occur-nlines 0)
+       (setq occur-pos-list nil))
+      (save-excursion
+       (goto-char (point-max))
        (while (and (not (input-pending-p)) (not (bobp)))
          (let ((end (point)))
+           ;; Scan the previous paragraph for invalidities.
            (search-backward "\n\n" nil 'move)
            (or (tex-validate-region (point) end)
-               (progn
-                 (push-mark (point))
-                 (message "Mismatch found in paragraph starting here")
-                 (sit-for 4)))))
-      (goto-char opoint))))
+               (let* ((end (save-excursion (forward-line 1) (point)))
+                      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*
+                 ;; and at the beginning of occur-pos-list.
+                 (save-excursion
+                   (setq tem (point-marker))
+                   (set-buffer standard-output)
+                   (goto-char (point-min))
+                   ;; Skip "Mismatches:" header line.
+                   (forward-line 1)
+                   (setq occur-pos-list (cons tem occur-pos-list))
+                   (insert-buffer-substring buffer start end)
+                   (forward-char (- start end))
+                   (insert (format "%3d: " linenum))))))))
+      (save-excursion
+       (set-buffer standard-output)
+       (if (null occur-pos-list)
+           (insert "None!\n"))
+       (if (interactive-p)
+           (message "%d mismatches found" (length occur-pos-list)))))))
 
 (defun tex-validate-region (start end)
   "Check for mismatched braces or $'s in region.