summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/layouter.nim14
-rw-r--r--compiler/parser.nim2
-rw-r--r--nimpretty/tests/exhaustive.nim9
-rw-r--r--nimpretty/tests/expected/exhaustive.nim10
4 files changed, 30 insertions, 5 deletions
diff --git a/compiler/layouter.nim b/compiler/layouter.nim
index 6cb129fc1..94664f41c 100644
--- a/compiler/layouter.nim
+++ b/compiler/layouter.nim
@@ -106,11 +106,15 @@ proc softLinebreak(em: var Emitter, lit: string) =
   # +2 because we blindly assume a comma or ' &' might follow
   if not em.inquote and em.col+lit.len+2 >= MaxLineLen:
     if em.lastTok in splitters:
-      while em.content.len > 0 and em.content[em.content.high] == ' ':
-        setLen(em.content, em.content.len-1)
-      wr("\L")
-      em.col = 0
-      for i in 1..em.indentLevel+moreIndent(em): wr(" ")
+      # bug #10295, check first if even more indentation would help:
+      let spaces = em.indentLevel+moreIndent(em)
+      if spaces < em.col:
+        let oldPos = em.content.len # we can undo our changes if not benefitial
+        while em.content.len > 0 and em.content[em.content.high] == ' ':
+          setLen(em.content, em.content.len-1)
+        wr("\L")
+        em.col = 0
+        for i in 1..spaces: wr(" ")
     else:
       # search backwards for a good split position:
       for a in mitems(em.altSplitPos):
diff --git a/compiler/parser.nim b/compiler/parser.nim
index c154e5eb0..2db7c7c91 100644
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -96,6 +96,8 @@ proc getTok(p: var TParser) =
   p.hasProgress = true
   when defined(nimpretty2):
     emitTok(p.em, p.lex, p.tok)
+    # skip the additional tokens that nimpretty needs but the parser has no
+    # interest in:
     while p.tok.tokType == tkComment:
       rawGetTok(p.lex, p.tok)
       emitTok(p.em, p.lex, p.tok)
diff --git a/nimpretty/tests/exhaustive.nim b/nimpretty/tests/exhaustive.nim
index 2903a59af..b8042af06 100644
--- a/nimpretty/tests/exhaustive.nim
+++ b/nimpretty/tests/exhaustive.nim
@@ -366,3 +366,12 @@ proc fun4() =
   var i = 0
   while i<a.len and i<a.len:
     return
+
+
+# bug #10295
+
+import osproc
+let res = execProcess(
+    "echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates")
+
+let res = execProcess("echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates")
diff --git a/nimpretty/tests/expected/exhaustive.nim b/nimpretty/tests/expected/exhaustive.nim
index cd3d136e7..91a2e9027 100644
--- a/nimpretty/tests/expected/exhaustive.nim
+++ b/nimpretty/tests/expected/exhaustive.nim
@@ -375,3 +375,13 @@ proc fun4() =
   var i = 0
   while i < a.len and i < a.len:
     return
+
+
+# bug #10295
+
+import osproc
+let res = execProcess(
+    "echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates")
+
+let res = execProcess(
+    "echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates")