prettier / prettier-emacs

Minor mode to format JS code on file save
http://jlongster.com/A-Prettier-Formatter
375 stars 54 forks source link

Use insert-file-contents #21

Closed aaronjensen closed 6 years ago

aaronjensen commented 6 years ago

insert-file-contents is a built-in function that is used by revert-buffer to replace the current buffer's contents with that of a file while maintaining point position and minimizing changes in the undo stack. In other words, it does more or less what diff + prettier-js--apply-rcs-patch do with less code.

This also eliminates one of the temp files by using call-process-region.

Benchmarks between the old and the new are practically identical on my machine, so the gain is pretty much only in code reduction. It could possibly be very slightly faster on machines with slower IO.

aaronjensen commented 6 years ago

Please don't merge this yet, there may be unfavorable behavior differences (the point is not maintained perfectly) between insert-file-contents and the rcs patch technique.

aaronjensen commented 6 years ago

I'm going to close this out, insert-file-contents does not maintain the point's location as well as the previous method, so it's not worth it.