code: def split_group(source, pos, maxline):
      
      first = []
      source.reverse()
      while source:
          tok = source.pop()
          first.append(tok)
          pos += len(tok)
          if source:
              tok = source[-1]
              allowed = (maxline + 1) if tok.endswith(' ') else (maxline - 4)
              if pos + len(tok) > allowed:
                  break
  
      source.reverse()
      return first, source
docs: Split a group into two subgroups.  The
          first will be appended to the current
          line, the second will start the new line.
  
          Note that the first group must always
          contain at least one item.
  
          The original group may be destroyed.