Skip to content

Proposal for an "ocsigen" OCamlformat profile#857

Draft
Julow wants to merge 1 commit into
ocsigen:masterfrom
Julow:ocamlformat-profile
Draft

Proposal for an "ocsigen" OCamlformat profile#857
Julow wants to merge 1 commit into
ocsigen:masterfrom
Julow:ocamlformat-profile

Conversation

@Julow
Copy link
Copy Markdown
Contributor

@Julow Julow commented Apr 22, 2026

I open this PR to ask for comments. I'd like to create an "ocsigen" profile in OCamlformat (the name can be debated) but it can't match exactly the profile used in ocsigen projects.

The reason is the ocp-indent-compat option, which is very unstable and is hard to maintain within OCamlformat. This option doesn't do what it says and causes formatting changes after each releases of OCamlformat. Internally, it just turns on many formatting specific to the janestreet profile.
It's not reasonable to use it in an other profile because it causes bugs in combination with other options that are very hard to debug.

This is the output of the profile I propose for the ocsigen projects.

Advantages:

  • This reduces the indentation of argument lists and of long (fun .. -> ..), which is in the spirit of the previous profile.
  • Formatting of comments is enabled. This might mess up the custom doc format, so we can revert this.
  • The closing *) of copyright headers is aligned with the rest of the comment.
  • It removes 1500 lines of code !

Other changes:

  • Arguments are no longer formatted one per line. This removes many lines but might be harder to edit.
  • I removed the options that were equal to the default.

@Julow Julow marked this pull request as draft April 22, 2026 14:37
@Julow
Copy link
Copy Markdown
Contributor Author

Julow commented Apr 22, 2026

In the last commit, I add an option to see more easily the end of "big" expression. It makes both reading and editing easier but it re-add the 1500 removed lines. I explain it better in the commit message.

@balat
Copy link
Copy Markdown
Member

balat commented Apr 22, 2026

I'm ok with these changes, except the indentation of comments. I recently added

parse-docstrings = false
wrap-comments = false

to the default .ocamlformat.

The ocp-indent compat is not a big deal.

Most the changes I see are closing parenthesis on a single line (but it's ok as it follow our "readability" principle)
and same for list and tuples with ; at the beginning of the line: having the closing parenthesis on a single line makes its even easier to cut/paste.

@Julow Julow force-pushed the ocamlformat-profile branch from 4191cd5 to 11ccf39 Compare April 22, 2026 15:25
This modifies the OCamlformat profile to make it possible to upstream it
into OCamlformat.

- Remove the "ocp-indent-compat" option

This option does more than what the doc says and enables formattings
that cannot be set with any other option.

It is very hard to maintain within OCamlformat and setting it in the
ocsigen profile would create a large maintenance cost.

Removing this option causes a lot of changes to the formatting but some
of the changes could be reverted by adding options to OCamlformat.
Something that was harder to do with the option set.

This also fixes a few bugs, like commas in tuple types or in header
comments, and allows using parse-docstrings without also formatting the
regular comments.

- Add "indicate-multiline-delimiters=closing-on-separate-line"

This adds a newline before the closing parenthese around a multiline
expression. This makes reading easier by delimiting the "big" expression
and editing easier by moving the parentheses that are not part of the
"small" expression to an other line.

    (match .. with
    | .. ->
        some
          (long
             (expression)))

becomes:

    ( match .. with
    | .. ->
        some
          (long
             (expression))
    )

- Remove options equal to the default
@Julow Julow force-pushed the ocamlformat-profile branch from 11ccf39 to 18b8bbb Compare April 22, 2026 15:27
@Julow
Copy link
Copy Markdown
Contributor Author

Julow commented Apr 22, 2026

Thanks for your feedback! I removed the formatting of comments and redid the change the latest version of OCamlformat.

@Julow
Copy link
Copy Markdown
Contributor Author

Julow commented Apr 22, 2026

Here's how the formatting of comments (but not of documentation) would look: Julow@7b05b9c

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants