Skip to content

Break long literal strings at the margin#1367

Merged
gpetiot merged 1 commit intoocaml-ppx:masterfrom
gpetiot:fmt-literal-strings
May 25, 2020
Merged

Break long literal strings at the margin#1367
gpetiot merged 1 commit intoocaml-ppx:masterfrom
gpetiot:fmt-literal-strings

Conversation

@gpetiot
Copy link
Copy Markdown
Collaborator

@gpetiot gpetiot commented May 19, 2020

Fix #1366
there was a bug in the printing of escaped newlines, no break was printed before a linebreak (and doing it causes way more regressions so this is not a good fix), as Carl suggested in #1366 I've merged the linebreaks with the preceding words to avoid having the linebreaks alone on their line.

As a side-effect it made some long argument list non-break anymore, but this but it looks like this break was a fortunate side-effect of the original code. It will be fixed with #1360 hopefully. I will check if this is really the case.

Here are the changes of test_branch (some are fixes as we are now correctly breaking at the margin, some will be fixed by #1360):

diff --git a/vendor/parse-wyc/menhir-recover/emitter.ml b/vendor/parse-wyc/menhir-recover/emitter.ml
index e6a664f..63f6cb1 100644
--- a/vendor/parse-wyc/menhir-recover/emitter.ml
+++ b/vendor/parse-wyc/menhir-recover/emitter.ml
@@ -294,8 +294,7 @@ end = struct
     in
     fprintf ppf
       "let token_of_terminal (type a) (t : a %s.terminal) (v : a) : token =\n\
-      \  match t with\n"
-      menhir;
+      \  match t with\n" menhir;
     Terminal.iter case
 
   let emit_nullable ppf =
diff --git a/infer/src/clang/cArithmetic_trans.ml b/infer/src/clang/cArithmetic_trans.ml
index 4a98df832..0f844757a 100644
--- a/infer/src/clang/cArithmetic_trans.ml
+++ b/infer/src/clang/cArithmetic_trans.ml
@@ -178,7 +178,8 @@ let unary_operation_instruction translation_unit_context uoi e typ loc =
       let uok = Clang_ast_j.string_of_unary_operator_kind uoi.Clang_ast_t.uoi_kind in
       L.(debug Capture Medium)
         "@\n\
-         WARNING: Missing translation for Unary Operator Kind %s. The construct has been ignored...@\n"
+         WARNING: Missing translation for Unary Operator Kind %s. The construct has been \
+         ignored...@\n"
         uok ;
       (e, [])
 
diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml
index b3a61788b..5db534ec6 100644
--- a/infer/src/clang/cTrans.ml
+++ b/infer/src/clang/cTrans.ml
@@ -2267,8 +2267,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
           L.debug Capture Medium
             "couldn't translate initListExpr properly: list lengths do not match:@\n\
             \  field_exps is %d: [%a]@\n\
-            \  stmts      is %d: [%a]@\n"
-            (List.length field_exps)
+            \  stmts      is %d: [%a]@\n" (List.length field_exps)
             (Pp.seq ~sep:"," (Pp.pair ~fst:Exp.pp ~snd:(Typ.pp Pp.text)))
             field_exps (List.length stmts)
             (Pp.seq ~sep:"," (Pp.of_string ~f:Clang_ast_proj.get_stmt_kind_string))
diff --git a/infer/src/concurrency/RacerDDomain.ml b/infer/src/concurrency/RacerDDomain.ml
index c97c4b5e0..6efde26d1 100644
--- a/infer/src/concurrency/RacerDDomain.ml
+++ b/infer/src/concurrency/RacerDDomain.ml
@@ -532,9 +532,9 @@ let pp_summary fmt {threads; locks; accesses; return_ownership; return_attribute
      Accesses %a @\n\
      Ownership: %a @\n\
      Return Attribute: %a @\n\
-     Attributes: %a @\n"
-    ThreadsDomain.pp threads LockDomain.pp locks AccessDomain.pp accesses OwnershipAbstractValue.pp
-    return_ownership Attribute.pp return_attribute AttributeMapDomain.pp attributes
+     Attributes: %a @\n" ThreadsDomain.pp threads LockDomain.pp locks AccessDomain.pp accesses
+    OwnershipAbstractValue.pp return_ownership Attribute.pp return_attribute AttributeMapDomain.pp
+    attributes
 
 
 let pp fmt {threads; locks; accesses; ownership; attribute_map} =
~
diff --git a/compiler/lib-runtime/gen/gen.ml b/compiler/lib-runtime/gen/gen.ml
index 9959ec8d2..31eb474d5 100644
--- a/compiler/lib-runtime/gen/gen.ml
+++ b/compiler/lib-runtime/gen/gen.ml
@@ -56,7 +56,8 @@ let () =
           let name = Filename.basename f in
           let content = read_file f in
           Printf.printf
-            "let %s = Js_of_ocaml_compiler.Builtins.register ~name:\"%s\" ~content:\"%s\"\n"
+            "let %s = Js_of_ocaml_compiler.Builtins.register ~name:\"%s\" \
+             ~content:\"%s\"\n"
             (to_ident (Filename.chop_extension name))
             (String.escaped name)
             (String.escaped content))

edit: #1360 is not enough to fix this regression
edit2: now fixed in this PR
edit3: no diff at all with test_branch now

@gpetiot gpetiot changed the title Fmt literal strings Break long literal strings at the margin May 19, 2020
@gpetiot gpetiot added this to the 0.15.0 milestone May 19, 2020
@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented May 20, 2020

Great, before merging this one I would like to test the combination of #1352, #1360 and #1367; if the output of test_branch looks good I will integrate them in the preview janestreet branch to check we are not causing regressions to avoid a rollback later.

@jberdine
Copy link
Copy Markdown
Collaborator

I would like to test the combination of #1352, #1360 and #1367

It is times like this when I think we should add changes entries only when doing the final merge into master.

@gpetiot gpetiot merged commit 273f6f6 into ocaml-ppx:master May 25, 2020
@gpetiot gpetiot deleted the fmt-literal-strings branch May 25, 2020 09:32
emillon added a commit to emillon/opam-repository that referenced this pull request Aug 6, 2020
CHANGES:

#### Changes

  + Do not break inline elements such as `{i blah}` in docstrings (ocaml-ppx/ocamlformat#1346, @jberdine)

  + Distinguish hash-getter from hash-comparison infix operators. Operators of the form `#**#` or `#**.` where `**` can be 0 or more operator chars are considered getter operators and are not surrounded by spaces, as opposed to regular infix operators (ocaml-ppx/ocamlformat#1376, @gpetiot)

  + Type constraint on return type of functions is now always printed before the function body (ocaml-ppx/ocamlformat#1381, ocaml-ppx/ocamlformat#1397, @gpetiot)

#### Bug fixes

  + Restore previous functionality for pre-post extension points (ocaml-ppx/ocamlformat#1342, @jberdine)

  + Fix extra break before `function` body of a `fun` (ocaml-ppx/ocamlformat#1343, @jberdine)
    Indent further args of anonymous functions (ocaml-ppx/ocamlformat#1440, @gpetiot)

  + Do not clear the emacs `*compilation*` buffer on successful reformat (ocaml-ppx/ocamlformat#1350, @jberdine)

  + Fix disabling with attributes on OCaml < 4.08 (ocaml-ppx/ocamlformat#1322, @emillon)

  + Preserve unwrapped comments by not adding artificial breaks when `wrap-comments=false` and `ocp-indent-compat=true` are set to avoid interfering with ocp-indent indentation. (ocaml-ppx/ocamlformat#1352, @gpetiot)

  + Break long literal strings at the margin (ocaml-ppx/ocamlformat#1367, @gpetiot)

  + Break after a multiline argument in an argument list (ocaml-ppx/ocamlformat#1360, @gpetiot)

  + Remove unnecessary parens around object (ocaml-ppx/ocamlformat#1379, @gpetiot)

  + Fix placement of comments on constants (ocaml-ppx/ocamlformat#1383, @gpetiot)

  + Do not escape arguments of some Odoc tags (ocaml-ppx/ocamlformat#1391, 1408, @gpetiot, @Julow)
    The characters `[]{}` must not be escaped in the arguments of `@raise`, `@author`, `@version` and others.

  + Fix missing open line between multi-line let-binding with poly-typexpr (ocaml-ppx/ocamlformat#1372, @jberdine)

  + Remove trailing space after expression when followed by an attribute and break before attributes attached to multi-line phrases (ocaml-ppx/ocamlformat#1382, @gpetiot)

  + Do not add a space to minimal comments `(* *)`, `(** *)` and `(*$ *)` (ocaml-ppx/ocamlformat#1407, @gpetiot)

  + Fix attributes position in labelled arguments type (ocaml-ppx/ocamlformat#1434, @gpetiot)

  + Add missing parens around type annotation in anonymous function (ocaml-ppx/ocamlformat#1433, @gpetiot)

  + Fix alignment of 'then' keyword in parenthesised expression (ocaml-ppx/ocamlformat#1421, @gpetiot)

#### New features

  + Support quoted extensions (added in ocaml 4.11) (ocaml-ppx/ocamlformat#1405, @gpetiot)

  + Recognise eliom file extensions (ocaml-ppx/ocamlformat#1430, @jrochel)
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.

Bug: newline escapes exceed margin

3 participants