summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2019-07-05 21:47:01 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-07-05 21:47:01 +0200
commit176eaf5c90579d76c60dcebbfea38c02a5b4d014 (patch)
treeb8091268ae06490bcd72fbfdd8ea5a062774a1b4 /compiler
parentd1f6c820ddc4afcfbe7b8c3fb595e9947680316a (diff)
downloadNim-176eaf5c90579d76c60dcebbfea38c02a5b4d014.tar.gz
nimpretty: don't touch formatted multiline comments (#11663)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/layouter.nim46
1 files changed, 27 insertions, 19 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index 24efc7142..b54fb93bf 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -300,29 +300,37 @@ proc emitMultilineComment(em: var Emitter, lit: string, col: int) =
   var i = 0
   var lastIndent = em.indentStack[^1]
   var b = 0
+  var dontIndent = false
   for commentLine in splitLines(lit):
-    let stripped = commentLine.strip()
-    var a = 0
-    while a < commentLine.len and commentLine[a] == ' ': inc a
-    if i == 0:
-      if em.kinds.len > 0 and em.kinds[^1] != ltTab:
-        wr(em, "", ltTab)
-    elif stripped.len == 0:
+    if i == 0 and (commentLine.endsWith("\\") or commentLine.endsWith("[")):
+      dontIndent = true
+      wr em, commentLine, ltComment
+    elif dontIndent:
       wrNewline em
+      wr em, commentLine, ltComment
     else:
-      if a > lastIndent:
-        b += em.indWidth
-        lastIndent = a
-      elif a < lastIndent:
-        b -= em.indWidth
-        lastIndent = a
-      wrNewline em
-      #wrSpaces em, col + b
-      if col + b > 0:
-        wr(em, repeat(' ', col+b), ltTab)
+      let stripped = commentLine.strip()
+      var a = 0
+      while a < commentLine.len and commentLine[a] == ' ': inc a
+      if i == 0:
+        if em.kinds.len > 0 and em.kinds[^1] != ltTab:
+          wr(em, "", ltTab)
+      elif stripped.len == 0:
+        wrNewline em
       else:
-        wr(em, "", ltTab)
-    wr em, stripped, ltComment
+        if a > lastIndent:
+          b += em.indWidth
+          lastIndent = a
+        elif a < lastIndent:
+          b -= em.indWidth
+          lastIndent = a
+        wrNewline em
+        #wrSpaces em, col + b
+        if col + b > 0:
+          wr(em, repeat(' ', col+b), ltTab)
+        else:
+          wr(em, "", ltTab)
+      wr em, stripped, ltComment
     inc i
 
 proc lastChar(s: string): char =