@@ -539,7 +539,7 @@ def __align_line_continuations(self, line, is_decl, indent_size, line_nr):
539539 self ._level = level
540540
541541
542- def inspect_ffile_format (infile , indent_size , orig_filename = None ):
542+ def inspect_ffile_format (infile , indent_size , strict_indent , orig_filename = None ):
543543 """
544544 Determine indentation by inspecting original Fortran file.
545545
@@ -573,9 +573,12 @@ def inspect_ffile_format(infile, indent_size, orig_filename=None):
573573 indents .append (offset - prev_offset )
574574
575575 # don't impose indentation for blocked do/if constructs:
576- if (prev_offset != offset or (not IF_RE .search (f_line ) and
577- not DO_RE .search (f_line ))):
576+ if (IF_RE .search (f_line ) or DO_RE .search (f_line )):
577+ if (prev_offset != offset or strict_indent ):
578+ indents [- 1 ] = indent_size
579+ else :
578580 indents [- 1 ] = indent_size
581+
579582 prev_offset = offset
580583
581584 return indents , first_indent
@@ -911,7 +914,7 @@ def reformat_inplace(filename, stdout=False, **kwargs): # pragma: no cover
911914 outfile .write (newfile .getvalue ())
912915
913916
914- def reformat_ffile (infile , outfile , impose_indent = True , indent_size = 3 , impose_whitespace = True ,
917+ def reformat_ffile (infile , outfile , impose_indent = True , indent_size = 3 , strict_indent = False , impose_whitespace = True ,
915918 whitespace = 2 , strip_comments = False , orig_filename = None ):
916919 """main method to be invoked for formatting a Fortran file."""
917920
@@ -920,7 +923,7 @@ def reformat_ffile(infile, outfile, impose_indent=True, indent_size=3, impose_wh
920923
921924 infile .seek (0 )
922925 req_indents , first_indent = inspect_ffile_format (
923- infile , indent_size , orig_filename )
926+ infile , indent_size , strict_indent , orig_filename )
924927 infile .seek (0 )
925928
926929 # initialization
@@ -1334,6 +1337,7 @@ def run(argv=sys.argv): # pragma: no cover
13341337 " | 2: operators, print/read, plus/minus"
13351338 " | 3: operators, print/read, plus/minus, muliply/divide"
13361339 " | 4: operators, print/read, plus/minus, muliply/divide, type component selector" )
1340+ parser .add_argument ("--strict-indent" , action = 'store_true' , default = False , help = "strictly impose indentation even for nested loops" )
13371341 parser .add_argument ("--disable-indent" , action = 'store_true' , default = False , help = "don't impose indentation" )
13381342 parser .add_argument ("--disable-whitespace" , action = 'store_true' , default = False , help = "don't impose whitespace formatting" )
13391343 parser .add_argument ("--strip-comments" , action = 'store_true' , default = False , help = "strip whitespaces before comments" )
@@ -1403,6 +1407,7 @@ def run(argv=sys.argv): # pragma: no cover
14031407 stdout = stdout ,
14041408 impose_indent = not args .disable_indent ,
14051409 indent_size = args .indent ,
1410+ strict_indent = args .strict_indent ,
14061411 impose_whitespace = not args .disable_whitespace ,
14071412 whitespace = args .whitespace ,
14081413 strip_comments = args .strip_comments )
0 commit comments