@@ -789,47 +789,43 @@ inferior GHCi process."
789
789
Use buffer as input and replace the whole buffer with the
790
790
output. If CMD fails the buffer remains unchanged."
791
791
(set-buffer-modified-p t )
792
- (let* ((chomp (lambda (str )
793
- (while (string-match " \\ `\n+\\|^\\s-+\\|\\s-+$\\|\n+\\' " str)
794
- (setq str (replace-match " " t t str)))
795
- str))
796
- (_errout (lambda (fmt &rest args )
797
- (let* ((warning-fill-prefix " " ))
798
- (display-warning cmd (apply 'format fmt args) :warning ))))
799
- (filename (buffer-file-name (current-buffer )))
800
- (cmd-prefix (replace-regexp-in-string " .*" " " cmd))
801
- (tmp-file (make-temp-file cmd-prefix))
802
- (err-file (make-temp-file cmd-prefix))
792
+ (let* ((tmp-buf (generate-new-buffer " stylish-output" ))
793
+ (err-file (make-temp-file " stylish-error" ))
803
794
(default-directory (if (and (boundp 'haskell-session )
804
795
haskell-session)
805
796
(haskell-session-cabal-dir haskell-session)
806
- default-directory))
807
- (_errcode (with-temp-file tmp-file
808
- (call-process cmd filename
809
- (list (current-buffer ) err-file) nil )))
810
- (stderr-output
811
- (with-temp-buffer
812
- (insert-file-contents err-file)
813
- (funcall chomp (buffer-substring-no-properties (point-min ) (point-max )))))
814
- (stdout-output
815
- (with-temp-buffer
816
- (insert-file-contents tmp-file)
817
- (buffer-substring-no-properties (point-min ) (point-max )))))
818
- (if (string= " " stderr-output)
819
- (if (string= " " stdout-output)
820
- (message " Error: %s produced no output, leaving buffer alone " cmd)
821
- (save-restriction
822
- (widen )
823
- ; ; command successful, insert file with replacement to preserve
824
- ; ; markers.
825
- (insert-file-contents tmp-file nil nil nil t )))
826
- (progn
827
- ; ; non-null stderr, command must have failed
828
- (message " Error: %s ended with errors, leaving buffer alone " cmd)
829
- ; ; use (warning-minimum-level :debug) to see this
830
- (display-warning cmd stderr-output :debug )))
831
- (delete-file tmp-file)
832
- (delete-file err-file)))
797
+ default-directory)))
798
+ (unwind-protect
799
+ (let* ((_errcode
800
+ (call-process-region (point-min ) (point-max ) cmd nil
801
+ (list (buffer-name tmp-buf) err-file)
802
+ nil ))
803
+ (stderr-output
804
+ (with-temp-buffer
805
+ (insert-file-contents err-file)
806
+ (buffer-substring-no-properties (point-min ) (point-max ))))
807
+ (stdout-output
808
+ (with-temp-buffer
809
+ (insert-buffer-substring tmp-buf)
810
+ (buffer-substring-no-properties (point-min ) (point-max )))))
811
+ (if (string= " " stderr-output)
812
+ (if (string= " " stdout-output)
813
+ (message " Error: %s produced no output, leaving buffer alone " cmd)
814
+ (save-restriction
815
+ (widen )
816
+ ; ; command successful, insert file with replacement to preserve
817
+ ; ; markers.
818
+ (erase-buffer )
819
+ (insert-buffer-substring tmp-buf)))
820
+ (progn
821
+ ; ; non-null stderr, command must have failed
822
+ (message " Error: %s ended with errors, leaving buffer alone " cmd)
823
+ ; ; use (warning-minimum-level :debug) to see this
824
+ (display-warning cmd stderr-output :debug ))))
825
+ (ignore-errors
826
+ (delete-file err-file))
827
+ (ignore-errors
828
+ (kill-buffer tmp-buf)))))
833
829
834
830
;;;### autoload
835
831
(defun haskell-mode-find-uses ()
0 commit comments