wvermin / findent Goto Github PK
View Code? Open in Web Editor NEWindent, relabel and convert Fortran sources
indent, relabel and convert Fortran sources
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
When cross-compiling findent the build step fails at the man-page generation here
findent/findent/src/Makefile.am
Lines 97 to 104 in e0822a3
What is the best way to obtain the man-page when cross-compiling or alternatively disabling the man-page generation step.
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
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
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 ?
findent-1.6.1-r1 is the first commit to github
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.
I have seen on the pyproj page (https://pypi.org/project/findent/4.1.1/) that it is suggested to manually indent all lines before using findent but is it possible to add an option to do this within the programme? Thanks for the great project!
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
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
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.
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
An equally reasonable way to indent would be
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.
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.
I stumbled onto this where the end procedure name
is not indented. Same goes for the contents of the procedure
.
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
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
cmd
)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
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)
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
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
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
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!
A few bug fixes; introduction of findentfix: correct rare findent mistakes by comments in source; extended documentation; interfaces for vim, gedit, emacs .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.