Java Emacs上的Eclipse缩进

Java Emacs上的Eclipse缩进,java,eclipse,emacs,Java,Eclipse,Emacs,我是一名emacs用户,刚开始为一家新公司工作,该公司的标准是eclipse。我已经尝试过eclipse,但我还想尝试JDEE(经过一段长时间的停顿后,我将回到Java)。到目前为止,主要的障碍是使缩进匹配。有没有一种简单的方法可以做到这一点,或者我需要深入研究emacs压痕的螺母和螺栓 编辑:很抱歉这个问题中的混乱:我不想让Eclipse模仿emacs,我想让emacs模仿Eclipse。我希望能够使用emacs修改代码,而不会弄糟Eclipse用户所期望的缩进。老实说,我不确定让Eclips

我是一名emacs用户,刚开始为一家新公司工作,该公司的标准是eclipse。我已经尝试过eclipse,但我还想尝试JDEE(经过一段长时间的停顿后,我将回到Java)。到目前为止,主要的障碍是使缩进匹配。有没有一种简单的方法可以做到这一点,或者我需要深入研究emacs压痕的螺母和螺栓


编辑:很抱歉这个问题中的混乱:我不想让Eclipse模仿emacs,我想让emacs模仿Eclipse。我希望能够使用emacs修改代码,而不会弄糟Eclipse用户所期望的缩进。

老实说,我不确定让Eclipse的缩进与emacs匹配到底是什么意思。但您可以在此处修改缩进:
Windows->Preferences-General->Editors

单击“文本编辑器”选项,您将看到选项卡宽度属性

还有一点需要注意的是,Eclipse内置了Emacs风格的键绑定:
Windows->Preferences->General->Keys

在“方案”下,有一个Emacs选项

注意:您还可以在此处修改Java代码的格式:
Windows->Preferences->Java->code Style->Formatter
您需要在Java模式下自定义缩进。看一看,.

我发现Eclipse(和IntelliJ)和Emacs默认java格式之间的主要区别在于Emacs将函数参数与以前的参数排成一行,例如Emacs:

BigLongJavaStuff.doFoobarToQuux("argument 1",
                                "argument 2");
Eclipse会:

BigLongJavaStuff.doFoobarToQuux("argument 1",
        "argument 2");
添加到~/.emacs文件中的以下内容将使emacs java模式执行相同的操作:

;; 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"))))

是的,由于Eclipse缩进的一些特性(或者至少是他们正在使用的样式),这就是我试图避免使用的螺母和螺栓。我希望有人已经编写了Eclipse风格的程序,我可以顺便来看看。谢谢你的参考书。好吧,如果你能完成的话,你能把它出版吗?甚至可能在这里?看看一个好的,简单的开始。正如阿卡迪所说,如果有人钉了这个,请张贴!相关的文章涉及到制表符和空格的基本问题,解决了前90%的问题。上面的答案试图解决一个还债10%的问题,从我所知道的。我发现这非常有用!我必须对其进行一些更改以获得我想要的行为--我希望能够在方法调用本身之后在行上启动参数列表。在(arglist cont nonempty.+)之后添加(arglist intro.+)(arglist cont.+)。(我还将++更改为+)