Does intelliJ have a concept of semantic indentation? or just fixed-constant indentation?

Answered

I would sometimes like indentation to depend on the context rather than sampling being fixed to a hard-coded (or even customizable constant) integer.  This is especially true in composed code.

Here is what it currently does:

````

def loop(s: Int, leftOccurances: Int, rightOccurances: Int, leaders: Int): Int = {
if (s == N || rightOccurances == 0)
leaders
else {
val thisOccurance = if (a(s) == a(leader))
1
else
0
val thisLeader = if (2 * (leftOccurances + thisOccurance) > (s + 1)
&& 2 * (rightOccurances - thisOccurance) > (N - s - 1))
thisOccurance
else
0
loop(s + 1, leftOccurances + thisOccurance, rightOccurances - thisOccurance, leaders + thisLeader)
}
}

````

 

But, I'd like the else to always line up with the corresponding if, and the consequent and alternative to be indented relative to the if and the else.  Additionally I'd like the && to indent inside the still-open-parenthesis.  Here is what I'd like to see

````

  def loop(s: Int, leftOccurances: Int, rightOccurances: Int, leaders: Int): Int = {
if (s == N || rightOccurances == 0)
leaders
else {
val thisOccurance = if (a(s) == a(leader))
1
else
0
val thisLeader = if (2 * (leftOccurances + thisOccurance) > (s + 1)
&& 2 * (rightOccurances - thisOccurance) > (N - s - 1))
thisOccurance
else
0
loop(s + 1, leftOccurances + thisOccurance, rightOccurances - thisOccurance, leaders + thisLeader)
}
}
if (leader == -1)
0
else
loop(0, 0, occurances, 0)
}

````

0
2 comments

No, request is welcome at https://youtrack.jetbrains.com/issues/IDEA.

Is there any tool which already does such indentation so that we can use it as a reference?

0

When I learned OCaml, the course had its own web-based editor which did semantically correct indentation like that.  Also it is the kind of indentation Lisp users expect, i.e., never have code to the left of a pending open paren.  I've heard it called emacs-like indentation.

Basically it means that once a command starts (textually) never put text to the left of its starting column until the command finishes.  That way you can recognize composed expressions by their indentation.

0

Please sign in to leave a comment.