@@ -75,6 +75,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
7575 def history = in.history
7676
7777 // classpath entries added via :cp
78+ @ deprecated(" Use reset, replay or require to update class path" , since = " 2.11" )
7879 var addedClasspath : String = " "
7980
8081 /** A reverse list of commands to replay if the user requests a :replay */
@@ -207,7 +208,6 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
207208
208209 /** Standard commands **/
209210 lazy val standardCommands = List (
210- cmd(" cp" , " <path>" , " add a jar or directory to the classpath" , addClasspath),
211211 cmd(" edit" , " <id>|<line>" , " edit history" , editCommand),
212212 cmd(" help" , " [command]" , " print this summary or command-specific help" , helpCommand),
213213 historyCommand,
@@ -220,11 +220,12 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
220220 cmd(" paste" , " [-raw] [path]" , " enter paste mode or paste a file" , pasteCommand),
221221 nullary(" power" , " enable power user mode" , powerCmd),
222222 nullary(" quit" , " exit the interpreter" , () => Result (keepRunning = false , None )),
223- nullary(" replay" , " reset execution and replay all previous commands" , replay),
224- nullary(" reset" , " reset the repl to its initial state, forgetting all session entries" , resetCommand),
223+ cmd(" replay" , " [options]" , " reset the repl and replay all previous commands" , replayCommand),
224+ // cmd("require", "<path>", "add a jar or directory to the classpath", require), // TODO
225+ cmd(" reset" , " [options]" , " reset the repl to its initial state, forgetting all session entries" , resetCommand),
225226 cmd(" save" , " <path>" , " save replayable session to a file" , saveCommand),
226227 shCommand,
227- cmd(" settings" , " [+|-] <options>" , " +enable/-disable flags, set compiler options " , changeSettings),
228+ cmd(" settings" , " <options>" , " update compiler options, if possible; see reset " , changeSettings),
228229 nullary(" silent" , " disable/enable automatic printing of results" , verbosity),
229230 cmd(" type" , " [-v] <expr>" , " display the type of an expression without evaluating it" , typeCommand),
230231 cmd(" kind" , " [-v] <expr>" , " display the kind of expression's type" , kindCommand),
@@ -304,57 +305,23 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
304305 intp.lastWarnings foreach { case (pos, msg) => intp.reporter.warning(pos, msg) }
305306 }
306307
307- private def changeSettings (args : String ): Result = {
308- def showSettings () = {
309- for (s <- settings.userSetSettings.toSeq.sorted) echo(s.toString)
310- }
311- def updateSettings () = {
312- // put aside +flag options
313- val (pluses, rest) = (args split " \\ s+" ).toList partition (_.startsWith(" +" ))
314- val tmps = new Settings
315- val (ok, leftover) = tmps.processArguments(rest, processAll = true )
316- if (! ok) echo(" Bad settings request." )
317- else if (leftover.nonEmpty) echo(" Unprocessed settings." )
318- else {
319- // boolean flags set-by-user on tmp copy should be off, not on
320- val offs = tmps.userSetSettings filter (_.isInstanceOf [Settings # BooleanSetting ])
321- val (minuses, nonbools) = rest partition (arg => offs exists (_ respondsTo arg))
322- // update non-flags
323- settings.processArguments(nonbools, processAll = true )
324- // also snag multi-value options for clearing, e.g. -Ylog: and -language:
325- for {
326- s <- settings.userSetSettings
327- if s.isInstanceOf [Settings # MultiStringSetting ] || s.isInstanceOf [Settings # PhasesSetting ]
328- if nonbools exists (arg => arg.head == '-' && arg.last == ':' && (s respondsTo arg.init))
329- } s match {
330- case c : Clearable => c.clear()
331- case _ =>
332- }
333- def update (bs : Seq [String ], name : String => String , setter : Settings # Setting => Unit ) = {
334- for (b <- bs)
335- settings.lookupSetting(name(b)) match {
336- case Some (s) =>
337- if (s.isInstanceOf [Settings # BooleanSetting ]) setter(s)
338- else echo(s " Not a boolean flag: $b" )
339- case _ =>
340- echo(s " Not an option: $b" )
341- }
342- }
343- update(minuses, identity, _.tryToSetFromPropertyValue(" false" )) // turn off
344- update(pluses, " -" + _.drop(1 ), _.tryToSet(Nil )) // turn on
345- }
346- }
347- if (args.isEmpty) showSettings() else updateSettings()
308+ private def changeSettings (line : String ): Result = {
309+ def showSettings () = for (s <- settings.userSetSettings.toSeq.sorted) echo(s.toString)
310+ if (line.isEmpty) showSettings() else { updateSettings(line) ; () }
311+ }
312+ private def updateSettings (line : String ) = {
313+ val (ok, rest) = settings.processArguments(words(line), processAll = false )
314+ ok && rest.isEmpty
348315 }
349316
350317 private def javapCommand (line : String ): Result = {
351318 if (javap == null )
352- " :javap unavailable, no tools.jar at %s . Set JDK_HOME." .format(jdkHome)
319+ s " :javap unavailable, no tools.jar at $jdkHome . Set JDK_HOME. "
353320 else if (line == " " )
354321 " :javap [-lcsvp] [path1 path2 ...]"
355322 else
356323 javap(words(line)) foreach { res =>
357- if (res.isError) return " Failed: " + res.value
324+ if (res.isError) return s " Failed: ${ res.value} "
358325 else res.show()
359326 }
360327 }
@@ -472,8 +439,16 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
472439 }
473440
474441 /** create a new interpreter and replay the given commands */
475- def replay () {
476- reset()
442+ def replayCommand (line : String ): Unit = {
443+ def run (destructive : Boolean ): Unit = {
444+ if (destructive) createInterpreter() else reset()
445+ replay()
446+ }
447+ if (line.isEmpty) run(destructive = false )
448+ else if (updateSettings(line)) run(destructive = true )
449+ }
450+ /** Announces as it replays. */
451+ def replay (): Unit = {
477452 if (replayCommandStack.isEmpty)
478453 echo(" Nothing to replay." )
479454 else for (cmd <- replayCommands) {
@@ -482,21 +457,28 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
482457 echo(" " )
483458 }
484459 }
485- def resetCommand () {
486- echo(" Resetting interpreter state." )
487- if (replayCommandStack.nonEmpty) {
488- echo(" Forgetting this session history:\n " )
489- replayCommands foreach echo
490- echo(" " )
491- replayCommandStack = Nil
460+ /** `reset` the interpreter in an attempt to start fresh.
461+ * Supplying settings creates a new compiler.
462+ */
463+ def resetCommand (line : String ): Unit = {
464+ def run (destructive : Boolean ): Unit = {
465+ echo(" Resetting interpreter state." )
466+ if (replayCommandStack.nonEmpty) {
467+ echo(" Forgetting this session history:\n " )
468+ replayCommands foreach echo
469+ echo(" " )
470+ replayCommandStack = Nil
471+ }
472+ if (intp.namedDefinedTerms.nonEmpty)
473+ echo(" Forgetting all expression results and named terms: " + intp.namedDefinedTerms.mkString(" , " ))
474+ if (intp.definedTypes.nonEmpty)
475+ echo(" Forgetting defined types: " + intp.definedTypes.mkString(" , " ))
476+ if (destructive) createInterpreter() else reset()
492477 }
493- if (intp.namedDefinedTerms.nonEmpty)
494- echo(" Forgetting all expression results and named terms: " + intp.namedDefinedTerms.mkString(" , " ))
495- if (intp.definedTypes.nonEmpty)
496- echo(" Forgetting defined types: " + intp.definedTypes.mkString(" , " ))
497-
498- reset()
478+ if (line.isEmpty) run(destructive = false )
479+ else if (updateSettings(line)) run(destructive = true )
499480 }
481+ /** Resets without announcements. */
500482 def reset () {
501483 intp.reset()
502484 unleashAndSetPhase()
@@ -619,6 +601,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
619601 else File (filename).printlnAll(replayCommands : _* )
620602 )
621603
604+ @ deprecated(" Use reset, replay or require to update class path" , since = " 2.11" )
622605 def addClasspath (arg : String ): Unit = {
623606 val f = File (arg).normalize
624607 if (f.exists) {
0 commit comments