From 4e45b41485bf86b29e9630052c0178b78554ec63 Mon Sep 17 00:00:00 2001 From: Matthew Wraith Date: Wed, 6 Apr 2016 13:37:12 -0500 Subject: [PATCH 1/2] Stylish-haskell runs on buffer instead of file on disk --- haskell-commands.el | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/haskell-commands.el b/haskell-commands.el index 519a77e5f..3cb37e2e2 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -806,47 +806,33 @@ inferior GHCi process." Use buffer as input and replace the whole buffer with the output. If CMD fails the buffer remains unchanged." (set-buffer-modified-p t) - (let* ((chomp (lambda (str) - (while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'" str) - (setq str (replace-match "" t t str))) - str)) - (_errout (lambda (fmt &rest args) - (let* ((warning-fill-prefix " ")) - (display-warning cmd (apply 'format fmt args) :warning)))) - (filename (buffer-file-name (current-buffer))) - (cmd-prefix (replace-regexp-in-string " .*" "" cmd)) - (tmp-file (make-temp-file cmd-prefix)) - (err-file (make-temp-file cmd-prefix)) + (let* ((cmd-prefix (replace-regexp-in-string " .*" "" cmd)) + (tmp-buf (generate-new-buffer cmd-prefix)) (default-directory (if (and (boundp 'haskell-session) haskell-session) (haskell-session-cabal-dir haskell-session) default-directory)) - (_errcode (with-temp-file tmp-file - (call-process cmd filename - (list (current-buffer) err-file) nil))) - (stderr-output - (with-temp-buffer - (insert-file-contents err-file) - (funcall chomp (buffer-substring-no-properties (point-min) (point-max))))) + (_errcode + (call-process-region (point-min) (point-max) cmd nil tmp-buf nil)) (stdout-output (with-temp-buffer - (insert-file-contents tmp-file) + (insert-buffer tmp-buf) (buffer-substring-no-properties (point-min) (point-max))))) - (if (string= "" stderr-output) + (if (zerop _errcode) (if (string= "" stdout-output) (message "Error: %s produced no output, leaving buffer alone" cmd) (save-restriction (widen) ;; command successful, insert file with replacement to preserve ;; markers. - (insert-file-contents tmp-file nil nil nil t))) + (erase-buffer) + (insert-buffer tmp-buf))) (progn ;; non-null stderr, command must have failed (message "Error: %s ended with errors, leaving buffer alone" cmd) ;; use (warning-minimum-level :debug) to see this (display-warning cmd stderr-output :debug))) - (delete-file tmp-file) - (delete-file err-file))) + (kill-buffer tmp-buf))) ;;;###autoload (defun haskell-mode-find-uses () From d1f4ed524294a23305a55e2a939d36bc56ad7149 Mon Sep 17 00:00:00 2001 From: Matthew Wraith Date: Wed, 6 Apr 2016 14:02:38 -0500 Subject: [PATCH 2/2] Handle stylish-haskell errors --- haskell-commands.el | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/haskell-commands.el b/haskell-commands.el index 3cb37e2e2..8595a3781 100644 --- a/haskell-commands.el +++ b/haskell-commands.el @@ -806,19 +806,23 @@ inferior GHCi process." Use buffer as input and replace the whole buffer with the output. If CMD fails the buffer remains unchanged." (set-buffer-modified-p t) - (let* ((cmd-prefix (replace-regexp-in-string " .*" "" cmd)) - (tmp-buf (generate-new-buffer cmd-prefix)) + (let* ((tmp-buf (generate-new-buffer " output")) + (err-buf (generate-new-buffer " error")) (default-directory (if (and (boundp 'haskell-session) haskell-session) (haskell-session-cabal-dir haskell-session) default-directory)) (_errcode - (call-process-region (point-min) (point-max) cmd nil tmp-buf nil)) + (call-process-region (point-min) (point-max) cmd nil (list (buffer-name tmp-buf) (buffer-name err-buf)) nil)) + (stderr-output + (with-temp-buffer + (insert-buffer err-buf) + (buffer-substring-no-properties (point-min) (point-max)))) (stdout-output (with-temp-buffer (insert-buffer tmp-buf) (buffer-substring-no-properties (point-min) (point-max))))) - (if (zerop _errcode) + (if (string= "" stderr-output) (if (string= "" stdout-output) (message "Error: %s produced no output, leaving buffer alone" cmd) (save-restriction @@ -832,6 +836,7 @@ output. If CMD fails the buffer remains unchanged." (message "Error: %s ended with errors, leaving buffer alone" cmd) ;; use (warning-minimum-level :debug) to see this (display-warning cmd stderr-output :debug))) + (kill-buffer err-buf) (kill-buffer tmp-buf))) ;;;###autoload