Return True if cursor (or text block) is on a block separator
501315
def is_cell_separator(self, cursor=None, block=None):
        """"""
        assert cursor is not None or block is not None
        if cursor is not None:
            cursor0 = QTextCursor(cursor)
            cursor0.select(QTextCursor.BlockUnderCursor)
            text = to_text_string(cursor0.selectedText())
        else:
            text = to_text_string(block.text())
        if self.cell_separators is None:
            return False
        else:
            return text.lstrip().startswith(self.cell_separators)
1212607
function(node) {
			//skip nodes with no name
			if (!node.name) {
				return true;
			}
	
			//skip formatting elements
			if (node.name === "b" || node.name === "i" || node.name === "em") { //$NON-NLS-0$ //$NON-NLS-1$ //$NON-NLS-2$
				return true;
			}
	
			//skip paragraphs and other blocks of formatted text
			if (node.name === "tt" || node.name === "code" || node.name === "blockquote") { //$NON-NLS-0$ //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
				return true;
			}
			//include the element if we have no reason to skip it
			return false;
		}
218672
def tryCComment(self, block):
        
        indentation = None

        prevNonEmptyBlock = self._prevNonEmptyBlock(block)
        if not prevNonEmptyBlock.isValid():
            return None

        prevNonEmptyBlockText = prevNonEmptyBlock.text()

        if prevNonEmptyBlockText.endswith('*/'):
            try:
                foundBlock, notUsedColumn = self.findTextBackward(prevNonEmptyBlock, prevNonEmptyBlock.length(), '/*')
            except ValueError:
                foundBlock = None

            if foundBlock is not None:
                dbg("tryCComment: success (1) in line %d" % foundBlock.blockNumber())
                return self._lineIndent(foundBlock.text())

        if prevNonEmptyBlock != block.previous():
            # inbetween was an empty line, so do not copy the "*" character
            return None

        blockTextStripped = block.text().strip()
        prevBlockTextStripped = prevNonEmptyBlockText.strip()

        if prevBlockTextStripped.startswith('/*') and not '*/' in prevBlockTextStripped:
            indentation = self._blockIndent(prevNonEmptyBlock)
            if CFG_AUTO_INSERT_STAR:
                # only add '*', if there is none yet.
                indentation += ' '
                if not blockTextStripped.endswith('*'):
                    indentation += '*'
                secondCharIsSpace = len(blockTextStripped) > 1 and blockTextStripped[1].isspace()
                if not secondCharIsSpace and \
                   not blockTextStripped.endswith("*/"):
                    indentation += ' '
            dbg("tryCComment: success (2) in line %d" % block.blockNumber())
            return indentation

        elif prevBlockTextStripped.startswith('*') and \
             (len(prevBlockTextStripped) == 1 or prevBlockTextStripped[1].isspace()):

            # in theory, we could search for opening /*, and use its indentation
            # and then one alignment character. Let's not do this for now, though.
            indentation = self._lineIndent(prevNonEmptyBlockText)
            # only add '*', if there is none yet.
            if CFG_AUTO_INSERT_STAR and not blockTextStripped.startswith('*'):
                indentation += '*'
                if len(blockTextStripped) < 2 or not blockTextStripped[1].isspace():
                    indentation += ' '

            dbg("tryCComment: success (2) in line %d" % block.blockNumber())
            return indentation

        return None
1245714
def checkCursor(self):
        ''
        # keep cursor within actual available rowset
        if self.nRows == 0 or self.cursorRowIndex <= 0:
            self.cursorRowIndex = 0
        elif self.cursorRowIndex >= self.nRows:
            self.cursorRowIndex = self.nRows-1

        if self.cursorVisibleColIndex <= 0:
            self.cursorVisibleColIndex = 0
        elif self.cursorVisibleColIndex >= self.nVisibleCols:
            self.cursorVisibleColIndex = self.nVisibleCols-1

        if self.topRowIndex <= 0:
            self.topRowIndex = 0
        elif self.topRowIndex > self.nRows-1:
            self.topRowIndex = self.nRows-1

        # (x,y) is relative cell within screen viewport
        x = self.cursorVisibleColIndex - self.leftVisibleColIndex
        y = self.cursorRowIndex - self.topRowIndex + 1  # header

        # check bounds, scroll if necessary
        if y < 1:
            self.topRowIndex = self.cursorRowIndex
        elif y > self.nVisibleRows:
            self.topRowIndex = self.cursorRowIndex-self.nVisibleRows+1

        if x <= 0:
            self.leftVisibleColIndex = self.cursorVisibleColIndex
        else:
            while True:
                if self.leftVisibleColIndex == self.cursorVisibleColIndex:  # not much more we can do
                    break
                self.calcColLayout()
                mincolidx, maxcolidx = min(self.visibleColLayout.keys()), max(self.visibleColLayout.keys())
                if self.cursorVisibleColIndex < mincolidx:
                    self.leftVisibleColIndex -= max((self.cursorVisibleColIndex - mincolid)//2, 1)
                    continue
                elif self.cursorVisibleColIndex > maxcolidx:
                    self.leftVisibleColIndex += max((maxcolidx - self.cursorVisibleColIndex)//2, 1)
                    continue

                cur_x, cur_w = self.visibleColLayout[self.cursorVisibleColIndex]
                if cur_x+cur_w < self.vd.windowWidth:  # current columns fit entirely on screen
                    break
                self.leftVisibleColIndex += 1
423447
def unindent(self):
        

        _logger().debug('unindent')
        cursor = self.editor.textCursor()
        _logger().debug('cursor has selection %r', cursor.hasSelection())
        if cursor.hasSelection():
            cursor.beginEditBlock()
            self.unindent_selection(cursor)
            cursor.endEditBlock()
            self.editor.setTextCursor(cursor)
        else:
            tab_len = self.editor.tab_length
            indentation = cursor.positionInBlock()
            indentation -= self.min_column
            if indentation == 0:
                return
            max_spaces = indentation % tab_len
            if max_spaces == 0:
                max_spaces = tab_len
            spaces = self.count_deletable_spaces(cursor, max_spaces)
            _logger().info('deleting %d space before cursor' % spaces)
            cursor.beginEditBlock()
            for _ in range(spaces):
                cursor.deletePreviousChar()
            cursor.endEditBlock()
            self.editor.setTextCursor(cursor)
            _logger().debug(cursor.block().text())
444740
private boolean handleSpan(TextCursor cursor, int blockEnd, ArrayList<MDText> elements) {
        if (mode != MODE_ONLY_LINKS) {
            int spanStart = findSpanStart(cursor, blockEnd);
            if (spanStart >= 0) {
                char span = cursor.text.charAt(spanStart);
                int spanEnd = findSpanEnd(cursor, spanStart, blockEnd, span);
                if (spanEnd >= 0) {

                    // Handling next elements before span
                    handleUrls(cursor, spanStart, elements);

                    // Increment offset before processing internal spans
                    cursor.currentOffset++;

                    // Building child spans
                    MDText[] spanElements = handleSpans(cursor, spanEnd - 1);

                    // End of search: move cursor after span
                    cursor.currentOffset = spanEnd;

                    MDSpan spanElement = new MDSpan(
                            span == '*' ? MDSpan.TYPE_BOLD : MDSpan.TYPE_ITALIC,
                            spanElements);

                    elements.add(spanElement);

                    return true;
                }
            }
        }

        handleUrls(cursor, blockEnd, elements);

        return false;
    }
68441
def indent(self):
        

        cursor = self.textCursor()
        if not cursor.hasSelection():
            cursor.insertText(self.__indent_marker)
        else:
            block = self.document().findBlock(cursor.selectionStart())
            while True:
                block_cursor = self.textCursor()
                block_cursor.setPosition(block.position())
                block_cursor.insertText(self.__indent_marker)
                if block.contains(cursor.selectionEnd()):
                    break
                block = block.next()
        return True
552627
def is_separator(self, char):
        
        if len(char) > 1:
            raise TypeError("Expected a char.")
        if char in self.separators:
            return True
        return False
330271
private int findCodeBlockStart(TextCursor cursor) {
        int offset = cursor.currentOffset;
        int index;
        while ((index = cursor.text.indexOf(CODE_BLOCK, offset)) >= 0) {
            if (isGoodAnchor(cursor.text, index - 1)) {
                return index;
            }
            offset = index + 3;
        }
        return -1;
    }
282143
def join_next_line(self, separator=' '):
        
        if not self.document.on_last_line:
            self.cursor_position += self.document.get_end_of_line_position()
            self.delete()

            # Remove spaces.
            self.text = (self.document.text_before_cursor + separator +
                         self.document.text_after_cursor.lstrip(' '))
321166
def textBlocks(self):
        '''
            
        '''
        myBlocks = self.blocks

        return [block for block in myBlocks if not issubclass(block.__class__, AdvancedTag)]
325651
def _findExpressionEnd(self, block):
        
        while block.isValid():
            column = self._lastColumn(block)
            if column > 0:
                return block, column
            block = block.previous()
        raise UserWarning()
1266449
private void handleTextBlock(TextCursor cursor, int blockEnd, ArrayList<MDSection> paragraphs) {
        MDText[] spans = handleSpans(cursor, blockEnd);
        paragraphs.add(new MDSection(spans));
        cursor.currentOffset = blockEnd;
    }
1081032
def _selectedBlocks(self):
        
        cursor = self.textCursor()
        return self.document().findBlock(cursor.selectionStart()), \
               self.document().findBlock(cursor.selectionEnd())
534918
def onChangeSelectedBlocksIndent(self, increase, withSpace=False):
        
        def blockIndentation(block):
            text = block.text()
            return text[:len(text) - len(text.lstrip())]

        def cursorAtSpaceEnd(block):
            cursor = QTextCursor(block)
            cursor.setPosition(block.position() + len(blockIndentation(block)))
            return cursor

        def indentBlock(block):
            cursor = cursorAtSpaceEnd(block)
            cursor.insertText(' ' if withSpace else self.text())

        def spacesCount(text):
            return len(text) - len(text.rstrip(' '))

        def unIndentBlock(block):
            currentIndent = blockIndentation(block)

            if currentIndent.endswith('\t'):
                charsToRemove = 1
            elif withSpace:
                charsToRemove = 1 if currentIndent else 0
            else:
                if self.useTabs:
                    charsToRemove = min(spacesCount(currentIndent), self.width)
                else:  # spaces
                    if currentIndent.endswith(self.text()):  # remove indent level
                        charsToRemove = self.width
                    else:  # remove all spaces
                        charsToRemove = min(spacesCount(currentIndent), self.width)

            if charsToRemove:
                cursor = cursorAtSpaceEnd(block)
                cursor.setPosition(cursor.position() - charsToRemove, QTextCursor.KeepAnchor)
                cursor.removeSelectedText()

        cursor = self._qpart.textCursor()

        startBlock = self._qpart.document().findBlock(cursor.selectionStart())
        endBlock = self._qpart.document().findBlock(cursor.selectionEnd())
        if(cursor.selectionStart() != cursor.selectionEnd() and
           endBlock.position() == cursor.selectionEnd() and
           endBlock.previous().isValid()):
            endBlock = endBlock.previous()  # do not indent not selected line if indenting multiple lines

        indentFunc = indentBlock if increase else unIndentBlock

        if startBlock != endBlock:  # indent multiply lines
            stopBlock = endBlock.next()

            block = startBlock

            with self._qpart:
                while block != stopBlock:
                    indentFunc(block)
                    block = block.next()

            newCursor = QTextCursor(startBlock)
            newCursor.setPosition(endBlock.position() + len(endBlock.text()), QTextCursor.KeepAnchor)
            self._qpart.setTextCursor(newCursor)
        else:  # indent 1 line
            indentFunc(startBlock)
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
1187977
def isBlockComment(self, line, column):
        
        return self._highlighter is not None and \
               self._highlighter.isBlockComment(self.document().findBlockByNumber(line), column)