diff --git a/elisp/hindent.el b/elisp/hindent.el
--- a/elisp/hindent.el
+++ b/elisp/hindent.el
@@ -59,12 +59,15 @@
                               (col (current-column)))
                           (delete-region (car start-end)
                                          (cdr start-end))
-                          (insert new-str)
-                          (goto-char (point-min))
-                          (forward-line (1- line))
-                          (goto-char (+ (line-beginning-position) col))
-                          (when (looking-back "^[ ]+")
-                            (back-to-indentation))
+                          (let ((new-start (point)))
+                            (insert new-str)
+                            (let ((new-end (point)))
+                              (goto-char (point-min))
+                              (forward-line (1- line))
+                              (goto-char (+ (line-beginning-position) col))
+                              (when (looking-back "^[ ]+")
+                                (back-to-indentation))
+                              (delete-trailing-whitespace new-start new-end)))
                           (message "Formatted."))
                       (message "Already formatted.")))))))))))))
 
diff --git a/hindent.cabal b/hindent.cabal
--- a/hindent.cabal
+++ b/hindent.cabal
@@ -1,5 +1,5 @@
 name:                hindent
-version:             3.3
+version:             3.4
 synopsis:            Extensible Haskell pretty printer
 description:         Extensible Haskell pretty printer. Both a library and an executable.
                      .
