<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff></diff>
      <filename>ebin/lfe_io_pretty.beam</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,8 @@
+2009-08-30  Robert Virding  &lt;rv@stanislaw.local&gt;
+
+	* lfe_io_pretty.erl (print1_list_max, print1_tail_max): Bit more
+	efficient pretty printing on the rest of the line.
+
 2009-08-13  Robert Virding  &lt;rv@stanislaw.local&gt;
 
 	* lfe_comp.erl (list_warnings, list_errors): Use lfe_io format.</diff>
      <filename>src/ChangeLog</filename>
    </modified>
    <modified>
      <diff>@@ -30,6 +30,7 @@
 %% The io functions have been split into the following modules:
 %% lfe_io        - basic read and write functions
 %% lfe_io_pretty - sexpr prettyprinter
+%% lfe_io_format - formatted output
 
 -module(lfe_io).
 </diff>
      <filename>src/lfe_io.erl</filename>
    </modified>
    <modified>
      <diff>@@ -31,14 +31,14 @@
 
 -export([print1/1,print1/2,print1/3,print1/4]).
 
-%% -compile(export_all).
+-compile(export_all).
 
--import(lists, [flatlength/1]).
+-import(lists, [reverse/1,flatlength/1]).
 
 %% print1(Sexpr) -&gt; [char()].
 %% print1(Sexpr, Depth) -&gt; [char()].
 %% print1(Sexpr, Depth, Indentation, LineLength) -&gt; [char()].
-%%  An relatively simple pretty print function, but with some
+%%  A relatively simple pretty print function, but with some
 %%  customisation.
 
 print1(S) -&gt; print1(S, -1, 0, 80).
@@ -60,12 +60,11 @@ print1(['unquote-splicing',E], D, I, L) -&gt; [&quot;,@&quot;,print1(E, D, I+2, L)];
 print1([Car|Cdr]=List, D, I, L) -&gt;
     %% Handle printable lists specially.
     case io_lib:printable_list(List) of
-	true -&gt; lfe_io:print1_string(List, 34);	%&quot;
+	true -&gt; lfe_io:print1_string(List, $&quot;);	%&quot;
 	false -&gt;
-	    Print = lfe_io:print1(List, D),	%Raw printing
-	    case flatlength(Print) of
-		Len when Len + I &lt; L -&gt; Print;
-		_ -&gt;
+	    case print1_list_max(List, D, I+2, L) of
+		{yes,Print} -&gt; [&quot;(&quot;,Print,&quot;)&quot;];
+		no -&gt;
 		    %% Customise printing of lists.
 		    case indent_type(Car) of
 			none -&gt;
@@ -85,12 +84,10 @@ print1([Car|Cdr]=List, D, I, L) -&gt;
 print1([], _, _, _) -&gt; &quot;()&quot;;
 print1({}, _, _, _) -&gt; &quot;#()&quot;;
 print1(Tup, D, I, L) when is_tuple(Tup) -&gt;
-    Print = lfe_io:print1(Tup, D),
-    case flatlength(Print) of
-	Len when Len + I &lt; L -&gt; Print;
-	_ -&gt;
-	    Es = tuple_to_list(Tup),
-	    [&quot;#(&quot;,print1_list(Es, D-1, I+2, L),&quot;)&quot;]
+    Es = tuple_to_list(Tup),
+    case print1_list_max(Es, D, I+3, L) of
+	{yes,Print}  -&gt; [&quot;#(&quot;,Print,&quot;)&quot;];
+	no -&gt; [&quot;#(&quot;,print1_list(Es, D-1, I+2, L),&quot;)&quot;]
     end;
 print1(Bit, _, _, _) when is_bitstring(Bit) -&gt;
     [&quot;#B(&quot;,lfe_io:print1_bits(Bit, 30),$)];	%First 30 bytes
@@ -107,6 +104,28 @@ split(N, [H|T]) -&gt;
     {H1,T1} = split(N-1, T),
     {[H|H1],T1}.
 
+%% print1_list_max(List, Depth, Indentation, LineLength) -&gt; {yes,Chars} | no.
+%%  Maybe print a list on one line, but abort if it goes past
+%%  LineLength.
+
+print1_list_max([Car|Cdr], D, I, L) -&gt;
+    Cs = print1(Car, D, 0, 99999),		%Never break the line
+    print1_tail_max(Cdr, D, I + flatlength(Cs), L, [Cs]);
+print1_list_max([], _, _, _) -&gt; {yes,[]}.
+
+%% print1_tail_max(Tail, Depth, Indentation, LineLength) -&gt; {yes,Chars} | no.
+%%  Maybe print the tail of a list on one line, but abort if it goes
+%%  past LineLength. We know about dotted pairs.
+
+print1_tail_max(_, _, I, L, _) when I &gt;= L -&gt; no;	%No more room
+print1_tail_max([], _, _, _, Acc) -&gt; {yes,reverse(Acc)};
+print1_tail_max([Car|Cdr], D, I, L, Acc) -&gt;
+    Cs = print1(Car, D, 0, 99999),		%Never break the line
+    print1_tail_max(Cdr, D, I + flatlength(Cs) + 1, L, [Cs,&quot; &quot;|Acc]);
+print1_tail_max(S, D, I, L, Acc) -&gt;
+    Cs = print1(S, D, 0, 99999),		%Never break the line
+    print1_tail_max([], D, I + flatlength(Cs) + 3, L, [Cs,&quot; . &quot;|Acc]).
+
 %% print1_list(List, Depth, Indentation, LineLength)
 %%  Print a list, one element per line. No leading/trailing ().
 
@@ -115,7 +134,7 @@ print1_list([Car|Cdr], D, I, L) -&gt;
 print1_list([], _, _, _) -&gt; [].
 
 %% print1_tail(Tail, Depth, Indentation, LineLength)
-%% Print the tail of a list. We know about dotted pairs.
+%%  Print the tail of a list. We know about dotted pairs.
 
 print1_tail([], _, _, _) -&gt; &quot;&quot;;
 print1_tail(_, 1, _, _) -&gt; &quot; ...&quot;;</diff>
      <filename>src/lfe_io_pretty.erl</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>350445f2a5fc147308c97b6e5064e29a0380e8a7</id>
    </parent>
  </parents>
  <author>
    <name>Robert Virding</name>
    <email>rvirding@gmail.com</email>
  </author>
  <url>http://github.com/rvirding/lfe/commit/4a44ac13fe6e5b0b2ab4597b9b9360ed8699e92e</url>
  <id>4a44ac13fe6e5b0b2ab4597b9b9360ed8699e92e</id>
  <committed-date>2009-08-29T18:27:05-07:00</committed-date>
  <authored-date>2009-08-29T18:23:48-07:00</authored-date>
  <message>More efficient pretty printing on the rest of the line.</message>
  <tree>a8955d7981ff22a2449593906a2a4efb02605696</tree>
  <committer>
    <name>Robert Virding</name>
    <email>rvirding@gmail.com</email>
  </committer>
</commit>
