             (const :tag "Echo area" echo)
             (const :tag "None" nil))
       :group 'reason-fmt)
+
+(defcustom reasonfmt-width-mode nil
+  "Specify width when formatting buffer contents."
+  :type '(choice
+          (const :tag "Window width" window)
+          (const :tag "Fill column" fill)
+          (const :tag "None" nil))
+  :group 'reason-fmt)
 
 ;;;###autoload
 (defun reasonfmt-before-save ()

                 (erase-buffer)))
           (with-current-buffer patchbuf
                         (erase-buffer))
           (if (zerop (call-process reasonfmt-command nil (list (list :file outputfile) errorfile)
                                    nil "-parse" "re" "-print" "re" bufferfile))
               (progn
                 (call-process-region (point-min) (point-max) "diff" nil patchbuf nil "-n" "-"
                                      outputfile)

         (errbuf (if reasonfmt-show-errors (get-buffer-create "*Reasonfmt Errors*")))
         (patchbuf (get-buffer-create "*Reasonfmt patch*"))
         (coding-system-for-read 'utf-8)
         (coding-system-for-write 'utf-8)
         (width-args
          (cond
           ((equal reasonfmt-width-mode 'window)
            (list "-print-width" (number-to-string (window-body-width))))
           ((equal reasonfmt-width-mode 'fill)
            (list "-print-width" (number-to-string fill-column)))
           (t
            '()))))
     (unwind-protect
         (save-restriction
           (widen)
