hvesalai / emacs-sbt-mode

An emacs mode for interacting with scala sbt and projects
GNU General Public License v3.0
125 stars 38 forks source link

Turn echo off for all sbt-mode interactions #132

Closed hvesalai closed 6 years ago

hvesalai commented 6 years ago

Both sbt and the REPL console started from within sbt have echo turned on when running from emacs.

This needs to change.

  1. create a new command emacs for emacs use instead of shell. Here it is...
import java.io.InputStreamReader
import sbt.BasicKeys.shellPrompt

val Emacs = "emacs"
def emacs = Command.command(Emacs) { s =>
  val prompt = (s get shellPrompt) match { case Some(pf) => pf(s); case None => "> " }
  System.out.print(prompt)
  val reader = new InputStreamReader(System.in)
  val first = reader.read
  val line = if (first == -1) None else {
    Some((Iterator.single(first) ++ Iterator.continually(reader.read)).takeWhile(c => !(c == -1 || c == '\n')).map(_.toChar).mkString)
  }

  line match {
    case Some(line) =>
      val newState = s.copy(onFailure = Some(Emacs), remainingCommands = line +: Emacs +: s.remainingCommands).setInteractive(true)
      if (line.trim.isEmpty) newState else newState.clearGlobalLog
    case None => s.setInteractive(false)
  }
}

commands += emacs

Until we have that in the main sbt release, people can place it in ~/.sbt/0.13/Emacs.sbt and modify sbt:program-options custom setting to run the command when starting sbt.

  1. The second thing is to do the same for the REPL, i.e. console. Currently the REPL has echo hardcoded in scala 2.12, but not in 2.13

For 2.12. there are two options here: a) modify the REPL (i.e. submit patch to scala) it self to read some system variable and not echo if that variable is set: here SimpleReader.scala#L28

b) modify sbt so that it doesn't create the default, echoing, version of the repl. This happens here for scala 2.11 and 2.12: https://github.com/sbt/zinc/blob/1.x/internal/compiler-bridge/src/main/scala_2.11-12/xsbt/ConsoleInterface.scala#L44

For 2.13 it has already been implemented: just set env.emacs to true (or any non-empty value)

  1. After the both step has been done, sbt-mode-comint.el should be modified so that comint-process-echoes is set to nil insteadof the current t.
hvesalai commented 6 years ago

ping @fommil

fommil commented 6 years ago

we could include this in sbt-ensime

hvesalai commented 6 years ago

For sbt 1.1 the thing has changed completely in commit https://github.com/sbt/sbt/commit/e83564a6b71639c7e51bbc002c2d083cf8c9ab5a

hvesalai commented 6 years ago

But I guess the same thing could still work, since they do have an oldShell akin to emacs in there BasicCommands.scala#L252

hvesalai commented 6 years ago

For both 0.13.x and 1.x we should have sbt follow the env.emacs variable and create a SimpleReader instead of FullReader. I'll make PRs to sbt

hvesalai commented 6 years ago

Also, we should try to get scala REPL to include a :completions command

hvesalai commented 6 years ago

https://github.com/sbt/sbt/pull/3982

hvesalai commented 6 years ago

I was wrong

hvesalai commented 6 years ago

See also #136 #134 #135