 ;;
 
 ;;;###autoload
-(defun +format-buffer ()
+(defun +format-buffer (formatter mode-result)
   "Format the source code in the current buffer.
 
 Returns any of the following values:


See `+format/buffer' for the interactive version of this function, and
`+format|buffer' to use as a `before-save-hook' hook."
  (require 'format-all)
  (cl-destructuring-bind (formatter mode-result)
      (format-all-probe)
    (unless formatter
      (error "Don't know how to format %S code" major-mode))
    (let ((f-function (gethash formatter format-all-format-table))
          (executable (format-all-formatter-executable formatter)))
      (cl-destructuring-bind (output errput first-diff)
          (+format--with-copy-of-buffer f-function executable mode-result)
        (unwind-protect
            (cond ((null output) 'error)
                  ((eq output t) 'noop)
                  ((let ((tmpfile (make-temp-file "doom-format"))
                         (patchbuf (get-buffer-create " *doom format patch*"))
                         (coding-system-for-read 'utf-8)
                         (coding-system-for-write 'utf-8))
                     (unwind-protect
                         (progn
                           (with-current-buffer patchbuf (erase-buffer))
                           (with-temp-file tmpfile (erase-buffer) (insert output))
                           (if (zerop (call-process-region (point-min) (point-max) "diff" nil patchbuf nil "-n" "-" tmpfile))
                               'noop
                             (+format--apply-rcs-patch patchbuf)
                             (list output errput first-diff))))
                     (kill-buffer patchbuf)
                     (delete-file tmpfile))))
          (unless (= 0 (length errput))
            (message "Formatter error output:\n%s" errput)))))))


;;

  (add-hook 'before-save-hook #'+format|buffer nil t))

;;;###autoload
(defun +format|buffer ()
  "Format the source code in the current buffer with minimal feedback.

Meant for `before-save-hook'."
  (cl-destructuring-bind (formatter mode-result) (format-all-probe)
    (pcase (+format-buffer formatter mode-result)
      (`error (message "Failed to format buffer due to errors"))
      (`noop (message "Buffer was already formatted"))
      (_ (message "Formatted (%s)" formatter)))))

