本文整理汇总了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