3737(require 'highlight-uses-mode )
3838(require 'haskell-cabal )
3939
40+ (defcustom haskell-mode-stylish-haskell-path " stylish-haskell"
41+ " Path to `stylish-haskell' executable."
42+ :group 'haskell
43+ :type 'string )
44+
4045;;;### autoload
4146(defun haskell-process-restart ()
4247 " Restart the inferior Haskell process."
@@ -783,7 +788,7 @@ inferior GHCi process."
783788 (interactive )
784789 (let ((column (current-column ))
785790 (line (line-number-at-pos )))
786- (haskell-mode-buffer-apply-command " stylish-haskell" )
791+ (haskell-mode-buffer-apply-command haskell-mode- stylish-haskell-path )
787792 (goto-char (point-min ))
788793 (forward-line (1- line))
789794 (goto-char (+ column (point )))))
@@ -793,47 +798,39 @@ inferior GHCi process."
793798Use buffer as input and replace the whole buffer with the
794799output. If CMD fails the buffer remains unchanged."
795800 (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)))))
837834
838835;;;### autoload
839836(defun haskell-mode-find-uses ()
0 commit comments