-
Notifications
You must be signed in to change notification settings - Fork 196
Feature request: Allow submodule-body indentations other than 2 spaces #1613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, my personal opinion about this kind of options is that it was a mistake to add them in ocamlformat in the first place, as it adds noise in the code, and it goes against the purpose of ocamlformat to promote a normalized formatting for the code of the community. I was personally considering removing these options for the 1.0 release (note that removing more and more options to progressively converge towards a unique style is our goal working towards the 1.0 release, and these indentation-options are the low hanging fruits of this simplification). Out of curiosity, why do you want to apply a 3-column indentation instead of 2? (if I'm not mistaken it seems that most people are happy with 2). Would removing these options be an issue for your project(s)? |
Well, there's kinda three points to make here:
Hope some of those thoughts would be useful! I'm not super-strongly opinionated about any of them, but it does seem like — if any options are to be kept — then the general, not-OCaml-specific ones are the most important options to "bend" the no-options rule on. (Specifically, I posit that it'd be good practice to allow interoperability with anything |
Sorry for the late update, my position didn't really change in the meantime, we still avoid adding new options, and so far most people seem happy with the current indentation of items. So we're unlikely to change it for now but we might reconsider if there is a stronger push from the community (we want to reflect the most commonly used styles and conventions and not focus on having something very customizable). I'm thus closing this issue :) |
Okay, I understand the constraints as a fellow maintainer. Here's hoping I'm not the only OCamleer who thinks 2 is a ridiculously small amount of space, though. Awaiting others' input with bated breath! |
Coming to stir the pot… ;) In the light of Anecdotally, as I’ve aged 2-spaced code has become harder and harder to read—and I used to be a proponent of 2-space indentation as a default 4 or so years ago. 2-space indentation is the default in the PureScript community and the compiler there doesn’t support tabs. Like the OP I prefer 3 or 4-spaced code personally as beyond 2 is where the indentation contrast actually ‘clicks’ and I can read the code a lot faster without the need to scrutinize. I recently picked up some OCaml to try a new language and had been using tabs since it’s supported by the compiler. I’d like to consider the language beyond a one-off, for-fun scripts so I went to find the community formatter, but I ended up in this issue because common code uses this formatter and is 2-spaced and difficult for me to read. |
If anyone is looking for a tab-support workaround in a Nix shell, here is a minimal-but-expandable Flake that can be used as a starter: {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }@inputs:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
nixpkgsFor = forAllSystems (system: import nixpkgs {
inherit system;
overlays = [ self.overlay ];
});
in
{
overlay = final: prev: {
ocamlformat-with-tabs = prev.writeShellScriptBin "ocamlformat" /* sh */ ''
set -euo pipefail
exec ${prev.lib.getExe prev.ocamlformat} "$@" | unexpand --first-only --tabs=2
'';
};
devShell = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
in
pkgs.mkShell {
buildInputs = with pkgs; [
ocamlformat-with-tabs
];
});
};
} (irony of this code being 2-space hasn’t escaped me but the same issue of 2-space code is in the Nix formatters too) This will put a wrapped |
This seems popular and have been closed too quickly, re-opening. Reducing the number of option is a goal but we also want to keep the reasonable options that people care about. |
Little ping to see the state of this issue. Wouldn't it be better to add parameter for deciding indent size for all the project ? The main problem with how ocamlformat handle indent size is that you must redifine the indent size for all types of elements (case-exp, extension, function ...). Wouldn't it be better to define a default tab size behavior, and then to be able to customize it for specific items ? |
It’s also worth noting that Topiary allows one to configure indentation & supports OCaml. Footnotes
|
I'd like to see more options for indentation. I have created a feature request here (prior to seeing this one) and started working on a PR.
As mentioned in my request, since modules are ocamls overarching programming unit it's quite hard to decide which syntax elements should be subject to a 'module-indent' option. I have proposed supporting something like configurable indent categories to replace the existing hard coded values:
As far as I can tell, this would be fairly straightforward to implement. Where there are hard coded values, these would simply be replaced by configuration: ...
| Lapply (li1, li2) ->
hvbox c.conf.fmt_opts.base_indent.v
( fmt_longident li1
$ wrap (cut_break $ str "(") (str ")") (fmt_longident li2) )
...
Or if more fine grained compatibility with existing indentation options is needed (assuming the existing indent options are consumed as Options): let box =
if c.conf.fmt_opts.ocp_indent_compat.v then
match pld with
| PStr [{pstr_desc= Pstr_eval _; _}] | PTyp _ | PPat _ ->
hvbox (c.conf.fmt_opts.extension_indent.v |> Option.value c.conf.fmt_opts.base_indent.v)
| PSig _ | PStr _ ->
hvbox (c.conf.fmt_opts.stritem_extension_indent.v |> Option.value c.conf.fmt_opts.base_indent.v)
else Fn.id I would be more than happy to implement this if supported by the maintainers @gpetiot @Julow. |
Is your feature request related to a problem? Please describe.
At the moment, as far as I can tell, there's no way to reliably produce output like the following:
Unlike, for instance, extensions, functions, let-bindings, and type-decls, submodule bodies seem to be hard-coded to always be two spaces!
Describe the solution you'd like
A indentation setting that applies to structs and signatures:
... producing, for the above:
The text was updated successfully, but these errors were encountered: