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

Format: spurious space at end of line #7720

Closed
vicuna opened this issue Feb 2, 2018 · 4 comments
Closed

Format: spurious space at end of line #7720

vicuna opened this issue Feb 2, 2018 · 4 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Feb 2, 2018

Original bug ID: 7720
Reporter: gmelquiond
Assigned to: @Octachron
Status: assigned (set by @Octachron on 2018-02-04T17:24:44Z)
Resolution: open
Priority: normal
Severity: minor
Version: 4.06.0
Category: standard library
Has duplicate: #7804

Bug description

The code

Format.set_margin 10; Format.printf "@[@[123456@ @[A@]@ B@]@]@\n";;

produces

123456=
A B

where = denotes a spurious space.

I am also wondering why A was not put at the end of the first line. (Removing the box around A does so. Removing one of the outer boxes does so too. Removing B does so too.) I guess the two issues are related.

@vicuna
Copy link
Author

vicuna commented Feb 2, 2018

Comment author: @Octachron

The space at the end of the line is not spurious from the point of view of Format's implementation.

This is due to the fact that "Format.set_margin 10" also sets the maximum indentation limit to 5. Consequently, the second box is rejected to the left with a forced new line. Since the break is introduced by the opening of the box, the previous break hint "@ " is printed as a space.

The easiest fix in this situation is to also adjust the maximum indentation limit:

Format.set_margin 10; Format.set_max_indent 8;
Format.printf "@[@[123456@ @[A@]@ B@]@]@\n";;

displays the expected output

123456·A
B

Similarly, the difference in behavior that you observed by shortening the length of the format string is due to the fact that when the content of a box fits on a line, all formatting indication (and the maximum indentation limit) are ignored because the box is replaced by a fits box.

@vicuna
Copy link
Author

vicuna commented Feb 2, 2018

Comment author: gmelquiond

There is something I am missing. The documentation of set_max_indent says: "once this limit is reached, new pretty-printing boxes are rejected to the left, if they do not fit on the current line." But the box containing A does fit on the line. So why would it be rejected to the left?

@vicuna
Copy link
Author

vicuna commented Feb 2, 2018

Comment author: @Octachron

You are right, there is a mismatch between the documentation and the implementation here: the rejection to the left happens if the parent box does not fit on the line, i.e.

"once this limit is reached, new pretty-printing boxes are rejected to the left, if their parent box do not fit on the current line."

@vicuna
Copy link
Author

vicuna commented Feb 3, 2018

Comment author: @Octachron

I have proposed a documentation fix at #1596.
Do you wish to be mentionned as a reporter, and if yes under which name?

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

No branches or pull requests

2 participants