 
   @doc false
   # TODO: Deprecate on Elixir v1.8
-  def surround_many(left, docs, right, %Inspect.Opts{} = inspect, fun, separator \\ @container_separator)
+  def surround_many(
+        left,
+        docs,
+        right,
+        %Inspect.Opts{} = inspect,
+        fun,
+        separator \\ @container_separator
+      )
       when is_doc(left) and is_list(docs) and is_doc(right) and is_function(fun, 2) do
     container_doc(left, docs, right, inspect, fun, separator: separator)
   end

  @typep mode :: :break | :flat | :next_fits | :no_fitting

  @spec fits?(integer, integer, [{integer, mode, t}]) :: boolean
  defp fits?(w, k, _) when k > w,                            do: false
  defp fits?(_, _, []),                                      do: true

  defp fits?(w, k, [{i, _, doc_fits(x, :disabled)} | t]),    do: fits?(w, k, [{i, :no_fitting, x} | t])
  defp fits?(w, k, [{i, :no_fitting, doc_group(x, _)} | t]), do: fits?(w, k, [{i, :no_fitting, x} | t])
  defp fits?(w, k, [{i, :no_fitting, doc_fits(x, _)} | t]),  do: fits?(w, k, [{i, :no_fitting, x} | t])

  defp fits?(w, k, [{i, _, doc_fits(x, :enabled)} | t]),     do: fits?(w, k, [{i, :next_fits, x} | t])
  defp fits?(w, k, [{i, :next_fits, doc_force(x)} | t]),     do: fits?(w, k, [{i, :next_fits, x} | t])
  defp fits?(w, k, [{i, :next_fits, doc_group(x, _)} | t]),  do: fits?(w, k, [{i, :next_fits, x} | t])
  defp fits?(_, _, [{_, :next_fits, doc_break(_, _)} | _]),  do: true
  defp fits?(_, _, [{_, :next_fits, :doc_line} | _]),        do: true

  defp fits?(w, k, [{_, _, :doc_nil} | t]),                  do: fits?(w, k, t)
  defp fits?(w, _, [{i, _, :doc_line} | t]),                 do: fits?(w, i, t)
  defp fits?(w, _, [{i, _, doc_collapse(_)} | t]),           do: fits?(w, i, t)
  defp fits?(w, k, [{i, m, doc_cons(x, y)} | t]),            do: fits?(w, k, [{i, m, x} | [{i, m, y} | t]])
  defp fits?(w, k, [{i, m, doc_color(x, _)} | t]),           do: fits?(w, k, [{i, m, x} | t])
  defp fits?(w, k, [{i, m, doc_nest(x, _, :break)} | t]),    do: fits?(w, k, [{i, m, x} | t])
  defp fits?(w, k, [{i, m, doc_nest(x, j, _)} | t]),         do: fits?(w, k, [{apply_nesting(i, k, j), m, x} | t])
  defp fits?(w, k, [{i, _, doc_group(x, _)} | t]),           do: fits?(w, k, [{i, :flat, x} | t])
  defp fits?(w, k, [{_, _, doc_string(_, l)} | t]),          do: fits?(w, k + l, t)
  defp fits?(w, k, [{_, _, s} | t]) when is_binary(s),       do: fits?(w, k + byte_size(s), t)
  defp fits?(_, _, [{_, _, doc_force(_)} | _]),              do: false
  defp fits?(_, _, [{_, :break, doc_break(_, _)} | _]),      do: true
  defp fits?(w, k, [{_, _, doc_break(s, _)} | t]),           do: fits?(w, k + byte_size(s), t)

  @spec format(integer | :infinity, integer, [{integer, mode, t}]) :: [binary]
  defp format(_, _, []),                                do: []
  defp format(w, k, [{_, _, :doc_nil} | t]),            do: format(w, k, t)
  defp format(w, _, [{i, _, :doc_line} | t]),           do: [indent(i) | format(w, i, t)]
  defp format(w, k, [{i, m, doc_cons(x, y)} | t]),      do: format(w, k, [{i, m, x} | [{i, m, y} | t]])
  defp format(w, k, [{i, m, doc_color(x, c)} | t]),     do: [ansi(c) | format(w, k, [{i, m, x} | t])]
  defp format(w, k, [{_, _, doc_string(s, l)} | t]),    do: [s | format(w, k + l, t)]
  defp format(w, k, [{_, _, s} | t]) when is_binary(s), do: [s | format(w, k + byte_size(s), t)]
  defp format(w, k, [{i, m, doc_force(x)} | t]),        do: format(w, k, [{i, m, x} | t])
  defp format(w, k, [{i, m, doc_fits(x, _)} | t]),      do: format(w, k, [{i, m, x} | t])
  defp format(w, _, [{i, _, doc_collapse(max)} | t]),   do: collapse(format(w, i, t), max, 0, i)

  # Flex breaks are not conditional to the mode
  defp format(w, k, [{i, _, doc_break(s, :flex)} | t]) do

  Converts an Elixir term to an algebra document
  according to the `Inspect` protocol.
  """
  @spec to_doc(any, Inspect.Opts.t()) :: t
  def to_doc(term, opts)

  def to_doc(%_{} = struct, %Inspect.Opts{} = opts) do
