当前位置: 首页>>代码示例>>Python>>正文


Python sublime.Region方法代码示例

本文整理汇总了Python中sublime.Region方法的典型用法代码示例。如果您正苦于以下问题:Python sublime.Region方法的具体用法?Python sublime.Region怎么用?Python sublime.Region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sublime的用法示例。


在下文中一共展示了sublime.Region方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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)) 
开发者ID:nojanath,项目名称:SublimeKSP,代码行数:18,代码来源:bbcode.py

示例2: _handle_apply_patches

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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 
开发者ID:typeintandem,项目名称:tandem,代码行数:27,代码来源:tandem.py

示例3: move

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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)) 
开发者ID:kublaios,项目名称:dired,代码行数:26,代码来源:common.py

示例4: _update_line_content

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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) 
开发者ID:Wramberg,项目名称:TerminalView,代码行数:25,代码来源:sublime_terminal_buffer.py

示例5: _update_line_colors

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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) 
开发者ID:Wramberg,项目名称:TerminalView,代码行数:25,代码来源:sublime_terminal_buffer.py

示例6: vcs_colorized

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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) 
开发者ID:aziz,项目名称:SublimeFileBrowser,代码行数:27,代码来源:dired_misc.py

示例7: run

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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}) 
开发者ID:aziz,项目名称:SublimeFileBrowser,代码行数:25,代码来源:dired_file_operations.py

示例8: move

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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) 
开发者ID:aziz,项目名称:SublimeFileBrowser,代码行数:22,代码来源:common.py

示例9: _add_sels

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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) 
开发者ID:aziz,项目名称:SublimeFileBrowser,代码行数:19,代码来源:common.py

示例10: buffer_fragment

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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)) 
开发者ID:PhaserEditor2D,项目名称:PhaserSublimePackage,代码行数:25,代码来源:tern.py

示例11: locate_call

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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) 
开发者ID:PhaserEditor2D,项目名称:PhaserSublimePackage,代码行数:20,代码来源:tern.py

示例12: _expand_words

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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) 
开发者ID:heyglen,项目名称:network_tech,代码行数:19,代码来源:selection_utility.py

示例13: scan

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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 
开发者ID:ggordan,项目名称:GutterColor,代码行数:20,代码来源:file.py

示例14: run

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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()) 
开发者ID:dvcrn,项目名称:sublimious,代码行数:25,代码来源:commands.py

示例15: get_view

# 需要导入模块: import sublime [as 别名]
# 或者: from sublime import Region [as 别名]
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 
开发者ID:jonathanrdelgado,项目名称:SublimeTodoReview,代码行数:21,代码来源:TodoReview.py


注:本文中的sublime.Region方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。