1

Is there a good way to highlight all compilation errors in emacs, specifically in haskell-mode?

The function 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?

1

It is very difficult to exploit next-error-function to find all errors, because it is implemented in very imperative fashion.

I have started a tiny project called complation-highlight-el that enables us to see more than one error at the same time.

https://github.com/m2ym/compilation-highlight-el

Still experimental stage, feel free to submit issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.