Skip to content

Improve: preserve blank lines in sequences#814

Merged
gpetiot merged 4 commits intoocaml-ppx:masterfrom
gpetiot:preserve-seq-blank-lines
May 10, 2019
Merged

Improve: preserve blank lines in sequences#814
gpetiot merged 4 commits intoocaml-ppx:masterfrom
gpetiot:preserve-seq-blank-lines

Conversation

@gpetiot
Copy link
Copy Markdown
Collaborator

@gpetiot gpetiot commented May 2, 2019

Fix #554
I changed the break-sequences option, but maybe it would be better to have two options instead?

Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good !

The option change is a breaking change. But I think it for good, variant options will be easier to improve in the future than boolean options.

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented May 2, 2019

cc @Wilfred, @ELLIOTTCABLE for feedback

@gpetiot gpetiot requested a review from Julow May 2, 2019 14:14
@ELLIOTTCABLE
Copy link
Copy Markdown

I'm sure I'd approve (anything that improves readability and negative space, I'm happy with!); but if you want more thorough commentary, would you mind pasting a few examples (input/before-change/after-change) into the Issue? [=

@Wilfred
Copy link
Copy Markdown
Contributor

Wilfred commented May 7, 2019

@gpetiot the logic looks good to me! My sample code from #554:

let foo x y =
  do_some_setup x ;
  do_some_setup y ;

  (* This is the important bit *)
  important_function x ;
  another_important_function x y ;

  cleanup x y

Is unchanged with ocamlformat --break-sequences=preserve --enable-outside-detected-project on this PR, which is exactly what I'd hoped for :). I also like that it collapses blank lines:

Before:

let foo x y =
  (* foo *)
  do_some_setup x ;



  cleanup x y

After:

let foo x y =
  (* foo *)
  do_some_setup x ;

  cleanup x y

My only concern is that it doesn't make sense to use --break-sequences here. Whether or not the user wants expressions grouped on a line or not (fit versus all) seems separate to how they want blank lines to be handled.

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented May 7, 2019

My only concern is that it doesn't make sense to use --break-sequences here. Whether or not the user wants expressions grouped on a line or not (fit versus all) seems separate to how they want blank lines to be handled.

I tend to agree with that, I will change it so it is a separate option.

Edit: done, I added an option, and there is no diff with test_branch (also tested the jane street profile).

@gpetiot gpetiot requested a review from Julow May 9, 2019 06:23
Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a blank line in a small sequence gives this:

let foo x y = do_some_setup y ;

              important_function x

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented May 9, 2019

I fixed this and added a test.

@gpetiot gpetiot requested a review from Julow May 9, 2019 10:03
Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great !

@gpetiot gpetiot merged commit 8e40d15 into ocaml-ppx:master May 10, 2019
@gpetiot gpetiot deleted the preserve-seq-blank-lines branch May 10, 2019 05:58
@avsm
Copy link
Copy Markdown
Contributor

avsm commented May 14, 2019

This looks like a good candidate for conventional. Collapsing multiple blank lines is good practise in most code.

@ELLIOTTCABLE
Copy link
Copy Markdown

@avsm can you elaborate? "ocaml avsm conventional" doesn't yield any interesting search-engine results :P

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented May 14, 2019

This is the name of a preset profile of ocamlformat, you can use it with --profile=conventional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve blank lines in function bodies

6 participants