diff options
author | Paul Phillips <paulp@improving.org> | 2010-01-17 20:50:47 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-01-17 20:50:47 +0000 |
commit | 3d47813cda5b0a13b095f2681296dcae6adefd07 (patch) | |
tree | 206adfc1363fde190670b1450799f86cfa3dff09 | |
parent | 4bb4b8a08e4f6c85743d73e78729df01ec0212d7 (diff) | |
download | scala-3d47813cda5b0a13b095f2681296dcae6adefd07.tar.gz scala-3d47813cda5b0a13b095f2681296dcae6adefd07.tar.bz2 scala-3d47813cda5b0a13b095f2681296dcae6adefd07.zip |
Don't insert whitespace on multiline strings an...
Don't insert whitespace on multiline strings and xml literals. Closes
#2115. No review.
-rw-r--r-- | src/compiler/scala/tools/nsc/Interpreter.scala | 9 | ||||
-rw-r--r-- | 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 = <a> - <b d="dd" c="c"></b></a> +<b d="dd" c="c"></b></a> 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. |