2015-12-02 14:23:39 +00:00
#+TITLE : Scala layer
2015-06-10 16:44:30 +00:00
[[file:img/scala.png ]] with [[file:img/ensime.png ]]
2016-04-01 03:59:00 +00:00
* Table of Contents :TOC_4_gh:noexport:
- [[#description ][Description ]]
- [[#layer-installation ][Layer Installation ]]
- [[#ensime ][Ensime ]]
- [[#installation ][Installation ]]
- [[#usage ][Usage ]]
- [[#scalastyle ][Scalastyle ]]
2016-05-06 11:35:30 +00:00
- [[#use-java-doc-style ][Use Java doc-style ]]
2016-04-01 03:59:00 +00:00
- [[#automatically-show-the-type-of-the-symbol-under-the-cursor ][Automatically show the type of the symbol under the cursor ]]
- [[#automatically-insert-asterisk-in-multiline-comments ][Automatically insert asterisk in multiline comments ]]
- [[#automatically-replace-arrows-with-unicode-ones ][Automatically replace arrows with unicode ones ]]
2016-07-25 16:17:03 +00:00
- [[#auto-start ][Auto-start ]]
2016-04-01 03:59:00 +00:00
- [[#key-bindings ][Key bindings ]]
- [[#ensime-key-bindings ][Ensime key bindings ]]
- [[#search ][Search ]]
- [[#sbt ][sbt ]]
- [[#typecheck ][Typecheck ]]
- [[#debug ][Debug ]]
- [[#errors ][Errors ]]
- [[#goto ][Goto ]]
2016-06-05 04:44:51 +00:00
- [[#print-and-yank-types ][Print and yank types ]]
2016-04-01 03:59:00 +00:00
- [[#documentation-inspect ][Documentation, Inspect ]]
- [[#server ][Server ]]
- [[#refactoring ][Refactoring ]]
- [[#tests ][Tests ]]
- [[#repl ][REPL ]]
2015-06-10 16:44:30 +00:00
* Description
2016-07-15 20:58:46 +00:00
This layer adds support for the Scala language using the excellent [[http://ensime.github.io/ ][ENSIME ]]
2015-06-10 16:44:30 +00:00
client/server.
* Layer Installation
2016-01-06 05:21:55 +00:00
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.
2015-06-10 16:44:30 +00:00
* Ensime
2016-08-21 07:55:25 +00:00
[[http://ensime.github.io/ ][ENSIME ]] provides IDE-like features, such as refactoring, incremental compilation
and project-wide type-checking.
2015-06-10 16:44:30 +00:00
ENSIME requires a configuration file at the root of each Scala project. It
provides an SBT plugin to generate these files.
** Installation
2016-08-21 07:55:25 +00:00
Refer to the [[https://ensime.github.io/build_tools/sbt/ ][Ensime installation instructions ]] to install the =sbt-ensime=
plugin.
2015-12-02 05:22:18 +00:00
2016-08-21 07:55:25 +00:00
Please note you have to use a version newer than =0.13.5= of =sbt= in your
project's =project/build.properties= . For example,
2016-06-21 17:05:21 +00:00
2015-12-02 05:22:18 +00:00
#+BEGIN_SRC scala
2016-06-21 17:05:21 +00:00
sbt.version=0.13.11
2015-12-02 05:22:18 +00:00
#+END_SRC
2015-06-10 16:44:30 +00:00
** Usage
1. Create a =.ensime= file at the root of your Scala project using =sbt
2016-05-24 16:27:36 +00:00
ensimeConfig= and =sbt ensimeConfigProject= at the shell.
2015-06-10 16:44:30 +00:00
2. Run =M-x ensime= within Emacs to start an ENSIME session.
2015-12-02 05:22:18 +00:00
2015-06-10 16:44:30 +00:00
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
2016-07-16 05:30:56 +00:00
[[http://www.scalastyle.org/ ][Scalastyle ]] provides style-checking and linting. The Emacs functionality is
2015-06-10 16:44:30 +00:00
provided by Flycheck.
To use scalastyle,
2016-07-16 05:30:56 +00:00
1. Download the [[http://www.scalastyle.org/#download ][scalastyle jar ]] and put it somewhere sensible
- If you are a brew user in OSX you can do: =brew install scalastyle=
2016-07-25 05:11:17 +00:00
2. Customise the =flycheck-scalastyle-jar= and =flycheck-scalastylerc= variables
in your =dotspacemacs/user-config= i.e.:
#+BEGIN_SRC emacs-lisp
(setq flycheck-scalastyle-jar
"/usr/local/Cellar/scalastyle/0.8.0/libexec/scalastyle_2.11-0.8.0-batch.jar")
(setq flycheck-scalastylerc
"/usr/local/etc/scalastyle_config.xml")
2016-07-16 05:30:56 +00:00
#+END_SRC
2015-12-02 05:22:18 +00:00
2016-07-25 05:11:17 +00:00
See the [[http://www.flycheck.org/en/latest/languages.html?highlight=scala#syntax-checker-scala-scalastyle ][flycheck documentation ]] and [[http://www.scalastyle.org/configuration.html ][scalastyle configuration ]] for up-to-date
configuration instructions.
2016-04-13 03:31:38 +00:00
2016-05-06 11:35:10 +00:00
** Use Java doc-style
2016-08-21 07:55:25 +00:00
To enable =java-doc-style= , set the variable =scala-indent:use-javadoc-style= to
=t=
2016-04-12 07:50:02 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
2016-05-06 11:35:10 +00:00
(scala :variables scala-indent:use-javadoc-style t)))
2016-04-12 07:50:02 +00:00
#+END_SRC
2015-11-21 21:37:16 +00:00
* Automatically show the type of the symbol under the cursor
2016-04-05 10:55:07 +00:00
To enable the feature =ensime-print-type-at-point= when cursor moves, set the
variable =scala-enable-eldoc= to =t= .
2015-11-21 21:37:16 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
2016-04-12 07:50:02 +00:00
(scala :variables scala-use-java-doc-style t)))
2015-11-21 21:37:16 +00:00
#+END_SRC
Enabling this option can cause slow editor performance.
2015-12-30 15:54:28 +00:00
* Automatically insert asterisk in multiline comments
2016-08-21 07:55:25 +00:00
To insert a leading asterisk in multiline comments automatically, set the
variable =scala-auto-insert-asterisk-in-comments= to =t= .
2015-12-30 15:54:28 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(scala :variables scala-auto-insert-asterisk-in-comments t)))
#+END_SRC
2016-01-18 08:58:01 +00:00
* 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.
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
(scala :variables scala-use-unicode-arrows t)))
2016-05-06 11:35:30 +00:00
#+END_SRC
2016-03-23 23:05:51 +00:00
2016-07-25 16:17:03 +00:00
* Auto-start
2016-08-21 07:55:25 +00:00
If you prefer to have Ensime start when you load a scala file, you can enable it
with
2016-03-23 23:05:51 +00:00
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers '(
2016-07-25 16:17:03 +00:00
(scala :variables scala-auto-start-ensime t)))
2016-01-18 08:58:01 +00:00
#+END_SRC
2015-06-10 16:44:30 +00:00
* Key bindings
** Ensime key bindings
*** Search
| Key Binding | Description |
|-------------+-----------------------------------------------------|
| ~SPC m /~ | incremental search using =ensime-scalex= major mode |
| ~SPC m ?~ | incremental search in all live buffers |
*** sbt
| Key Binding | Description |
|-------------+---------------------|
2016-10-03 02:25:08 +00:00
| ~SPC m b .~ | sbt transient state |
| ~SPC m b b~ | sbt command |
| ~SPC m b c~ | compile |
2015-06-10 16:44:30 +00:00
| ~SPC m b C~ | clean command |
| ~SPC m b i~ | switch to sbt shell |
| ~SPC m b p~ | package command |
| ~SPC m b r~ | run command |
*** Typecheck
| Key Binding | Description |
|-------------+---------------------------------|
| ~SPC m c t~ | type check the current file |
| ~SPC m c T~ | type check all the open buffers |
*** Debug
| Key Binding | Description |
|-------------+-----------------------------|
| ~SPC m d A~ | Attach to a remote debugger |
| ~SPC m d b~ | set breakpoint |
| ~SPC m d B~ | clear breakpoint |
| ~SPC m d C~ | clear all breakpoints |
| ~SPC m d c~ | continue |
| ~SPC m d d~ | start a debug session |
| ~SPC m d i~ | inspect value at point |
| ~SPC m d l~ | list local variables |
| ~SPC m d n~ | next |
| ~SPC m d o~ | step out |
| ~SPC m d q~ | quit |
| ~SPC m d r~ | run |
| ~SPC m d s~ | step |
| ~SPC m d t~ | backtrace |
2016-01-30 11:32:53 +00:00
*Note:* These key bindings need a transient-state, PR welcome :-)
2015-06-10 16:44:30 +00:00
*** Errors
| Key Binding | Description |
|-------------+----------------------------------------------------|
| ~SPC m e e~ | print error at point |
| ~SPC m e l~ | show all errors and warnings |
| ~SPC m e s~ | switch to buffer containing the stack trace parser |
*** Goto
| Key Binding | Description |
|-------------+----------------------|
| ~SPC m g g~ | go to definition |
| ~SPC m g i~ | go to implementation |
| ~SPC m g t~ | go to test |
2016-06-03 06:40:14 +00:00
*** Print and yank types
|-------------+--------------------------------|
2016-06-05 04:44:51 +00:00
| ~SPC m h T~ | print full type name at point |
| ~SPC m h t~ | print short type name at point |
| ~SPC m y T~ | yank full type name at point |
2016-06-03 06:40:14 +00:00
| ~SPC m y t~ | yank short type name at point |
2015-06-10 16:44:30 +00:00
*** Documentation, Inspect
| Key Binding | Description |
|-------------+----------------------------------------|
| ~SPC m h h~ | show documentation for symbol at point |
| ~SPC m h u~ | show uses for symbol at point |
| ~SPC m i i~ | inspect type at point |
| ~SPC m i I~ | inspect type in other frame |
| ~SPC m i p~ | inspect project package |
*** Server
| Key Binding | Description |
|-------------+--------------------------------------------------------|
| ~SPC m n F~ | reload open files |
| ~SPC m n s~ | start ensime server |
| ~SPC m n S~ | regenerate the =.ensime= and restart the ensime server |
*** Refactoring
| Key Binding | Description |
|-------------+----------------------------------------------------------------------|
2016-03-09 04:09:40 +00:00
| ~SPC m r a~ | add type annotation |
2015-06-10 16:44:30 +00:00
| ~SPC m r f~ | format source |
| ~SPC m r d~ | get rid of an intermediate variable (=ensime-refactor-inline-local=) |
| ~SPC m r D~ | get rid of an intermediate variable (=ensime-undo-peek=) |
| ~SPC m r i~ | organize imports |
| ~SPC m r m~ | extract a range of code into a method |
| ~SPC m r r~ | rename a symbol project wide |
| ~SPC m r t~ | import type at point |
| ~SPC m r v~ | extract a range of code into a variable |
| ~SPC m z~ | expand/contract region |
*** Tests
| Key Binding | Description |
|-------------+--------------------------|
| ~SPC m t a~ | test command (sbt) |
| ~SPC m t r~ | test quick command (sbt) |
| ~SPC m t t~ | test only (sbt) |
*** REPL
| Key Binding | Description |
|-------------+---------------------------------------------------------------------|
| ~SPC m s a~ | ask for a file to be loaded in the REPL |
| ~SPC m s b~ | send buffer to the REPL |
| ~SPC m s B~ | send buffer to the REPL and focus the REPL buffer in =insert state= |
| ~SPC m s i~ | start or switch to the REPL inferior process |
| ~SPC m s r~ | send region to the REPL |
| ~SPC m s R~ | send region to the REPL and focus the REPL buffer in =insert state= |