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:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
- [[#layer-installation ][Layer Installation ]]
- [[#ensime ][Ensime ]]
- [[#scalastyle ][Scalastyle ]]
- [[#use-java-doc-style ][Use Java doc-style ]]
- [[#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 ]]
- [[#auto-start ][Auto-start ]]
- [[#key-bindings ][Key bindings ]]
2015-06-10 16:44:30 +00:00
* Description
2017-04-25 15:42:58 +00:00
This layer adds support for the Scala language using the excellent [[http://ensime.org/ ][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
2016-11-22 04:18:03 +00:00
Then, you should modify your =~/.spacemacs= to use the recommended Ensime
version (Stable). Please add the following lines to =dotspacemacs/user-init= :
#+BEGIN_SRC emacs-lisp
(push '("melpa-stable" . "stable.melpa.org/packages/ ") configuration-layer--elpa-archives)
(push '(ensime . "melpa-stable") package-pinned-packages)
#+END_SRC
2015-06-10 16:44:30 +00:00
* Ensime
2017-04-25 15:42:58 +00:00
[[http://ensime.org/ ][ENSIME ]] provides IDE-like features, such as refactoring, incremental compilation
2016-08-21 07:55:25 +00:00
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.
2017-02-09 22:22:38 +00:00
Installation instructions and usage can be found in the =Java= layer
[[file:../java/README.org::#ensime ][README.org ]].
2015-06-10 16:44:30 +00:00
* 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.
2016-10-02 19:23:40 +00:00
To use scalastyle, it must be present as an executable in your =PATH= .
2015-06-10 16:44:30 +00:00
2016-10-02 19:23:40 +00:00
- OSX users: =brew install scalastyle=
- Linux, please see http://www.scalastyle.org/command-line.html
To test if =scalastyle= executable is in your path, run =scalastyle= in a new
terminal, it should output something like:
#+BEGIN_SRC bash
$ scalastyle
scalastyle 0.8.0
Usage: scalastyle [options] <source directory >
...
#+END_SRC
Finally, enable the =syntax-checking= layer and set the =flycheck-scalastylerc=
variable to a valid location.
2016-07-25 05:11:17 +00:00
#+BEGIN_SRC emacs-lisp
2016-10-02 19:23:40 +00:00
(setq-default 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-10-21 18:13:35 +00:00
(scala :variables scala-enable-eldoc 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
2017-02-09 22:22:38 +00:00
All ensime key bindings are listed in the =java= layer [[file:../java/README.org::#ensime-key-bindings ][README.org ]].