mpickering / hlint-refactor-mode

Emacs bindings for hlint's --refactor option
MIT License
27 stars 5 forks source link

ennoying stderr in the buffer #11

Open jbpotonnier opened 5 years ago

jbpotonnier commented 5 years ago

When applying refactoring, hlint command sometimes produce messages on stderr, that appear in the target buffer, introducing compilation error.

For example : "Loaded package environment from /home/path/to/my/project/src/.ghc.environment.x86_64-linux-8.6.3"

I suggest to modify the call-process-region like this, to avoid copying stderr in tte buffer.

(defun hlint-refactor-call-process-region-checked (start end program &optional args)
  "Send text from START to END to PROGRAM with ARGS.
This is a wrapper around `call-process-region' that doesn't replace
the region with the output of PROGRAM if it returned a non-zero
exit code."
  (let ((exit (apply 'call-process-region
                     start end
                     program            ; name of program
                     t                  ; delete region
                     '(t nil)           ; send output to buffer, ignoring stderr
                     nil                ; no redisplay during output
                     args
                     )))
    (unless (eq exit 0) (primitive-undo 1 buffer-undo-list))))