[Release] pasfmt out now!

We’re excited to share the first public release of pasfmt, a free and open-source code formatter for Delphi.

It is a complete and opinionated formatting tool.

The latest release has support for:

  • Complete line wrapping (and unwrapping) for all Delphi structures
  • Configurable line length limit
  • Removing trailing whitespace
  • Change spacing around all tokens (e.g., operators and keywords)
  • Parallel file formatting with directory traversal
  • Removing repeated empty newlines
  • Line ending normalisation

To get started, either try our web demo, or download the executable (this one for Windows) and follow the getting started guide.

Additionally, there is an IDE plugin with support for:

  • In-editor formatting
  • Format-on-save
  • Cursor tracking

You may be wondering how this tool compares to the existing formatters (e.g., GExperts, JEDI, Formatter.exe).

This tool goes a lot further than the alternatives by having a complete opinion on how every line should be wrapped or unwrapped; the original layout is (almost) ignored.

By ignoring most of the input format, it produces consistently styled code across a whole codebase.

We hope that you enjoy pasfmt, let us know what you think!

2 Likes

This is absolutely extraordinarily good! [Yes, two superlatives, THAT’S how good it is!]

I thought, for sure, I could catch it out - but no, it was perfect!

Excellent work Jonah.

Thanks Ian!

For quite some time, my team has wanted to improve the formatting story for Delphi.
All credit goes to Joshua Gardner and Zane Duffield for delivering such a great formatter.

1 Like

Could you pass on my thanks to them too? Excellent work.

1 Like

This is how my IDE looks from now on for demos… :slight_smile:

2 Likes

Can I configure as below. I am old school before it was decided to format pas files like this:

for x:= 1 to 2 do
begin
  do something;
end

the standard format was

for i := 0 to 1 do
  begin
     do something;
     if( i = 0 )then
        begin
           do only first time;
        end;
  end;

Yes, I am just trying to work out how to tweak the formatting choices. It puts the begin on the same line as the if statement - a mortal sin at Embarcadero! :wink:

I found the .toml file instructions but I am not sure if that’s going to be enough.
It does do an excellent job though.

pasfmt is fairly opinionated, but it does allow configuration around the placement of begin.

To always have begin on the next line, add the following to pasfmt.toml:

begin_style = "always_wrap"

You can see all available configuration options with:

pasfmt -C help
1 Like

begin_style [ auto | always_wrap ] (default: auto) Places the beginafter control flow statements (e.g.if). If "always_wrap", the begin will always be placed on the next line at the same indentation as the statement it is within

The above as far as I can see will not indent on the next line of the control flow statement, which is what i would need to use this utility.

pasfmt is an opinionated formatter, meaning it exposes very few configuration options and aims for a highly consistent style.

We aren’t aiming to expose configuration options catering to every style permutation that might already be in existing codebases.

1 Like

I just love the anthropomorphising of your software: “opinionated”. Classic hahahah happy Friday!

Yes, not a problem. I missed the:

thing, doh!

No problem with it being opinionated - it’s just that some styles are fairly common like the begin on new lines, and - as you know - lots of development teams are pretty opinionated too! :joy:

A really nice piece of work.

1 Like

It might also be a prompt for more of us to learn a bit more about Rust.

I can hope to see, in the future, a presentation going through how the code is structured and how to adapt a fork to your own ends.