Skip to content

Latest commit

 

History

History
266 lines (213 loc) · 10.3 KB

README.org

File metadata and controls

266 lines (213 loc) · 10.3 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

Refer to the Ensime installation instructions to install the sbt-ensime plugin.

Please note you have to use a version newer than 0.13.5 of sbt in your project’s project/build.properties. For example,

sbt.version=0.13.11

Usage

  1. Create a .ensime file at the root of your Scala project using sbt ensimeConfig and sbt ensimeConfigProject 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, it must be present as an executable in your PATH.

To test if scalastyle executable is in your path, run scalastyle in a new terminal, it should output something like:

$ scalastyle
scalastyle 0.8.0
Usage: scalastyle [options] <source directory>
...

Finally, enable the syntax-checking layer and set the flycheck-scalastylerc variable to a valid location.

(setq-default flycheck-scalastylerc "/usr/local/etc/scalastyle_config.xml")

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

Use Java doc-style

To enable java-doc-style, set the variable scala-indent:use-javadoc-style to t

(setq-default dotspacemacs-configuration-layers '(
  (scala :variables scala-indent:use-javadoc-style t)))

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 to t.

(setq-default dotspacemacs-configuration-layers '(
  (scala :variables scala-enable-eldoc 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)))

Automatically replace arrows with unicode ones

To replace =>, -> and <- with unicode arrows , and , set the variable scala-use-unicode-arrows to t.

If in some occasions you don’t want the arrows replaced (for example when defining compound operators like =>>), you can always undo the change and get the ascii arrows back.

(setq-default dotspacemacs-configuration-layers '(
  (scala :variables scala-use-unicode-arrows t)))

Auto-start

If you prefer to have Ensime start when you load a scala file, you can enable it with

(setq-default dotspacemacs-configuration-layers '(
    (scala :variables scala-auto-start-ensime 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 .sbt transient state
SPC m b bsbt command
SPC m b ccompile
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 istep
SPC m d nnext
SPC m d ostep out
SPC m d qquit
SPC m d rrun
SPC m d tbacktrace
SPC m d vinspect value at point

Note: These key bindings need a transient-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

Print and yank types

SPC m h Tprint full type name at point
SPC m h tprint short type name at point
SPC m y Tyank full type name at point
SPC m y tyank short type name at point

Documentation, Inspect

Key BindingDescription
SPC m h hshow documentation for symbol at point
SPC m h ushow uses for symbol 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 aadd type annotation
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