Heuristically extracts the base indentation from the provided code.

    Finds the smallest indentation following a newline not at the end of the
    string.
1788
def get_base_indentation(code, include_start=False):
    
    new_line_indentation = re_new_line_indentation[include_start].finditer(code)
    new_line_indentation = tuple(m.groups(0)[0] for m in new_line_indentation)
    if new_line_indentation:
        return min(new_line_indentation, key=len)
    else:
        return ""
486376
def decompose_code(code):
    
    code = "%-6s" % code
    ind1 = code[3:4]
    if ind1 == " ": ind1 = "_"
    ind2 = code[4:5]
    if ind2 == " ": ind2 = "_"
    subcode = code[5:6]
    if subcode == " ": subcode = None
    return (code[0:3], ind1, ind2, subcode)
317096
def _decreaseIndent(self, indent):
        
        if indent.endswith(self._qpartIndent()):
            return indent[:-len(self._qpartIndent())]
        else:  # oops, strange indentation, just return previous indent
            return indent
169750
function(code) {
    var lines = [];
    code.split(/\n/).forEach(line => {
      var segs = line.split(/(\s*#)/);
      var ln = {code: segs[0]};
      if (segs.length > 1)
        ln.comment = segs.reduce((c, seg, i) => i > 1 ? c + seg : seg, '');
      lines.push(ln);
    });
    return lines;
  }
189050
def fix_indentation(code, new_indents):
    """"""
    min_indents = find_minimum_indents(code)
    return indent_lines(code, new_indents - min_indents)
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
413854
def find_cell_end(self, lines):
        """"""
        if self.in_region:
            self.cell_type = 'markdown'
            for i, line in enumerate(lines):
                if self.end_region_re.match(line):
                    return i, i + 1, True
        elif self.metadata is None:
            # default markdown: (last) two consecutive blank lines, except when in code blocks
            self.cell_type = 'markdown'
            prev_blank = 0
            in_explicit_code_block = False
            in_indented_code_block = False

            for i, line in enumerate(lines):
                if in_explicit_code_block and self.end_code_re.match(line):
                    in_explicit_code_block = False
                    continue

                if self.non_jupyter_code_re and self.non_jupyter_code_re.match(line):
                    in_explicit_code_block = True
                    prev_blank = 0
                    continue

                if prev_blank and line.startswith('    ') and not _BLANK_LINE.match(line):
                    in_indented_code_block = True
                    prev_blank = 0
                    continue

                if in_indented_code_block and not _BLANK_LINE.match(line) and not line.startswith('    '):
                    in_indented_code_block = False

                if in_indented_code_block or in_explicit_code_block:
                    continue

                if self.start_code_re.match(line) or self.start_region_re.match(line):
                    if i > 1 and prev_blank:
                        return i - 1, i, False
                    return i, i, False

                if self.split_at_heading and line.startswith('#') and prev_blank >= 1:
                    return i - 1, i, False

                if _BLANK_LINE.match(lines[i]):
                    prev_blank += 1
                elif i > 2 and prev_blank >= 2:
                    return i - 2, i, True
                else:
                    prev_blank = 0
        else:
            self.cell_type = 'code'
            for i, line in enumerate(lines):
                # skip cell header
                if i == 0:
                    continue
                if self.end_code_re.match(line):
                    return i, i + 1, True

        # End not found
        return len(lines), len(lines), False
589571
def get_total_indentation(self, index):
        
        n = 0
        while index.isValid():
            n += 1
            index = index.parent()
        return n * self.indentation()
11770
def indentation(node):
    
    while node.parent is not None and node.parent.type != syms.suite:
        node = node.parent
    if node.parent is None:
        return u""
    # The first three children of a suite are NEWLINE, INDENT, (some other node)
    # INDENT.value contains the indentation for this suite
    # anything after (some other node) has the indentation as its prefix.
    if node.type == token.INDENT:
        return node.value
    elif node.prev_sibling is not None and node.prev_sibling.type == token.INDENT:
        return node.prev_sibling.value
    elif node.prev_sibling is None:
        return u""
    else:
        return node.prefix
151861
def get_indented_lines(indent)
      buffer = ''

      # Gather multiple blank lines between lines of text
      blank_lines = proc do
        while lookahead_next_line :line_whitespace
          @line = @code[(@i += 1)]
          @offset = 0

          buffer += accept :line_whitespace
        end
      end

      # Get blank lines until we match something
      blank_lines[]

      # Get the next indentation after the parent line
      # and set it as primary indent
      first_indent = (lookahead_next_line(:indent).to_s || '').size
      next_indent = first_indent

      # While the indentation is smaller, add the line feed  to our buffer
      while next_indent > indent
        # Advance current line and reset offset
        @line = @code[(@i += 1)]
        @offset = 0

        # Get leading whitespace trimmed with first_indent's size
        next_line_indent = accept(:indent)[first_indent..-1] || ''
        next_line_indent = next_line_indent.size

        # Add next line feed, prepend the indent and append the newline
        buffer += ' ' * next_line_indent if next_line_indent > 0
        buffer += accept_stripped(:line_feed) || ''
        buffer += accept(:newline) || ''

        # Get blank lines until we match something
        blank_lines[]

        # Check the indentation on the following line. When we reach EOF,
        # set the indentation to 0 and cause the loop to stop
        if (next_indent = lookahead_next_line :indent)
          next_indent = next_indent[0].size
        else
          next_indent = 0
        end
      end

      buffer
    end
496254
private static int findEndOfLine(final ByteBuf buffer) {
        final int n = buffer.writerIndex();
        for (int i = buffer.readerIndex(); i < n; i++) {
            final byte b = buffer.getByte(i);
            if (b == '\r' && i < n - 1 && buffer.getByte(i + 1) == '\n') {
                return i;  // \r\n
            }
        }
        return -1;  // Not found.
    }
854165
function getOffset() {
      var indentation = []
      var pos = line + 1

      // Done.  Called when the last character is eaten to retrieve the range’s
      // offsets.
      return function() {
        var last = line + 1

        while (pos < last) {
          indentation.push((offset[pos] || 0) + 1)

          pos++
        }

        return indentation
      }
    }
1231245
private static int findMinimumLeadingSpaces(String line, int count) {
        int length = line.length();
        int index = 0;
        while (index < length && index < count && Character.isWhitespace(line.charAt(index))) index++;
        return index;
    }
1056724
def check_indent(self, definition, docstring):
        
        if docstring:
            indent = self._get_docstring_indent(definition, docstring)
            lines = docstring.split('\n')
            if len(lines) > 1:
                lines = lines[1:]  # First line does not need indent.
                indents = [leading_space(l) for l in lines if not is_blank(l)]
                if set(' \t') == set(''.join(indents) + indent):
                    yield violations.D206()
                if (len(indents) > 1 and min(indents[:-1]) > indent or
                        indents[-1] > indent):
                    yield violations.D208()
                if min(indents) < indent:
                    yield violations.D207()
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]
575302
def Indentation( logical_line,
                 previous_logical,
                 indent_level,
                 previous_indent_level ):
  """"""
  comment = '' if logical_line else ' (comment)'
  if indent_level % 2:
    code = 'YCM111' if logical_line else 'YCM114'
    message = ' indentation is not a multiple of two spaces' + comment
    yield 0, code + message
  if ( previous_logical.endswith( ':' ) and
       ( indent_level - previous_indent_level != 2 ) ):
    code = 'YCM112' if logical_line else 'YCM115'
    message = ' expected an indented block of {} spaces{}'.format(
      previous_indent_level + 2, comment )
    yield 0, code + message
431872
def code_block(self, code, language, indent=0):
        
        if language not in [None, "console", "python", "ruby", "c"]:
            raise
        prefix = "\t" * indent
        code_prefix = "\t" * (indent + 1)
        lines = list()
        lines.append(prefix + ".. code-block:: %s" % language)
        lines.append(prefix)
        for line in code.split("\n"):
            lines.append(code_prefix + line.strip())
        return "\n".join(lines)