Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indenting continuation lines #9

Closed
sindizzy opened this issue Feb 10, 2022 · 4 comments
Closed

Indenting continuation lines #9

sindizzy opened this issue Feb 10, 2022 · 4 comments

Comments

@sindizzy
Copy link

First of all thanks for such an incredible tool!!! I inherited a project with indentations that are making me question my sanity.

So I am using the tool with the -Ia switch which I think is going to be my best option. However, there are some continuation lines which I cant figure out how to indent to my liking.

Example:

   LOGICAL  ALPHA, BETA200 , &
            BZT    , ISOKEQP ,  & !added a flag for equipment               
            Use_Default_V , B100 , Have_T

ends up looking like this

   LOGICAL  ALPHA, BETA200 , &
      BZT    , ISOKEQP ,  & !added a flag for equipment               
      Use_Default_V , B100 , Have_T

I have been experimenting with -k, -kd, and --align_paren but can't seem to get continuation lines to indent to the main line's contents, if that makes sense.

Another example is when this:

                   Write(*,*) ADT(1:2) // ' ' // ADT(3:4) // '  ' // SPEED// '   ' // Config // '  ' // &
                              ADT(1:8) // ' ' // Nums(I) // '.' // Nums(J)

becomes this:

                   Write(*,*) ADT(1:2) // ' ' // ADT(3:4) // '  ' // SPEED// '   ' // Config // '  ' // &
                      ADT(1:8) // ' ' // Nums(I) // '.' // Nums(J)

Any help is appreciated. Again thanks for this great tool.

@wvermin
Copy link
Owner

wvermin commented Feb 11, 2022

Thanks for your comment about indenting continuation lines.

What you ask for is not unreasonable, but implementation in findent is problematic:

  • a sloppy implementation would be to have an option to indent continuation lines, taking into account the original leading number of spaces. This method has the disadvantage that it is not reversible: once you forget to give the relevant flag, your desired indentation cannot be restored. This method would also not work with your original, very ill indented source.
  • a better implementation would be to let findent recognize all patterns that are candidate for your proposed indentation: decralartions like LOGICAL or REAL, DIMENSION(N), INTENT(IN) :: or WRITE(COMPLICATED EXPRESSION TO COMPUTE UNIT NUMBER,*). As it is now, findent only recognizes structures that are amenable for changing the indent, it does not know about LOGICAL, WRITE and so on. So, implementation of this method would be difficult.

However, I see two solutions for you:

  • The most easy: change
  LOGICAL A,B,C, &
    D,E

into:

   LOGICAL &
   A,B,C, &
   D,E

findent will indent this thusly:

LOGICAL &
   A,B,C, &
   D,E
  • A better way, with somewhat more work for you, change your code into something like this:
   program issue9
       character(len=10) adt, speed, config, nums(5) ! to get the write(*,*) compiled

       LOGICAL  ALPHA         , BETA200 ,        &
       &        BZT           , ISOKEQP ,        & !added a flag for equipment
       &        Use_Default_V , B100    , Have_T

       Write(*,*) ADT(1:2) // ' ' // ADT(3:4) // '  ' // SPEED// '   ' // Config // '  ' // &
       &          ADT(1:8) // ' ' // Nums(I)  // '.'  // Nums(J)
    end program

I.e. add the continuation character (&) at the start of the continuation line, this way you have complete control about the lay out.

Hoping this helps,

Willem

@wvermin wvermin closed this as completed Feb 11, 2022
@wvermin wvermin reopened this Feb 11, 2022
@wvermin
Copy link
Owner

wvermin commented Feb 11, 2022

accidentally closed, re-opened it

@sindizzy
Copy link
Author

Yes it does help. many thanks. I think either way I have some manual tweaking to do afterwards. The codebase is not large so I'm not against doing some manual alterations after findent.

@wvermin
Copy link
Owner

wvermin commented Feb 12, 2022

Ok, closing now after a little edit of my answer above.

@wvermin wvermin closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants