我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用sublime.CLASS_WORD_START。
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 at_word_start(view, pt): return (view.classify(pt) & CLASS_WORD_START) == CLASS_WORD_START
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 get_region(self, view): if self.line is None: return None if self.column is None: point = view.text_point(self.line-1, 0) return view.full_line(point) point = view.text_point(self.line-1, self.column-1) point_class = view.classify(point) if point_class & (sublime.CLASS_WORD_START|sublime.CLASS_WORD_END): return view.word(point) else: return view.full_line(point)
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