fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
370 stars 76 forks source link

option to not indent after contains #71

Closed BaconPancakes closed 3 years ago

BaconPancakes commented 4 years ago

I know formatters are opinionated and all, but can we have have an option to keep the subroutine definitions at the same level as the contains statement, like below? This is actually a bit of a dealbreaker for me (and the codebase that I maintain).

module my_module
    implicit none
    private
    public my_subroutine

contains

subroutine my_subroutine
    ! my code

end subroutine my_subroutine

end module my_module
pseewald commented 4 years ago

I consider the above formatting as inconsistent since the first part of the module content is indented (everything before contains) but the second part (everything after contains) is not. Also I've never seen this in any fortran project.

BaconPancakes commented 4 years ago

We’re following something akin to https://www.fortran90.org/src/best-practices.html

But after thinking about it, you’re right, it’s not exactly consistent. The idea is that a single subroutine is the meat of the file, so having two levels of indenting after the contains statement is unwieldy (and unnecessary, since we only ever use contains once).

Perhaps the consistent approach is as you say, not to indent at the “module” level, but only at the procedure level.

pseewald commented 4 years ago

Perhaps the consistent approach is as you say, not to indent at the “module” level, but only at the procedure level.

This sounds reasonable and useful, so we should make it an option (leaving the default as it is now). Unfortunately I don't have time at the moment. If you'd like to give it a try yourself, the scopes (or levels) are defined here: just removing MOD_RE, CONTAINS_RE and ENDMOD_RE from the dictionaries should give you what you want.

BaconPancakes commented 4 years ago

Those edits seem to work well. Thanks.

pseewald commented 4 years ago

Thanks for your feedback, I'll make this an option once I find time.