Skip to content

Allow only single indentation width for function/subroutine calls that span multiple lines #159

@aerosayan

Description

@aerosayan

Hi, I recently started using fprettify and I'm liking it very much.

Feature Request:

Currently, fprettify indents function/subroutine arguments to the opening of the bracket ... like this.

    call ImportSu2Mesh("onera-m6.su2", nodes, cells, &
                       numNodes, numCells)

Issue: Aesthetically, I like it, but in practice, this creates lot of git diff noise when we change the function name during development. Since Fortran function calls can be long, and span multiple lines, this shifts and changes multiple lines at once.

I would like it to be like this by indenting by 4 spaces ...

    call ImportSu2Mesh("onera-m6.su2", nodes, cells, &
         numNodes, numCells)

or like this by indenting by 8 spaces ...

    call ImportSu2Mesh("onera-m6.su2", nodes, cells, &
             numNodes, numCells)

The indentation width should be customizable by the user.

clang-format supports this for C/C++ with ...

  1. AlignAfterOpenBracket: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#alignafteropenbracket
  2. ContinuationIndentWidth: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#continuationindentwidth

Essentially, if a line is continued to the next line, it is indented by the values of ContinuationIndentWidth. We can set it to 2space, 4 spaces, or 8 spaces. It's customized by the user for their preference.

Some line continuation indentation examples clang shows are ...

// Example 1
someLongFunction(argument1,
    argument2);

// Example 2
int i =         //  VeryVeryVeryVeryVeryLongComment
    longFunction( // Again a long comment
    arg);

Do note that when a subroutine or one or more functions are called at once, then the indention rule would apply based on the last line, and context i.e if last line starts at column n, the next line would start at column n+indentationWidth.

call ImportSu2Mesh("onera-m6.su2", nodes, cells, &
    numNodes, numCells, numDeadCells, numBoundaryCells, &
    FunctionToCalculateRandomThing(a, b, c, d,  &  ! <<< New function called
        e, f, g, h, i , j, k, l) &  ! <<< Line is indented right
    backToOriginalIndentation, endOfSubroutineArguments) ! <<< Line is indented left

Since a new function is continued to the next line, the next line is further indented to the right, and when the function argument list is over, the line is indented left.

Would it not be possible to develop a feature like this?

Currently fprettify does shift everything to the right, in the feature I'm proposing, the shift would just be constant value of 4 spaces or 8 spaces, or as customized by the user.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions