fprettify icon indicating copy to clipboard operation
fprettify copied to clipboard

Strange blank space after allocate in allocate(xxx)

Open BarrySmith opened this issue 6 months ago • 4 comments

fprettify puts a space after allocate, for example

allocate (dmList(2))

same for deallocate. This seems odd and is jarring.

BarrySmith avatar Sep 25 '25 19:09 BarrySmith

I believe you can control spaces for intrinsics like allocate or write with the option --whitespace-intrinsics, ie. compare the difference in formatting for

fprettify -d --whitespace-intrinsics false <file>

and

fprettify -d --whitespace-intrinsics true <file>

dbroemmel avatar Nov 11 '25 14:11 dbroemmel

Thanks for the suggestion, it does indeed remove the blank after allocate before the (

But sadly, it also removes the blank after "end" resulting in code like

endtype gridinfo

which IMHO is even more odd and jarring, so my concern is not resolved.

BarrySmith avatar Nov 11 '25 17:11 BarrySmith

Well, --whitespace-intrinsics is very broad and it could be differentiated into sub options - the only question is how many special cases we should support since there are so many fortran statements followed by a bracket and I believe fprettify formats them all consistently with a space. For instance, if (.true.) has a space after if, and so does allocate.

pseewald avatar Nov 11 '25 19:11 pseewald

You are right that if (xxx) and allocate (xxx) have the same pattern, and I (perhaps unfairly) expect different behavior for each of them. It is because I view if (xxx) as being part of Fortran syntax while I view allocate(xxx) as being the equivalent of a function call and not Fortran "syntax". This makes me suggest --whitespace-intrinsic-function-like as a suboption, which would include allocate, deallocate, and probably lots of other ones, but would not include if (xxx) or end xxx name.

BarrySmith avatar Nov 11 '25 22:11 BarrySmith