Skip to content
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

Pretty printer line break unexpected #7913

Closed
vicuna opened this issue Feb 7, 2019 · 4 comments · Fixed by #9618
Closed

Pretty printer line break unexpected #7913

vicuna opened this issue Feb 7, 2019 · 4 comments · Fixed by #9618

Comments

@vicuna
Copy link

vicuna commented Feb 7, 2019

Original bug ID: 7913
Reporter: ramsdell0
Assigned to: @Octachron
Status: assigned (set by @Octachron on 2019-02-18T08:45:19Z)
Resolution: open
Priority: normal
Severity: minor
Platform: x86_64
OS: Mac OS
OS Version: Mojave
Version: 4.07.1
Category: documentation
Related to: #7804
Monitored by: @nojb

Bug description

The enclosed program shows a case in which a line of text is broken in an unexpected place. The pretty printer only allows line breaks after commas, but the program breaks a line after an open parenthesis.

The output of the enclosed program is:

$ ./ppterm
pred(a12(x1, y1), a1234(x1, y1), a1234(x1, y1), a1234(x1, y1), a1234(
x1, y1), a1234(x1, y1))

Steps to reproduce

$ ocamlc -o ppterm ppterm.ml
$ ./ppterm

File attachments

@vicuna
Copy link
Author

vicuna commented Feb 7, 2019

Comment author: @Octachron

This is the maximum indentation feature in action (cf. http://caml.inria.fr/pub/docs/manual-ocaml/libref/Format.html#1_Maximumindentationlimit): boxes opened beyond the current value of the maximum indentation are rejected to the left. Your specific issue can be fixed by increasing this maximum indentation with

let () =
let f = formatter_of_out_channel stdout in
Format.pp_set_max_indent f (Format.pp_get_margin f ()-1);
pp_print_term f example;
pp_print_newline f ()

@vicuna
Copy link
Author

vicuna commented Feb 7, 2019

Comment author: ramsdell0

Thank you for your quick reply. The snippet of code I submitted was
extracted from a larger set of programs, one of which read the flawed
pretty printing output and exhibited a subtle bug as a result. The
patch you sent eliminates erroneous output and squashes the bug.

I ask that goal for responding to this bug report be to change the
documentation in the Format library's source code. I reread that
documentation and I do not see how others have a chance at figuring
out the correct way to obtain the desired behavior. Let me offer some
words for you to consider to add to the file.

(** {1:breaks Break hints} *)

(** The pretty printer will split a line at a location specified by a
break hint or when boxes are opened beyond the current maximum
indentation limit. The second case will be explained in the section
titled "Maximum indentation limit". *)

...

(** {1 Maximum indentation limit} *)

val pp_set_max_indent : formatter -> int -> unit
val set_max_indent : int -> unit
(**...

If [d] is greater or equal than the current margin, it is ignored,
and the current maximum indentation limit is kept.

...

To insure that a pretty printer splits lines only under the
direction of break hints, set the maximum margin as follows.
{[pp_set_max_margin f (pp_get_margin f () - 1)]}

See also {!pp_set_geometry}.
*)

@vicuna
Copy link
Author

vicuna commented Feb 18, 2019

Comment author: @Octachron

I agree that the documentation should be updated.

@github-actions
Copy link

github-actions bot commented May 6, 2020

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

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

Successfully merging a pull request may close this issue.

2 participants