GithubHelp home page GithubHelp logo

scala-cli-repl's Introduction

Scala CLI REPL

The REPL of scala-cli in Emacs term mode.

demo.gif

Installation

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.

Ob-scala-cli

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:

demo-ob-scala-cli.gif

Installing scala-cli

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

Org Babel

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))

Supported parameters

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.

Useful options

  • 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.

Similar projects

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"))

scala-cli-repl's People

Contributors

ag91 avatar vsuharnikov avatar jakdar avatar rossabaker avatar

Stargazers

Oscar Vargas Torres avatar  avatar Roman Greshny avatar  avatar Alexandre Moreno avatar Bruno Henriques avatar Michael Steinkogler avatar Phuthasone SANAVONGSAY avatar  avatar S. Rey-Coyrehourcq avatar  avatar

Watchers

Roman Greshny avatar Songpeng Zu avatar  avatar  avatar

scala-cli-repl's Issues

Emacs isn't responding, sequencep error when specified jvm parameter

Hello! Thanks for your module, very appreciated your work.

  1. I tried to use an org-babel integration and Emacs wasn't responding. All I see is the message "Waiting for scala-cli to start" with a lot of attempts. The solution was simple:

    (setq scala-cli-repl-program (executable-find "scala-cli")) ;; HACK for macOS + nix (?)
    
  2. There is a missed useful scala-cli parameter - :jvm. To support this, add it as mentioned in README:

     (setq ob-scala-cli-supported-params '(:scala-version :dep :jvm))
    

    But you can get an error, e.g.:

    #+begin_src scala :scala-version 2.13.11 :jvm 11
    println(s"test1 ${1+1}")
    #+end_src
    

    format: Wrong type argument: sequencep, 11

    To solve it, change the jvm argument type to the string: :jvm "11"

Wrong number of arguments (when executing the code-block?)

Hello,

Thank you for creating an alternative to ob-ammonite but compatible with scala-cli 🙇 I was looking forward for this!

I am somewhat a Emacs newbie and I am using doom-emacs. I was used to Ctrl-C Ctrl-C to execute code-blocks and see the results back. I managed to setup the plugin but I get a "Wrong number of arguments" error right after I execute the code-block:

image

To be honest, I am still getting acquainted with the emacs setup after a short break from using it. What is the best approach to debug? It is very likely a bug in my setup, although it is mostly vanilla Doom Emacs.

I am using Emacs 29.2, latest doom-emacs and the following config:

;; under packages.el
(package! scala-cli-repl
  :recipe (:host github :repo "ag91/scala-cli-repl" :files ("*.el")) :pin "e19457e3a78674154959ad305a0ab7c3f87e6bab")

;; under config.el
(after! org-mode
  :config
    (add-to-list 'org-babel-load-languages '(scala-cli . t) '(scala .))
    (setq ob-scala-cli-default-params '(:scala-version "3.3.1" :jvm 21)))

Thank you in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.