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