[comp.emacs] a new-next-error command for gnu-emacs lovers

cef@wb1.cs.cmu.edu.UUCP (04/17/87)

Well, I finally got fed up enough to do something about it. How many 
times have you ran a compilation or a grep and wanted to skip over some of
the errors (finds) for whatever reason. Well, I wrote a new command
that accepts a prefix argument to say how many errors (finds) to skip over.
As the documentation string says, give it a positive prefix arg and it will
skip over that many errors. Give it zero as a prefix arg, and it will reparse
the errors and start again. I blew off negative prefix args... maybe later.

Enjoy

Charlie Fineman
cef@h.cs.cmu.edu!seismo

----------------------------------- CUT HERE ---------------------------------

(defun new-next-error (&optional argp)
  "Visit next compilation error message and corresponding source code.
This operates on the output from the \\[compile] command.
If all preparsed error messages have been processed,
the error message buffer is checked for new ones.
If the prefix arg is 0, it means reparse the error message
buffer and start at the first error. A positive prefix arg
means move forward that many errors. A negative prefix arg
will generate an error."
  (interactive "p")
  (if (or (eq compilation-error-list t)
	  (eq argp 0))
      (progn (compilation-forget-errors)
	     (setq compilation-parsing-end 1)))
  (if compilation-error-list
      nil
    (save-excursion
      (switch-to-buffer "*compilation*")
      (set-buffer-modified-p nil)
      (compilation-parse-errors)))
  (let ((next-error (nth (or argp 1) compilation-error-list)))
    (if (null next-error)
	(error (concat compilation-error-message
		       (if (and compilation-process
				(eq (process-status compilation-process)
				    'run))
			   " yet" ""))))
    (setq compilation-error-list (nthcdr (or argp 1) compilation-error-list))
    (if (null (car (cdr next-error)))
	nil
      (switch-to-buffer (marker-buffer (car (cdr next-error))))
      (goto-char (car (cdr next-error)))
      (set-marker (car (cdr next-error)) nil))
    (let* ((pop-up-windows t)
	   (w (display-buffer (marker-buffer (car next-error)))))
      (set-window-point w (car next-error))
      (set-window-start w (car next-error)))
    (set-marker (car next-error) nil)))