Giter Site home page Giter Site logo

wvermin / findent Goto Github PK

View Code? Open in Web Editor NEW
40.0 40.0 6.0 2.74 MB

indent, relabel and convert Fortran sources

C++ 40.42% Shell 16.35% C 0.47% Java 3.14% Lex 1.92% Yacc 1.74% Makefile 16.22% M4 3.20% Roff 15.00% Python 0.58% Emacs Lisp 0.16% Batchfile 0.07% Vim Script 0.72%

findent's People

Contributors

wvermin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

findent's Issues

Bug: end procedure in submodule not indented

I stumbled onto this where the end procedure name is not indented. Same goes for the contents of the procedure.

MWE

start with

submodule( foo_module) submodule1
implicit none
contains
module procedure foo1
  WRITE(*,"(A)") "testing :: "// trim(a) // "::"// trim(b)
end procedure foo1
end submodule submodule1

expected output is

submodule( foo_module) submodule1
   implicit none
contains
   module procedure foo1
      WRITE(*,"(A)") "testing :: "// trim(a) // "::"// trim(b)
   end procedure foo1
end submodule submodule1

findent output (v4.1.2.pre11) is

submodule( foo_module) submodule1
   implicit none
contains
   module procedure foo1
   WRITE(*,"(A)") "testing :: "// trim(a) // "::"// trim(b)
end procedure foo1
end submodule submodule1

Something else I spotted which might be worth opening a separate issue for is that if you run -Rr or -RR it relabels to the wrong name. Am I doing something wrong here?

submodule( foo_module) submodule1
   implicit none
contains
   module procedure foo1
   WRITE(*,"(A)") "testing :: "// trim(a) // "::"// trim(b)
end submodule submodule1
end submodule submodule1

Support for installing findent using pip in MSYS2 UCRT64 environment on Windows

Environment details

Windows Command Prompt (cmd)

System Information (neofetch)

OS: Windows 10 (Home) x86_64
Kernel: WIN32_NT 10.0.19045.4412 (22H2)
Uptime: 4 hours, 1 min
Shell: CMD 10.0.19041.4355
Resolution: 1920x1080
DE: Fluent
WM: Desktop Window Manager
WM Theme: Custom - #0078D7 (System: Light, Apps: Light)
Icons: This PC, Recycle Bin
Terminal: Windows Console 10.0.19041.4355
Terminal Font: Consolas 16
CPU: Intel(R) Core(TM) i7-9700 (8) @ 4.70 GHz
GPU: NVIDIA GeForce RTX 2060 (5958 MiB) [Discrete]
Memory: 3534 MiB / 16332 MiB

Python and pip versions

C:\Users\user>where python
D:\Develop\msys64\ucrt64\bin\python.exe
C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe

C:\Users\user>where pip
D:\Develop\msys64\ucrt64\bin\pip.exe

C:\Users\user>python --version
Python 3.11.9

C:\Users\user>pip --version
pip 24.0 from D:\Develop\msys64\ucrt64\lib\python3.11\site-packages\pip (python 3.11)

Error encountered

C:\Users\user>pip install --user findent
ERROR: Could not find a version that satisfies the requirement findent (from versions: none)
ERROR: No matching distribution found for findent

MSYS2 UCRT64 Shell

System Information (neofetch)

OS: Windows 10 (Home) x86_64
Kernel: WIN32_NT 10.0.19045.4412 (22H2)
Uptime: 4 hours, 12 mins
hPackages: 309 (pacman)
Shell: sh
Resolution: 1920x1080
DE: Fluent
WM: Desktop Window Manager
WM Theme: Custom - #0078D7 (System: Light, Apps: Light)
Icons: This PC, Recycle Bin
Terminal: mintty 3.7.1
Terminal Font: Lucida Console 9
CPU: Intel(R) Core(TM) i7-9700 (8) @ 4.70 GHz
GPU: NVIDIA GeForce RTX 2060 (5958 MiB) [Discrete]
Memory: 3585 MiB / 16332 MiB

Error encountered

user@DESKTOP-XXXXXXXX UCRT64 ~
$ pip install --user findent
ERROR: Could not find a version that satisfies the requirement findent (from versions: none)
ERROR: No matching distribution found for findent

Description

I am encountering an issue when trying to install the findent package using pip in both the Windows Command Prompt and MSYS2 UCRT64 shell. Despite having Python and pip correctly installed and configured, pip cannot find the findent package.

Could you please provide support or guidance on how to resolve this issue?

Thank you for your assistance!

Feat req: Indentation for line continuation with non-fixed ammout

I know that findent currently supports indent continuation through the option -k<n>, however indenting code by a fixed amount can yield into some vary unreadable code. Take the following code for example and how it is currently indented

image

An equally reasonable way to indent would be

image

Also, this still adheres to the promise of findent to "not make irreversible changes to the source" (with the known exceptions relabelling, converting, etc.).

I don't necessarily think that what I am proposing should be the default option, but I do believe that there should be an option between fixed indentation of line continuations and no indentation at all.

Wrong identation after one-line do loop

I use findent in the vscode. For fortran, the findent incorrectly aligns the code if I use an one-line loop. The following is an example of correct and incorrect alignment:

  do ic=1,2
    c(ic) = 0
  end do
  call xxx        ! correct indentation

  do ic=1,2; c(ic) = 0; end do
    call xxx     ! wrong indentation, two extra spaces are included

findent 2.8.0

A few bug fixes; introduction of findentfix: correct rare findent mistakes by comments in source; extended documentation; interfaces for vim, gedit, emacs .

Structures (Derived Types)

I have an issue with indentation when using Derived Types, here a two simple examples, one is correctly indented (ok.f90), the other is NOT (nok.f90):

ok.f90

program ok
implicit none
type mytype
integer:: i
real*8 :: a(3)
end type mytype

type (mytype) :: var
type (mytype) :: stuff(3)
var % i = 3
var % a(1) = 4.0d0
stuff(1) % a(2) = 8.0d0
stuff(1) % i = 4
end program ok

result of $ findent <ok.f90

program ok
   implicit none
   type mytype
      integer:: i
      real*8 :: a(3)
   end type mytype

   type (mytype) :: var
   type (mytype) :: stuff(3)
   var % i = 3
   var % a(1) = 4.0d0
   stuff(1) % a(2) = 8.0d0
   stuff(1) % i = 4
end program ok

nok.f90

program nok
implicit none
type domain_data
real, dimension(:, :), allocatable :: temperature
integer:: ibound, icopy, todomain
end type

type(domain_data), dimension(2), target :: dom
allocate(dom(1) % temperature(20, 20))
dom(1) % temperature = 0.
dom(1) % temperature(:, 1) = 1.
end program nok

result of $ findent <nok.f90

program nok
   implicit none
   type domain_data
      real, dimension(:, :), allocatable :: temperature
      integer:: ibound, icopy, todomain
   end type

   type(domain_data), dimension(2), target :: dom
   allocate(dom(1) % temperature(20, 20))
   dom(1) % temperature = 0.
      dom(1) % temperature(:, 1) = 1.
      end program nok

Is there a special switch I can use ?

preprocessor issue

Hi - super-impressed by findent - great utility!

On a large codebase (onetep.org) we find a few issues preventing us routinely running over the whole code.

The most notable seems to be a bug in handling of nested preprocessor directives. I boiled it down to a very simple test with deliberately wrong indenting that needs fixing:

module findent_issue_demo

contains

   subroutine my_sub()

      use other_module, only: one_thing, &
#if defined(MPI) && !defined(NOMPIIO)
         another, &
#ifdef HDF5
         a_third, &
#endif
#endif
      final_one

      implicit none

      do i=1,3

      if (2>1) then
      a=b
      else
      c=d
      endif

      enddo

      end subroutine my_sub

      end module findent_issue_demo

The #if's and #ifdef's control which things are brought in by the use statement. With them nested as above, the processing seems to get bugged and no further indenting eg of the do loop or the if statement happens for the rest of the file.

I am using findent version 4.2.6 installed via pip.

Bug: Refactor procedures ignores interface keyword

Requesting to indent and refactor (-Rr) the following code the interface block is completely ignored.

   INTERFACE MatCreateShell
      SUBROUTINE MatCreateShell(comm,mloc,nloc,m,n,ctx,mat,ierr)
         use petsc
      MPI_Comm :: comm
      PetscInt :: mloc,nloc,m,n
      TYPE(integer) :: ctx
      Mat :: mat
      PetscErrorCode :: ierr
      END SUBROUTINE MatCreateShell
   END INTERFACE MatCreateShell

image

On a separate note, I understand that the -Rr | -RR are only meant to change the case of the end ... lines but it would be nice/reasonable if the casing of the of the function/subroutine/procedure/... also used the same casing e.g.

      subroutine MatCreateShell(comm,mloc,nloc,m,n,ctx,mat,ierr)
         use petsc
         MPI_Comm :: comm
         PetscInt :: mloc,nloc,m,n
         TYPE(integer) :: ctx
         Mat :: mat
         PetscErrorCode :: ierr
      end subroutine MatCreateShell

Feat req: Trim whitespaces between characters

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.

Indenting continuation lines

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.

Contains different types of indentation

I raise this issue to begin a discussion since I am not entirely sure what the correct indentation of the code below should be.
From the point of collapsable scopes (hiding code) it would make sense if the contains was indented within the type and lines underneath it were indented once more, e.g.

   type :: node
      private
      type(node), pointer :: next => null()
      class(*), allocatable :: item

      contains
         final :: node_finalizer

   end type node

Running findent (v4.1.1) with no options yields the following code which is non collapsible but one would argue it is still sensibly indented with regards to the contains keyword.

   type :: node
      private
      type(node), pointer :: next => null()
      class(*), allocatable :: item

   contains
      final :: node_finalizer

   end type node

You can always disable the indentation of contains with -C0 but I am not sure this makes much sense for the contains to be indented at the same level as it's components

   type :: node
      private
      type(node), pointer :: next => null()
      class(*), allocatable :: item

      contains
      final :: node_finalizer

   end type node

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.