The REPL of scala-cli in Emacs term mode.
You can access the REPL loading scala-cli-repl.el
and running scala-cli-repl
.
It is possible to load an Sbt project in the REPL (i.e., be able to
evaluate symbols defined in your project from the REPL) by setting the
custom variable (setq scala-cli-load-repl-in-sbt-context )
.
Also, if you like literate programming in Org Mode, you can load also
ob-scala-cli.el
, which lets you run blocks like the following
#+begin_src scala :scala-version 3.0.0 :dep '("com.lihaoyi::os-lib:0.9.0")
println("This is:" + os.pwd)
#+end_src
into the scala-cli REPL.
It is sufficient to have (scala . t)
in your
org-babel-load-languages
, because ob-scala-cli will run for scala
org blocks. For more information on how to enable an org babel
language check here and here.
If you use lsp-mode and lsp-metals, you can also setup IDE style
completion from within a src block with ob-scala-cli-lsp-org
:
You can check the instructions for your platform on https://scala-cli.virtuslab.org/install/.
At the time of writing this, the easy way (on Linux) is:
curl -fL https://github.com/Virtuslab/scala-cli/releases/latest/download/scala-cli-x86_64-pc-linux.gz | gzip -d > scala-cli
chmod +x scala-cli
sudo mv scala-cli /usr/local/bin/scala-cli
Make sure to use this snippet in your configuration to make sure that scala blocks get picked up by ob-scala-cli:
(add-to-list 'org-babel-load-languages '(scala-cli . t))
Currently supported header parameters are:
- :scala-version
you can define the Scala version you want your code to be evaluated in.
- :dep
you pass a list of dependencies in Mill format as a list, see example block above
- :jvm
you can set the JVM version to use for evaluating your code
**Note**: the code is evaluated in a global scope by default, so you can use variables and functions across the blocks. If you don’t want definitions to leak, wrap them in curly braces.
If you enjoy Elisp, you can get an updated list of valid parameters
evaluating ob-scala-cli-supported-params
.
Also see usage examples.
ob-scala-cli-default-params
you can define default parameters locally or globally and don’t specify them each block. Example:
(setq ob-scala-cli-default-params '(:scala-version "2.13.11" :jvm 17))
then just write a code:
println(s""" |Scala version: ${scala.util.Properties.versionString} |JVM version: ${System.getProperty("java.version")}""".stripMargin)
**Note**: if you use dependencies in multiple blocks specify also
:deps
for faster evaluation.scala-cli-ob-force-kill
if you run blocks with different options (Scala version, JVM version, deps, etc.), you could face with an error:
Buffer ”Scala-Cli” has a running process; kill it? (y or n)
Set this flag if you want to forcely kill the process and the buffer.
This is a port of ammonite-term-repl, which is now an archived repository.
You can still use Ammonite through this mode with:
(setq scala-cli-repl-program-args '("--power" "--amm"))