fprettify icon indicating copy to clipboard operation
fprettify copied to clipboard

Indenting over multiple #ifdef blocks

Open Migelo opened this issue 1 year ago • 0 comments
trafficstars

Hi!

I have a question about how fprettify handles indentation over multiple #ifdef blocks. Here is a code snippet formatted with. $ fprettify --whitespace-comma --enable-decl -i 4 debug.f90

program hello
    implicit none
    integer :: i, j, k
    print *, "Hello, World!"

#ifdef THREEDSIM
    do k = 1, 2
        print *, "Hello, World!"
#elif defined(TWODSIM)
        do j = 1, 2
            print *, "Hello, World!"
#else
            do i = 1, 2
                print *, "Hello, World!"
#endif
#ifdef THREEDSIM
            end do
#elif defined(TWODSIM)
        end do
#else
    end do
#endif

end program hello

You can see that subsequent do loops get indented every time, even though neither THREEDSIM nor TWODSIM are defined.

Is there a flag (I tried most of them and failed) that would result in code like this?

program hello
   implicit none
   integer :: i, j, k
   print *, "Hello, World!"

#ifdef THREEDSIM
   do k = 1, 2
      print *, "Hello, World!"
#elif defined(TWODSIM)
   do j = 1, 2
      print *, "Hello, World!"
#else
   do i = 1, 2
      print *, "Hello, World!"
#endif
#ifdef THREEDSIM
   end do
#elif defined(TWODSIM)
   end do
#else
   end do
#endif

end program hello

If not, please point me to the place in fprettify where I should start looking to make this way of formatting code possible. Thank you!

Migelo avatar Sep 11 '24 20:09 Migelo