Re:A Prettier JavaScript Formatter
by flukus on Tuesday January 10, 2017 @08:58PM
(#13371140)
Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.
[ Parent
| on HN ]
> Why does the formatter need to solve this and not the editor? The editor has more information available to it, like the present screen space.
Because making the line wrapping nice requires deep syntax-aware editor integration. Most languages try to be at least somewhat plain-text-editor-friendly.
> Because making the line wrapping nice requires deep syntax-aware editor integration.
Why does it need to be syntax aware?
Think what happens when you break a line comment (or a string, in languages where it can't span several lines). And that's an easy example at that.
What happens? Nothing as far as I'm aware. The code is still one line.
> Because making the line wrapping nice requires deep syntax-aware editor integration.
'nice' is the key word here
Re:A Prettier JavaScript Formatter
by Manishearth on Tuesday January 10, 2017 @09:59PM
(#13371395)
Theoretically, an editor could. I have yet to see one that does this well. Most do dumb wrapping, with no language sensitivity.
I think it's just a matter of programmer habit now -- folks expect their editor to mirror the code without formatting tweaks.
It gets confusing when you realize that programmers may insert their own indentation and wrapping, and sometimes you want to make this part of the actual file, and sometimes you want to remove it before serializing.
I've been pretty happy with vim and "set breakindent" where the broken line is indented to the parent one. I pretty frequently work with small views of a file.
Re:A Prettier JavaScript Formatter
by Sophistifunk on Tuesday January 10, 2017 @10:19PM
(#13371471)
I wish more people would realise this.