Skip to content
Add groovy imports easily in Emacs
Emacs Lisp Makefile
Branch: master
Clone or download
Pull request Compare This branch is 12 commits ahead, 7 commits behind dakrone:master.
Latest commit e56d7dd Oct 3, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
test Semicolons are optional in groovy. Sep 20, 2016
.gitignore Add stuff from cask-package-toolset Dec 11, 2015
Cask Clean up dependencies Sep 20, 2016
Makefile Don't have any ecukes yet Dec 11, 2015 fix badge links Sep 27, 2016
groovy-imports.el RELEASE 1.0 Oct 3, 2016

Emacs Groovy Imports


This is a fork of emacs-java-imports that is modified to work with Groovy programming language. Code is mostly the same (all credits go to original author of emacs-java-imports), except that it deals with the fact that semicolons are optional in groovy.

This package adds the import-groovy-class function, which will prompt for the class at point, then the package, then add the required import statement for the class and cache a “class-name -> package” relationship for any future importing of the class.


groovy-imports is available in the MELPA repository.

Do this, if MELPA isn’t already in your sources:

(require 'package)
(add-to-list 'package-archives
             '("MELPA" . "" ))

Then run M-x package-refresh-contents to load the contents of the new repository, and M-x package-install RET groovy-imports RET to install groovy-imports.


(require 'groovy-imports)

;; whatever you want to bind it to
(define-key groovy-mode-map (kbd "M-I") 'groovy-imports-add-import-dwim)

;; See customization below for where to put groovy imports
(setq groovy-imports-find-block-function 'groovy-imports-find-place-sorted-block)

I also recommend having groovy-imports automatically add any seen imports to the import cache by adding:

(add-hook 'groovy-mode-hook 'groovy-imports-scan-file)


Functions you may want to bind to a key in Groovy-mode:

groovy-imports-add-import-dwimAdd import for the symbol at point (or ask if none)
groovy-imports-add-importAdd import for symbol at point, confirming class first
groovy-imports-scan-fileScan imports in the file, adding them to the cache

Other useful functions for writing your own tools:



Saving buffer automatically after adding an import

groovy-imports will default to saving the buffer after adding an import, but you can customize groovy-imports-save-buffer-after-import-added to change this.


By default packages are cached the first time they’re manually entered, if you want to overwrite what’s in the cache you can invoke groovy-imports-add-import with the prefix key (C-u).

To disable caching, set groovy-imports-use-cache to nil.

Import style

You can customize groovy-imports-find-block-function, either setting it to a custom function, or one of the included ones:

  • groovy-imports-find-place-after-last-import (default)

    Simply appends the import to the end of the list of imports

  • groovy-imports-find-place-sorted-block

    Places the import alphabetically sorted into the list of imports, so they will go into:

<package declaration>

<alphabetical non-JDK imports>

<alphabetical JDK imports>

class Whatever {

Cache name

By default groovy-imports will use ”groovy-imports” as the name of the cache of class->package names, however, if you want to have separate caches per project, you can customize groovy-imports-cache-name to have a separate String name (perhaps in a .dir-locals.el for per-project imports).

You can’t perform that action at this time.