nimpretty: add #!nimpretty on/off directives
This commit is contained in:
parent
ed38079b9b
commit
f3c0703b7d
5 changed files with 43 additions and 9 deletions
|
|
@ -31,7 +31,7 @@ type
|
|||
inquote: bool
|
||||
semicolons: SemicolonKind
|
||||
col, lastLineNumber, lineSpan, indentLevel, indWidth: int
|
||||
inParamList*: int
|
||||
keepIndents*: int
|
||||
doIndentMore*: int
|
||||
content: string
|
||||
indentStack: seq[int]
|
||||
|
|
@ -134,6 +134,22 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
|||
for i in 1 .. LineCommentColumn - em.col: wr(" ")
|
||||
wr lit
|
||||
|
||||
if tok.tokType == tkComment and tok.literal.startsWith("#!nimpretty"):
|
||||
case tok.literal
|
||||
of "#!nimpretty off":
|
||||
inc em.keepIndents
|
||||
wr("\L")
|
||||
em.lastLineNumber = tok.line + 1
|
||||
of "#!nimpretty on":
|
||||
dec em.keepIndents
|
||||
em.lastLineNumber = tok.line
|
||||
wr("\L")
|
||||
#for i in 1 .. tok.indent: wr " "
|
||||
wr tok.literal
|
||||
em.col = 0
|
||||
em.lineSpan = 0
|
||||
return
|
||||
|
||||
var preventComment = false
|
||||
if tok.tokType == tkComment and tok.line == em.lastLineNumber and tok.indent >= 0:
|
||||
# we have an inline comment so handle it before the indentation token:
|
||||
|
|
@ -142,7 +158,7 @@ proc emitTok*(em: var Emitter; L: TLexer; tok: TToken) =
|
|||
em.fixedUntil = em.content.high
|
||||
|
||||
elif tok.indent >= 0:
|
||||
if em.lastTok in (splitters + oprSet) or em.inParamList > 0:
|
||||
if em.lastTok in (splitters + oprSet) or em.keepIndents > 0:
|
||||
em.indentLevel = tok.indent
|
||||
else:
|
||||
if tok.indent > em.indentStack[^1]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue