Skip to content
Pere Villega
Go back

Emacs and Scala in Mac OS X Yosemite

After hearing a lot about the benefits of using Emacs to code in Scala, I’ve decided to give it a go and also to document the steps to work with it, in case anyone else feels crazy enough to try this.

Why?

I guess first I should explain why would I use Emacs when there are products like IntelliJ IDEA which provide a lot of functionality and are easy (easier?) to use. This is a personal decision, but some reasons I’ve found to try Emacs are:

Environment

I’m going to install Emacs in a MacBook Pro with Yosemite.

There are several Emacs packages you can choose from, the one I’ve been recommended is Scapemacs so I’ll be trying this one.

For Scala goodness I’ll use Ensime and its Emacs plugin.

I won’t research any other plugins by now, geting used to Emacs is enough.

Installing Spacemacs

Spacemacs is a bundle of configuration and plugins for Emacs, as a consequence before starting you will need Emacs installed. As of today Spacemacs recommends to use the emacs-mac-port package, available in Homebrew:

	$ brew tap railwaycat/emacsmacport
	$ brew install emacs-mac --with-spacemacs-icon

After that, it is recommended to backup your current Emacs config:

	cd ~
	mv .emacs.d .emacs.bak

To install Spacemacs, just clone the repo along its submodules to ~/.emacs.d:

	git clone --recursive https://github.com/syl20bnr/spacemacs ~/.emacs.d

Once done, launch Emacs and wait for the set up to be done:

	$ emacs

Scala and Emacs

Spacemacs provides integration with Ensime via this package. It works as a layer, to install it just edit your ~/.spacemacs file and find dotspacemacs-configuration-layers near the top of the file. Add scala as a new layer:

	dotspacemacs-configuration-layers
	   '(
	     ;; ----------------------------------------------------------------
	     ;; Example of useful layers you may want to use right away.
	     ;; Uncomment some layer names and press <SPC f e R> (Vim style) or
	     ;; <M-m f e R> (Emacs style) to install them.
	     ;; ----------------------------------------------------------------
	     ;; auto-completion
	     ;; better-defaults
	     emacs-lisp
	     ;; git
	     ;; markdown
	     ;; org
	     ;; (shell :variables
	     ;;        shell-default-height 30
	     ;;        shell-default-position 'bottom)
	     ;; syntax-checking
	     version-control
	     scala
	     )

Then restart Emacs. Next create a global plugins.sbt at ~/.sbt/0.13/plugins/plugin.sbt and add to it:

	resolvers += Resolver.sonatypeRepo("snapshots")

	addSbtPlugin("org.ensime" % "ensime-sbt" % "0.1.5-SNAPSHOT")

Run sbt once in some of your projects to download the dependency.

To work with a Scala project you will need to create a .ensime file by running

	sbt gen-ensime

At the root. To load Ensime, type SPC : ensime and wait until the environment is configured, which may take a while the first time.

Learning Spacemacs

After Emacs loads all the configuration you are welcomed by… an ugly yellow screen. Ugh. Yes, it will take a while to get used to this, no one said it would be easy ;) There are two resources I’m using to get started:

I started with the Evil-adapted Vimtutor to get familiar with the key bindings. Press SPC h T to launch it.

First day feelings

This is hard. I’m ashamed to acknowledge how long did it take me to open a file in Emacs, much less to compile it via Sbt.

I can see the benefits of learning Emacs and not having to use the mouse much, but it will take effort to get used to this and to get the ‘right’ environment setup working.


Share this post on:

Previous Post
Scala Exchange 2015 Day One
Next Post
Scala REPL