nimpretty: more comment indentation fixes

(cherry picked from commit 96d49608c0)
This commit is contained in:
narimiran
2019-07-09 13:15:35 +02:00
parent 8afe92a1ab
commit da2a149522
3 changed files with 33 additions and 6 deletions

View File

@@ -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) =

View File

@@ -43,3 +43,16 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
if tue:
foo() # comment here
# end if
proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
## Splits and distributes a sequence `s` into `num` sub-sequences.
let num = int(num) # XXX probably only needed because of .. bug
# This is part of the above.
result = newSeq[seq[T]](num)
proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
## Splits and distributes a sequence `s` into `num` sub-sequences.
let num = int(num) # XXX probably only needed because of .. bug
# This belongs below.
result = newSeq[seq[T]](num)

View File

@@ -43,3 +43,16 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
if tue:
foo() # comment here
# end if
proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
## Splits and distributes a sequence `s` into `num` sub-sequences.
let num = int(num) # XXX probably only needed because of .. bug
# This is part of the above.
result = newSeq[seq[T]](num)
proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
## Splits and distributes a sequence `s` into `num` sub-sequences.
let num = int(num) # XXX probably only needed because of .. bug
# This belongs below.
result = newSeq[seq[T]](num)