- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
Scala, Emacs and Yasnippet
Created by nielsen on 2008-12-01. Updated: 2009-11-08, 17:40
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.
This version (0.5.99.5) 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 () (yas/minor-mode-on)))
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.