Getting around LibFormat

Hi,

I'm working on trying to make changes to LibFormat to support Haiku's
coding style [1], but I'm having some trouble trying to figure out
where indentation gets calculated. I've tried various things, but
everything I've tried so far only affects some lines and not others.

For example, I'm trying to format comments with an extra indent if the
line above at what would be same indent without the extra tab for
comment is not whitespace in a function:

if (someCondition) {
    DoSomething();
        // Comments that only affect a single line are usually
        // written after it, and are indented by a single tab
    DoSomethingElse();
} else if (someOtherCondition) {
    DoSomethingElse();
    DoSomething();
}

At the moment, I'm just trying to indent comments an extra tab
unconditionally to identify what might be the right approach, but as
stated above, I've only managed to affect a partial set of what I
want. Finding the documentation just a little too sparse to see how it
all fits together. Some changes are definitely simpler than others...
some pointers would be very much appreciated :slight_smile:

Jessica

[1] Coding Guidelines | Haiku Project

  • Krasimir

Hi!

Unfortunately comment formatting is all over the place. For your use case, it might be worth looking at TokenAnnotator::setCommentLineLevels: it computes the Level-s of comment tokens based on the next non-comment token. So I’d say that an additional level there might work, but haven’t really tried.

Best regards,
Krasimir

That seems to have done the trick! Somehow managed to miss this with
all my grepping :slight_smile:

And if I want to format a particular block of code conditionally, how
would I go about that?

E.g. we have different variable alignment rules for class definitions
compared to function definitions. In a class, member variable names
are aligned, but in functions, there is no variable name alignment.