@@ -276,7 +276,8 @@ defmodule Code.Formatter do
276276 defp next_eol ( '\r \n ' ++ rest , count ) , do: next_eol ( rest , count + 1 )
277277 defp next_eol ( _ , count ) , do: count
278278
279- defp previous_eol ( [ { token , { _ , _ , count } } | _ ] ) when token in [ :eol , :"," , :";" ] and count > 0 do
279+ defp previous_eol ( [ { token , { _ , _ , count } } | _ ] )
280+ when token in [ :eol , :"," , :";" ] and count > 0 do
280281 count
281282 end
282283
@@ -453,7 +454,8 @@ defmodule Code.Formatter do
453454 { atom_to_algebra ( atom ) , state }
454455 end
455456
456- defp quoted_to_algebra ( { :__block__ , meta , [ integer ] } , _context , state ) when is_integer ( integer ) do
457+ defp quoted_to_algebra ( { :__block__ , meta , [ integer ] } , _context , state )
458+ when is_integer ( integer ) do
457459 { integer_to_algebra ( Keyword . fetch! ( meta , :original ) ) , state }
458460 end
459461
@@ -915,7 +917,8 @@ defmodule Code.Formatter do
915917 # Mod.function()
916918 # var.function
917919 # expression.function(arguments)
918- defp remote_to_algebra ( { { :. , _ , [ target , fun ] } , meta , args } , context , state ) when is_atom ( fun ) do
920+ defp remote_to_algebra ( { { :. , _ , [ target , fun ] } , meta , args } , context , state )
921+ when is_atom ( fun ) do
919922 { target_doc , state } = remote_target_to_algebra ( target , state )
920923 fun = remote_fun_to_algebra ( target , fun , length ( args ) , state )
921924 remote_doc = target_doc |> concat ( "." ) |> concat ( string ( fun ) )
@@ -1082,6 +1085,10 @@ defmodule Code.Formatter do
10821085 & quoted_to_algebra ( & 1 , context , & 2 )
10831086 )
10841087
1088+ # If we have a single argument, then we won't have an option to break
1089+ # before the "extra" part, so we ungroup it and build it later.
1090+ args_doc = ungroup_if_group ( args_doc )
1091+
10851092 doc =
10861093 if skip_parens? do
10871094 " "
@@ -1196,7 +1203,8 @@ defmodule Code.Formatter do
11961203 [ "\n " | entries ]
11971204 end
11981205
1199- defp interpolation_to_algebra ( [ entry | entries ] , escape , state , acc , last ) when is_binary ( entry ) do
1206+ defp interpolation_to_algebra ( [ entry | entries ] , escape , state , acc , last )
1207+ when is_binary ( entry ) do
12001208 acc = concat ( acc , escape_string ( entry , escape ) )
12011209 interpolation_to_algebra ( entries , escape , state , acc , last )
12021210 end
@@ -2041,6 +2049,9 @@ defmodule Code.Formatter do
20412049
20422050 ## Algebra helpers
20432051
2052+ defp ungroup_if_group ( { :doc_group , group , _mode } ) , do: group
2053+ defp ungroup_if_group ( other ) , do: other
2054+
20442055 defp format_to_string ( doc ) do
20452056 doc |> Inspect.Algebra . format ( :infinity ) |> IO . iodata_to_binary ( )
20462057 end
0 commit comments