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

Change all indentation from 3 spaces to 2 using findent #80

Closed
wants to merge 2 commits into from

Conversation

JamieJQuinn
Copy link
Collaborator

Used pip-installed findent 4.3.1 to change all indentation from 3 spaces to 2 using the following fish command:

for f in (find . -name '*.f90'); findent -i2 -I2 < $f > $f.temp; mv $f.temp $f; end

@@ -283,11 +283,11 @@ subroutine divergence_v2p(self, div_u, u, v, w)
! Interpolation for v field in x
! Interpolation for w field in x
call self%backend%tds_solve(du_x, u, self%xdirps, &
self%xdirps%stagder_v2p)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, I would expect the continuation from the parentheses, isn't this more common?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can play with this parameter

       --align_paren[=<n>]
              align continuation lines not preceded
                by '&' with preceding unmatched left parenthesis.
               n=0, or flag omitted: do not align.
               n=1: do align (default).

though the default should be do leave it as is

last_r = ffr(1)

du(i, 1, b) = coeffs_s(1, 1)*u_s(i, 1, b) &
+ coeffs_s(2, 1)*u_s(i, 2, b) &
Copy link
Member

@semi-h semi-h Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be very confusing, very surprised fprettify findent allows this to be honest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again not visible here on the comment tab, but + coeff... starts from all the way left with two spaces, however I would expect it to start from right below the previous variable after the =

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I didn't see any way in the manual to indent continuation lines after a = nor a :: with findent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with :: its not the end of the world, one can argue its better to follow findent way, but with + I think things would get very confusing and hard to follow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am tempted to write a small script just to handle these tbh. This is pretty lacking indeed

@@ -1,37 +1,37 @@
module m_allocator
Copy link
Member

@semi-h semi-h Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also interesting, even the module declaration starts with two spacing. Is there a way to disable it? seems like a waste of two spaces to me. (Because its like +2 in every single line due to this)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the -I2 parameter, this can be removed

!! by calling the type bound procedure
!! [[m_allocator(module):release_block(subroutine)]]. The
!! released block is then pushed in front of the block list.
module m_allocator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented on the wrong side and its actually not visible due to that. I mean the 2 spaces before module m_allocator

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u_y, v_y, w_y, du_y, dv_y, dw_y, &
u_z, w_z, dw_z
u_y, v_y, w_y, du_y, dv_y, dw_y, &
u_z, w_z, dw_z
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually everywhere but had to comment on a specific example. I would expect the continuation line to start aligned with the first variable like it used to be.

last_r = ffr(1)

du(i, 1, b) = coeffs_s(1, 1)*u_s(i, 1, b) &
+ coeffs_s(2, 1)*u_s(i, 2, b) &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting here just to show the actual change with spacing

case (RDR_Z2Y)
dir_in = DIR_Z
dir_out = DIR_Y
case (RDR_X2Y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another interesting point. case is shifted only one space, not two, and also the lines inside the case are shifted by one.

Copy link
Collaborator

@Nanoseb Nanoseb Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one will be fixed by using --indent_select=4 --indent_case=2

yky(i) = yky(ny-i+2)
eys(i) = eys(ny-i+2)
yk2(i) = yk2(ny-i+2)
yky(i) = yky(ny-i+2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like findent (at least with current settings) doesn't enforce anything between operators. (I think this particular line is not compatible with our current preference (spacing around - and + but no spacing around * and /) it would be nice if findent can identify and enforce a spacing based on our preference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findent doesn't support modifying these things. It is really mainly doing indentation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its actually good. Because fprettify is too restrictive with spacing around operators, and I don't really like it. For example, when passing a keyword argument to a function, I would rather not using spaces around =, but of course prefer spaces around assingment = normally. And fprettify can't tell them apart and want you to pick one and use it everywhere. Also with if and allocate. You may want space after if, but no space after allocate, but fprettify won't let you do this because it considers these two in the same group and the rule is defined for the whole group...

RDR_Y2X, 0, RDR_Y2Z, RDR_Y2C, &
RDR_Z2X, RDR_Z2Y, 0, RDR_Z2C, &
RDR_C2X, RDR_C2Y, RDR_C2Z, 0], shape=[4, 4])
RDR_Y2X, 0, RDR_Y2Z, RDR_Y2C, &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a good one to test findent. With the settings @Nanoseb recommended I would expect this line to start after the [ above. Curious to see what will happen

Copy link
Collaborator

@Nanoseb Nanoseb Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my surprise, it does work:

  integer, protected :: &
      rdr_map(4, 4) = reshape([0, RDR_X2Y, RDR_X2Z, RDR_X2C, &
                               RDR_Y2X, 0, RDR_Y2Z, RDR_Y2C, &
                               RDR_Z2X, RDR_Z2Y, 0, RDR_Z2C, &
                               RDR_C2X, RDR_C2Y, RDR_C2Z, 0], shape=[4, 4])

With findent --align_paren=1 < common.f90

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@Nanoseb
Copy link
Collaborator

Nanoseb commented Mar 26, 2024

Used pip-installed findent 4.3.1 to change all indentation from 3 spaces to 2 using the following fish command:

for f in (find . -name '*.f90'); findent -i2 -I2 < $f > $f.temp; mv $f.temp $f; end

I would add

  • --align_paren=1 to align multilines parenthesis)
  • --refactor_end to add subroutine names after end subroutine
  • --indent_select=4 --indent_case=2 to for case/select statements

@semi-h
Copy link
Member

semi-h commented Mar 26, 2024

Is there any setting for alignment for multi-line assignments and for multi-line variable declarations?

@Nanoseb
Copy link
Collaborator

Nanoseb commented Mar 26, 2024

Is there any setting for alignment for multi-line assignments and for multi-line variable declarations?

no, unfortunately I haven't seen anything about that in the help page

to use in combination with findent
@Nanoseb
Copy link
Collaborator

Nanoseb commented Mar 26, 2024

Because the main limitation of findent is line continuation after =, :: and :. I wrote a small script to handle only these. It is to be used on findent output.

findent < in.f90 | script/indent_continuation.py > out.f90

@Nanoseb Nanoseb changed the title Change all indentation from 3 spaces to 2 Change all indentation from 3 spaces to 2 using findent Mar 27, 2024
@Nanoseb Nanoseb closed this Mar 29, 2024
@Nanoseb
Copy link
Collaborator

Nanoseb commented Mar 29, 2024

using fprettify instead see #81

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

Successfully merging this pull request may close these issues.

None yet

3 participants