Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code-formatting: How to align multiline code to special characters?

Is IDEA or one of its plugins capable of aligning code to special characters?

I mean so that the code

Map(
  'name -> "Peter",
  'age -> 27,
  'company -> "Foobar"
)

is transformed to

Map(
  'name    -> "Peter",
  'age     -> 27,
  'company -> "Foobar"
)

Example2:

execute("x", true, 27)
execute("foobar", false, 0)

transformed to

execute("x"     , true , 27)
execute("foobar", false, 0 )
like image 972
Stefan Endrullis Avatar asked Feb 21 '13 11:02

Stefan Endrullis


2 Answers

You can align case statements, however:

value match {
  case s: String => Some(java.lang.Long.parseLong(s))
  case bi: BigInt => Some(bi.longValue)
  case _ => None
}

Like so:

value match {
  case s: String  => Some(java.lang.Long.parseLong(s))
  case bi: BigInt => Some(bi.longValue)
  case _          => None
}

Use option:

Settings -> Code Style -> Scala => Wrapping and Braces -> 'match' and 'case' statements -> Align in columns 'case' branches

like image 157
zbstof Avatar answered Oct 07 '22 06:10

zbstof


In IDEA 12 if you're using the Scala plugin you can configure "Align when multiline" for many things, including method parenthesis. Your particular example of multiple invokations on separate lines is not supported however.

like image 38
iwein Avatar answered Oct 07 '22 04:10

iwein