fortran-lang / fprettify

auto-formatter for modern fortran source code
https://pypi.python.org/pypi/fprettify
Other
368 stars 73 forks source link

Indenting line labels #141

Open blaylockbk opened 1 year ago

blaylockbk commented 1 year ago

I'm using this example from Milan Curcic's book https://github.com/modern-fortran/stock-prices/blob/master/src/mod_io.f90

integer function num_records(filename)
  ! Return the number of records (lines) of a text file.
  character(len=*), intent(in) :: filename
  integer :: fileunit
  open(newunit=fileunit, file=filename)
  num_records = 0
  do
    read(unit=fileunit, fmt=*, end=1)
    num_records = num_records + 1
  end do
  1 continue
  close(unit=fileunit)
end function num_records

When fprettify formats this, the line label is pushed all the way left.

integer function num_records(filepath)
   ! Return the number of records (lines) of a text file.
   character(len=*), intent(in) :: filepath
   integer :: fileunit
   open (newunit=fileunit, file=filepath)
   num_records = 0
   do
      read (unit=fileunit, fmt=*, end=1)
      num_records = num_records + 1
   end do
1  continue                           ! <----- Note this line is dedented
   close (unit=fileunit)
end function num_records

I realize there are legacy reasons for putting the line label in the first column, but this interferes with code folding (VS Code). Is there any possibility of turning this off and letting the line label to be aligned with the rest of the content?

vickysharma0812 commented 1 year ago

This behavior is correct. Although, I am not able to find an official documentation about the label specifier. From my experience, it is a good practice to put label at the first column of a line.