diff options
author | Som Snytt <som.snytt@gmail.com> | 2015-09-27 22:00:21 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2015-09-27 22:00:21 -0700 |
commit | f29096285f39dfea25c0644ed3066fb9630def78 (patch) | |
tree | ac948636328d5918ab5f4c33b8dbd2315cf12a42 /src | |
parent | bc3589d3ebab7735fbbb130fbb7c8ccb1146eef7 (diff) | |
download | scala-f29096285f39dfea25c0644ed3066fb9630def78.tar.gz scala-f29096285f39dfea25c0644ed3066fb9630def78.tar.bz2 scala-f29096285f39dfea25c0644ed3066fb9630def78.zip |
SI-9492 Line trimming paste
Use `-` stripmargin character to indicate trim (i.e.
remove leading indentation). `<<` looks more like
shift left, but is already the standard here doc sequence.
Indentation is often mangled by pasting, so trimming
normalizes lines for error messages. The entire paste
text was already trimmed as a whole.
`-Dscala.repl.here` provides a default end string, which
is unset unless specified.
```
scala> :pa <-
// Entering paste mode (ctrl-D to finish)
def g = 10
def f! = 27
--
// Exiting paste mode, now interpreting.
<console>:2: error: '=' expected but identifier found.
def f! = 27
^
```
Diffstat (limited to 'src')
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ILoop.scala | 9 | ||||
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ReplProps.scala | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala index b4fa5b607c..bf7c8551e5 100644 --- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala @@ -734,10 +734,13 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) } getOrElse "" case (eof, _) => echo(s"// Entering paste mode (${ eof getOrElse "ctrl-D" } to finish)\n") - val input = readWhile(s => eof.isEmpty || eof.get != s) mkString "\n" + val delimiter = eof orElse replProps.pasteDelimiter.option + val input = readWhile(s => delimiter.isEmpty || delimiter.get != s) mkString "\n" val text = ( - margin filter (_.nonEmpty) map (input stripMargin _.head) // ignore excess chars in "<<||" - getOrElse input + margin filter (_.nonEmpty) map { + case "-" => input.lines map (_.trim) mkString "\n" + case m => input stripMargin m.head // ignore excess chars in "<<||" + } getOrElse input ).trim if (text.isEmpty) echo("\n// Nothing pasted, nothing gained.\n") else echo("\n// Exiting paste mode, now interpreting.\n") diff --git a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala index 588d92f81b..f3115d9800 100644 --- a/src/repl/scala/tools/nsc/interpreter/ReplProps.scala +++ b/src/repl/scala/tools/nsc/interpreter/ReplProps.scala @@ -64,6 +64,8 @@ class ReplProps { if (p.isSet) p.get else shellWelcomeString } + val pasteDelimiter = Prop[String]("scala.repl.here") + /** CSV of paged,across to enable pagination or `-x` style * columns, "across" instead of down the column. Since * pagination turns off columnar output, these flags are |