Skip to content

Latest commit

 

History

History
221 lines (168 loc) · 8.71 KB

README.org

File metadata and controls

221 lines (168 loc) · 8.71 KB

Scala layer

img/scala.png with img/ensime.png

Table of Contents

Description

This layer adds support for the Scala language using the excellent ENSIME client/server.

Layer Installation

To use this configuration layer, add it to your ~/.spacemacs. You will need to add scala to the existing dotspacemacs-configuration-layers list in this file.

Ensime

ENSIME provides IDE-like features, such as refactoring, incremental compilation and project-wide type-checking.

ENSIME requires a configuration file at the root of each Scala project. It provides an SBT plugin to generate these files.

Installation

Configure the ENSIME sbt plugin by adding the following to ~/.sbt/0.13/plugins/plugins.sbt:

addSbtPlugin("org.ensime" % "ensime-sbt" % "0.2.3")

Please go to ensime-sbt Github Page to check the latest version of ensime-sbt plugin.

Please note your projects’ project/build.properties need to use a version newer that 0.13.5 of sbt.

sbt.version=0.13.9

Usage

  1. Create a .ensime file at the root of your Scala project using sbt gen-ensime at the shell.
  2. Run M-x ensime within Emacs to start an ENSIME session.

Each Scala project uses a dedicated ENSIME session, so you only need to run M-x ensime once per project. Any Scala files you create or visit within the project will automatically use ENSIME for the remainder of your editing session.

Scalastyle

Scalastyle provides style-checking and linting. The Emacs functionality is provided by Flycheck.

To use scalastyle,

  1. Download the scalastyle jar and put it somewhere sensible
  2. Customise the flycheck-scalastyle-jar variable and set it to the path of the jar.

See the flycheck documentation for up-to-date configuration instructions.

Automatically show the type of the symbol under the cursor

To enable the feature ensime-print-type-at-point when cursor moves, set the variable scala-enable-eldoc-mode to t.

(setq-default dotspacemacs-configuration-layers '(
  (scala :variables scala-enable-eldoc-mode t)))

Enabling this option can cause slow editor performance.

Automatically insert asterisk in multiline comments

To insert a leading asterisk in multiline comments automatically, set the variable scala-auto-insert-asterisk-in-comments to t.

(setq-default dotspacemacs-configuration-layers '(
  (scala :variables scala-auto-insert-asterisk-in-comments t)))

Key bindings

Ensime key bindings

Search

Key BindingDescription
SPC m /incremental search using ensime-scalex major mode
SPC m ?incremental search in all live buffers

sbt

Key BindingDescription
SPC m b ccompile command
SPC m b Cclean command
SPC m b iswitch to sbt shell
SPC m b ppackage command
SPC m b rrun command

Typecheck

Key BindingDescription
SPC m c ttype check the current file
SPC m c Ttype check all the open buffers

Debug

Key BindingDescription
SPC m d AAttach to a remote debugger
SPC m d bset breakpoint
SPC m d Bclear breakpoint
SPC m d Cclear all breakpoints
SPC m d ccontinue
SPC m d dstart a debug session
SPC m d iinspect value at point
SPC m d llist local variables
SPC m d nnext
SPC m d ostep out
SPC m d qquit
SPC m d rrun
SPC m d sstep
SPC m d tbacktrace

Note: These key bindings need a micro-state, PR welcome :-)

Errors

Key BindingDescription
SPC m e eprint error at point
SPC m e lshow all errors and warnings
SPC m e sswitch to buffer containing the stack trace parser

Goto

Key BindingDescription
SPC m g ggo to definition
SPC m g igo to implementation
SPC m g tgo to test

Documentation, Inspect

Key BindingDescription
SPC m h hshow documentation for symbol at point
SPC m h ushow uses for symbol at point
SPC m h tprint type at point
SPC m i iinspect type at point
SPC m i Iinspect type in other frame
SPC m i pinspect project package

Server

Key BindingDescription
SPC m n Freload open files
SPC m n sstart ensime server
SPC m n Sregenerate the .ensime and restart the ensime server

Refactoring

Key BindingDescription
SPC m r fformat source
SPC m r dget rid of an intermediate variable (ensime-refactor-inline-local)
SPC m r Dget rid of an intermediate variable (ensime-undo-peek)
SPC m r iorganize imports
SPC m r mextract a range of code into a method
SPC m r rrename a symbol project wide
SPC m r timport type at point
SPC m r vextract a range of code into a variable
SPC m zexpand/contract region

Tests

Key BindingDescription
SPC m t atest command (sbt)
SPC m t rtest quick command (sbt)
SPC m t ttest only (sbt)

REPL

Key BindingDescription
SPC m s aask for a file to be loaded in the REPL
SPC m s bsend buffer to the REPL
SPC m s Bsend buffer to the REPL and focus the REPL buffer in insert state
SPC m s istart or switch to the REPL inferior process
SPC m s rsend region to the REPL
SPC m s Rsend region to the REPL and focus the REPL buffer in insert state