Compute indent for the block
774380
def computeSmartIndent(self, block, char):
        
        try:
            foundBlock, foundColumn = self._findExpressionStart(block.previous())
        except UserWarning:
            return ''
        expression = foundBlock.text()[foundColumn:].rstrip()
        beforeExpression = foundBlock.text()[:foundColumn].strip()

        if beforeExpression.startswith('(module'):  # special case
            return ''
        elif beforeExpression.endswith('define'):  # special case
            return ' ' * (len(beforeExpression) - len('define') + 1)
        elif beforeExpression.endswith('let'):  # special case
            return ' ' * (len(beforeExpression) - len('let') + 1)
        else:
            return ' ' * foundColumn
1258005
def set_block_scalar_indent(token_class):
        """"""
        def callback(lexer, match, context):
            text = match.group()
            context.block_scalar_indent = None
            if not text:
                return
            increment = match.group(1)
            if increment:
                current_indent = max(context.indent, 0)
                increment = int(increment)
                context.block_scalar_indent = current_indent + increment
            if text:
                yield match.start(), token_class, text
                context.pos = match.end()
        return callback
1747
function indent(string, nchars, prefix) {
    "use strict";
    return string.split('\n').map(function(line) {
        return (prefix || '') + new Array(nchars).join(' ') + line;
    }).join('\n');
}
883790
def parse_block_scalar_indent(token_class):
        """"""
        def callback(lexer, match, context):
            text = match.group()
            if context.block_scalar_indent is None:
                if len(text) <= max(context.indent, 0):
                    context.stack.pop()
                    context.stack.pop()
                    return
                context.block_scalar_indent = len(text)
            else:
                if len(text) < context.block_scalar_indent:
                    context.stack.pop()
                    context.stack.pop()
                    return
            if text:
                yield match.start(), token_class, text
                context.pos = match.end()
        return callback
970434
def __indent(self, lines, indent, initial=2):
		""""""
		tagempty = re.compile(r"""<\w+(\s+[^>]*?)*/>""")
		tagopen = re.compile(r"""<\w+(\s+[^>]*?)*>""")
		tagclose = re.compile(r"""</\w+\s*>""")
		prefix = indent * initial
		for i in range(len(lines)):
			line = lines[i].strip()
			if tagempty.match(line):
				line = prefix + line
			elif tagopen.match(line):
				line = prefix + line
				prefix = prefix + indent
			elif tagclose.match(line):
				prefix = prefix[:-len(indent)]
				line = prefix + line
			elif '\n' in line:
				line = [prefix + l.strip() for l in line.split('\n')]
				line = os.linesep.join(line)
			else:
				line = prefix + line
			lines[i] = line + os.linesep
242754
def set_indent(TokenClass, implicit=False):
    """"""
    def callback(lexer, match, context):
        text = match.group()
        if context.indent < context.next_indent:
            context.indent_stack.append(context.indent)
            context.indent = context.next_indent
        if not implicit:
            context.next_indent += len(text)
        yield match.start(), TokenClass, text
        context.pos = match.end()
    return callback
719942
function() {
    var tok = this.expect('block');

    var node = 'indent' == this.peek().type
      ? this.block()
      : this.emptyBlock(tok.line);
    node.type = 'NamedBlock';
    node.name = tok.val.trim();
    node.mode = tok.mode;
    node.line = tok.line;

    return node;
  }
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
697140
def gen_lines(self, block, indent):
        
        prefix1 = indent + self.PS1
        prefix2 = indent + self.PS2
        prefix = prefix1
        for line in block:
            if line.startswith(prefix):
                yield line[len(prefix):]
            elif line == prefix.rstrip() + u"\n":
                yield u"\n"
            else:
                raise AssertionError("line=%r, prefix=%r" % (line, prefix))
            prefix = prefix2
        while True:
            yield ""
885643
function (block) {
        es.readArray([
          '<!--',
          '  processed by htmlbuild',
          '-->'
        ].map(function (str) {
          return block.indent + str;
        })).pipe(block);
      }
838068
def calculate_indent(text):
    
    indent = 0
    for c in text:
        if c is '\t':
            raise ValueError()
        if c is not ' ':
            return indent,text[indent:]
        indent += 1
    return indent,''
1181236
def _set_line_indent(src, line, indent):
    '''
    
    '''
    if not indent:
        return line

    idt = []
    for c in src:
        if c not in ['\t', ' ']:
            break
        idt.append(c)

    return ''.join(idt) + line.lstrip()
1165902
def detect_fold_level(self, prev_block, block):
        
        text = block.text()
        prev_lvl = TextBlockHelper().get_fold_lvl(prev_block)
        # round down to previous indentation guide to ensure contiguous block
        # fold level evolution.
        indent_len = 0
        if (prev_lvl and prev_block is not None and
           not self.editor.is_comment(prev_block)):
            # ignore commented lines (could have arbitary indentation)
            prev_text = prev_block.text()
            indent_len = (len(prev_text) - len(prev_text.lstrip())) // prev_lvl
        if indent_len == 0:
            indent_len = len(self.editor.indent_chars)

        return (len(text) - len(text.lstrip())) // indent_len
1181084
def unindent(self):
        

        cursor = self.textCursor()
        if not cursor.hasSelection():
            cursor.movePosition(QTextCursor.StartOfBlock)
            line = foundations.strings.to_string(self.document().findBlockByNumber(cursor.blockNumber()).text())
            indent_marker = re.match(r"({0})".format(self.__indent_marker), line)
            if indent_marker:
                foundations.common.repeat(cursor.deleteChar, len(indent_marker.group(1)))
        else:
            block = self.document().findBlock(cursor.selectionStart())
            while True:
                block_cursor = self.textCursor()
                block_cursor.setPosition(block.position())
                indent_marker = re.match(r"({0})".format(self.__indent_marker), block.text())
                if indent_marker:
                    foundations.common.repeat(block_cursor.deleteChar, len(indent_marker.group(1)))
                if block.contains(cursor.selectionEnd()):
                    break
                block = block.next()
        return True
589571
def get_total_indentation(self, index):
        
        n = 0
        while index.isValid():
            n += 1
            index = index.parent()
        return n * self.indentation()
1064455
def indent(self, indent):
        """"""
        curr_docparts = self._docparts
        self._docparts = []
        self.indentation += indent
        try:
            yield
        finally:
            self.indentation -= indent
            indented_docparts = self._docparts
            self._docparts = curr_docparts
            self._docparts.append(nest(indent, concat(indented_docparts)))
387379
def indent(text: str, num: int = 2) -> str:
    """"""
    lines = text.splitlines()
    return "\n".join(indent_iterable(lines, num=num))