我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用sublime.LITERAL。
def get_QueryRegions ( QUERY, REGEX_ENABLED, IGNORE_CASE ): if REGEX_ENABLED == True and IGNORE_CASE == True: queryRegions = V.view.find_all ( QUERY, sublime.IGNORECASE ) elif REGEX_ENABLED == True and IGNORE_CASE == False: queryRegions = V.view.find_all ( QUERY ) elif REGEX_ENABLED == False and IGNORE_CASE == True: queryRegions = V.view.find_all ( QUERY, sublime.LITERAL|sublime.IGNORECASE ) elif REGEX_ENABLED == False and IGNORE_CASE == False: queryRegions = V.view.find_all ( QUERY, sublime.LITERAL ) return ( queryRegions ) #?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¦?# #??????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????‡# #???????? { Variables } ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????c3# #??????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????‡# #?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????¦?#
def _get_match_info(self, current_region, match_word): ''' ???????? ''' index = 0 all_match_regions = self.view.find_all(match_word, sublime.LITERAL) for region in all_match_regions: if region == current_region: break index += 1 if index >= len(all_match_regions): index = len(all_match_regions) return all_match_regions, index
def run(self, edit, **args): if not self._is_current_finding: self.view.erase_regions(self.FINDING_KEY) self.view.settings().set("is_finding", False) current_region = current.wordregion(self.view) current_word = current.word(self.view) first_region = self.view.find(current_word, 0, sublime.LITERAL) self._draw_regions([current_region, first_region]) self.view.settings().set("is_finding", True) self.view.show(first_region) return visible_region = self.view.visible_region() for region in self._match_regions: if not visible_region.contains(region): self.view.show(region) return
def replace(self, edit, s, replace_what): old, new = (replace_what, '') open_, close_ = get_surround_pairs(self.view).get(old, (old, old)) if len(open_) == 1 and open_ == 't': open_, close_ = ('<.*?>', '</.*?>') next_ = self.view.find(close_, s.b) prev_ = reverse_search(self.view, open_, end=s.b, start=0) else: # brute force next_ = self.view.find(close_, s.b, sublime.LITERAL) prev_ = reverse_search(self.view, open_, end=s.b, start=0, flags=sublime.LITERAL) if not (next_ and prev_): return self.view.replace(edit, next_, new) self.view.replace(edit, prev_, new)
def calculate_flags(self): # TODO: Implement smartcase? flags = 0 if self.view.settings().get('vintageous_magic') is False: flags |= sublime.LITERAL if self.view.settings().get('vintageous_ignorecase') is True: flags |= sublime.IGNORECASE return flags
def find_balanced_closing_bracket(self, start, brackets, unbalanced=0): new_start = start for i in range(unbalanced or 1): next_closing_bracket = find_in_range(self.view, brackets[1], start=new_start, end=self.view.size(), flags=LITERAL) if next_closing_bracket is None: # Unbalanced brackets; nothing we can do. return new_start = next_closing_bracket.end() nested = 0 while True: next_opening_bracket = find_in_range(self.view, brackets[0], start=start, end=next_closing_bracket.end(), flags=LITERAL) if not next_opening_bracket: break nested += 1 start = next_opening_bracket.end() if nested > 0: return self.find_balanced_closing_bracket(next_closing_bracket.end(), brackets, nested) else: return next_closing_bracket.begin()
def find_balanced_opening_bracket(self, start, brackets, unbalanced=0): new_start = start for i in range(unbalanced or 1): prev_opening_bracket = reverse_search_by_pt(self.view, brackets[0], start=0, end=new_start, flags=LITERAL) if prev_opening_bracket is None: # Unbalanced brackets; nothing we can do. return new_start = prev_opening_bracket.begin() nested = 0 while True: next_closing_bracket = reverse_search_by_pt(self.view, brackets[1], start=prev_opening_bracket.a, end=start, flags=LITERAL) if not next_closing_bracket: break nested += 1 start = next_closing_bracket.begin() if nested > 0: return self.find_balanced_opening_bracket(prev_opening_bracket.begin(), brackets, nested) else: return prev_opening_bracket.begin()
def run(self): view = self.window.new_file() regions = view.sel() view.set_syntax_file('Packages/Chains' '/Chains.tmLanguage') view.run_command("chains") # view.run_command("highlight_today") msg_r = view.find(INITIAL_MESSAGE, 0, sublime.LITERAL) region = region_cursor_start(msg_r) regions.clear() regions.add(region)
def display_footer(self, hit_count): regions = self.whoosh_view.find_all(self.search_string, sublime.LITERAL | sublime.IGNORECASE) reg_num = len(regions) - 1 text = "\n%d matches across %d files\n" % (reg_num if reg_num >= 0 else 0, hit_count) self.whoosh_view.run_command("whoosh_view_append_text", {"text" : text, "search_string" : None})
def run(self, edit, text, search_string): start_point = self.view.size() self.view.insert(edit, start_point, text) if search_string is not None: regions = self.view.find_all(search_string, sublime.LITERAL | sublime.IGNORECASE) self.view.add_regions('whoosh_regions', regions[1:], "text.find-in-files", "", sublime.DRAW_OUTLINED)
def run(self, edit, start_point, word, replacement): region = self.view.find(word, start_point, sublime.LITERAL) if region: self.view.run_command("erase_snippet", {"start_point": region.a, "end_point": region.b }) self.view.run_command("insert_issue_snippet", {"start_point":region.a, "snippet": replacement})
def finishGoingToLocation(caller, view): # Highlight the text position = view.sel()[0].a line = view.substr(view.line(position)) view.sel().clear() view.sel().add(view.line(position)) if (caller['text'] in line): return # Find where the line might be regions = view.find_all(caller['text'], sublime.LITERAL) if not regions: return # Find the closest region to our current position closest_region = None for region in regions: if closest_region is None: closest_region = region continue if abs(region.a - closest_region.a) < abs(closest_region.a - position): closest_region = region view.show_at_center(closest_region) view.sel().clear() view.sel().add(closest_region)
def run(self, view): path = self.path window = self.view.window() names = os.listdir(path) f = [] for name in names: if isdir(join(path, name)): name += os.sep f.append(name) def on_done(select): if not select == -1 : line_str = f[select] r_list = self.view.find_all(line_str, sublime.LITERAL) # Make match whole word. if len(r_list) > 1 : for r in r_list : find_str = self.view.substr(self.view.line(r)) if find_str == line_str : break else : r = r_list[0] if self.p_key : window.run_command('dired_preview_refresh', {'path':path + line_str}) self.view.sel().clear() self.view.sel().add(r.a) self.view.show(r.a) if self.p_key : self.view.settings().set('preview_key', True) self.p_key = self.view.settings().get('preview_key') self.view.settings().set('preview_key', False) window.show_quick_panel(f, on_done)
def run(self, search_string='', mode=None, count=1): def f(view, s): if mode == modes.VISUAL: return sublime.Region(s.a, match.a + 1) elif mode == modes.INTERNAL_NORMAL: return sublime.Region(s.a, match.a) elif mode == modes.NORMAL: return sublime.Region(match.a, match.a) elif mode == modes.VISUAL_LINE: return sublime.Region(s.a, view.full_line(match.b - 1).b) return s # This happens when we attempt to repeat the search and there's no search term stored yet. if not search_string: return # We want to start searching right after the current selection. current_sel = self.view.sel()[0] start = current_sel.b if not current_sel.empty() else current_sel.b + 1 wrapped_end = self.view.size() # TODO: What should we do here? Case-sensitive or case-insensitive search? Configurable? # Search wrapping around the end of the buffer. # flags = sublime.IGNORECASE | sublime.LITERAL flags = self.calculate_flags() match = find_wrapping(self.view, search_string, start, wrapped_end, flags=flags, times=count) if not match: return regions_transformer(self.view, f) self.hilite(search_string)
def find_balanced_closing_bracket(self, start, brackets, unbalanced=0): new_start = start for i in range(unbalanced or 1): next_closing_bracket = find_in_range(self.view, brackets[1], start=new_start, end=self.view.size(), flags=sublime.LITERAL) if next_closing_bracket is None: # Unbalanced brackets; nothing we can do. return new_start = next_closing_bracket.end() nested = 0 while True: next_opening_bracket = find_in_range(self.view, brackets[0], start=start, end=next_closing_bracket.end(), flags=sublime.LITERAL) if not next_opening_bracket: break nested += 1 start = next_opening_bracket.end() if nested > 0: return self.find_balanced_closing_bracket(next_closing_bracket.end(), brackets, nested) else: return next_closing_bracket.begin()
def find_balanced_opening_bracket(self, start, brackets, unbalanced=0): new_start = start for i in range(unbalanced or 1): prev_opening_bracket = reverse_search_by_pt(self.view, brackets[0], start=0, end=new_start, flags=sublime.LITERAL) if prev_opening_bracket is None: # Unbalanced brackets; nothing we can do. return new_start = prev_opening_bracket.begin() nested = 0 while True: next_closing_bracket = reverse_search_by_pt(self.view, brackets[1], start=prev_opening_bracket.a, end=start, flags=sublime.LITERAL) if not next_closing_bracket: break nested += 1 start = next_closing_bracket.begin() if nested > 0: return self.find_balanced_opening_bracket(prev_opening_bracket.begin(), brackets, nested) else: return prev_opening_bracket.begin()
def calculate_flags(self): # TODO: Implement smartcase? flags = 0 if self.view.settings().get('vintageous_magic') == False: flags |= sublime.LITERAL if self.view.settings().get('vintageous_ignorecase') == True: flags |= sublime.IGNORECASE return flags
def set_sels(self, sels): """ Enables adding selections to the buffer text using a minilanguage: S = add empty sel before S and delete S x = add empty sel before x v = add sel from before the first 'v' to after the last contiguous 'v' """ self.view.sel().clear() self.view.sel().add_all(sels) return if test.args['mode'] in ('mode_normal', 'mode_internal_normal'): regions = self.view.find_all(r'$', sublime.LITERAL) if not regions: # TODO(guillermooo): report this? we should expect some regions return self.view.sel().add_all(regions) self.view.run_command('right_delete') return if test.args ['mode'] == 'mode_visual': visual_mode_regs = self.view.find_all(r'v+') for vmr in visual_mode_regs: self.view.sel().add(vmr) if len(self.view.sel()) > 0: return visual_mode_regs = self.view.find_all(r'S') for vmr in visual_mode_regs: self.view.sel().add(sublime.Region(vmr.a)) self.view.run_command('right_delete')
def _replace(self, edit, s, replace_what): if len(replace_what) != 2: # TODO REVIEW replace single argument with two: *target* and *replacement* # TODO REVIEW should an exception be raised, and if yes, what type of exception e.g. package, module, plugin, generic? # noqa: E501 return s target_pairs = { ')': ('(', ')'), '(': ('(', ')'), ']': ('[', ']'), '[': ('[', ']'), '}': ('{', '}'), '{': ('{', '}'), '>': ('<', '>'), } replacement_pairs = { ')': ('(', ')'), '(': ('( ', ' )'), ']': ('[', ']'), '[': ('[ ', ' ]'), '}': ('{', '}'), '{': ('{ ', ' }'), '>': ('<', '>'), } old, new = tuple(replace_what) open_, close_ = target_pairs.get(old, (old, old)) new_open, new_close = replacement_pairs.get(new, (new, new)) if len(open_) == 1 and open_ == 't': open_, close_ = ('<.*?>', '</.*?>') next_ = self.view.find(close_, s.b) prev_ = reverse_search(self.view, open_, end=s.b, start=0) else: # brute force next_ = self.view.find(close_, s.b, flags=LITERAL) prev_ = reverse_search(self.view, open_, end=s.b, start=0, flags=LITERAL) if not (next_ and prev_): return s self.view.replace(edit, next_, new_close) self.view.replace(edit, prev_, new_open) return Region(prev_.begin())
def run(self, char=None, mode=None, count=1, inclusive=True, skipping=False): # Contrary to *f*, *t* does not look past the caret's position, so if # @character is under the caret, nothing happens. def f(view, s): if mode == modes.VISUAL_LINE: raise ValueError( 'this operator is not valid in mode {}'.format(mode)) b = s.b # If we are in any visual mode, get the actual insertion point. if s.size() > 0: b = resolve_insertion_point_at_b(s) # Vim skips a character while performing the search # if the command is ';' or ',' after a 't' or 'T' if skipping: b = b + 1 eol = view.line(b).end() match = Region(b + 1) for i in range(count): # Define search range as 'rest of the line to the right'. search_range = Region(match.end(), eol) match = find_in_range(view, char, search_range.a, search_range.b, LITERAL) # Count too high or simply no match; break. if match is None: return s target_pos = match.a if not inclusive: target_pos = target_pos - 1 if mode == modes.NORMAL: return Region(target_pos) elif mode == modes.INTERNAL_NORMAL: return Region(s.a, target_pos + 1) # For visual modes... else: new_a = resolve_insertion_point_at_a(s) return utils.new_inclusive_region(new_a, target_pos) if not all([char, mode]): raise ValueError('bad parameters') char = utils.translate_char(char) regions_transformer(self.view, f)
def run(self, char=None, mode=None, count=1, inclusive=True, skipping=False): # Contrary to *f*, *t* does not look past the caret's position, so if # @character is under the caret, nothing happens. def f(view, s): if mode == modes.VISUAL_LINE: raise ValueError( 'this operator is not valid in mode {}'.format(mode)) b = s.b # If we are in any visual mode, get the actual insertion point. if s.size() > 0: b = resolve_insertion_point_at_b(s) # Vim skips a character while performing the search # if the command is ';' or ',' after a 't' or 'T' if skipping: b = b + 1 eol = view.line(b).end() match = R(b + 1) for i in range(count): # Define search range as 'rest of the line to the right'. search_range = R(match.end(), eol) match = find_in_range(view, char, search_range.a, search_range.b, sublime.LITERAL) # Count too high or simply no match; break. if match is None: return s target_pos = match.a if not inclusive: target_pos = target_pos - 1 if mode == modes.NORMAL: return R(target_pos) elif mode == modes.INTERNAL_NORMAL: return R(s.a, target_pos + 1) # For visual modes... else: new_a = resolve_insertion_point_at_a(s) return utils.new_inclusive_region(new_a, target_pos) if not all([char, mode]): raise ValueError('bad parameters') char = utils.translate_char(char) state = self.state regions_transformer(self.view, f)