From 3d47813cda5b0a13b095f2681296dcae6adefd07 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sun, 17 Jan 2010 20:50:47 +0000 Subject: Don't insert whitespace on multiline strings an... Don't insert whitespace on multiline strings and xml literals. Closes #2115. No review. --- src/compiler/scala/tools/nsc/Interpreter.scala | 9 +++++++-- test/files/jvm/interpreter.check | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 1185600c94..b2c5bc2415 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -240,13 +240,18 @@ class Interpreter(val settings: Settings, out: PrintWriter) * This way, compiler error messages read better. */ private final val spaces = List.fill(7)(" ").mkString - def indentCode(code: String) = + def indentCode(code: String) = { + /** Heuristic to avoid indenting and thereby corrupting """-strings and XML literals. */ + val noIndent = (code contains "\n") && (List("\"\"\"", "") exists (code contains _)) stringFrom(str => for (line <- code.lines) { - str.print(spaces) + if (!noIndent) + str.print(spaces) + str.print(line + "\n") str.flush() }) + } implicit def name2string(name: Name) = name.toString diff --git a/test/files/jvm/interpreter.check b/test/files/jvm/interpreter.check index e17cc15a0a..6c89318470 100644 --- a/test/files/jvm/interpreter.check +++ b/test/files/jvm/interpreter.check @@ -189,7 +189,7 @@ scala> scala> scala> | | | | res8: scala.xml.Elem = - + scala> scala> @@ -199,9 +199,9 @@ scala> scala> scala> | | | res9: java.lang.String = - hello - there - +hello +there + scala> scala> | | You typed two blank lines. Starting a new command. -- cgit v1.2.3