当前位置: 首页>>代码示例>>Python>>正文


Python Lexer.wordCharacters方法代码示例

本文整理汇总了Python中lexer.Lexer.wordCharacters方法的典型用法代码示例。如果您正苦于以下问题:Python Lexer.wordCharacters方法的具体用法?Python Lexer.wordCharacters怎么用?Python Lexer.wordCharacters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lexer.Lexer的用法示例。


在下文中一共展示了Lexer.wordCharacters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Editor

# 需要导入模块: from lexer import Lexer [as 别名]
# 或者: from lexer.Lexer import wordCharacters [as 别名]

#.........这里部分代码省略.........
    def _moveLines(self, disposition):
        """Move selected lines down
        """
        clipboard = QApplication.instance().clipboard()
        selectionBuffer = clipboard.text(clipboard.Selection)
        copyBuffer = clipboard.text(clipboard.Clipboard)
        start, end = self.selection()
        startLine, startCol = start
        endLine, endCol = end
        
        if startLine == endLine and startCol == endCol:  # empty selection, select 1 line
            endCol = len(self.line(endLine))
        
        startCol = 0  # always cut whole line
        if endCol > 0:
            if (endLine + 1) < self.lineCount():
                # expand to line end (with \n)
                endCol = 0
                endLine += 1
            else:
                # expand to line end WITHOUT \n
                endCol = len(self.line(endLine))

        if startLine != endLine or startCol != endCol:  # if have text to move
            if disposition < 0:  # move up
                canMove = startLine + disposition >= 0
            else:  # move down
                endAbsPos = self._toAbsPosition(endLine, endCol)
                canMove = endAbsPos + 1 < len(self.text())
            
            if canMove:
                self.beginUndoAction()
                self.qscintilla.setSelection(startLine, startCol, endLine, endCol)
                self.qscintilla.cut()
                
                # add missing line to end before pasting, if necessary
                if self.lineCount() <= startLine + disposition:
                    lineBefore = startLine + disposition - 1
                    self.setCursorPosition(line=lineBefore,
                                           column = len(self.line(lineBefore)))
                    self.qscintilla.insert('\n')
                    newlineAddedWhenCut = True
                else:
                    newlineAddedWhenCut = False

                self.setCursorPosition(line=startLine + disposition, column = 0)
                text = QApplication.instance().clipboard().text()
                if not text.endswith('\n'):  # if copied line without \n, add it
                    text += '\n'
                
                if newlineAddedWhenCut:
                    text = text[:-1]
                
                self.qscintilla.insert(text)
                self.qscintilla.setSelection(startLine + disposition, startCol, endLine + disposition, endCol)
                self.endUndoAction()
                clipboard.setText(selectionBuffer, clipboard.Selection)
                clipboard.setText(copyBuffer, clipboard.Clipboard)

    def moveLinesDown(self):
        """Move selected lines down
        """
        return self._moveLines(1)

    def moveLinesUp(self):
        """Move selected lines up
        """
        return self._moveLines(-1)

    def wordUnderCursor(self):
        """Get word under cursor.
        What is a "word" depends on current language
        """
        wordCharacters = self.lexer.wordCharacters()
        
        line, col = self.cursorPosition()
        lineText = self.line(line)

        textBefore = lineText[:col]
        countBefore = 0
        for character in textBefore[::-1]:
            if character in wordCharacters:
                countBefore += 1
            else:
                break
        
        textAfter = lineText[col:]
        countAfter = 0
        for character in textAfter:
            if character in wordCharacters:
                countAfter += 1
            else:
                break
        
        if countBefore or countAfter:
            word = lineText[col - countBefore:col + countAfter]
            absPos = self.absCursorPosition()
            return word, absPos - countBefore, absPos + countAfter
        else:
            return None, None, None
开发者ID:polovik,项目名称:enki,代码行数:104,代码来源:editor.py


注:本文中的lexer.Lexer.wordCharacters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。