Eclim based java layer

This commit is contained in:
Lukasz Klich 2015-05-20 23:06:46 +02:00 committed by syl20bnr
parent 600046f667
commit e77eb259ec
4 changed files with 329 additions and 0 deletions

View file

@ -0,0 +1,165 @@
# Java contribution layer for Spacemacs
## Description
This layer adds support for the Java language using the [Eclim](http://eclim.org)
client/server.
## Layer Installation
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**
- [Java contribution layer for Spacemacs](#java-contribution-layer-for-spacemacs)
- [Description](#description)
- [Layer Installation](#layer-installation)
- [Eclim](#eclim)
- [Installation](#installation)
- [Usage](#usage)
- [Key bindings](#key-bindings)
- [Eclim key bindings in java-mode](#eclim-key-bindings-in-java-mode)
- [Project management](#project-management)
- [Maven](#maven)
- [Goto](#goto)
- [Refactoring](#refactoring)
- [Documentation, Find](#documentation-find)
- [Problems](#problems)
- [Tests](#tests)
- [Eclim keybindings in problems buffer](#eclim-keybindings-in-problems-buffer)
- [Eclim keybindings in projects buffer](#eclim-keybindings-in-projects-buffer)
<!-- markdown-toc end -->
Add this layer to your `~/.spacemacs`.
```elisp
(setq-default dotspacemacs-configuration-layers '(java))
```
and also in `~/.spacemacs` set eclipse and eclim paths:
```elisp
(custom-set-variables
'(eclim-eclipse-dirs '("~/opt/eclipse"))
'(eclim-executable "~/opt/eclipse/eclim"))
```
## Eclim
[Eclim]() provides the ability to access Eclipse code editing features (code completion, searching, code validation, and many more) via the command line or a local network connection, allowing those features to be integrated with your favorite editor.
### Installation
For installation check [official page](http://eclim.org/install.html#download)
### Usage
Currently you have to have eclimd already started. This layer doesn't try to control eclimd in no way although there's that option in `emacs-eclim` itself.
This layer uses `company` as a completion framework. If you want to use `auto-complete` I encourage you to make it configurable.
## Key bindings
### Eclim key bindings in java-mode
#### Project management
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>SPC m p j</kbd> | Information about project
<kbd>SPC m p o</kbd> | Open project
<kbd>SPC m p b</kbd> | Build project
<kbd>SPC m p d</kbd> | Delete project
<kbd>SPC m p g</kbd> | Open file in current project
<kbd>SPC m p i</kbd> | Import project
<kbd>SPC m p c</kbd> | Create project
<kbd>SPC m p k</kbd> | Close project
<kbd>SPC m p s</kbd> | Open project management buffer
<kbd>SPC m p u</kbd> | Update project
#### Maven
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>SPC m m p</kbd> | Run one already goal from list
<kbd>SPC m m R</kbd> | Run one maven goal
<kbd>SPC m m r</kbd> | Run maven goals
<kbd>SPC m m t</kbd> | Run maven test
<kbd>SPC m m i</kbd> | Run maven clean install
<kbd>SPC m m I</kbd> | Run maven install
#### Goto
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>SPC m g g</kbd> or <kbd> M-.</kbd> | go to declaration
<kbd>M-,</kbd> | jump back from go to declaration/definition
<kbd>SPC m g t</kbd> | go to type definition
#### Refactoring
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>SPC m r f</kbd> | Format file
<kbd>SPC m r r</kbd> | Rename symbol
<kbd>SPC m r i</kbd> | optimize imports
#### Documentation, Find
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>SPC m h h</kbd> | show documentation for symbol at point
<kbd>SPC m h u</kbd> | show usages for symbol at point
<kbd>SPC m f f</kbd> | general find in project
#### Problems
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>SPC m e o</kbd> | open buffer with problems
<kbd>SPC m e b</kbd> | open buffer with problems
<kbd>SPC m e a</kbd> | set all problems for next/prev action
<kbd>SPC m e e</kbd> | set only errors for next/prev action
<kbd>SPC m e w</kbd> | set warnings for next/prev action
<kbd>SPC m e f</kbd> | set only current file for next/prev action
<kbd>SPC m e n</kbd> | set all problems for next/prev action
<kbd>SPC m e n</kbd> | go to next problem
<kbd>SPC m e p</kbd> | go to previous problem
<kbd>SPC m e c</kbd> | show options with problem corrections
#### Tests
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>SPC m t t</kbd> | run JUnit tests for current method or current file or project
<kbd>SPC m t T</kbd> | run maven test phase
### Eclim keybindings in problems buffer
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>a</kbd> | show all problems
<kbd>e</kbd> | show only errors
<kbd>g</kbd> | refresh problems
<kbd>q</kbd> | quit
<kbd>w</kbd> | show only warnings
<kbd>f</kbd> | show problems only for current file
<kbd>RET</kbd> | go to problem place
### Eclim keybindings in projects buffer
Key Binding | Description
----------------------|------------------------------------------------------------
<kbd>N</kbd> | create new project
<kbd>m</kbd> | mark current project
<kbd>M</kbd> | mark all projects
<kbd>u</kbd> | unmark current project
<kbd>U</kbd> | unmark all projects
<kbd>o</kbd> | open project
<kbd>c</kbd> | go to problem place
<kbd>i</kbd> | info about current project
<kbd>I</kbd> | import existing project into the workspace
<kbd>RET</kbd> | go to current project
<kbd>D</kbd> | delete project
<kbd>p</kbd> | update project
<kbd>g</kbd> | refresh buffer
<kbd>R</kbd> | rename current project
<kbd>q</kbd> | quit

View file

@ -0,0 +1,2 @@
;; Define the buffer local company backend variable
(spacemacs|defvar-company-backends java-mode)

View file

@ -0,0 +1,22 @@
(defun java/completing-dot ()
"Insert a period and show company completions."
(interactive "*")
(when (s-matches? (rx (+ (not space)))
(buffer-substring (line-beginning-position) (point)))
(delete-horizontal-space t))
(insert ".")
(company-emacs-eclim 'interactive))
(defun java/maven-test ()
(interactive)
(eclim-maven-run "test"))
(defun java/maven-clean-install ()
(interactive)
(eclim-maven-run "clean install"))
(defun java/maven-install ()
(interactive)
(eclim-maven-run "install"))

View file

@ -0,0 +1,140 @@
;;; packages.el --- Java Layer packages File for Spacemacs
;;
;; Copyright (c) 2015 Lukasz Klich
;;
;; Author: Lukasz Klich <klich.lukasz@gmail.com>
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defvar java-packages
'(
projectile
emacs-eclim
company
))
(defun java/init-projectile ()
(use-package projectile
:defer t))
(defun java/init-emacs-eclim ()
(use-package eclim
:config
(progn
(message "starting eclim mode")
(global-eclim-mode)
(setq help-at-pt-display-when-idle t)
(setq help-at-pt-timer-delay 0.1)
(help-at-pt-set-timer)
(add-to-list 'minor-mode-alist
'(eclim-mode (:eval (eclim-modeline-string))))
(evil-define-key 'insert java-mode-map
(kbd ".") 'java/completing-dot
(kbd "M-.") 'eclim-java-find-declaration
(kbd "M-,") 'pop-tag-mark
(kbd "M-<mouse-3>") 'eclim-java-find-declaration
(kbd "<mouse-8>") 'pop-tag-mark)
(evil-define-key 'normal java-mode-map
(kbd "M-.") 'eclim-java-find-declaration
(kbd "M-,") 'pop-tag-mark
(kbd "M-<mouse-3>") 'eclim-java-find-declaration
(kbd "<mouse-8>") 'pop-tag-mark)
(evil-define-key 'normal eclim-problems-mode-map
(kbd "a") 'eclim-problems-show-all
(kbd "e") 'eclim-problems-show-errors
(kbd "g") 'eclim-problems-buffer-refresh
(kbd "q") 'eclim-quit-window
(kbd "w") 'eclim-problems-show-warnings
(kbd "f") 'eclim-problems-toggle-filefilter
(kbd "c") 'eclim-problems-correct
(kbd "RET") 'eclim-problems-open-current)
(evil-define-key 'normal eclim-project-mode-map
(kbd "N") 'eclim-project-create
(kbd "m") 'eclim-project-mark-current
(kbd "M") 'eclim-project-mark-all
(kbd "u") 'eclim-project-unmark-current
(kbd "U") 'eclim-project-unmark-all
(kbd "o") 'eclim-project-open
(kbd "c") 'eclim-project-close
(kbd "i") 'eclim-project-info-mode
(kbd "I") 'eclim-project-import
(kbd "RET") 'eclim-project-goto
(kbd "D") 'eclim-project-delete
(kbd "p") 'eclim-project-update
(kbd "g") 'eclim-project-mode-refresh
(kbd "R") 'eclim-project-rename
(kbd "q") 'eclim-quit-window)
(evil-leader/set-key-for-mode 'java-mode
"meo" 'eclim-problems-open
"meb" 'eclim-problems
"mea" 'eclim-problems-show-all
"mee" 'eclim-problems-show-errors
"mew" 'eclim-problems-show-warnings
"mef" 'eclim-problems-toggle-filefilter
"men" 'eclim-problems-next-same-window
"mep" 'eclim-problems-previous-same-window
"mec" 'eclim-problems-correct
"mgg" 'eclim-java-find-declaration
"mgt" 'eclim-java-find-type
"mff" 'eclim-java-find-generic
"mrf" 'eclim-java-format
"mrr" 'eclim-java-refactor-rename-symbol-at-point
"mri" 'eclim-java-import-organize
"mrg" 'eclim-java-generate-getter-and-setter
"mrc" 'eclim-java-constructor
"mrj" 'eclim-java-implement
"mhh" 'eclim-java-show-documentation-for-current-element
"mhu" 'eclim-java-find-references
"mhc" 'eclim-java-call-hierarchy
"mhi" 'eclim-java-hierarchy
"mmm" 'java/maven-clean-install
"mmp" 'eclim-maven-lifecycle-phases
"mmR" 'eclim-maven-lifecycle-phase-run
"mmr" 'eclim-maven-run
"mmt" 'java/maven-test
"mmi" 'java/maven-clean-install
"mmI" 'java/maven-install
"maa" 'eclim-ant-run
"mar" 'eclim-ant-run
"mav" 'eclim-ant-validate
"mac" 'eclim-ant-clear-cache
"mpj" 'eclim-project-info-mode
"mpo" 'eclim-project-open
"mpb" 'eclim-project-build
"mpd" 'eclim-project-delete
"mpg" 'eclim-project-goto
"mpi" 'eclim-project-import
"mpc" 'eclim-project-create
"mpk" 'eclim-project-close
"mpp" 'eclim-project-mode
"mpu" 'eclim-project-update
"mtt" 'eclim-run-junit
"mtT" 'java/maven-test)))
(use-package company-emacs-eclim
;;:if (configuration-layer/layer-usedp 'company)
:config (progn
(message "company-emacs-eclim-setup")
(company-emacs-eclim-setup)
(global-company-mode t))))
(defun java/post-init-company ()
(spacemacs|add-company-hook java-mode))