From 380af78843891b0994f625d392fad674c1bc4fef Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Mon, 4 Jun 2018 13:58:02 +0200 Subject: stdlib: Make pP insert no line breaks with field width zero See also https://bugs.erlang.org/browse/ERL-607. A zero field width used to insert line breaks "everywhere", but with this patch no line breaks are inserted. --- lib/stdlib/doc/src/io.xml | 17 ++++++++++++++--- lib/stdlib/src/io_lib_pretty.erl | 2 ++ lib/stdlib/test/io_SUITE.erl | 22 ++++++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lib/stdlib/doc/src/io.xml b/lib/stdlib/doc/src/io.xml index f1037ec76b..d4a2713840 100644 --- a/lib/stdlib/doc/src/io.xml +++ b/lib/stdlib/doc/src/io.xml @@ -4,7 +4,7 @@
- 19962017 + 19962018 Ericsson AB. All Rights Reserved. @@ -332,11 +332,22 @@ Here T = [{attributes,[[{id,age,1.5}, {tag,{'PRIVATE',3}}, {mode,implicit}] ok + +

As from Erlang/OTP 21.0, a field width of value + 0 can be used for specifying that a line is + infinitely long, which means that no line breaks + are inserted. For example:

+ +
+5> io:fwrite("~0p~n", [lists:seq(1, 30)]).
+[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
+ok
+

When the modifier l is specified, no detection of printable character lists takes place, for example:

-5> S = [{a,"a"}, {b, "b"}].
-6> io:fwrite("~15p~n", [S]).
+6> S = [{a,"a"}, {b, "b"}],
+   io:fwrite("~15p~n", [S]).
 [{a,"a"},
  {b,"b"}]
 ok
diff --git a/lib/stdlib/src/io_lib_pretty.erl b/lib/stdlib/src/io_lib_pretty.erl
index 3d5a979b3e..dca1b37ef3 100644
--- a/lib/stdlib/src/io_lib_pretty.erl
+++ b/lib/stdlib/src/io_lib_pretty.erl
@@ -131,6 +131,8 @@ print(Term, Col, Ll, D, M0, T, RecDefFun, Enc, Str) when is_tuple(Term);
     %% use Len as CHAR_MAX if M0 = -1
     M = max_cs(M0, Len),
     if
+        Ll =:= 0 ->
+            write(If);
         Len < Ll - Col, Len =< M ->
             %% write the whole thing on a single line when there is room
             write(If);
diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl
index 13f2cbd27b..91fe1133f6 100644
--- a/lib/stdlib/test/io_SUITE.erl
+++ b/lib/stdlib/test/io_SUITE.erl
@@ -31,7 +31,7 @@
          otp_10836/1, io_lib_width_too_small/1,
          io_with_huge_message_queue/1, format_string/1,
 	 maps/1, coverage/1, otp_14178_unicode_atoms/1, otp_14175/1,
-         otp_14285/1, limit_term/1, otp_14983/1]).
+         otp_14285/1, limit_term/1, otp_14983/1, otp_15103/1]).
 
 -export([pretty/2, trf/3]).
 
@@ -63,7 +63,7 @@ all() ->
      io_lib_print_binary_depth_one, otp_10302, otp_10755, otp_10836,
      io_lib_width_too_small, io_with_huge_message_queue,
      format_string, maps, coverage, otp_14178_unicode_atoms, otp_14175,
-     otp_14285, limit_term, otp_14983].
+     otp_14285, limit_term, otp_14983, otp_15103].
 
 %% Error cases for output.
 error_1(Config) when is_list(Config) ->
@@ -2615,3 +2615,21 @@ trf(Format, Args, T) ->
 
 trf(Format, Args, T, Opts) ->
     lists:flatten(io_lib:format(Format, Args, [{chars_limit, T}|Opts])).
+
+otp_15103(_Config) ->
+    T = lists:duplicate(5, {a,b,c}),
+
+    S1 = io_lib:format("~0p", [T]),
+    "[{a,b,c},{a,b,c},{a,b,c},{a,b,c},{a,b,c}]" = lists:flatten(S1),
+    S2 = io_lib:format("~-0p", [T]),
+    "[{a,b,c},{a,b,c},{a,b,c},{a,b,c},{a,b,c}]" = lists:flatten(S2),
+    S3 = io_lib:format("~1p", [T]),
+    "[{a,\n  b,\n  c},\n {a,\n  b,\n  c},\n {a,\n  b,\n  c},\n {a,\n  b,\n"
+    "  c},\n {a,\n  b,\n  c}]" = lists:flatten(S3),
+
+    S4 = io_lib:format("~0P", [T, 5]),
+    "[{a,b,c},{a,b,...},{a,...},{...}|...]" = lists:flatten(S4),
+    S5 = io_lib:format("~1P", [T, 5]),
+    "[{a,\n  b,\n  c},\n {a,\n  b,...},\n {a,...},\n {...}|...]" =
+        lists:flatten(S5),
+    ok.
-- 
cgit v1.2.3


From 6bd15f9791e0c781f0a7b107315af46e8339558e Mon Sep 17 00:00:00 2001
From: Hans Bolinder 
Date: Fri, 8 Jun 2018 14:09:01 +0200
Subject: common_test: Use ~0p

---
 lib/common_test/test_server/ts_run.erl | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/common_test/test_server/ts_run.erl b/lib/common_test/test_server/ts_run.erl
index 5dbbaca916..7e12b9652c 100644
--- a/lib/common_test/test_server/ts_run.erl
+++ b/lib/common_test/test_server/ts_run.erl
@@ -1,7 +1,7 @@
 %%
 %% %CopyrightBegin%
 %%
-%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2018. All Rights Reserved.
 %%
 %% Licensed under the Apache License, Version 2.0 (the "License");
 %% you may not use this file except in compliance with the License.
@@ -411,9 +411,9 @@ make_common_test_args(Args0, Options0, _Vars) ->
 		end,
     ConfigFiles = [{config,[filename:join(ConfigPath,File)
 			    || File <- get_config_files()]}],
-    io_lib:format("~100000p",[[{abort_if_missing_suites,true} | 
-			       Args0++Trace++Cover++Logdir++
-			       ConfigFiles++Options++TimeTrap]]).
+    io_lib:format("~0p",[[{abort_if_missing_suites,true} |
+                          Args0++Trace++Cover++Logdir++
+                              ConfigFiles++Options++TimeTrap]]).
 
 to_list(X) when is_atom(X) ->
     atom_to_list(X);
-- 
cgit v1.2.3


From fd5e2d90c63182601bd5a397f601958e449722d2 Mon Sep 17 00:00:00 2001
From: Hans Bolinder 
Date: Fri, 8 Jun 2018 14:09:26 +0200
Subject: debugger: Use ~0p

---
 lib/debugger/src/dbg_wx_trace.erl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/debugger/src/dbg_wx_trace.erl b/lib/debugger/src/dbg_wx_trace.erl
index 505d53005f..25f32ca7e7 100644
--- a/lib/debugger/src/dbg_wx_trace.erl
+++ b/lib/debugger/src/dbg_wx_trace.erl
@@ -1,7 +1,7 @@
 %%
 %% %CopyrightBegin%
 %% 
-%% Copyright Ericsson AB 2008-2017. All Rights Reserved.
+%% Copyright Ericsson AB 2008-2018. All Rights Reserved.
 %% 
 %% Licensed under the Apache License, Version 2.0 (the "License");
 %% you may not use this file except in compliance with the License.
@@ -518,8 +518,8 @@ gui_cmd({user_command, Cmd}, State) ->
 gui_cmd({edit, {Var, Value}}, State) ->
     Window = dbg_wx_trace_win:get_window(State#state.win),
     Val = case State#state.strings of
-              []        -> dbg_wx_win:to_string("~999999lp",[Value]);
-              [str_on]  -> dbg_wx_win:to_string("~999999tp",[Value])
+              []        -> dbg_wx_win:to_string("~0lp",[Value]);
+              [str_on]  -> dbg_wx_win:to_string("~0tp",[Value])
           end,
     case dbg_wx_win:entry(Window, "Edit variable", Var, {term, Val}) of
 	cancel ->
-- 
cgit v1.2.3


From 7a5ae72a5f46059d8c862a4e5964b4799d1fda4b Mon Sep 17 00:00:00 2001
From: Hans Bolinder 
Date: Fri, 8 Jun 2018 14:09:49 +0200
Subject: kernel: Use ~0p

---
 lib/kernel/src/application_controller.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/kernel/src/application_controller.erl b/lib/kernel/src/application_controller.erl
index ff5df667b5..6906ad0d6e 100644
--- a/lib/kernel/src/application_controller.erl
+++ b/lib/kernel/src/application_controller.erl
@@ -1,7 +1,7 @@
 %%
 %% %CopyrightBegin%
 %%
-%% Copyright Ericsson AB 1996-2017. All Rights Reserved.
+%% Copyright Ericsson AB 1996-2018. All Rights Reserved.
 %%
 %% Licensed under the Apache License, Version 2.0 (the "License");
 %% you may not use this file except in compliance with the License.
@@ -2013,5 +2013,5 @@ to_string(Term) ->
 	true ->
 	    Term;
 	false ->
-	    lists:flatten(io_lib:format("~134217728p", [Term]))
+	    lists:flatten(io_lib:format("~0p", [Term]))
     end.
-- 
cgit v1.2.3