Skip to content

Files

Latest commit

35109c4 · May 10, 2017

History

History
84 lines (64 loc) · 3.96 KB

Ensime.md

File metadata and controls

84 lines (64 loc) · 3.96 KB

Installing Ensime

Useful links

Some useful links for using Emacs and Ensime with sbt:

Installation

I am assuming that you are already familar with Emacs and have it installed on your system. If this is not the case, I recommend using the Scala IDE for the short course, as Emacs has a fairly steep learning curve. You can always investigate Emacs and Ensime later once you are more familiar with Scala.

Ensime is installed using MELPA - the Emacs package archive. If you don't currently use MELPA, you must first enable it by copying a snippet of code like:

;; MELPA package manager
(require 'package)
(setq
 package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                    ("org" . "http://orgmode.org/elpa/")
                    ("melpa" . "http://melpa.org/packages/")
                    ("melpa-stable" . "http://stable.melpa.org/packages/"))
 package-archive-priorities '(("melpa-stable" . 1)))

(package-initialize)
(when (not package-archive-contents)
  (package-refresh-contents)
  (package-install 'use-package))
(require 'use-package)

into your .emacs or .emacs.d/init.el file. Try restarting Emacs and check there are no errors. If for some reason this doesn't work, you could try adding the snippet:

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

immediately before the final line. See the Learning Emacs page for further details.

Once you have MELPA set up, installing Ensime should be as simple as copying the snippet:

(use-package ensime
  :ensure t
  :pin melpa)

to the end of your init file and restarting Emacs, but see the Installing with Emacs page for further details.

To use Ensime with sbt, you also need to install the Ensime plugin for sbt. This should be as simple as adding the line:

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

to your ~/.sbt/0.13/plugins/plugins.sbt file. Create this file if you don't already have it. It's also a good idea to add the lines:

import org.ensime.EnsimeCoursierKeys._
ensimeServerVersion in ThisBuild := "2.0.0-SNAPSHOT"

to your ~/sbt/0.13/global.sbt file (again, create it if you don't have it). See the Sbt plugin for Ensime page for further details.

Using Ensime

The main thing to understand is that Ensime needs to know about the structure of your sbt project. This information is encoded in a file .ensime in the top-level directory of your sbt project (where the file build.sbt will often be present). An initial .ensime file for an sbt project can be generated using the ensimeConfig sbt task provided by the sbt-ensime plugin.

So, before using Emacs/Ensime with a particular sbt project for the first time, first run

sbt ensimeConfig

to analyse the project and create a .ensime file for it. You should probably re-run this after editing build.sbt or other build configuration files. Then start emacs with a command like emacs src/main/scala/blah/*.scala &. This will start up emacs and some basic syntax highlighting will be provided by scala-mode. However, you still need to start up Ensime with M-x ensime. Once you are up-and-running, Ensime provides fairly sophisticated IDE functionality. Some commonly used commands include:

  • M-x ensime - Start up Ensime
  • C-c C-v d - Scaladoc for symbol at cursor
  • C-c C-v f - Reformat source code in this buffer
  • C-c C-b c - sbt compile
  • C-c C-b r - sbt run

See the Emacs Ensime User Guide for further details.

eof