Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ensime java mode to java layer? #5708

Closed
brcolow opened this issue Apr 6, 2016 · 14 comments
Closed

Add ensime java mode to java layer? #5708

brcolow opened this issue Apr 6, 2016 · 14 comments

Comments

@brcolow
Copy link

brcolow commented Apr 6, 2016

Currently it seems that the java layer has only eclim support - but there is an alternative - namely: ensime (which has a java mode "enjime").

More details here: http://ensime.github.io/editors/emacs/

I am not proficient enough with LISP, Emacs, or Spacemacs to try and implement this myself, but am opening it as an issue as I believe it would be a good addition to the java layer (and, more honestly, would love to try it myself!).

Thanks.

@biocyberman
Copy link

This will be very nice. I am using ensime-based scala-mode and like it very much.

@ghost
Copy link

ghost commented Apr 9, 2016

Funny that you mention this. I just went through the trouble of doing this around yesterday (I haven't made a layer, I just shoehorned the code into the .spacemacs file). I'll put up what I did to get it working here in case that's helpful.

Changed dotspacemacs-additional-packages to include '(ensime, sbt-mode)

This was placed in my dotspacemacs/user-config() function

  (setq exec-path (append exec-path '("/usr/local/bin")))
  (setq exec-path (append exec-path '("/usr/local/sbin")))
  (setenv "PATH" (shell-command-to-string "/bin/bash -c 'echo -n $PATH'"))

  ;; this obviously isn't required for ensime but it is for eclim. I probably don't need these two lines
  (setq eclim-eclipse-dirs "/usr/lib/eclipse"
        eclim-executable "/usr/lib/eclipse/eclim")

  (use-package ensime
    :commands ensime ensime-mode)
  (add-hook 'java-mode-hook 'ensime-mode)
  (add-hook 'scala-mode-hook 'ensime-mode)

  (use-package sbt-mode
    :commands sbt-start sbt-command
    :config
    ;; WORKAROUND: https://github.com/ensime/emacs-sbt-mode/issues/31
    ;; allows using SPACE when in the minibuffer
    (substitute-key-definition
     'minibuffer-complete-word
     'self-insert-command
     minibuffer-local-completion-map))

Everything after this point is just installing sbt onto your computer, and setting up stuff outside of emacs. To finish the actual layer off would require key binding. I would suggest a variable for the java package such as java-backend with the parameters either ecim or ensime and then enable each setup as necessary.

Eclim and ensime are not very compatible with each other and they will fight each other in annoying ways. Luckily since each one has different functions for everything there's no direct conflict but since keybinds are probably going to be reused for the same purpose, they should be bound depending on the backend variable set.

99% of the setup for ensime java can be used for ensime scala and vice versa. Ensime was originally designed for scala and it is only recently that it even works at all in any meaningful way with java. I might suggest looking into stealing from the scala layer and/or upgrading it in parallel with this one.

@liujoey
Copy link
Contributor

liujoey commented Apr 16, 2016

for now as a workaround I disabled java layer, only added scala layer, and added these lines to my user configure for java support. It's working perfectly for a pure Java project with SBT.

  (setq exec-path (append exec-path '("/usr/local/bin")))
  (add-hook 'java-mode-hook 'scala/configure-ensime)
  (add-hook 'java-mode-hook 'scala/maybe-start-ensime)

@mahinshaw
Copy link
Contributor

I updated my version of the scala layer last night to optionally start ensime when in java mode. It's not part of the java layer, but I am happy to make a PR. Thought I would get some consensus on whether or not it belongs with the scala layer or not. I think it works nicely since the scala layer is mostly about ensime.

@rationalis
Copy link

I think it'd make more sense to have a variable for the java layer that selects between ensime and eclim (and java layer with ensime should not automatically enable scala layer). I'm not sure which it should default to, but I'd lean towards eclim, just because it's the one that's currently supported.

@mahinshaw
Copy link
Contributor

mahinshaw commented Jun 29, 2016

The only issue I have with adding it to the java layer is the massive amount of code duplication. But I do understand not wanting to be tied to scala.

@rationalis
Copy link

Having it under the java layer is just for the benefit of the user, I don't think there should be code duplication. I'm not too familiar with spacemacs yet, so I'm not sure if this possible (or if it would be even messier) -- but I was thinking that enabling the java layer with a variable set to use ensime, would enable the scala layer, configure it for java usage, and disable it for scala unless the actual scala layer is enabled.

@sandric
Copy link

sandric commented Jul 26, 2016

Hm, strange, I did everything like @thang1thang2 described and looks like ensime is working but parses my .java files like scala ones - for example on line with:

import java.awt.SystemColor;

gives me

ERROR: illegal start of type : line 3

in ensime-compilation-results buffer and highlights with red in file's buffer.

MB my build.sbt written wrong - I know literally nothing about scala, can anyone who figured everything out show me his .sbt file maybe, here's mine:

organization := "your.group.id"
name := "Test"
version := "1.0-SNAPSHOT"

@worldwar2008
Copy link

In the mode of ensime, why i can't import my own java package?
There is an warn "The object is not the member of my own java package"

@hedning
Copy link
Contributor

hedning commented Nov 14, 2016

I've started refactoring ensime out of the scala layer into it's own layer, which both scala and java can depend (branch). That seems like the most reasonable way to make the cross dependency work. So far I've just put it under layers/+lang/ensime, but it might be more appropriate under +misc or +tools.

@TheBB
Copy link
Collaborator

TheBB commented Nov 14, 2016

Sounds exciting!

@peng051410
Copy link

@thang1thang2 Can you provide a complete configuration?Thank you!

@delaanthonio
Copy link
Contributor

@brcolow it looks like this issue can be closed

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
@brcolow brcolow closed this as completed Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Mailing list
  
New packages or layers
Development

No branches or pull requests