nimpretty: don't touch formatted multiline comments (#11663)

This commit is contained in:
Miran 2019-07-05 21:47:01 +02:00 • committed by Andreas Rumpf
commit 176eaf5c90
3 changed files with 87 additions and 23 deletions

View file

@ -300,7 +300,15 @@ proc emitMultilineComment(em: var Emitter, lit: string, col: int) =
var i = 0 var i = 0
var lastIndent = em.indentStack[^1] var lastIndent = em.indentStack[^1]
var b = 0 var b = 0
var dontIndent = false
for commentLine in splitLines(lit): for commentLine in splitLines(lit):
if i == 0 and (commentLine.endsWith("\\") or commentLine.endsWith("[")):
dontIndent = true
wr em, commentLine, ltComment
elif dontIndent:
wrNewline em
wr em, commentLine, ltComment
else:
let stripped = commentLine.strip() let stripped = commentLine.strip()
var a = 0 var a = 0
while a < commentLine.len and commentLine[a] == ' ': inc a while a < commentLine.len and commentLine[a] == ' ': inc a

View file

@ -689,6 +689,34 @@ proc newRecordGen(ctx: Context; typ: TypRef): PNode =
typ.recFields.map(newRecFieldGen)))) typ.recFields.map(newRecFieldGen))))
##[
String `interpolation`:idx: / `format`:idx: inspired by
Python's ``f``-strings.
.. code-block:: nim
import strformat
let msg = "hello"
doAssert fmt"{msg}\n" == "hello\\n"
Because the literal is a raw string literal, the ``\n`` is not interpreted as
an escape sequence.
================= ====================================================
Sign Meaning
================= ====================================================
``+`` Indicates that a sign should be used for both
positive as well as negative numbers.
``-`` Indicates that a sign should be used only for
negative numbers (this is the default behavior).
(space) Indicates that a leading space should be used on
positive numbers.
================= ====================================================
]##
let let
lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment
llb = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is a very long comment which should be split llb = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is a very long comment which should be split

View file

@ -695,6 +695,34 @@ proc newRecordGen(ctx: Context; typ: TypRef): PNode =
typ.recFields.map(newRecFieldGen)))) typ.recFields.map(newRecFieldGen))))
##[
String `interpolation`:idx: / `format`:idx: inspired by
Python's ``f``-strings.
.. code-block:: nim
import strformat
let msg = "hello"
doAssert fmt"{msg}\n" == "hello\\n"
Because the literal is a raw string literal, the ``\n`` is not interpreted as
an escape sequence.
================= ====================================================
Sign Meaning
================= ====================================================
``+`` Indicates that a sign should be used for both
positive as well as negative numbers.
``-`` Indicates that a sign should be used only for
negative numbers (this is the default behavior).
(space) Indicates that a leading space should be used on
positive numbers.
================= ====================================================
]##
let let
lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment lla = 42394219 - 42429849 + 1293293 - 13918391 + 424242 # this here is an okayish comment
llb = 42394219 - 42429849 + 1293293 - 13918391 + llb = 42394219 - 42429849 + 1293293 - 13918391 +