@@ -780,21 +780,50 @@ This function will be called with no arguments.")
780
780
replace the whole buffer with the output. If CMD fails the
781
781
buffer remains unchanged."
782
782
(set-buffer-modified-p t )
783
- (let* ((filename (buffer-file-name (current-buffer )))
784
- (tmp-file (make-temp-file (replace-regexp-in-string " .*" " " cmd)))
783
+ (flet
784
+ ((chomp (str)
785
+ (while (string-match " \\ `\n+\\|^\\s-+\\|\\s-+$\\|\n+\\' "
786
+ str)
787
+ (setq str (replace-match " " t t str)))
788
+ str)
789
+ (errout
790
+ (fmt &rest args)
791
+ (let* ((warning-fill-prefix " " ))
792
+ (display-warning cmd (apply 'format fmt args) :warning ))))
793
+ (let*
794
+ ((filename (buffer-file-name (current-buffer )))
795
+ (cmd-prefix (replace-regexp-in-string " .*" " " cmd))
796
+ (tmp-file (make-temp-file cmd-prefix))
797
+ (err-file (make-temp-file cmd-prefix))
785
798
(default-directory (if (and (boundp 'haskell-session )
786
799
haskell-session)
787
800
(haskell-session-cabal-dir haskell-session)
788
801
default-directory))
789
- (nbytes (with-temp-file tmp-file
790
- (call-process cmd filename t nil )
791
- (point-max ))))
792
- (unless (= 0 nbytes)
793
- (save-restriction
794
- (widen )
795
- ; insert file with replacement to preserve markers.
796
- (insert-file-contents tmp-file nil nil nil t )))
797
- (delete-file tmp-file)))
802
+ (errcode (call-process cmd filename
803
+ (list (list :file tmp-file) err-file) nil ))
804
+ (stderr-output
805
+ (with-temp-buffer
806
+ (insert-file-contents err-file)
807
+ (chomp (buffer-substring-no-properties (point-min ) (point-max )))))
808
+ (stdout-output
809
+ (with-temp-buffer
810
+ (insert-file-contents tmp-file)
811
+ (buffer-substring-no-properties (point-min ) (point-max )))))
812
+ (if (string= " " stderr-output)
813
+ (if (string= " " stdout-output)
814
+ (errout
815
+ " Error: %s produced no output, leaving buffer alone" cmd)
816
+ (save-restriction
817
+ (widen )
818
+ ; ; command successful, insert file with replacement to preserve
819
+ ; ; markers.
820
+ (insert-file-contents tmp-file nil nil nil t )))
821
+ ; ; non-null stderr, command must have failed
822
+ (errout " %s failed: %s" cmd stderr-output)
823
+ )
824
+ (delete-file tmp-file)
825
+ (delete-file err-file)
826
+ )))
798
827
799
828
(defun haskell-mode-stylish-buffer ()
800
829
" Apply stylish-haskell to the current buffer."
0 commit comments