Skip to content

Commit

Permalink
JLine 3: be emacs friendly (adjust :completions support)
Browse files Browse the repository at this point in the history
based on review feedback from hvesalai
  • Loading branch information
SethTisue committed Mar 25, 2020
1 parent 328c5db commit 2738c38
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/repl-frontend/scala/tools/nsc/interpreter/shell/ILoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,21 @@ class ILoop(config: ShellConfig, inOverride: BufferedReader = null,
else NoCompletions
}

// this may be used by editors that embed the REPL (e.g. emacs) to present completions themselves;
// it's also used by ReplTest
def completionsCommand(what: String): Result = {
val completions = in.completion.complete(what, what.length)
val prefix = if (completions == NoCompletions) "" else what.substring(0, completions.cursor)
completions.candidates.map(c => s"[completions] $prefix$c").foreach(echo)
if (completions.candidates.nonEmpty) {
val prefix =
if (completions == NoCompletions) ""
else what.substring(0, completions.cursor)
// hvesalai (emacs sbt-mode maintainer) says it's important to echo only once and not per-line
echo(
completions.candidates
.map(c => s"[completions] $prefix$c")
.mkString("\n")
)
}
Result.default // never record completions
}

Expand Down

0 comments on commit 2738c38

Please sign in to comment.