nimpretty: don't produce trailing whitespace; fixes the rendering of unary operators
This commit is contained in:
parent
837d0c7270
commit
c3090fcb48
3 changed files with 16 additions and 11 deletions
|
|
@ -93,6 +93,8 @@ proc softLinebreak(em: var Emitter, lit: string) =
|
||||||
# +2 because we blindly assume a comma or ' &' might follow
|
# +2 because we blindly assume a comma or ' &' might follow
|
||||||
if not em.inquote and em.col+lit.len+2 >= MaxLineLen:
|
if not em.inquote and em.col+lit.len+2 >= MaxLineLen:
|
||||||
if em.lastTok in splitters:
|
if em.lastTok in splitters:
|
||||||
|
while em.content.len > 0 and em.content[em.content.high] == ' ':
|
||||||
|
setLen(em.content, em.content.len-1)
|
||||||
wr("\L")
|
wr("\L")
|
||||||
em.col = 0
|
em.col = 0
|
||||||
for i in 1..em.indentLevel+moreIndent(em): wr(" ")
|
for i in 1..em.indentLevel+moreIndent(em): wr(" ")
|
||||||
|
|
@ -100,8 +102,11 @@ proc softLinebreak(em: var Emitter, lit: string) =
|
||||||
# search backwards for a good split position:
|
# search backwards for a good split position:
|
||||||
for a in em.altSplitPos:
|
for a in em.altSplitPos:
|
||||||
if a > em.fixedUntil:
|
if a > em.fixedUntil:
|
||||||
let ws = "\L" & repeat(' ',em.indentLevel+moreIndent(em) -
|
var spaces = 0
|
||||||
ord(em.content[a] == ' '))
|
while a+spaces < em.content.len and em.content[a+spaces] == ' ':
|
||||||
|
inc spaces
|
||||||
|
if spaces > 0: delete(em.content, a, a+spaces-1)
|
||||||
|
let ws = "\L" & repeat(' ',em.indentLevel+moreIndent(em))
|
||||||
em.col = em.content.len - a
|
em.col = em.content.len - a
|
||||||
em.content.insert(ws, a)
|
em.content.insert(ws, a)
|
||||||
break
|
break
|
||||||
|
|
@ -186,8 +191,8 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
wr(" ")
|
wr(" ")
|
||||||
of tkSemicolon, tkComma:
|
of tkSemicolon, tkComma:
|
||||||
wr(TokTypeToStr[tok.tokType])
|
wr(TokTypeToStr[tok.tokType])
|
||||||
wr(" ")
|
|
||||||
rememberSplit(splitComma)
|
rememberSplit(splitComma)
|
||||||
|
wr(" ")
|
||||||
of tkParDotLe, tkParLe, tkBracketDotLe, tkBracketLe,
|
of tkParDotLe, tkParLe, tkBracketDotLe, tkBracketLe,
|
||||||
tkCurlyLe, tkCurlyDotLe, tkBracketLeColon:
|
tkCurlyLe, tkCurlyDotLe, tkBracketLeColon:
|
||||||
if tok.strongSpaceA > 0 and not em.endsInWhite:
|
if tok.strongSpaceA > 0 and not em.endsInWhite:
|
||||||
|
|
@ -215,7 +220,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
||||||
template isUnary(tok): bool =
|
template isUnary(tok): bool =
|
||||||
tok.strongSpaceB == 0 and tok.strongSpaceA > 0
|
tok.strongSpaceB == 0 and tok.strongSpaceA > 0
|
||||||
|
|
||||||
if not isUnary(tok) or em.lastTok in {tkOpr, tkDotDot}:
|
if not isUnary(tok):
|
||||||
wr(" ")
|
wr(" ")
|
||||||
rememberSplit(splitBinary)
|
rememberSplit(splitBinary)
|
||||||
of tkAccent:
|
of tkAccent:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ type
|
||||||
var x*: string
|
var x*: string
|
||||||
var y: seq[string] #[ yay inline comments. So nice I have to care bout these. ]#
|
var y: seq[string] #[ yay inline comments. So nice I have to care bout these. ]#
|
||||||
|
|
||||||
echo "#", x, "##", y, "#"
|
echo "#", x, "##", y, "#" & "string" & $test
|
||||||
|
|
||||||
echo (tup, here)
|
echo (tup, here)
|
||||||
echo(argA, argB)
|
echo(argA, argB)
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ type
|
||||||
var x*: string
|
var x*: string
|
||||||
var y: seq[string] #[ yay inline comments. So nice I have to care bout these. ]#
|
var y: seq[string] #[ yay inline comments. So nice I have to care bout these. ]#
|
||||||
|
|
||||||
echo "#", x, "##", y, "#"
|
echo "#", x, "##", y, "#" & "string" & $test
|
||||||
|
|
||||||
echo (tup, here)
|
echo (tup, here)
|
||||||
echo(argA, argB)
|
echo(argA, argB)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue