Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Friday, June 24, 2016

Eclipse indentation on Emacs

Eclipse indentation on Emacs


I'm an emacs user who just started working for a new company where eclipse is the standard. I've tried eclipse, but I want to also experiment with JDEE (I'm coming back to Java after a long hiatus). The major stumbling block so far is getting the indentation to match. Is there an easy way to do this, or am I going to need to dig deeply into the nuts and bolts of emacs indentation?

EDIT: sorry for the confusion in this question: I do not want to get Eclipse to mimic emacs, I want emacs to mimic Eclipse. I want to be able to use emacs to modify code without screwing up the indentation that the Eclipse users expect.

Answer by bedwyr for Eclipse indentation on Emacs


I'll be honest: I'm not sure exactly what you mean by making Eclipse's indentation match Emacs. But you can modify indentation here: Windows->Preferences-General->Editors

Click on the 'Text Editors' option, and you'll see the tab width properties.

One more little note, Eclipse has Emacs-style key bindings built into it: Windows->Preferences->General->Keys

Under 'Scheme', there's an option for Emacs.

Note: you can also modify the format of your Java code here: Windows->Preferences->Java->Code Style->Formatter

Answer by Arkadiy for Eclipse indentation on Emacs


You need to customize the indentation in java mode. Take a look here, here and here.

Answer by rzr for Eclipse indentation on Emacs


Maybe one alternative is to use a command line tool such as indent , or run eclipse in batch from emacs :-)

Answer by user563439 for Eclipse indentation on Emacs


The main difference I found between Eclipse (and IntelliJ) and Emacs default java formatting is that Emacs lines up function arguments continued onto a new line with the previous arguments e.g. emacs does:

BigLongJavaStuff.doFoobarToQuux("argument 1",                                  "argument 2");  

and Eclipse does:

BigLongJavaStuff.doFoobarToQuux("argument 1",          "argument 2");  

The following added to you ~/.emacs file will make Emacs java-mode do the same:

;; eclipse-java-style is the same as the "java" style (copied from  ;; cc-styles.el) with the addition of (arglist-cont-nonempty . ++) to  ;; c-offsets-alist to make it more like default Eclipse formatting -- function  ;; arguments starting on a new line are indented by 8 characters  ;; (++ = 2 x normal offset) rather than lined up with the arguments on the  ;; previous line  (defconst eclipse-java-style    '((c-basic-offset . 4)      (c-comment-only-line-offset . (0 . 0))      ;; the following preserves Javadoc starter lines      (c-offsets-alist . ((inline-open . 0)                          (topmost-intro-cont    . +)                          (statement-block-intro . +)                          (knr-argdecl-intro     . 5)                          (substatement-open     . +)                          (substatement-label    . +)                          (label                 . +)                          (statement-case-open   . +)                          (statement-cont        . +)                          (arglist-intro  . c-lineup-arglist-intro-after-paren)                          (arglist-close  . c-lineup-arglist)                          (access-label   . 0)                          (inher-cont     . c-lineup-java-inher)                          (func-decl-cont . c-lineup-java-throws)                          (arglist-cont-nonempty . ++)                          )))    "Eclipse Java Programming Style")  (c-add-style "ECLIPSE" eclipse-java-style)  (customize-set-variable 'c-default-style (quote ((java-mode . "eclipse") (awk-mode . "awk") (other . "gnu"))))  

Answer by phils for Eclipse indentation on Emacs


If all else fails, take a look at Mulgasoft's Emacs+ Eclipse Plug-in, which adds a pretty impressive amount of Emacs functionality to that IDE.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.