Python sublime.Region() Examples
The following are 30
code examples of sublime.Region().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sublime
, or try the search function
.
Example #1
Source File: common.py From SublimeFileBrowser with MIT License | 6 votes |
def _add_sels(self, sels=None): self.view.sel().clear() if sels: eof = self.view.size() for s in sels: if s.begin() <= eof: self.view.sel().add(s) if not sels or not list(self.view.sel()): # all sels more than eof item = (self.view.find_by_selector('text.dired dired.item.parent_dir ') or self.view.find_by_selector('text.dired dired.item.directory string.name.directory.dired ') or self.view.find_by_selector('text.dired dired.item.file string.name.file.dired ')) s = Region(item[0].a, item[0].a) if item else Region(0, 0) self.view.sel().add(s) self.view.show_at_center(s)
Example #2
Source File: selection_utility.py From network_tech with Apache License 2.0 | 6 votes |
def _expand_words(cls, view, region, classes, repeat=1, forward=True): word = cls._get_word_on_cursor(view, region) line = cls._get_line_on_cursor(view, region) current_word = word for expand in range(repeat): next_word_end = view.find_by_class( current_word.end() if forward else current_word.begin(), forward=forward, classes=classes ) next_word = cls._get_word_on_cursor(view, next_word_end) if line == cls._get_line_on_cursor(view, next_word): current_word = cls._get_word_on_cursor(view, next_word_end) start = word.begin() if forward else current_word.begin() end = current_word.end() if forward else word.end() return sublime.Region(start, end)
Example #3
Source File: tern.py From PhaserSublimePackage with MIT License | 6 votes |
def locate_call(view): sel = view.sel()[0] if sel.a != sel.b: return (None, 0) context = view.substr(sublime.Region(max(0, sel.b - 500), sel.b)) pos = len(context) depth = argpos = 0 while pos > 0: pos -= 1 ch = context[pos] if ch == "}" or ch == ")" or ch == "]": depth += 1 elif ch == "{" or ch == "(" or ch == "[": if depth > 0: depth -= 1 elif ch == "(": return (pos + sel.b - len(context), argpos) else: return (None, 0) elif ch == "," and depth == 0: argpos += 1 return (None, 0)
Example #4
Source File: file.py From GutterColor with MIT License | 6 votes |
def scan(self): """Scan the file for colours and add/remove regions appropriately""" # Return a list of all the line regions in the current file if self.action == 'update': regions = [self.view.line(s) for s in self.view.sel()] else: regions = self.view.lines(Region(0, self.view.size())) for region in regions: line = Line(self.view, region, self.id) if line.has_color(): line.add_region() else: try: self.view.erase_regions("gutter_color_%s" % region.a) except: pass
Example #5
Source File: sublime_terminal_buffer.py From TerminalView with MIT License | 6 votes |
def _update_line_colors(self, line_no, line_color_map): # Note this function has been optimized quite a bit. Calls to the ST3 # API has been left out on purpose as they are slower than the # alternative. view_region_cache = self._sub_buffer.view_region_cache() view_content_cache = self._sub_buffer.view_content_cache() for idx, field in line_color_map.items(): length = field["field_length"] color_scope = "terminalview.%s_%s" % (field["color"][0], field["color"][1]) # Get text point where color should start line_start, _ = view_content_cache.get_line_start_and_end_points(line_no) color_start = line_start + idx # Make region that should be colored buffer_region = sublime.Region(color_start, color_start + length) region_key = "%i,%s" % (line_no, idx) # Add the region flags = sublime.DRAW_NO_OUTLINE | sublime.PERSISTENT self.view.add_regions(region_key, [buffer_region], color_scope, flags=flags) view_region_cache.add(line_no, region_key)
Example #6
Source File: sublime_terminal_buffer.py From TerminalView with MIT License | 6 votes |
def _update_line_content(self, edit, line_no, content): # Note this function has been optimized quite a bit. Calls to the ST3 # API has been left out on purpose as they are slower than the # alternative. # We need to add a newline otherwise ST3 does not break the line content_w_newline = content + "\n" # Check in our local buffer that the content line is different from what # we are already showing - otherwise we can stop now view_content_cache = self._sub_buffer.view_content_cache() if view_content_cache.has_line(line_no): if view_content_cache.get_line(line_no) == content_w_newline: return # Content is different - make ST3 region that spans the line. Start by # geting start and end point of the line line_start, line_end = view_content_cache.get_line_start_and_end_points(line_no) # Make region spanning entire line (including any newline at the end) line_region = sublime.Region(line_start, line_end) self.view.replace(edit, line_region, content_w_newline) view_content_cache.update_line(line_no, content_w_newline)
Example #7
Source File: dired_misc.py From SublimeFileBrowser with MIT License | 6 votes |
def vcs_colorized(self, changed_items): '''called on main thread''' if not self.view.settings().has('dired_index'): return # view was closed modified, untracked = [], [] files_regions = dict((f, r) for f, r in zip(self.get_all(), self.view.split_by_newlines(Region(0, self.view.size())))) colorblind = self.view.settings().get('vcs_color_blind', False) offset = 1 if not colorblind else 0 for fn in changed_items.keys(): full_fn = normpath(fn) r = files_regions.get(full_fn, 0) if r: icon = self._get_name_point(r) - 2 r = Region(icon, icon + offset) status = changed_items[fn] if status == 'M': modified.append(r) elif status == '?': untracked.append(r) if colorblind: self.view.add_regions('M', modified, 'item.colorblind.dired', '', MARK_OPTIONS | sublime.DRAW_EMPTY_AS_OVERWRITE) self.view.add_regions('?', untracked, 'item.colorblind.dired', '', MARK_OPTIONS | sublime.DRAW_EMPTY) else: self.view.add_regions('M', modified, 'item.modified.dired', '', MARK_OPTIONS) self.view.add_regions('?', untracked, 'item.untracked.dired', '', MARK_OPTIONS)
Example #8
Source File: dired_file_operations.py From SublimeFileBrowser with MIT License | 6 votes |
def run(self, edit): self.which = self.view.settings().get('which', '') if not self.which: return sublime.error_message('oops, does not work!') self.refresh = False value = self.view.substr(Region(0, self.view.size())) fqn = self.on_done(value) if not fqn: return sublime.status_message('oops, does not work!') sublime.active_window().run_command('hide_panel', {'cancel': True}) dired_view = sublime.active_window().active_view() if dired_view.settings().has('dired_path'): self.refresh = True if self.which == 'directory': dired_view.settings().set('dired_path', fqn + os.sep) else: sublime.active_window().open_file(fqn) if self.refresh: emit_event(u'watch_view', dired_view.id(), plugin=u'FileBrowserWFS') dired_view.run_command('dired_refresh', {'goto': fqn})
Example #9
Source File: tern.py From PhaserSublimePackage with MIT License | 6 votes |
def buffer_fragment(view, pos): region = None for js_region in view.find_by_selector("source.js"): if js_region.a <= pos and js_region.b >= pos: region = js_region break if region is None: return sublime.Region(pos, pos) start = view.line(max(region.a, pos - 1000)).a if start < pos - 1500: start = pos - 1500 cur = start min_indent = 10000 while True: next = view.find("\\bfunction\\b", cur) if next is None or next.b > pos or (next.a == -1 and next.b == -1): break line = view.line(next.a) if line.a < pos - 1500: line = sublime.Region(pos - 1500, line.b) indent = count_indentation(view.substr(line)) if indent < min_indent: min_indent = indent start = line.a cur = line.b return sublime.Region(start, min(pos + 500, region.b))
Example #10
Source File: commands.py From sublimious with GNU General Public License v3.0 | 6 votes |
def run(self, edit, arr): if len(arr) == 0: return self.view.set_read_only(False) self.view.erase(edit, sublime.Region(0, self.view.size())) s = [] for key, definition in sorted(arr.items()): s.append("%s ➜ %-20s" % ("[%s]" % key, definition)) for i, val in enumerate(s): if (i + 1) % 4 == 0: self.view.insert(edit, self.view.size(), "%s\n" % val) continue self.view.insert(edit, self.view.size(), val) self.view.settings().set("word_wrap", False) self.view.settings().set('color_scheme', 'Packages/sublimious/keyhelper/keyhelper.tmTheme') self.view.set_syntax_file("Packages/sublimious/keyhelper/keyhelper.sublime-syntax") self.view.set_read_only(True) self.view.show(self.view.size())
Example #11
Source File: common.py From dired with MIT License | 6 votes |
def move(self, forward=None): """ Moves the cursor one line forward or backwards. Clears all sections. """ assert forward in (True, False), 'forward must be set to True or False' files = self.fileregion() if files.empty(): return pt = self.view.sel()[0].a if files.contains(pt): # Try moving by one line. line = self.view.line(pt) pt = forward and (line.b + 1) or (line.a - 1) if not files.contains(pt): # Not (or no longer) in the list of files, so move to the closest edge. pt = (pt > files.b) and files.b or files.a line = self.view.line(pt) self.view.sel().clear() self.view.sel().add(Region(line.a, line.a))
Example #12
Source File: tandem.py From tandem with Apache License 2.0 | 6 votes |
def _handle_apply_patches(self, message): for patch in message.patch_list: start = patch["oldStart"] end = patch["oldEnd"] text = patch["newText"] start_point = self._view.text_point( start["row"], start["column"], ) end_point = self._view.text_point( end["row"], end["column"], ) """ Edit cannot be passed around https://forum.sublimetext.com/t/multithreaded-plugin/14439 Use view abstraction instead. """ with Edit(self._view) as edit: edit.replace( sublime.Region(start_point, end_point), text, ) self._buffer = self._current_buffer
Example #13
Source File: TodoReview.py From SublimeTodoReview with MIT License | 6 votes |
def get_view(self): self.window = sublime.active_window() for view in self.window.views(): if view.settings().get('todo_results', False): view.erase(self.edit, sublime.Region(0, view.size())) return view view = self.window.new_file() view.set_name('TodoReview') view.set_scratch(True) view.settings().set('todo_results', True) if sys.version_info < (3,0,0): view.set_syntax_file('Packages/TodoReview/TodoReview.hidden-tmLanguage') else: view.assign_syntax('Packages/TodoReview/TodoReview.hidden-tmLanguage') view.settings().set('line_padding_bottom', 2) view.settings().set('line_padding_top', 2) view.settings().set('word_wrap', False) view.settings().set('command_mode', True) return view
Example #14
Source File: bbcode.py From SublimeKSP with GNU General Public License v3.0 | 6 votes |
def run(self, *args, **kwargs): view = sublime.active_window().active_view() #settings = sublime.load_settings('KSP.sublime-settings') #scheme_file = settings.get('color_scheme', 'Packages/SublimeKSP/KScript Light.tmTheme') scheme_file = 'Packages/SublimeKSP/KScript Light.tmTheme' plist = readPlistFromBytes(sublime.load_binary_resource(scheme_file)) result = ['[pre]'] start, end = view.sel()[0].a, view.sel()[0].b if start == end: start, end = 0, view.size() for a, b, scopes in get_ranges(view.scope_name(i) for i in range(start, end)): result.append(self.apply_style(scopes, plist, view.substr(sublime.Region(start+a, start+b)))) result.append('[/pre]') sublime.set_clipboard(''.join(result))
Example #15
Source File: TodoReview.py From SublimeTodoReview with MIT License | 6 votes |
def draw_results(self): data = [x[:] for x in [[]] * 2] for patt, items in self.sorted: items = list(items) res = '\n## %t (%n)\n' \ .replace('%t', patt.upper()) \ .replace('%n', str(len(items))) self.rview.insert(self.edit, self.rview.size(), res) for idx, item in enumerate(items, 1): line = '%i. %f' \ .replace('%i', str(idx)) \ .replace('%f', self.draw_file(item)) res = '%f%s%n\n' \ .replace('%f', line) \ .replace('%s', ' '*max((self.largest - len(line)), 1)) \ .replace('%n', item['note']) start = self.rview.size() self.rview.insert(self.edit, start, res) region = sublime.Region(start, self.rview.size()) data[0].append(region) data[1].append(item) self.rview.add_regions('results', data[0], '') d = dict(('{0},{1}'.format(k.a, k.b), v) for k, v in zip(data[0], data[1])) self.rview.settings().set('review_results', d)
Example #16
Source File: common.py From SublimeFileBrowser with MIT License | 6 votes |
def move(self, forward=None): """ Moves the cursor one line forward or backwards. Clears all sections. """ assert forward in (True, False), 'forward must be set to True or False' files = self.fileregion(with_parent_link=True) if not files: return new_sels = [] for s in list(self.view.sel()): new_sels.append(self._get_name_point(self.next_line(forward, s.a, files))) self.view.sel().clear() for n in new_sels: self.view.sel().add(Region(n, n)) name_point = new_sels[~0] if forward else new_sels[0] surroundings = True if self.view.rowcol(name_point)[0] < 3 else False self.view.show(name_point, surroundings)
Example #17
Source File: tern.py From PhaserSublimePackage with MIT License | 5 votes |
def ensure_completions_cached(pfile, view): pos = view.sel()[0].b if pfile.cached_completions is not None: c_start, c_word, c_completions = pfile.cached_completions if c_start <= pos: slice = view.substr(sublime.Region(c_start, pos)) if slice.startswith(c_word) and not re.match(".*\\W", slice): return (c_completions, False) data = run_command(view, {"type": "completions", "types": True, "includeKeywords": True}) if data is None: return (None, False) completions = [] completions_arity = [] for rec in data["completions"]: rec_name = rec.get('name').replace('$', '\\$') rec_type = rec.get("type", None) if completion_icon(rec_type) == " (fn)": if arg_completion_enabled: arguments = get_arguments(rec_type) fn_name = rec_name + "(" + create_arg_str(arguments) + ")" completions.append((rec.get("name") + fn_completion_icon(arguments), fn_name)) # Modified by Arian # # do not add a method for each parameter, else one method with all of them # #for i in range(len(arguments) - 1, -1, -1): # fn_name = rec_name + "(" + create_arg_str(arguments[0:i]) + ")" # completions_arity.append((rec.get("name") + fn_completion_icon(arguments[0:i]), fn_name)) else: completions.append((rec.get("name") + completion_icon(rec_type), rec_name + "(${1})")) else: completions.append((rec.get("name") + completion_icon(rec_type), rec_name)) # put the auto completions of functions with lower arity at the bottom of the autocomplete list # so they don't clog up the autocompeltions at the top of the list completions = completions + completions_arity pfile.cached_completions = (data["start"], view.substr(sublime.Region(data["start"], pos)), completions) return (completions, True)
Example #18
Source File: diffy.py From diffy with MIT License | 5 votes |
def get_entire_content(self, view): selection = sublime.Region(0, view.size()) content = view.substr(selection) return content
Example #19
Source File: command_replace_region.py From FuzzyFilePath with Do What The F*ck You Want To Public License | 5 votes |
def move_skip(self, point): length = 0 word_region = self.view.word(point) line_region = self.view.line(point) post_region = sublime.Region(word_region.b, line_region.b) post = self.view.substr(post_region) to_move = re.search(settings.get("POST_INSERT_MOVE_CHARACTERS"), post) if to_move: length = len(to_move.group(0)) self.move_cursor(point + length)
Example #20
Source File: command_replace_region.py From FuzzyFilePath with Do What The F*ck You Want To Public License | 5 votes |
def run(self, edit, a, b, string, move_cursor=False): if settings.get("DISABLE_KEYMAP_ACTIONS") is True: return False self.view.replace(edit, sublime.Region(a, b), string) if move_cursor and settings.get("POST_INSERT_MOVE_CHARACTERS"): self.move_skip(a + len(string))
Example #21
Source File: TodoReview.py From SublimeTodoReview with MIT License | 5 votes |
def extract(self, files): encoding = settings.get('encoding', 'utf-8') for p in files: try: if p in self.open_files: for view in self.open: if view.file_name() == p: f = [] lines = view.lines(sublime.Region(0, view.size())) for line in lines: f.append(view.substr(line)) break else: f = io.open(p, 'r', encoding=encoding) for num, line in enumerate(f, 1): for result in self.patterns.finditer(line): for patt, note in result.groupdict().items(): if not note and note != '': continue priority_match = self.priority.search(note) if(priority_match): priority = int(priority_match.group(1)) else: priority = 50 yield { 'file': p, 'patt': patt, 'note': note, 'line': num, 'priority': priority } except(IOError, UnicodeDecodeError): f = None finally: thread.increment() if f is not None and type(f) is not list: f.close()
Example #22
Source File: selection_utility.py From network_tech with Apache License 2.0 | 5 votes |
def _get_word_on_cursor(cls, view, point): if isinstance(point, sublime.Region): point = point.end() return view.word(point)
Example #23
Source File: GlueSidebarOpener.py From glue with MIT License | 5 votes |
def go_to_end(self): line, row = self.window.active_view().rowcol(self.window.active_view().size()) pt = self.window.active_view().text_point(line, 0) self.window.active_view().sel().clear() self.window.active_view().sel().add(sublime.Region(pt)) self.window.active_view().show(pt)
Example #24
Source File: tern.py From PhaserSublimePackage with MIT License | 5 votes |
def run(self, edit, **args): data = run_command(self.view, "refs", fragments=False) if data is None: return file = relative_file(get_pfile(self.view)) shown_error = False regions = [] for ref in data["refs"]: if ref["file"] != file: if not shown_error: sublime.error_message("Not all uses of this variable are file-local. Selecting only local ones.") shown_error = True else: regions.append(sublime.Region(ref["start"], ref["end"])) self.view.sel().clear() for r in regions: self.view.sel().add(r)
Example #25
Source File: main_metadata.py From SalesforceXyTools with Apache License 2.0 | 5 votes |
def _updateLux(self): body = self.view.substr(sublime.Region(0, self.view.size())) tooling_api = util.sf_login(self.sf_basic_config, Soap_Type=ToolingApi) status_code, result = tooling_api.updateLux(self.meta_attr["id"], {"Source" : body}) if status_code > 300: self.sublconsole.showlog(result, type="error") else: self.metadata_util.update_metadata_cache(self.file_name, self.meta_attr["id"]) self.sublconsole.showlog("update metadata done: Id=%s, Name=%s, Type=%s." % (self.meta_attr["id"], self.meta_attr["file_name"], self.meta_attr["type"])) # apex, visualforce, trigger, component update
Example #26
Source File: standard-format.py From sublime-standard-format with MIT License | 5 votes |
def run(self, edit): # Figure out if the desired formatter is available command = get_command(settings.get("commands")) if platform == "windows" and command is not None: # Windows hax command[0] = shutil.which(command[0], path=local_path) if not command: # Noop if we don't have the right tools. return None view = self.view view_syntax = view.settings().get('syntax', '') if view_syntax: match = SYNTAX_RE.search(view_syntax) if match: view_syntax = match.group(1).lower() else: view_syntax = '' if view_syntax and view_syntax in settings.get('extensions', []): selectors = settings.get("selectors") selector = selectors[view_syntax] else: selector = None os.chdir(os.path.dirname(view.file_name())) regions = [] # sel = view.sel() if selector: regions = view.find_by_selector(selector) else: allreg = sublime.Region(0, view.size()) regions.append(allreg) for region in regions: self.do_format(edit, region, view, command)
Example #27
Source File: tern.py From PhaserSublimePackage with MIT License | 5 votes |
def view_js_text(view): text, pos = ("", 0) for region in view.find_by_selector("source.js"): if region.a > pos: text += ";" + re.sub(r'[^\n]', " ", view.substr(sublime.Region(pos + 1, region.a))) text += view.substr(region) pos = region.b return text
Example #28
Source File: main_metadata.py From SalesforceXyTools with Apache License 2.0 | 5 votes |
def _update_meta_to_server(self): body = self.view.substr(sublime.Region(0, self.view.size())) tooling_api = util.sf_login(self.sf_basic_config, Soap_Type=ToolingApi) result = tooling_api.updateMetadata(self.meta_attr["type"], self.meta_attr["id"], body) self.sublconsole.showlog(result) if not result["is_success"]: self._show_err_popuo(result) else: self.metadata_util.update_metadata_cache(self.file_name, self.meta_attr["id"]) self.sublconsole.showlog("update metadata done: Id=%s, Name=%s, Type=%s." % (self.meta_attr["id"], self.meta_attr["file_name"], self.meta_attr["type"]))
Example #29
Source File: main_metadata.py From SalesforceXyTools with Apache License 2.0 | 5 votes |
def is_enabled(self): file_name = self.view.file_name() if file_name is None: return False contents = self.view.substr(sublime.Region(0, self.view.size())) check = os.path.isfile(file_name) and \ file_name.find(".cls") > -1 and \ (( contents.find("@isTest") > -1 ) or \ ( contents.find("testMethod") > -1 ) ) return check
Example #30
Source File: main.py From SalesforceXyTools with Apache License 2.0 | 5 votes |
def run(self, edit): try: self.sf_basic_config = SfBasicConfig() self.settings = self.sf_basic_config.get_setting() self.sublconsole = SublConsole(self.sf_basic_config) file_name = self.view.file_name() if file_name is None: return check = os.path.isfile(file_name) and ( file_name.find(".cls") > -1 ) if not check: self.sublconsole.show_in_dialog('Error file type! Please select a cls file.') return sel_string = self.view.substr(sublime.Region(0, self.view.size())) test_code,sfdc_name_map = codecreator.get_testclass(sel_string) # self.sublconsole.show_in_new_tab(test_code) is_open = True file_name = sfdc_name_map['test_class_file'] save_dir = os.path.join(self.sf_basic_config.get_sfdc_module_dir(), "code-creator-test", "src", "classes") self.sublconsole.save_and_open_in_panel(test_code, save_dir, file_name, is_open) except Exception as e: self.sublconsole.showlog(e) return