Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs auto-complete mode for Groovy?

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.

like image 987
mbsheikh Avatar asked Apr 04 '12 20:04

mbsheikh


People also ask

How do I Autocomplete in Emacs?

The key to triggering the auto-completion in emacs is the Tab key. You will get a list of suggestions from the compiler. To select something from the list of suggestions, we recommend you to use C-n and C-p, but the down and up arrow keys can be used as well.

Does Emacs have auto complete?

Auto-Complete is an intelligent auto-completion extension for Emacs. It extends the standard Emacs completion interface and provides an environment that allows users to concentrate more on their own work. Its features are: a visual interface, reduce overhead of completion by using statistic method, extensibility.


2 Answers

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

like image 83
Christopher Monsanto Avatar answered Oct 14 '22 21:10

Christopher Monsanto


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

  • git clone https://github.com/yveszoundi/eclim
  • cd eclim && ant -Declipse.home=YOUR_ECLIPSE_FOLDER
  • git clone https://github.com/yveszoundi/emacs-eclim
  • Add emacs-eclim folder to your load-path

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)))))    
like image 38
rimero Avatar answered Oct 14 '22 23:10

rimero