13
votes

Is there a Groovy compatible auto-complete mode for emacs?

I also was not able to find a keyword dictionary that I can use with emacs autocomplete.

Help would be much appreciated.

2

2 Answers

3
votes

AFAIK there is no working (intelligent) auto-complete for Groovy. If you are inclined to a bit of hacking, the easiest way to achieving this would be to modify emacs-eclim (an Emacs package for talking to Eclipse) to work with the Eclipse Groovy plugin. Shouldn't be that bad, as there is existing code for working with Eclipse Java that you could use as scaffolding.

HTH and sorry :(

3
votes

I have 'hacked' both emacs-eclim and Eclim to get code completion, not pretty or feature-complete, good enough for few hours of work.

1. Notes:

  • Code completion is supported, but it is slow with auto-complete-mode sometimes, especially when completion is triggered automatically. I use TAB to start the autocomplete popup and ALT-TAB for the completions buffer, if I'm looking up all possible completions.
  • Source update for issues reporting is supported but not fully accurate. As you save the buffer an incremental build is performed and the errors report is available (Problems via C-c C-e o.

If using auto-complete, set the following:

(ac-set-trigger-key "TAB")
(setq ac-auto-start nil)

2. Installation

3. Sample Emacs configuration via use-package and ELPA.

If you don't use use-package, adapt as needed...

(use-package eclim                                                                                                               
  :ensure emacs-eclim // overwrite ELPA install with my copy                                                                                                           

  :init (setq help-at-pt-display-when-idle t                                                                                     
              eclimd-default-workspace "~/Documents/workspace/"                                                                  
              help-at-pt-timer-delay 0.1)                                                                                        

  :config (progn (help-at-pt-set-timer)                                                                                          
                 (mapc #'require '(eclimd auto-complete-config))                                                                 
                 (ac-config-default)                                                                                             
                 (add-hook 'groovy-mode-hook 'auto-complete-mode)                                                                
                 (require 'ac-emacs-eclim-source)                                                                                
                 (ac-emacs-eclim-config)                                                                                         

                 (defun ers/eclim-run-class ()                                                                                   
                   (interactive)                                                                                                 
                   (beginning-of-buffer)                                                                                         
                   (search "class ")                                                                                             
                   (forward-word)                                                                                                
                   (eclim-run-class))                                                                                            

                 (bind-keys :map eclim-mode-map                                                                                  
                            ("C-c C-e l m" . eclim-manage-projects)                                                              
                            ("C-c C-e l r" . ers/eclim-run-class)                                                                
                            ("C-c C-e l c" . garbage-collect)                                                                    
                            ("C-c C-e l b" . eclim-project-build))                                                               

                 (add-hook 'groovy-mode-hook                                                                                     
                           (lambda ()                                                                                            
                             (remove 'ac-source-clang 'ac-sources)                                                               
                             (eclim-mode t)))                                                                                    

                 (add-hook 'java-mode-hook                                                                                       
                           (lambda ()                                                                                            
                             (remove 'ac-source-clang 'ac-sources)                                                               
                             (eclim-mode t)))))