summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorMiran <narimiran@disroot.org>2019-07-07 20:13:10 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-07-07 20:13:10 +0200
commitd0616ed115840053f705a8bf45fa5cf566d3e2b1 (patch)
treeea7169b5b77c26584ccd853114b870a79fb1d751 /compiler
parent085a21ebf41e5eebe2a735cfad73c0767ab73755 (diff)
downloadNim-d0616ed115840053f705a8bf45fa5cf566d3e2b1.tar.gz
nimpretty: don't introduce extra spaces after a colon or a comma (#11672)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/layouter.nim10
1 files changed, 7 insertions, 3 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index a6891f564..0c5ed5fa2 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -69,6 +69,7 @@ proc openEmitter*(em: var Emitter, cache: IdentCache;
 
 proc computeMax(em: Emitter; pos: int): int =
   var p = pos
+  var extraSpace = 0
   result = 0
   while p < em.tokens.len and em.kinds[p] != ltEndSection:
     var lhs = 0
@@ -76,10 +77,12 @@ proc computeMax(em: Emitter; pos: int): int =
     var foundTab = false
     while p < em.tokens.len and em.kinds[p] != ltEndSection:
       if em.kinds[p] in {ltCrucialNewline, ltSplittingNewline}:
-        if foundTab and lineLen <= MaxLineLen: result = max(result, lhs+1)
+        if foundTab and lineLen <= MaxLineLen:
+          result = max(result, lhs + extraSpace)
         inc p
         break
       if em.kinds[p] == ltTab:
+        extraSpace = if em.kinds[p-1] == ltSpaces: 0 else: 1
         foundTab = true
       else:
         if not foundTab:
@@ -160,8 +163,9 @@ proc closeEmitter*(em: var Emitter) =
         maxLhs = 0
 
       if maxLhs == 0:
-        content.add em.tokens[i]
-        inc lineLen, em.tokens[i].len
+        if em.kinds[i-1] != ltSpaces:
+          content.add em.tokens[i]
+          inc lineLen, em.tokens[i].len
       else:
         # pick the shorter indentation token:
         var spaces = maxLhs - lineLen