Is there a good way to highlight all compilation errors in emacs, specifically in haskell-mode?
next-error (C-x `) highlights only a single error, but it doesn't set
match-data to the error, at least in
haskell-mode, with its
haskell-interactive-mode-next-error. Even less helpfully, it calls
(error "No more errors") at the last error, so I think maybe it is only meant to be called interactively.
I did the following to create highlight overlays at every compilation error, but it is really clunky and unreliable.
next-error-function is supposed to be defined by the compilation mode (
haskell-interaction-mode in my case); on return, match-data seems to point to some string. I use the variable
compilation-highlight-overlay to get the overlay that next-error creates.
(let (buf (just-started t) errors overlays) ;; Ask next-error to create all the highlighting overlays, save ;; their locations, then delete them, use the locations to ;; create our own overlays. (ignore-errors (when (setq buf (next-error-find-buffer)) (save-match-data (save-excursion (dotimes (max-iter 10) (with-current-buffer buf (funcall next-error-function 1 just-started) (setq just-started nil) (let* ((o compilation-highlight-overlay) (start (overlay-start o)) (end (overlay-end o))) ;; (message "Found (%s,%s)" start end) (push (cons start end) errors) (push o overlays)))))))) (mapc 'delete-overlay overlays) (dolist (err errors) (let ((o (make-overlay (car err) (cdr err)))) (overlay-put o 'category 'error-highlight))))
Is there some kind of canonical way of doing this?