Browse files

Don't replace buffer when stylish-haskell fails.

  • Loading branch information...
1 parent 32fae3b commit 344c0e1a72745c8415bc6b33eff4b9208c08ee49 Luminous Fennell committed Jun 3, 2012
Showing with 9 additions and 1 deletion.
  1. +9 −1 haskell-mode.el
@@ -760,12 +760,20 @@ This function will be called with no arguments.")
(when haskell-tags-on-save
+(defun haskell-mode-buffer-apply-command (cmd)
+ "Execute shell command CMD with current buffer as input and
+ replace the whole buffer with the output. If CMD fails the
+ buffer remains unchanged"
+ (when (= 0 (shell-command-on-region (point-min) (point-max) cmd))
+ (erase-buffer)
+ (insert-buffer "*Shell Command Output*")))
(defun haskell-mode-stylish-buffer ()
"Apply stylish-haskell to the current buffer."
(let ((column (current-column))
(line (line-number-at-pos)))
- (shell-command-on-region (point-min) (point-max) "stylish-haskell" (current-buffer))
+ (haskell-mode-buffer-apply-command "stylish-haskell")
(goto-line line)
(goto-char (+ column (point)))))

0 comments on commit 344c0e1

Please sign in to comment.