我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用sublime.HIDDEN。
def focus_on(view, position): """ Focus the given help view on the provided position to ensure that is is visible. This alters the selection to the given position. If position is a point, the view is focused on that point and the cursor is placed there. If it is a Region, the region is selected and the cursor is left at the beginning of the region instead of at the end. """ if isinstance(position, int): position = sublime.Region(position, position) else: position = sublime.Region(position.end(), position.begin()) view.show_at_center(position) view.sel().clear() view.sel().add(position) # Hack to make the view update properly. See: # https://github.com/SublimeTextIssues/Core/issues/485 view.add_regions("_hh_rk", [], "", "", sublime.HIDDEN) view.erase_regions("_hh_rk")
def update_view_markers(view=None): if view is None: view = sublime.active_window().active_view() fn = view.file_name() if fn is not None: fn = normalize(fn) pos_scope = get_setting("position_scope", "entity.name.class") pos_icon = get_setting("position_icon", "bookmark") cursor = [] if fn == gdb_cursor and gdb_cursor_position != 0: cursor.append(view.full_line(view.text_point(gdb_cursor_position - 1, 0))) global gdb_last_cursor_view if gdb_last_cursor_view is not None: gdb_last_cursor_view.erase_regions("sublimegdb.position") gdb_last_cursor_view = view view.add_regions("sublimegdb.position", cursor, pos_scope, pos_icon, sublime.HIDDEN) gdb_callstack_view.update_marker(pos_scope, pos_icon) gdb_threads_view.update_marker(pos_scope, pos_icon) gdb_breakpoint_view.update_marker(view)
def update_markers(view): # collect markers rgn = {"error": [], "info": [], "warning": []} for marker in markers.get(view.window().id(), []): if marker['file'] != view.file_name(): continue location = view.text_point(marker['row'], marker['col']) line = view.line(location) found = False for m in rgn[marker['type']]: if m == line: found = True break if not found: rgn[marker['type']].append(line) # send to sublime for (key, value) in rgn.items(): view.add_regions("build_" + key, value, "build_" + key, "Packages/SublimeAnarchy/images/" + key + ".png", sublime.HIDDEN)
def update_marker(self, pos_scope, pos_icon): if self.is_open(): view = self.get_view() if gdb_stack_index != -1: line = 0 for i in range(gdb_stack_index): line += self.frames[i].lines view.add_regions("sublimegdb.stackframe", [view.line(view.text_point(line, 0))], pos_scope, pos_icon, sublime.HIDDEN) else: view.erase_regions("sublimegdb.stackframe")
def update_marker(self, pos_scope, pos_icon): if self.is_open(): view = self.get_view() line = -1 for i in range(len(self.threads)): if self.threads[i].id == self.current_thread: line = i break if line != -1: view.add_regions("sublimegdb.currentthread", [view.line(view.text_point(line, 0))], pos_scope, pos_icon, sublime.HIDDEN) else: view.erase_regions("sublimegdb.currentthread")
def update_disassembly(self): if not self.should_update(): return pc = parse_result_line(run_cmd("-data-evaluate-expression $pc", True))["value"] if " " in pc: pc = pc[:pc.find(" ")] pc = int(pc, 16) if not (pc >= self.start and pc <= self.end): l = run_cmd("-data-disassemble -s \"$pc-32\" -e \"$pc+200\" -- 1", True) asms = parse_result_line(l) self.clear() if get_result(l) != "error": asms = asms["asm_insns"] if "src_and_asm_line" in asms: l = listify(asms["src_and_asm_line"]) for src_asm in l: line = src_asm["line"] file = src_asm["file"] self.add_line("%s:%s\n" % (file, line)) self.add_insns(src_asm["line_asm_insn"]) else: self.add_insns(asms) self.update() view = self.get_view() reg = view.find("^0x[0]*%x:" % pc, 0) if reg is None: view.erase_regions("sublimegdb.programcounter") else: pos_scope = get_setting("position_scope", "entity.name.class") pos_icon = get_setting("position_icon", "bookmark") view.add_regions("sublimegdb.programcounter", [reg], pos_scope, pos_icon, sublime.HIDDEN)
def update_marker(self, view): bps = [] fn = view.file_name() if fn is None: return fn = normalize(fn) for bkpt in self.breakpoints: if bkpt.filename == fn and not (bkpt.line == gdb_cursor_position and fn == gdb_cursor): bps.append(view.full_line(view.text_point(bkpt.line - 1, 0))) view.add_regions("sublimegdb.breakpoints", bps, get_setting("breakpoint_scope", "keyword.gdb"), get_setting("breakpoint_icon", "circle"), sublime.HIDDEN)
def refresh_selections(view): """ Workaround for bug #485 where the view is not repainted See https://github.com/SublimeTextIssues/Core/issues/485 """ view.add_regions('gotousage_485fix', [], "no_scope", "", sublime.HIDDEN) view.erase_regions('gotousage_485fix')
def add_bookmarks(self, view): lhs = get_prefs() svt = lhs.get('severity') bmark_enable = lhs.get('bookmark_enable', True) if not bmark_enable: return # goto 1st error line region = self.regions['error'] if len(region) > 0: self.goto_line = region[0] # bookmark icon / navigation regions_all = [] if ST3: for i, k in enumerate(severity_list): icon = (svt.get(k)).get('icon') if icon: if icon == 'dot' or icon == 'circle' or icon == 'bookmark': icon = icon else: icon = "Packages/Log Highlight/icons/" + icon view.add_regions(k, self.regions[k], "bookmarks", icon, sublime.HIDDEN | sublime.PERSISTENT) for r in self.regions[k]: regions_all.append(r) else: for i, k in enumerate(severity_list): icon = (svt.get(k)).get('icon') if icon: if icon == 'dot' or icon == 'circle' or icon == 'bookmark': view.add_regions(k, self.regions[k], "bookmarks", icon, sublime.HIDDEN | sublime.PERSISTENT) else: view.add_regions(k, self.regions[k], "bookmarks", "dot", sublime.HIDDEN | sublime.PERSISTENT) for r in self.regions[k]: regions_all.append(r) # for navigation view.add_regions("bookmarks", regions_all, "bookmarks", '', sublime.HIDDEN | sublime.PERSISTENT) return
def on_modified(self, view): if not self.enable(view): return cursor = view.size() line = view.line(cursor - 1) if "filename" in view.scope_name(line.begin()): line_text = view.substr(line) parts = [p.strip() for p in line_text.split(":", maxsplit=5)] filename = os.path.join(os.path.dirname(view.window().project_file_name()), parts[0]) marker = "info" if "error:" in line_text: marker = "error" elif "warning:" in line_text: marker = "warning" if view.window().id() not in markers: markers[view.window().id()] = [] # save the marker markers[view.window().id()].append({ "type": marker, "file": filename, "panel_line": line, "row": int(parts[1]) - 1, "col": int(parts[2]) - 1, "text": parts[4], }) markers_updated[view.window().id()] = datetime.now() # update view rgn = {"error": [], "info": [], "warning": []} for marker in markers[view.window().id()]: rgn[marker['type']].append(marker["panel_line"]) for (key, value) in rgn.items(): view.add_regions("mark_" + key, value, "mark_" + key, "Packages/SublimeAnarchy/images/" + key + ".png", sublime.HIDDEN)
def hide(self): self.view.hide_popup() pt1 = self.word_point.begin() pt2 = self.word_point.end() self.view.add_regions('ToolTipHelper', [sublime.Region(pt1, pt2)], 'invalid', '' , sublime.HIDDEN)
def update_breakpoint_marker(view): breakpoints = view.window().project_data().get('settings', {}).get('SublimeAnarchyDebug', {}).get('breakpoints', []) enabled_markers = [] disabled_markers = [] for bp in breakpoints: if bp['file'] == view.file_name(): location = view.line(view.text_point(bp['line'], 0)) if bp['enabled']: enabled_markers.append(location) else: disabled_markers.append(location) view.add_regions("breakpoint_enabled", enabled_markers, "breakpoint_enabled", "Packages/SublimeAnarchyDebug/images/breakpoint_enabled.png", sublime.HIDDEN) view.add_regions("breakpoint_disabled", disabled_markers, "breakpoint_disabled", "Packages/SublimeAnarchyDebug/images/breakpoint_disabled.png", sublime.HIDDEN)
def add_lint_marks(view, lines, **errors): """Adds lint marks to view on the given lines. """ erase_lint_marks(view) types = { 'warning': errors['warning_underlines'], 'illegal': errors['error_underlines'], 'violation': errors['violation_underlines'], } style = get_settings(view, 'anaconda_linter_mark_style', 'outline') show_underlines = get_settings(view, 'anaconda_linter_underlines', True) if show_underlines: for type_name, underlines in types.items(): if len(underlines) > 0: view.add_regions( 'anaconda-lint-underline-{}'.format(type_name), underlines, 'anaconda.underline.{}'.format(type_name), flags=sublime.DRAW_EMPTY_AS_OVERWRITE ) if len(lines) > 0: outline_style = { 'solid_underline': sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE, 'stippled_underline': sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_STIPPLED_UNDERLINE, 'squiggly_underline': sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SQUIGGLY_UNDERLINE, 'outline': sublime.DRAW_OUTLINED, 'none': sublime.HIDDEN, 'fill': None } gutter_theme = get_settings( view, 'anaconda_gutter_theme', 'basic').lower() package_name = os.path.dirname(__file__).rsplit(os.path.sep, 3)[1] ico_path = ( 'Packages/' + package_name + '/anaconda_lib/linting/' 'gutter_mark_themes/{theme}-{type}.png' ) for lint_type, lints in get_outlines(view).items(): if len(lints) > 0: if get_settings(view, 'anaconda_gutter_marks', False): if gutter_theme == 'basic': gutter_marks = marks[lint_type] else: gutter_marks = ico_path.format(theme=gutter_theme, type=lint_type) else: gutter_marks = '' args = [ 'anaconda-lint-outlines-{}'.format(lint_type), lints, 'anaconda.outline.{}'.format(lint_type), gutter_marks ] draw_style = outline_style.get(style, sublime.DRAW_OUTLINED) if draw_style is not None: args.append(draw_style) view.add_regions(*args)