From 2738c38fd248fbf7a3fd5ea366ba3f8ce24f1b8b Mon Sep 17 00:00:00 2001 From: Seth Tisue Date: Tue, 10 Mar 2020 11:20:27 +0100 Subject: [PATCH] JLine 3: be emacs friendly (adjust :completions support) based on review feedback from hvesalai --- .../scala/tools/nsc/interpreter/shell/ILoop.scala | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/repl-frontend/scala/tools/nsc/interpreter/shell/ILoop.scala b/src/repl-frontend/scala/tools/nsc/interpreter/shell/ILoop.scala index 836274d6fa7d..c1d115123a75 100644 --- a/src/repl-frontend/scala/tools/nsc/interpreter/shell/ILoop.scala +++ b/src/repl-frontend/scala/tools/nsc/interpreter/shell/ILoop.scala @@ -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 }