Skip to content

mbezjak/emacs-groovy-imports

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Emacs Groovy Imports

Introduction

https://travis-ci.org/mbezjak/emacs-groovy-imports.svg http://melpa.org/packages/groovy-imports-badge.svg

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.

Installation

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" . "https://melpa.org/packages/" ))

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.

Usage

(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

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

FunctionUse
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:

Function
groovy-imports-add-import-with-package
groovy-imports-list-imports

Customization

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.

Caching

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).

How to run the tests?

You’ll need: https://github.com/cask/cask

Run in the terminal:

  1. make install
  2. make test

About

Add groovy imports easily in Emacs

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Emacs Lisp 99.1%
  • Makefile 0.9%