Menu

#207 Add an option to indent multi line if conditions

open
nobody
None
5
2025-10-11
2025-10-11
No

Currently code like this ...

  if Condition1
    and Condition2 then begin
    doSomething;
  end;

... gets the same indentation for the second line of the if condition ("and condition2") as the code in the if block ("doSomething")
There should be an option to indent that line further like this:

  if Condition1
     and Condition2 then begin
    doSomething;
  end;

(an addtional space -> indented to the same column as the first condition after the if)
or this:

  if Condition1
      and Condition2 then begin
    doSomething;
  end;

(Indented by one additional indentation unit.)
or this:

  if      Condition1
      and Condition2 then begin
    doSomething;
  end;

(Condition1 indented to match the position of Condition2)
If the latter is implemented, all conditions should be indented the same, regardless of it using "and" or "or"

  if      Condition1
      and Condition2
      or  Condition2 then begin
    doSomething;
  end;

Of course with more complex and/or concatenations, this could still be improved. So maybe there should be an option to indent the whole condition relative to the indentation of the first line (similar to the handling of multiline string literals). So this ...

  SomeCode;
   if     Condition1
      and Condition2
       or Condition2 then begin
    doSomething;
  end;

(note the wrong indentation of the if statement)
... becomes this ...

  SomeCode;
  if     Condition1
     and Condition2
      or Condition2 then begin
    doSomething;
  end;

(The whole if statement is moved one space to the left, keeping the user's formatting intact.)

Discussion


Log in to post a comment.