Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't replace buffer when stylish-haskell fails.

  • Loading branch information...
commit 344c0e1a72745c8415bc6b33eff4b9208c08ee49 1 parent 32fae3b
@mstrlu mstrlu authored
Showing with 9 additions and 1 deletion.
  1. +9 −1 haskell-mode.el
View
10 haskell-mode.el
@@ -760,12 +760,20 @@ This function will be called with no arguments.")
(when haskell-tags-on-save
(haskell-process-generate-tags)))))
+(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."
(interactive)
(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)))))
Please sign in to comment.
Something went wrong with that request. Please try again.