gpt4 book ai didi

java - Emacs 上的 Eclipse 缩进

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:08:03 24 4
gpt4 key购买 nike

我是一名 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 - Emacs 上的 Eclipse 缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/805050/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com