diff options
author | Araq <rumpf_a@web.de> | 2019-07-18 11:28:25 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-07-18 11:28:25 +0200 |
commit | 7deb49e992b734d5ae513460fdc9cf68d4000588 (patch) | |
tree | 7c1ee1c35e3c7dc25b6667c42757cedf0d4cfe13 /compiler | |
parent | 5b7273b4f8f716c1f5d4f582ebe23f8adbd48b0b (diff) | |
download | Nim-7deb49e992b734d5ae513460fdc9cf68d4000588.tar.gz |
nimpretty: fixes #11699
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/layouter.nim | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim index 2bf0552ff..367d2aead 100644 --- a/compiler/layouter.nim +++ b/compiler/layouter.nim @@ -153,8 +153,15 @@ proc lenOfNextTokens(em: Emitter; pos: int): int = if em.kinds[pos+i] in {ltCrucialNewline, ltSplittingNewline, ltOptionalNewline}: break inc result, em.tokens[pos+i].len -proc lacksGuidingInd(em: Emitter; pos: int): bool = - result = true +proc guidingInd(em: Emitter; pos: int): int = + var i = pos - 1 + while i >= 0 and em.kinds[i] != ltSomeParLe: + dec i + while i+1 <= em.kinds.high and em.kinds[i] != ltSomeParRi: + if em.kinds[i] == ltSplittingNewline and em.kinds[i+1] == ltSpaces: + return em.tokens[i+1].len + inc i + result = -1 proc closeEmitter*(em: var Emitter) = template defaultCase() = @@ -209,11 +216,13 @@ proc closeEmitter*(em: var Emitter) = let spaces = em.tokens[i-1].len content.setLen(content.len - spaces) content.add "\L" - content.add em.tokens[i] - lineLen = em.tokens[i].len - if false: # openPars == 0 or lacksGuidingInd(em, i): - content.add repeat(' ', em.indWidth*2) - lineLen += em.indWidth*2 + let guide = if openPars > 0: guidingInd(em, i) else: -1 + if guide >= 0: + content.add repeat(' ', guide) + lineLen = guide + else: + content.add em.tokens[i] + lineLen = em.tokens[i].len lineBegin = i+1 if i+1 < em.kinds.len and em.kinds[i+1] == ltSpaces: # inhibit extra spaces at the start of a new line |