Configuring a Groovy Mode for Emacs

For work, I need to start learning Groovy. As I want to focus on the language and how this do work, I’ll use Emacs. This post explains how to configure an Emacs major mode for Groovy on a fresh installation of Emacs 23.2.1 on Linux.

Create ~/.emacs.d/

The ~/.emacs.d/ folder is the default folder for additional per-user Emacs-specific files.

# touch ~/.emacs

Download a Groovy Mode for Emacs

I chose to use the Groovy mode for emacs by Russel Winder. We will download the file into the modes subfolder.

# mkdir ~/.emacs.d
# cd ~/.emacs/d
# mkdir modes
# cd modes
# wget

Create ~/.emacs init file

The ~/.emacs file contain Lisp code to execute when starting up Emacs.

Configure .emacs to load the Groovy mode

Add the following lines to the ~/.emacs file

;;; add modes to the load path
(add-to-list 'load-path "~/.emacs.d/modes/")

Configure .emacs to use the Groovy mode

Let’s now add the required configuration to use Groovy mode.

;;; use groovy-mode when file ends in .groovy or has #!/bin/groovy at start
(autoload 'groovy-mode "groovy-mode" "Groovy editing mode." t)
(add-to-list 'auto-mode-alist '("\.groovy$" . groovy-mode))
(add-to-list 'interpreter-mode-alist '("groovy" . groovy-mode))


%d bloggers like this: