                        "--name" buffer-file-name
                        "--output" outputfile bufferfile))))
              (progn
-               (call-process-region
-                 (point-min) (point-max) "diff" nil patchbuf nil "-n" "-"
-                 outputfile)
-               (ocamlformat--apply-rcs-patch patchbuf)
+               (if ocamlformat--support-replace-buffer-contents
+		   (replace-buffer-contents (find-file-noselect outputfile))
+		 (ocamlformat--patch-buffer outputfile))
                (message "Applied ocamlformat"))
              (if errbuf
                (progn

                 (ocamlformat--process-errors
                   (buffer-file-name) bufferfile errorfile errbuf)))
             (message "Could not apply ocamlformat"))))
     (kill-buffer patchbuf)
     (delete-file errorfile)
     (delete-file bufferfile)
     (delete-file outputfile)))

                (get-buffer-create "*compilation*"))
              ((eq ocamlformat-show-errors 'echo)
                (get-buffer-create "*OCamlFormat stderr*"))))
          (coding-system-for-read 'utf-8)
          (coding-system-for-write 'utf-8)
          (margin-args
