From 2001851983d5cd8ed7f25a62e066f09758c67ab1 Mon Sep 17 00:00:00 2001 From: toastal Date: Thu, 23 Feb 2023 19:41:20 +0700 Subject: [PATCH] Add ocamlformat (wrapped with tab support) --- flake.nix | 29 ++++++- srht_markup_massager/.ocamlformat | 14 ++++ srht_markup_massager/srht_markup_massager.ml | 83 +++++++++----------- 3 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 srht_markup_massager/.ocamlformat diff --git a/flake.nix b/flake.nix index 8e32274..0a07143 100755 --- a/flake.nix +++ b/flake.nix @@ -15,11 +15,35 @@ nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; - overlays = [ self.overlay ]; + overlays = [ self.overlay.default ]; }); in { - overlay = final: prev: { }; + overlay.default = final: prev: + let + appendFlags = new: old: + with builtins; + if isString old then prev.lib.concatStringsSep " " ([ old ] ++ new) + else if isList old then prev.lib.concatStringsSep " " (old ++ new) + else (prev.lib.concatStringsSep " " new); + + of = prev.ocamlformat.overrideAttrs (old: { + flambdaSupport = true; + configureFlags = appendFlags [ "-O3" ] (old.configureFlags or null); + }); + in + { + ocamlformat-with-tabs = prev.symlinkJoin { + name = "ocamlformat"; + paths = [ + (prev.writeShellScriptBin "ocamlformat" '' + set -euo pipefail + exec ${prev.lib.getExe of} "$@" | unexpand --first-only --tabs=2 + '') + of + ]; + }; + }; defaultPackage = forAllSystems (system: self.packages.${system}.${name}); @@ -73,6 +97,7 @@ buildInputs = with pkgs; [ dhall nixpkgs-fmt + ocamlformat-with-tabs ]; inputsFrom = builtins.attrValues self.packages.${system}; }); diff --git a/srht_markup_massager/.ocamlformat b/srht_markup_massager/.ocamlformat new file mode 100644 index 0000000..030dd1a --- /dev/null +++ b/srht_markup_massager/.ocamlformat @@ -0,0 +1,14 @@ +profile = ocamlformat +break-fun-sig = fit-or-vertical +cases-exp-indent = 2 +cases-matching-exp-indent = compact +field-space = loose +function-indent = 2 +margin = 90 +nested-match = align +leading-nested-match-parens = false +space-around-arrays = true +space-around-lists = true +space-around-records = true +space-around-variants = true +wrap-comments = true diff --git a/srht_markup_massager/srht_markup_massager.ml b/srht_markup_massager/srht_markup_massager.ml index b0a6214..cca9bbe 100755 --- a/srht_markup_massager/srht_markup_massager.ml +++ b/srht_markup_massager/srht_markup_massager.ml @@ -1,7 +1,5 @@ -(* - SPDX-FileCopyrightText 2022 toastal - SPDX-License-Identifier: LGPL-2.1-or-later -*) +(* SPDX-FileCopyrightText 2022 toastal SPDX-License-Identifier: + LGPL-2.1-or-later *) let unicon node = let () = Soup.remove_class "icon" node in Soup.add_class "Icon" node @@ -11,43 +9,43 @@ let mk_del node = Soup.set_name "del" node let unwrap_lone_p soup parent_selector = - Soup.select (String.concat "" [ parent_selector; ">"; "p:only-child" ]) soup + soup + |> Soup.select (String.concat "" [ parent_selector; ">"; "p:only-child" ]) |> Soup.iter Soup.unwrap let unwrap_definition_list_items node = match Soup.parent node with + | None -> + () | Some parent -> match Soup.parent parent with | Some parent' -> let () = Soup.select "li" node |> Soup.iter (Soup.set_name "dd") in let () = Soup.replace parent' node in Soup.unwrap node - | None -> () - | None -> () + | None -> + () let markdown_wrapper node = - let wrapper = Soup.create_element ~class_:"markdown" "div" in + let wrapper = Soup.create_element ~class_:"markdown" "div" in Soup.wrap node wrapper let aside_n_color_admonitions node = (* `aside` is a more semantic element *) - (* SourceHut doesn’t support