Replaces base_indentation at beginning of lines with correct_indentation.

    If base_indentation is None, tries to find it using get_base_indentation.
    modifiers are passed to re_line_and_indentation. See there for doc.
179144
def fix_indentation(code, base_indentation=None, correct_indentation="",
                    modifiers=(True, True)):
    
    if base_indentation is None:
        base_indentation = get_base_indentation(code, modifiers[0])
    return re_line_and_indentation(base_indentation, modifiers).sub(
        "\n" + correct_indentation, code)
1140853
private boolean commentLinesBefore( String content, int line ) {
        int offset = rootElement.getElement(line).getStartOffset();
        // Start of comment not found, nothing to do
        int startDelimiter = lastIndexOf(content, getStartDelimiter(), offset - 2);
        if (startDelimiter < 0)
            return false;
        // Matching start/end of comment found, nothing to do
        int endDelimiter = indexOf(content, getEndDelimiter(), startDelimiter);
        if (endDelimiter < offset & endDelimiter != -1)
            return false;
        // End of comment not found, highlight the lines
        doc.setCharacterAttributes(startDelimiter, offset - startDelimiter + 1, comment, false);
        return true;
    }
234042
def _shorten_line(tokens, source, indentation, indent_word,
                  aggressive=False, previous_line=''):
    
    for (token_type,
         token_string,
         start_offset,
         end_offset) in token_offsets(tokens):

        if (
            token_type == tokenize.COMMENT and
            not is_probably_part_of_multiline(previous_line) and
            not is_probably_part_of_multiline(source) and
            not source[start_offset + 1:].strip().lower().startswith(
                ('noqa', 'pragma:', 'pylint:'))
        ):
            # Move inline comments to previous line.
            first = source[:start_offset]
            second = source[start_offset:]
            yield (indentation + second.strip() + '\n' +
                   indentation + first.strip() + '\n')
        elif token_type == token.OP and token_string != '=':
            # Don't break on '=' after keyword as this violates PEP 8.

            assert token_type != token.INDENT

            first = source[:end_offset]

            second_indent = indentation
            if (first.rstrip().endswith('(') and
                    source[end_offset:].lstrip().startswith(')')):
                pass
            elif first.rstrip().endswith('('):
                second_indent += indent_word
            elif '(' in first:
                second_indent += ' ' * (1 + first.find('('))
            else:
                second_indent += indent_word

            second = (second_indent + source[end_offset:].lstrip())
            if (
                not second.strip() or
                second.lstrip().startswith('#')
            ):
                continue

            # Do not begin a line with a comma
            if second.lstrip().startswith(','):
                continue
            # Do end a line with a dot
            if first.rstrip().endswith('.'):
                continue
            if token_string in '+-*/':
                fixed = first + ' \\' + '\n' + second
            else:
                fixed = first + '\n' + second

            # Only fix if syntax is okay.
            if check_syntax(normalize_multiline(fixed)
                            if aggressive else fixed):
                yield indentation + fixed
87999
function indent(string, column) {
  const spaces = new Array(++column).join(COLUMN);

  return string.replace(RE_LINE_BEGIN, spaces);
}
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:]])
751545
def _indent(code, by=1):
    """"""
    return "".join(
        ("    " * by if line else "") + line for line in code.splitlines(True)
    )
1200744
function getExpectedIndent(line) {
            const offset = offsets.get(line)
            if (!offset) {
                const index = sourceCode.getIndexFromLoc({ line, column: 0 })
                const templateTag = microTemplateService.getTemplateTagByRangeIndex(
                    index
                )
                return getTopLevelIndentByTemplateTag(templateTag)
            }
            if (offset.expectedIndent !== undefined) {
                return offset.expectedIndent
            }

            const baseLineTemplate = microTemplateService
                .getMicroTemplateTokens()
                .find(t => t.loc.start.line === offset.baseline)

            let baseIndent = undefined
            if (baseLineTemplate) {
                baseIndent = getTopLevelIndentByTemplateTag(baseLineTemplate)
            } else {
                baseIndent = getExpectedIndent(offset.baseline)
            }

            const expectedNumberOfIndent =
                baseIndent.indent + offset.offset * options.indentSize

            const expectedIndent = new ExpectedIndent(
                baseIndent.baseIndentText,
                expectedNumberOfIndent
            )
            offset.expectedIndent = expectedIndent
            return expectedIndent
        }
387630
def go_to_new_line(self):
        """"""
        self.stdkey_end(False, False)
        self.insert_text(self.get_line_separator())
1168807
def add_line_with_subsequent_indent(self, line, indent=4):
        
        if isinstance(line, (list, tuple)):
            line = ''.join(line)
        line = line.strip()
        width = self.textwidth-self.indent-indent
        wrapped_lines = textwrap.wrap(line[indent:], width=width)
        for i in range(len(wrapped_lines)):
            if wrapped_lines[i] != '':
                wrapped_lines[i] = indent * ' ' + wrapped_lines[i]
        self.pieces.append(line[:indent] + '\n'.join(wrapped_lines)[indent:] + '  \n')
45301
def increase_indent(func):
    
    def wrapper(*args, **kwargs):
        global _debug_indent
        _debug_indent += 1
        result = func(*args, **kwargs)
        _debug_indent -= 1
        return result
    return wrapper
787115
def _indent_change(change, out, options, indent):
    

    show_unchanged = getattr(options, "show_unchanged", False)
    show_ignored = getattr(options, "show_ignored", False)

    show = False
    desc = change.get_description()

    if change.is_change():
        if change.is_ignored(options):
            if show_ignored:
                show = True
                _indent(out, indent, desc, " [IGNORED]")
        else:
            show = True
            _indent(out, indent, desc)
    elif show_unchanged:
        show = True
        _indent(out, indent, desc)

    if show:
        indent += 1
        for sub in change.collect():
            _indent_change(sub, out, options, indent)
1287844
def _replace_lines(fn, startswith, new_line):
  """"""
  new_lines = []
  for line in open(fn):
    if line.startswith(startswith):
      new_lines.append(new_line)
    else:
      new_lines.append(line)
  with open(fn, 'w') as f:
    f.write('\n'.join(new_lines))
885465
function defineFix(line, actualText, expectedIndent) {
                return fixer => {
                    const start = sourceCode.getIndexFromLoc({
                        line,
                        column: 0,
                    })
                    const indent = expectedIndent.indentText
                    return fixer.replaceTextRange(
                        [start, start + actualText.length],
                        indent
                    )
                }
            }
73401
def find_newline(source):
    
    assert not isinstance(source, unicode)

    counter = collections.defaultdict(int)
    for line in source:
        if line.endswith(CRLF):
            counter[CRLF] += 1
        elif line.endswith(CR):
            counter[CR] += 1
        elif line.endswith(LF):
            counter[LF] += 1

    return (sorted(counter, key=counter.get, reverse=True) or [LF])[0]
1177667
def _modify_new_lines(code_to_modify, offset, code_to_insert):
    
    # There's a nice overview of co_lnotab in
    # https://github.com/python/cpython/blob/3.6/Objects/lnotab_notes.txt

    new_list = list(code_to_modify.co_lnotab)
    if not new_list:
        # Could happen on a lambda (in this case, a breakpoint in the lambda should fallback to
        # tracing).
        return None

    # As all numbers are relative, what we want is to hide the code we inserted in the previous line
    # (it should be the last thing right before we increment the line so that we have a line event
    # right after the inserted code).
    bytecode_delta = len(code_to_insert)

    byte_increments = code_to_modify.co_lnotab[0::2]
    line_increments = code_to_modify.co_lnotab[1::2]

    if offset == 0:
        new_list[0] += bytecode_delta
    else:
        addr = 0
        it = zip(byte_increments, line_increments)
        for i, (byte_incr, _line_incr) in enumerate(it):
            addr += byte_incr
            if addr == offset:
                new_list[i * 2] += bytecode_delta
                break

    return bytes(new_list)
467152
def _check_for_indent(self, newline_token):
        
        indent_delta = self._get_next_line_indent_delta(newline_token)
        if indent_delta is None or indent_delta == 1:
            # Next line's indent isn't relevant (e.g. it's a comment) OR
            # next line is correctly indented.
            return None
        else:
            self.errors.append(
                ('Line continuation must increment indent by 1.',
                 newline_token.lexer.lineno))
543116
def _shorten_line_at_tokens_new(tokens, source, indentation,
                                max_line_length):
    
    # Yield the original source so to see if it's a better choice than the
    # shortened candidate lines we generate here.
    yield indentation + source

    parsed_tokens = _parse_tokens(tokens)

    if parsed_tokens:
        # Perform two reflows. The first one starts on the same line as the
        # prefix. The second starts on the line after the prefix.
        fixed = _reflow_lines(parsed_tokens, indentation, max_line_length,
                              start_on_prefix_line=True)
        if fixed and check_syntax(normalize_multiline(fixed.lstrip())):
            yield fixed

        fixed = _reflow_lines(parsed_tokens, indentation, max_line_length,
                              start_on_prefix_line=False)
        if fixed and check_syntax(normalize_multiline(fixed.lstrip())):
            yield fixed