diff options
author | narimiran <narimiran@disroot.org> | 2019-07-09 13:15:35 +0200 |
---|---|---|
committer | narimiran <narimiran@disroot.org> | 2019-07-09 13:15:35 +0200 |
commit | 96d49608c05647ed5ea22a6b4321b864034bd495 (patch) | |
tree | 5340d7f5849ea10978d3ca88416e98e0705fd043 /compiler | |
parent | eefcea88927ee4845d3c46f38394fa39172c9987 (diff) | |
download | Nim-96d49608c05647ed5ea22a6b4321b864034bd495.tar.gz |
nimpretty: more comment indentation fixes
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/layouter.nim | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim index 5d65c012f..221afc78c 100644 --- a/compiler/layouter.nim +++ b/compiler/layouter.nim @@ -307,7 +307,7 @@ proc emitMultilineComment(em: var Emitter, lit: string, col: int; dontIndent: bo var lastIndent = if em.keepIndents > 0: em.indentLevel else: em.indentStack[^1] var b = 0 var dontIndent = dontIndent - var lastWasEmpty = false + var hasEmptyLine = false for commentLine in splitLines(lit): if i == 0 and (commentLine.endsWith("\\") or commentLine.endsWith("[")): dontIndent = true @@ -322,7 +322,7 @@ proc emitMultilineComment(em: var Emitter, lit: string, col: int; dontIndent: bo wr(em, "", ltTab) elif stripped.len == 0: wrNewline em - lastWasEmpty = true + hasEmptyLine = true else: var a = 0 while a < commentLine.len and commentLine[a] == ' ': inc a @@ -334,13 +334,13 @@ proc emitMultilineComment(em: var Emitter, lit: string, col: int; dontIndent: bo b -= em.indWidth lastIndent = a wrNewline em - #wrSpaces em, col + b - if not lastWasEmpty or col + b < 15: + if not hasEmptyLine or col + b < 15: if col + b > 0: wr(em, repeat(' ', col+b), ltTab) else: wr(em, "", ltTab) - #lastWasEmpty = stripped.len == 0 + else: + wr(em, repeat(' ', a), ltSpaces) wr em, stripped, ltComment inc i @@ -363,7 +363,7 @@ proc endsInAlpha(em: Emitter): bool = result = if i >= 0: em.tokens[i].lastChar in SymChars+{'_'} else: false proc emitComment(em: var Emitter; tok: TToken; dontIndent: bool) = - let col = em.col + var col = em.col let lit = strip fileSection(em.config, em.fid, tok.commentOffsetA, tok.commentOffsetB) em.lineSpan = countNewlines(lit) if em.lineSpan > 0: calcCol(em, lit) @@ -374,6 +374,7 @@ proc emitComment(em: var Emitter; tok: TToken; dontIndent: bool) = else: if not endsInWhite(em): wrTab em + inc col emitMultilineComment(em, lit, col, dontIndent) proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) = |