This page is no longer maintained — Please continue to the home page at

Scala, Emacs and Yasnippet

Developers today are used to working with tools like Visual Studio or Eclipse where one of the selling points are templates (snippets) for many standard operations and also code completions for variables, methods and argument names. Sorry to say that this is not about Scala code completion features in Emacs, but a feature that is just as useful - the insertion of templates for various standard Scala constructs. All this has been done by modifying the Scala mode and adding the power of Yasnippet to Emacs. The video below shows how it works in practice.

Get the Flash Player to see this player.

To use these new features one needs to install the Yasnippet package. This is a great package that already includes snippets for html, css, obj-c and many more, but most importantly the Scala snippets. Download a version 0.5.7 or newer of Yasnippet and follow the installation instructions for the non-bundle version. Now get the newest version of the Scala Emacs mode from the subversion repository.

svn co scala-mode

This version ( does not override the TAB button, as the previous versions did and will therefore work with Yasnippet. Follow the normal installation procedure for the Scala Emacs mode and add the following to you .emacs file to use the new snippets.

(add-hook 'scala-mode-hook
          '(lambda ()

This will load Yasnippet when editing a Scala file. Currently all the Scala snippets are shipped with the Yasnippet package, but there may in the future be snippets that are shipped with the Scala Emacs mode before being moved to the Yasnippet package. To use these snippets, add the following to your .emacs file.

(setq yas/my-directory "/path/to/some/directory/scala-mode/contrib/yasnippet/snippets")
(yas/load-directory yas/my-directory)

Happy Scala hacking and enjoy this new feature.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland