Improve line breaking

This commit is contained in:
Hackerpilot 2015-02-17 21:49:24 -08:00
parent e39f2916b1
commit a124e2dfc9
1 changed files with 24 additions and 4 deletions

View File

@ -391,7 +391,7 @@ private:
writeBraces(); writeBraces();
break; break;
case tok!".": case tok!".":
if (currentLineLength + nextTokenLength() >= config.columnSoftLimit) if (currentLineLength + nextTokenLength() >= config.columnHardLimit)
{ {
pushIndent(); pushIndent();
newline(); newline();
@ -451,7 +451,7 @@ private:
case tok!"%": case tok!"%":
case tok!"+=": case tok!"+=":
binary: binary:
if (currentLineLength + nextTokenLength() >= config.columnSoftLimit) if (currentLineLength + distanceToNextPreferredBreak() >= config.columnSoftLimit)
{ {
pushIndent(); pushIndent();
newline(); newline();
@ -743,11 +743,31 @@ private:
int nextTokenLength() pure @safe @nogc int nextTokenLength() pure @safe @nogc
{ {
if (index + 1 >= tokens.length) immutable size_t i = index + 1;
if (i >= tokens.length)
return INVALID_TOKEN_LENGTH; return INVALID_TOKEN_LENGTH;
return tokenLength(index + 1); return tokenLength(i);
} }
int distanceToNextPreferredBreak() pure @safe @nogc
{
size_t i = index + 1;
int l;
loop: while (i < tokens.length) switch (tokens[i].type)
{
case tok!"||":
case tok!"&&":
case tok!";":
case tok!")":
break loop;
default:
l += tokenLength(i);
i++;
break;
}
return l;
}
ref current() const @property ref current() const @property
in in
{ {