如何在java模式下配置emacs,使其不会自动对齐方法参数 [英] How to I configure emacs in java mode so that it doesn't automatically align method parameters

查看:23
本文介绍了如何在java模式下配置emacs,使其不会自动对齐方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 emacs 中,当我输入:

public void foo(字符串一,字符串二) {

它是这样的:

public void foo(字符串一,字符串二) {

我宁愿它没有,只是像其他行延续一样对齐参数.我怎样才能配置它不这样做?

解决方案

这来自 Emacs CC 模式的 Info 手册,在 Windows 上使用 GNU Emacs 23.1:

  1. 开始构建缩进不正确的 Java 类.就您而言,正是您在上面输入的内容.
  2. 将光标移到缩进不正确的行的开头.在您的情况下,字符串二){".
  3. 点击 C-c C-s (c-show-syntactic-information) 询问 Emacs 它认为您正在查看什么语法元素.在您的情况下,它会说类似 ((arglist-cont-nonempty n m)).
  4. 使用 C-c C-o (c-set-offset) 告诉它您要更改此句法元素的缩进级别.
  5. 它默认为它认为的语法元素,例如,arglist-cont-nonempty.如果默认值正确,只需点击 RET.
  6. 现在它想知道使用什么表达式来计算偏移量.在您的情况下,默认值是一个 elisp 表达式.删除它,并使用一个加号 + 代替.
  7. 测试它以确保它正常工作:在不同的行上按 TAB 一堆,或者 M-x indent-region 或类似的.
  8. 要使其永久化,请将其添加到您的 .emacs 文件中:

<块引用>

(setq c-offsets-alist '((arglist-cont-nonempty . +)))

In emacs, when I type:

public void foo(String one,
    String two) {

It tabifies like this:

public void foo(String one,
                String two) {

I'd rather it didn't, and just aligned parameters like other line continuations. How can I configure it not to do this?

解决方案

This comes from the Info manual for Emacs CC Mode, using GNU Emacs 23.1 on Windows:

  1. Start building your Java class that's not indenting properly. In your case, exactly what you've typed above.
  2. Move your cursor to the start of the line that's not indenting properly. In your case, "String two) {".
  3. Hit C-c C-s (c-show-syntactic-information) to ask Emacs what syntax element it thinks you're looking at. In your case, it'll say something like ((arglist-cont-nonempty n m)).
  4. Use C-c C-o (c-set-offset) to tell it you want to change the indentation level for this syntactic element.
  5. It defaults to what it thinks that syntactic element is, e.g., arglist-cont-nonempty. Just hit RET if that default is correct.
  6. Now it wants to know what expression to use to calculate the offset. In your case, the default is an elisp expression. Delete that, and just use a single plus sign + instead.
  7. Test it out to make sure it's working correctly: Hit TAB a bunch on different lines, or M-x indent-region or similar.
  8. To make it permanent, add this to your .emacs file:

(setq c-offsets-alist '((arglist-cont-nonempty . +)))

这篇关于如何在java模式下配置emacs,使其不会自动对齐方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆