Hot answers tagged

20

I'm going to be conservative and say no, Emacs is not a drop-in replacement for Eclipse (especially not out of the box). However, that doesn't mean that it's not suitable for Java development. Since you are already familiar with Eclipse I suggest you have a look at eclim: Eclim provides the ability to access Eclipse code editing features (code completion,...


12

You can't directly write an Emacs package in Java. There is currently no way to extend Emacs in Java, nor is there a Java to Elisp transpiler. It's common, though, to have Emacs run other programs to do work for it. You could write a helper program like this in Java. Whether this makes sense depends on what exactly you intend to do.


11

Emacs/eclim has been my primary Java IDE for the last couple of years and would say it works fairy well, even with large code bases (my current emacs/eclim workspace has more than 4000 Java files). It's true that emacs-eclim requires the file to be saved before making its call to eclimd, but it's not that big of a problem IMO. The editing experience is still ...


9

At this point(2018), LSP Java(https://github.com/emacs-lsp/lsp-java) is pretty good. Few of the features: Autocomplete Refactoring (extract method, rename, implement interface, extract local, extract constant and so on.) Auto import Code navigation while working on multiple projects Find references, implementations, open type. Maven/Gradle project import, ...


9

which-function-mode displays the current method name. The following configuration, which I got from Emacs Redux, displays the current method / function / orgmode heading in the top header line rather than the mode line: ;; Show the current function name in the header line (which-function-mode) (setq-default header-line-format '((which-func-...


8

You can make your style look like this instead: '((c-basic-offset . 8) (c-offsets-alist . ((inline-open . 0) (topmost-intro-cont . +) (statement-block-intro . +) (knr-argdecl-intro . 5) (substatement-open . +) (substatement-label . +)...


7

Here's a little snippet that allows to run a single Java file: (defun java-eval-nofocus () "Run current Java file." (interactive) (save-buffer) (let* ((source (file-name-nondirectory buffer-file-name)) (out (file-name-sans-extension source)) (class (concat out ".class"))) (setenv "CLASSPATH" default-directory) (shell-...


6

Set option indent-tabs-mode to nil: Put this in your init file, to make Emacs always indent using SPC characters, never TAB characters. (setq-default indent-tabs-mode nil)


4

Disclaimer: I'm not that familiar with cc-mode styles, so there might be simpler ways to do that, and also unforeseen side-effects to my code. (defun my-java-lineup-cascaded-calls (langelem) (save-excursion (back-to-indentation) (let ((operator (and (looking-at "\\.") (regexp-quote (match-string 0)))) (stmt-start ...


4

After some poking around, it looks like this has fixed it (getting called in java-mode-hook): (c-set-offset 'inexpr-class 0) By default it is set to +. inexpr-class controls the indentation level for anonymous classes and anonymous initialisation.


3

I would suggest Meghanada. It is light weighted, much easier to setup (compared to JDEE). It is not mature enough, but already supports auto-completion, syntax-checking and runs junit tests. It will also parse maven and gradle projects automatically. The overall experience is smooth enough for small and moderate scale projects. Refactoring support is still ...


3

You can use describe-char or C-u C-x = (= what-cursor-position with a prefix arg) to obtain a buffer giving as much information as possible about the character at point : font, syntax, properties and, of course, faces. If not too unlucky, the name of the face will give you the library name that added it.


3

Try the following: (defun my/point-in-defun-declaration-p () (let ((bod (save-excursion (c-beginning-of-defun) (point)))) (<= bod (point) (save-excursion (goto-char bod) (re-search-forward "{") (point))))) (defun my/arglist-cont-nonempty-indentation (arg) ...


2

Try enabling eclim-mode when editing the file. That should bring up the completion automatically.


2

I recommend you having look at emacs-eclim. It uses Eclipse as a backend and provides many feature you'd want, like context aware auto-completion, correction-suggestions, documentation lookup and source navigation. To give you an overview: So to set it up with an existing project, do $ mvn eclipse:eclipse inside your project, then open up Eclipse and do a "...


2

so why is this the only file missing? Because the CEDET guys feel that the Java support hasn't received enough attention (development, testing, adoption) to be ready for inclusion into Emacs. To use it, you'll have to install the upstream CEDET, or maybe Alex Ott's branch (see this question and answer). And what can I do to fix it? Show some activity ...


2

You could try: (electric-indent-mode +1) (defun my-newline-and-indent-mode-hook () (local-set-key (kbd "RET") (key-binding (kbd "M-j"))) (local-set-key (kbd "<C-return>") #'electric-indent-just-newline)) (add-hook 'prog-mode-hook #'my-newline-and-indent-mode-hook) Pressing return will continue comment or newline-and-indent -- press C-return to ...


2

I saw that you already solved this, but I thought that I could share the following anyway: You can use Font-lock studio (an interactive debugger for font-lock keywords) to single step each font-lock rule using the n command. That way, you can easily see which one caused the problem. If you are lucky and the rule contains a function call (instead of a plain ...


2

How embarrassing. A few minutes after asking the question, the solution came to me. I might make the case that the asking of the question led to the solution, though. In any case, the answer that came to me is that I should find the face description using a character in the pinkish text. This led to using M-x describe-face which put a query into the ...


2

Try this Find full directory path where emacs expects ditaa.jar to be located. This code is copied from ob-ditaa.el #+begin_src elisp (expand-file-name "ditaa.jar" (file-name-as-directory (expand-file-name "scripts" (file-name-as-directory (expand-file-name ...


2

You can try https://github.com/emacs-lsp/lsp-java , it uses Eclipse JDT Language Server as backend.


2

You can do that using https://github.com/emacs-lsp/lsp-java by setting lsp-java-format-settings-url to https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml (setq lsp-java-format-settings-url "https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml") Edit: the correct url must be raw https://raw....


1

It seems that ensime requires the src.zip file to be in the JAVA_HOME directory, the error message is misleading. On Ubuntu 16.04 and with Java 8 you can get this by running sudo apt-get install openjdk-8-source. It's probably something similar on other OSes.


1

I don't know if you'd consider it "lightweight," but I've had good luck with eclim. It uses eclipse for the heavy lifting, but it also integrates well with eclipse's project management. It has company integration that works well. There's a bit to learn, but not a whole lot. It works well to reduce the pain of working with Java in Emacs to just the pain ...


1

This problem is solved. Thanks to Phil Newton (sodaware) for creating this extension to integrate with PHP_beautifier. This application was released 5 hours ago (on March 28, 2017). I have tried some of my PHP Code, and it works well. This is some gif from when I gave it a try.


1

In addition to what @YoungFrog offered, you can often find what a given face is at places where you cannot put the cursor, by using M-x list-faces-display. That will show you all faces currently defined, WYSIWYG, and that will usually enable you to narrow the list of faces that it could be. It can become a bit more complicated when faces are merged (...


1

OK I got it... I started jdb with: jdb -attach <port> but starting it with: jdb -attach <port> -sourcepath<source path on disk> gud-break now works as expected.


1

I am afraid that moving files manually will mess up my system, confuse my package manager and only work until the next update. Instead, you can simply added the true path for ditaa.jar to your .emacs or .emacs.d/init.el. In my case: (setq org-ditaa-jar-path "/usr/share/ditaa/lib/ditaa.jar")


1

Base on Melioratus answer I did this: cd .emacs.d/elpa && mkdir contrib cd contrib %% mkdir scripts cd scripts which ditaa ## I have mine in /usr/local/bin ln -s /usr/local/bin/ditaa0_9.jar ditaa.jar ln -s /usr/local/bin/DitaaEps.jar DitaaEps.jar Now emacs/ org-babel can find ditaa, success!


1

My dev branch of CEDET has some extensions for better work with Java, like basic Maven & Ant support, etc. But it wasn't updated for at least a year - I plan to spend some time over the Christmas to sync it with current HEAD...


Only top voted, non community-wiki answers of a minimum length are eligible