Split line into leading indent and main.
977395
def split_trailing_indent(line, max_indents=None):
    """"""
    indent = ""
    while (
        (max_indents is None or max_indents > 0)
        and line.endswith((openindent, closeindent))
    ) or line.rstrip() != line:
        if max_indents is not None and (line.endswith(openindent) or line.endswith(closeindent)):
            max_indents -= 1
        indent = line[-1] + indent
        line = line[:-1]
    return line, indent
929627
def unindent(self, lines):
        """"""
        indent = min(
            len(self.re.match(r'^ *', line).group()) for line in lines)
        return [line[indent:].rstrip() for line in lines]
918270
function(text, pad) {
			var lines = this.splitByLines(text);
			var pl = pad.length;
			for (var i = 0, il = lines.length, line; i < il; i++) {
				line = lines[i];
				if (line.substr(0, pl) === pad) {
					lines[i] = line.substr(pl);
				}
			}
			
			return lines.join('\n');
		}
1252058
def indent(text, amount, ch=' '):
    """"""
    padding = amount * ch
    return ''.join(padding+line for line in text.splitlines(True))
1158808
function formatLinesWith (formatter, str) {
  return str
    .split('\n')
    .map(function (line) {
      return line.length ? formatter(line) : ''
    })
    .join('\n')
}
130859
def _reflow_lines(parsed_tokens, indentation, max_line_length,
                  start_on_prefix_line):
    """"""

    if unicode(parsed_tokens[0]) == 'def':
        # A function definition gets indented a bit more.
        continued_indent = indentation + ' ' * 2 * DEFAULT_INDENT_SIZE
    else:
        continued_indent = indentation + ' ' * DEFAULT_INDENT_SIZE

    break_after_open_bracket = not start_on_prefix_line

    lines = ReformattedLines(max_line_length)
    lines.add_indent(len(indentation.lstrip('\r\n')))

    if not start_on_prefix_line:
        # If splitting after the opening bracket will cause the first element
        # to be aligned weirdly, don't try it.
        first_token = get_item(parsed_tokens, 0)
        second_token = get_item(parsed_tokens, 1)

        if (
            first_token and second_token and
            unicode(second_token)[0] == '(' and
            len(indentation) + len(first_token) + 1 == len(continued_indent)
        ):
            return None

    for item in parsed_tokens:
        lines.add_space_if_needed(unicode(item), equal=True)

        save_continued_indent = continued_indent
        if start_on_prefix_line and isinstance(item, Container):
            start_on_prefix_line = False
            continued_indent = ' ' * (lines.current_size() + 1)

        item.reflow(lines, continued_indent, break_after_open_bracket)
        continued_indent = save_continued_indent

    return lines.emit()
24516
function(str, indent) {
			var lines = str.split("\n");
			for (var i=0; i<lines.length; i++)
				lines[i] = indent + lines[i];
			return lines.join("\n");
		}
114171
def indentsize(line):
    """"""
    expline = string.expandtabs(line)
    return len(expline) - len(string.lstrip(expline))
305619
def format_lines(var_name, seq, raw=False, indent_level=0):
    """"""
    lines = []
    base_indent = ' ' * indent_level * 4
    inner_indent = ' ' * (indent_level + 1) * 4
    lines.append(base_indent + var_name + ' = (')
    if raw:
        # These should be preformatted reprs of, say, tuples.
        for i in seq:
            lines.append(inner_indent + i + ',')
    else:
        for i in seq:
            # Force use of single quotes
            r = repr(i + '"')
            lines.append(inner_indent + r[:-2] + r[-1] + ',')
    lines.append(base_indent + ')')
    return '\n'.join(lines)
235063
def indent(text, num=4):
    """"""
    str_indent = ' ' * num
    return str_indent + ('\n' + str_indent).join(text.splitlines())
496686
def shorten_line(tokens, source, indentation, indent_word, max_line_length,
                 aggressive=False, experimental=False, previous_line=''):
    
    for candidate in _shorten_line(tokens=tokens,
                                   source=source,
                                   indentation=indentation,
                                   indent_word=indent_word,
                                   aggressive=aggressive,
                                   previous_line=previous_line):
        yield candidate

    if aggressive:
        for key_token_strings in SHORTEN_OPERATOR_GROUPS:
            shortened = _shorten_line_at_tokens(
                tokens=tokens,
                source=source,
                indentation=indentation,
                indent_word=indent_word,
                key_token_strings=key_token_strings,
                aggressive=aggressive)

            if shortened is not None and shortened != source:
                yield shortened

    if experimental:
        for shortened in _shorten_line_at_tokens_new(
                tokens=tokens,
                source=source,
                indentation=indentation,
                max_line_length=max_line_length):

            yield shortened
1093808
def add_indent_lines(prefix, s):
    
    if not s:
        return prefix
    prefix_len = str_visible_len(prefix)
    lines = s.splitlines(True)
    return "".join([prefix + lines[0]] + [" " * prefix_len + l for l in lines[1:]])
528812
def indent_block(amount, text, indent_char='\t'):
    
    rst = ""
    for line in text.splitlines():
        if amount > 0:
            rst += indent_char*amount + line + "\n"
        else:
            rst += ''.join([c for i,c in enumerate(line) if (c == indent_char and (i+1) > abs(amount)) or (not c == indent_char)]) + "\n"
    return rst
987
function splitLine(line) {
	var idx = String(line).indexOf(':');

	if (!line || idx < 0) {
		return null;
	}

	return [line.slice(0, idx), line.slice(idx + 1)];
}
763365
def split_call(lines, open_paren_line=0):
    """"""
    num_open = 0
    num_closed = 0
    for i, line in enumerate(lines):
        c = line.count('(')
        num_open += c
        if not c and i==open_paren_line:
            raise Exception('Exception open parenthesis in line %d but there is not one there: %s' % (i, str(lines)))
        num_closed += line.count(')')

        if num_open == num_closed:
            return (lines[:i+1], lines[i+1:])

    print(''.join(lines))
    raise Exception('parenthesis are mismatched (%d open, %d closed found)' % (num_open, num_closed))
904915
function(sInput, levels, indentString) {
		var indentedLineBreak;

		indentString = indentString || '\t';
		indentedLineBreak = '\n'+ ( new Array( levels + 1 ).join( indentString ) );

		return indentedLineBreak + sInput.split('\n').join(indentedLineBreak);
	}
17962
function splitCommand(line) {
    // Make sure we get the same results irrespective of leading/trailing spaces
    var match = line.match(TOKEN_WHITESPACE);
    if (!match) {
        return {
            name: line.toUpperCase(),
            rest: ''
        };
    }
    var name = line.substr(0, match.index).toUpperCase();
    var rest = line.substr(match.index + match[0].length);

    return {
        name: name,
        rest: rest
    };
}