Skip to content

SI-4684 Repl supports whole-file paste#2696

Closed
som-snytt wants to merge 2 commits intoscala:masterfrom
som-snytt:topic/repl-paste-file
Closed

SI-4684 Repl supports whole-file paste#2696
som-snytt wants to merge 2 commits intoscala:masterfrom
som-snytt:topic/repl-paste-file

Conversation

@som-snytt
Copy link
Contributor

Add a file argument to the :paste command which loads the
file's contents as though entered in :paste mode.

The :paste command is replayable.

Samples, including companions defined together:

scala> :paste junk.scala
File contains no code: junk.scala

scala> :paste no-file.scala
That file does not exist

scala> :paste obj-repl.scala
Pasting file obj-repl.scala...
<console>:2: error: expected start of definition
         private foo = 7
                 ^

scala> :paste hw-repl.scala
Pasting file hw-repl.scala...
The pasted code is incomplete!

<pastie>:5: error: illegal start of simple expression
}
^

scala> :replay
Replaying: :paste junk.scala
File contains no code: junk.scala

Replaying: :paste obj-repl.scala
Pasting file obj-repl.scala...
defined trait Foo
defined object Foo

Replaying: Foo(new Foo{})
res0: Int = 7

Review by @retronym for whom I'll throw in :paste -raw if it otherwise looks good to him.

-raw is repl speak for "without wrapping", hence top-level.

@retronym
Copy link
Member

retronym commented Jul 1, 2013

Great!

We should really change the help text of :load. Currently, it is "load and interpret a Scala file". Not sure of a pithy wording to communicate its line-wise nature, though.

You ought to be able to test this easily enough, see: test/files/run/repl-paste.scala

Here's a variation I'd really like:

:paste -toplevel
package acme { class Wotzit }
^D

scala> new _root_.acme.Wotzit

@som-snytt
Copy link
Contributor Author

In fact, I did look at the paste tests, but it wasn't obvious how to supply a robust path. But on second look, I guess there's testPath.

@som-snytt
Copy link
Contributor Author

@retronym Line-wise = non-pastily.

@som-snytt
Copy link
Contributor Author

"interpret lines in a file". I didn't attempt to align compile error output with the pasted file name, since line numbers would be misleading anyway.

Add a file argument to the :paste command which loads the
file's contents as though entered in :paste mode.

The :paste command is replayable.

Samples, including companions defined together:

```
scala> :paste junk.scala
File contains no code: junk.scala

scala> :paste no-file.scala
That file does not exist

scala> :paste obj-repl.scala
Pasting file obj-repl.scala...
<console>:2: error: expected start of definition
         private foo = 7
                 ^

scala> :paste hw-repl.scala
Pasting file hw-repl.scala...
The pasted code is incomplete!

<pastie>:5: error: illegal start of simple expression
}
^

scala> :replay
Replaying: :paste junk.scala
File contains no code: junk.scala

Replaying: :paste obj-repl.scala
Pasting file obj-repl.scala...
defined trait Foo
defined object Foo

Replaying: Foo(new Foo{})
res0: Int = 7
```
@som-snytt
Copy link
Contributor Author

The cwd is right for the simple path after all in the test paste command.

At least now I know the meaning of true companionship.

@scala-jenkins
Copy link

IDE validation running at https://scala-webapps.epfl.ch/jenkins/job/pr-scala/60/

By special request, :paste -raw simply compiles the pasted
code to the repl output dir.

The -raw flag means no wrapping; the pasted code must be
ordinary top level Scala code, not script.
@adriaanm
Copy link
Contributor

I'm no replxpert, but LGTM.

@adriaanm adriaanm mentioned this pull request Jul 10, 2013
@adriaanm
Copy link
Contributor

I am a rebasepert, though.

@SethTisue
Copy link
Member

SethTisue commented Mar 19, 2018

<SethTisue> a PR adding some variation on :load that makes it compile the whole thing at once instead of evaluating it one form at a time would be accepted, I think
<SethTisue> omg https://github.com/scala/scala/pull/2696
<SethTisue> TIL! just use `:paste Foo.scala` instead of `:load Foo.scala

TIL!

@SethTisue
Copy link
Member

for anyone happening upon this PR, note that Jason's :paste -toplevel idea was implemented as :paste -raw

http://docs.scala-lang.org/overviews/repl/overview.html has :paste -raw but doesn't have :paste <filename>

@SethTisue
Copy link
Member

We should really change the help text of :load. Currently, it is "load and interpret a Scala file". Not sure of a pithy wording to communicate its line-wise nature, though

now that http://docs.scala-lang.org/overviews/repl/overview.html exists we can write a Moby Dick about this instead of a haiku

@som-snytt
Copy link
Contributor Author

For anyone chancing upon this PR before @SethTisue quits his day job to write his novel, here is the back of the napkin.

Paul's -raw idea was implemented as just see if it's a package statement.

scala> :pa < END
// Entering paste mode (END to finish)

package p
class C
END

// Exiting paste mode, now interpreting.


scala> new p.C
res1: p.C = p.C@3520963d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants