LuaFormatter icon indicating copy to clipboard operation
LuaFormatter copied to clipboard

All the new lines are now replaced with "<0x0d>"

Open dvdvideo1234 opened this issue 5 years ago • 8 comments
trafficstars

image

dvdvideo1234 avatar Oct 13 '20 06:10 dvdvideo1234

it looks like you are on Windows. So for windows a newline is not a mere '\n', it's '\r\n'. '\n' is indeed hard coded everywhere in the formatter, but the fix should be simple. perhaps just '\n' -> std::endl

tammela avatar Oct 16 '20 18:10 tammela

Yep. The extension automatically puts \n\r even when the file itself is \n. You can easily workaround this by replacing the <0x0d> with an empty string

dvdvideo1234 avatar Oct 16 '20 19:10 dvdvideo1234

Yep. The extension automatically puts \n\r even when the file itself is \n. ...

That doesn't sound right - are you sure you mean \n\r and not \r\n?! https://en.wikipedia.org/wiki/Newline

Is a \r\n (Carriage-Return {ASCII code 13 - <Cntr>+M} followed by Line-Feed {ASCII code 10 - <Cntr>+J} compulsory for the End-of-Line marking for this formatter or can it be configured to be \n even on Windows?

SlySven avatar Mar 12 '21 21:03 SlySven

@SlySven It was a typo. \r\n ( CR LF )is the correct one. Standard windows ending line. Why does it force \r\n

dvdvideo1234 avatar Mar 13 '21 19:03 dvdvideo1234

... Why does it force \r\n

I do not know that it does - that is what I wanted to check as the project I code for ( https://github.com/Mudlet/Mudlet ) already uses a different Lua code formatter. That one means bundling up a couple of hundred Lua files as a third-party element to the project and it has been suggested we consider this one instead...

SlySven avatar Mar 16 '21 02:03 SlySven

I'm not a user of windows, so it seems that in windows you can have editors that support the unix newline right?

If that's the case we can add a CLI options to enforce a unix newline even if the host is Windows.

Em seg., 15 de mar. de 2021 às 23:28, Stephen Lyons < @.***> escreveu:

... Why does it force \r\n

I do not know that it does - that is what I wanted to check as the project I code for ( https://github.com/Mudlet/Mudlet ) already uses a different Lua code formatter. That one means bundling up a couple of hundred Lua files as a third-party element to the project and it has been suggested we consider this one instead...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Koihik/LuaFormatter/issues/146#issuecomment-799895151, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACECBMYTQMKIO3H2MCOW4J3TD266FANCNFSM4SOHKEWA .

tammela avatar Mar 16 '21 15:03 tammela

I think it rather detect the OS and puts \r\n automatically. Just like the end lines in the Ubuntu console end with \r\n or some other stuff like that. This is unexpected no-no for me, because I have to code on windows for Linux machines. and my dev enviromnet is setup to always use \n instead of \r\n

dvdvideo1234 avatar Mar 17 '21 14:03 dvdvideo1234

Using lua-formatter plugin with sublime on windows. Line endings set to windows:

hexdump -C scripts/test_zinc_scripts.lua
00000000  23 21 2f 75 73 72 2f 62  69 6e 2f 65 6e 76 20 6c  |#!/usr/bin/env l|
00000010  75 61 0d 0d 0a 0d 0d 0a  2d 2d 20 48 65 6c 70 65  |ua......-- Helpe|

Line endings set to linux:

hexdump -C scripts/test_zinc_scripts.lua
00000000  23 21 2f 75 73 72 2f 62  69 6e 2f 65 6e 76 20 6c  |#!/usr/bin/env l|
00000010  75 61 0d 0a 0d 0a 2d 2d  20 48 65 6c 70 65 72 20  |ua....-- Helper |

Regardless of line endings, an extra \r is inserted. So if line endings are set to windows, you get \r\r\n

drbartling avatar Jun 28 '21 20:06 drbartling