Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java-Mode Argument Indenting in Emacs

Tags:

java

emacs

lisp

My java-mode in emacs wants to indent function arguments like this:

someLongFunctionName(
                     argumentNumberOne,
                     argumentNumberTwo,
                     argumentNumberThree,
                     argumentNumberFour
                     );

There are two problems here. Firstly, it wants to line up the start of the arguments with the end of the function name. Secondly, it wants to treat the the closet paren as if it were an argument, and thus lines it up with all other arguments. I don't like either of those behaviors.

I would much rather it indent my code like this:

someLongFunctionName(
    argumentNumberOne,
    argumentNumberTwo,
    argumentNumberThree,
    argumentNumberFour
);

c-mode does a much better job of this by default, and I would like to carry over the behavior to java-mode if possible.

I still need to learn how the emacs indentation engine works, and at the moment I don't honestly really even know that much lisp. Those two learning exercises are definitely on my plate, but at the moment a quick copy-paste solution would be pretty awesome.

like image 331
fieldtensor Avatar asked Aug 05 '11 06:08

fieldtensor


1 Answers

Try this

(defun my-indent-setup ()
  (c-set-offset 'arglist-intro '+))
(add-hook 'java-mode-hook 'my-indent-setup)

From http://www.emacswiki.org/emacs/IndentingC

like image 176
Rohan Monga Avatar answered Oct 04 '22 17:10

Rohan Monga