Feature Request: Preserve Line Breaks
I am often annoyed if formatters don't give me the option to put line breaks where I want. For instance, let's say I want to define a matrix like this:
local mtx33 = {
1, 2, 3,
4, 5, 6,
7, 8, 9
}
I haven't found a formatter that lets me do this without hacks like putting empty comments in the end of each line. And even then, it often messes up the formatting of the following lines.
I would like to have the option that the formatter just doesn't touch line breaks at all.
Would that be possible?
I think it should be possible but won't be easy.
I found a dirty hack to make this work in C++, should be the same with lua: Before formatting, replace every "\n" in the code with "--\n", then format, then replace every "--\n" with "\n" and done :) So far I implemented this as a macro in vscode but it is probably easy to embed into formatters as well. I am aware how ugly this is tho, so I don't expect you to do it like this. Just if anyone stumbles upon this post, that's how they can patch this.
Would it be possible to just use some comments to disable and enable formatting?
-- @format-disable
local mtx33 = {
1, 2, 3,
4, 5, 6,
7, 8, 9
}
-- @format-enable
I also really want this too for situations where the number of arguments passed to a function is long and 1 may be an inline function. It looks weird when it gets moved onto its own line:
After formatting:
local listener = em:GetEventListenerByID("OnChange") or
em:CreateEventListenerWithID(
"OnChange", function()
local canListen = CanListenToChanges();
if (canListen) then
-- do stuff
else
data.disabled = true;
handleDisable();
end
end);
I'd prefer it to look like this:
local listener =
em:GetEventListenerByID("OnChange") or
em:CreateEventListenerWithID("OnChange", function()
local canListen = CanListenToChanges();
if (canListen) then
-- do stuff
else
data.disabled = true;
handleDisable();
end
end);