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

Feat req: Trim whitespaces between characters #8

Open
gnikit opened this issue Oct 5, 2021 · 0 comments
Open

Feat req: Trim whitespaces between characters #8

gnikit opened this issue Oct 5, 2021 · 0 comments

Comments

@gnikit
Copy link

gnikit commented Oct 5, 2021

Extremely poorly written code often does not have a consistent styling between statements. As it currently stands findent will not try and fix that. I am curious if this is a useful feature for findent to have

MWE

program main

   implicit none

   real    ::    b(3,3)
   integer   ::   j,   k

   b    =    foo(     10 )

   write      (*, '(*(g0))')   (   (  b  (j, k) , ' ', k  =  1 , 3 ), new_line('A'), j  =  1, 3)

contains

   function                  foo  ( var   )    result( res )
      integer       , intent(    in   )           ::            var
      real,  dimension( 3 , 3 )       ::  res


      integer   :: i

      res( : , 1  )  =   [  0, 1 ,  2   ]
      res( : , 2  )  =   (/  4 , 5, 6  /)
      call        random_number (   res( :, 3  )   )

      if     (  any   ( res( :, 3)  >  0.5 ) )    then
         do     i    =  3  ,   1  ,   -  1
            res( i  ,  3) = -i
         end    do
      end if

      print   *  ,  'nightmare fuel'

   end         function   foo

end   program main

Formatted

A formatted version of that should roughly look something like this (this preserves the number of lines)

program main

   implicit none

   real :: b(3, 3)
   integer :: j, k

   b = foo(10)

   write (*, '(*(g0))') ((b(j, k), ' ', k=1, 3), new_line('A'), j=1, 3)

contains

   function foo(var) result(res)
      integer, intent(in) :: var
      real, dimension(3, 3) :: res


      integer   :: i

      res(:, 1) = [0, 1, 2]
      res(:, 2) = (/4, 5, 6/)
      call random_number(res(:, 3))

      if (any(res(:, 3) > 0.5)) then
         do i = 3, 1, -1
            res(i, 3) = -i
         end do
      end if

      print *, 'nightmare fuel'

   end function foo

end program main

This issue goes into styling preferences, which are highly subjective, and to the best of my knowledge are not really standardised in Fortran. But I would argue that having the option to impose a consistent styling across a file is better than not.

More than happy to work on this.

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

1 participant