radian-software / apheleia

🌷 Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.
MIT License
560 stars 77 forks source link

Mixed line ending after formatting in windows + msys #53

Open asif-mahmud opened 2 years ago

asif-mahmud commented 2 years ago

Hi, first of all thanks for your great work. I have been using this package for a while now. Recently i have also been using it on windows machine. On windows i have msys64 setup for various unix/linux tools, that includes the diff tool as well. so apheleia is using diff from msys setup. The code's line ending is CRLF, but when i edit some and format code, it inserts ^M as line ending. its probably the diff tool's doing. i took screenshots from various buffers to show you here, hope you can find out the problem,

main code after formatting -

main-code

prettier-stdout buffer -

prettier-stdout

diff-stdout buffer - diff-stdout

sorry i can not show you the full code. my emacs config is here - emacs configuration. i am using windows 10, emacs 28, msys64, diff tool was install via base-devel package of msys64.

raxod502 commented 2 years ago

Hmmm. But, if your code is in CRLF format, then you'd except ^M to be everywhere, right (^M is just a CR)? You just expect for it to be invisible. The problem might be that Apheleia is messing up your buffer so that Emacs thinks it is in LF rather than CRLF format, and therefore the CRs (^M) become visible.

Unfortunately, I can't think of why this might be, and I don't have the ability to test a hypothesis with my current hardware. It might, however, be worth checking on the buffer-file-coding-system of these various buffers before and after running Apheleia, and checking the literal content of the buffers before and after (i.e. what ASCII codes do they contain; do you have LF or CRLF at each step).

asif-mahmud commented 2 years ago

yes thats what i expected but only the formatted part had it. thats what bugging me. the file itself is in CRLF mode. so if the formatted part has the same line ending then ^M shouldn't be visible separately as the rest of the file doesn't show ^M separately. i will do some testing today when i get back home. will let you know.

asif-mahmud commented 2 years ago

hi, i think i found a solution. adding --strip-trailing-cr to diff solves the problem for me. haven't tested on linux setup, can't do that right now. but i think it does solve it in general.