def get_region(self, view=None, can_select_entire_buffer=False):
'''Get the value under the cursor, or cursors.'''
value = ''
view, window = self.get_view_and_window(view)
# If there is no view then all bets are off:
#
if view is not None:
# Get the selection:
#
selection = view.sel()
# If there is no selection then optionally use the entire buffer:
#
if can_select_entire_buffer is True:
if len(selection) == 1 and selection[0].empty():
selection = [sublime.Region(0, view.size())]
if selection is not None:
# For each region in the selection, either use it directly,
# or expand it to take in the 'word' that the cursor is on:
#
for region in selection:
if region.empty():
region = view.expand_by_class(
region,
sublime.CLASS_WORD_START | sublime.CLASS_WORD_END,
' ():'
)
value = value + ' ' + view.substr(region)
return value
评论列表
文章目录