我是一名emacs用户,他刚刚开始为一家以eclipse为标准的新公司工作.我已经尝试过eclipse,但我也想尝试使用JDEE(经过长时间的中断后我回到了Java).到目前为止,主要的绊脚石是让缩进匹配.有没有一种简单的方法可以做到这一点,或者我是否需要深入研究emacs缩进的细节?
编辑:对不起这个问题的困惑:我不想让Eclipse模仿emacs,我想让emacs模仿Eclipse.我希望能够使用emacs来修改代码,而不会搞砸Eclipse用户期望的缩进.
我发现Eclipse(和IntelliJ)和Emacs默认java格式之间的主要区别在于Emacs将函数参数排成一行,并使用前面的参数继续到新行,例如emacs:
BigLongJavaStuff.doFoobarToQuux("argument 1", "argument 2");
和Eclipse做:
BigLongJavaStuff.doFoobarToQuux("argument 1", "argument 2");
以下添加〜/ .emacs文件将使Emacs java-mode执行相同的操作:
;; 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"))))
您需要在java模式下自定义缩进.看看这里,这里和这里.