def next_word_start(view, pt):
if is_at_punctuation(view, pt):
# Skip all punctuation surrounding the caret and any trailing spaces.
end = get_punctuation_region(view, pt).b
if view.substr(end) in (' ', '\n'):
end = view.find_by_class(end, forward=True, classes=ANCHOR_NEXT_WORD_BOUNDARY)
return end
elif is_at_space(view, pt):
# Skip all spaces surrounding the cursor and the text word.
end = get_space_region(view, pt).b
if is_at_word(view, end) or is_at_punctuation(view, end):
end = view.find_by_class(
end,
forward=True,
classes=CLASS_WORD_END | CLASS_PUNCTUATION_END | CLASS_LINE_END
)
return end
# Skip the word under the caret and any trailing spaces.
return view.find_by_class(pt, forward=True, classes=ANCHOR_NEXT_WORD_BOUNDARY)
python类CLASS_WORD_END的实例源码
def run(self, edit):
flags = sublime.CLASS_WORD_START | sublime.CLASS_WORD_END
path = utils.get_node_content(self.view, flags)
imagepath = INFOS.addon.translate_path(path)
if not os.path.exists(imagepath):
return None
if os.path.isdir(imagepath):
self.files = []
for (_dirpath, _dirnames, filenames) in os.walk(imagepath):
self.files.extend(filenames)
break
self.files = [imagepath + s for s in self.files]
else:
self.files = [imagepath]
sublime.active_window().show_quick_panel(items=self.files,
on_select=self.on_done,
selected_index=0,
on_highlight=self.show_preview)
def findLocalLabelInView(self, symbol_region):
''' Try to expand the region so that it includes a local label (including macro ones) '''
# check if there is a punctuation at the start
if self.view.classify(symbol_region.begin()) & sublime.CLASS_PUNCTUATION_END:
# cool, there is a punctuation expand selection with custom logic
new_region = self.view.expand_by_class(symbol_region,
sublime.CLASS_WORD_START | sublime.CLASS_WORD_END,
"()[]:, ")
region_word = self.view.substr(new_region).strip()
# we could also use self.view.indexed_symbols() here instead of the scopes
# get the global label point closest to this local one
closest_global = 0
for r in self.view.find_by_selector("rgbds.label.global"):
if r.end() < symbol_region.begin():
closest_global = r.end()
# now get all local labels and stop at the one after the global point
for r in self.view.find_by_selector("rgbds.label.local"):
if self.view.substr(r) == region_word and r.begin() > closest_global:
return (self.view.file_name(), r)
return None
def show(self,region,location):
# If nothing is selected expand selection to word
if region.empty() :
region = self.view.word(region)
# Make sure a whole word is selected
elif (self.view.classify(region.a) & sublime.CLASS_WORD_START)==0 or (self.view.classify(region.b) & sublime.CLASS_WORD_END)==0:
if (self.view.classify(region.a) & sublime.CLASS_WORD_START)==0:
region.a = self.view.find_by_class(region.a,False,sublime.CLASS_WORD_START)
if (self.view.classify(region.b) & sublime.CLASS_WORD_END)==0:
region.b = self.view.find_by_class(region.b,True,sublime.CLASS_WORD_END)
v = self.view.substr(region)
# trigger on valid word only
if not re.match(r'^[A-Za-z_]\w*$',v):
return
#
s,ti = self.get_type(v,region)
if not s:
sublime.status_message('No definition found for ' + v)
else :
s = self.color_str(s,ti)
s = '<style>{css}</style><div class="content">{txt}</div>'.format(css=tooltip_css, txt=s)
self.view.show_popup(s,location=location, flags=tooltip_flag, max_width=500, on_navigate=self.on_navigate)
def next_word_start(view, pt):
if is_at_punctuation(view, pt):
# Skip all punctuation surrounding the caret and any trailing spaces.
end = get_punctuation_region(view, pt).b
if view.substr(end) in (' ', '\n'):
end = view.find_by_class(end, forward=True,
classes=ANCHOR_NEXT_WORD_BOUNDARY)
return end
elif is_at_space(view, pt):
# Skip all spaces surrounding the cursor and the text word.
end = get_space_region(view, pt).b
if is_at_word(view, end) or is_at_punctuation(view, end):
end = view.find_by_class(end, forward=True,
classes=CLASS_WORD_END |
CLASS_PUNCTUATION_END |
CLASS_LINE_END)
return end
# Skip the word under the caret and any trailing spaces.
return view.find_by_class(pt, forward=True,
classes=ANCHOR_NEXT_WORD_BOUNDARY)
def at_word_end(view, pt):
return (view.classify(pt) & CLASS_WORD_END) == CLASS_WORD_END
def skip_word(view, pt):
while True:
if at_punctuation(view, pt):
pt = view.find_by_class(pt, forward=True, classes=CLASS_PUNCTUATION_END)
elif at_word(view, pt):
pt = view.find_by_class(pt, forward=True, classes=CLASS_WORD_END)
else:
break
return pt
def run(self, pack_textures=True):
path = utils.get_node_content(view=self.window.active_view(),
flags=sublime.CLASS_WORD_START | sublime.CLASS_WORD_END)
imagepath = INFOS.addon.translate_path(path)
if not os.path.exists(imagepath):
return None
webbrowser.open(imagepath)
def is_visible(self):
if not INFOS.addon or not INFOS.addon.media_path:
return False
flags = sublime.CLASS_WORD_START | sublime.CLASS_WORD_END
content = utils.get_node_content(self.view, flags)
return "/" in content or "\\" in content
def run(self):
flags = sublime.CLASS_WORD_START | sublime.CLASS_WORD_END
view = self.window.active_view()
position = INFOS.go_to_tag(keyword=utils.get_node_content(view, flags),
folder=view.file_name().split(os.sep)[-2])
if position:
self.window.open_file(position, sublime.ENCODED_POSITION)
def at_word_end(view, pt):
return (view.classify(pt) & CLASS_WORD_END) == CLASS_WORD_END
def skip_word(view, pt):
while True:
if at_punctuation(view, pt):
pt = view.find_by_class(pt, forward=True, classes=CLASS_PUNCTUATION_END)
elif at_word(view, pt):
pt = view.find_by_class(pt, forward=True, classes=CLASS_WORD_END)
else:
break
return pt
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