How to I configure emacs in java mode so that it doesn't automatically align method parameters

这一生的挚爱 提交于 2019-11-29 20:29:39
Chris Jones

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 . +)))

I like to specify the mode style in each source file's first line. Try:

// -*- mode: java; c-file-style: "stroustrup" -*-

This will give you rational tabification. You might also try "k&r".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!