Ejemplo n.º 1
0
  def run(self, edit, language="", undo=False, debug=True):
    view = self.view

    if (undo):
      string = view.substr(sublime.Region(0, view.size()))
      start = view.sel()[0].begin()
      end = view.sel()[0].end()
      result = expand_region_handler.undo(string, start, end, view.settings())
      if (result):
        view.sel().clear()
        view.sel().add(sublime.Region(result["start"], result["end"]))
      return

    if not language:
      language = (_detect_language(view, "ExpandRegion") or
                  _detect_language(view, "ExpandRegionFallback"))
    if debug:
      print("Determined language: '{0}'".format(language))

    for region in view.sel():
      string = view.substr(sublime.Region(0, view.size()))
      start = region.begin()
      end = region.end()

      result = expand_region_handler.expand(string, start, end, language, view.settings())
      if result:
        view.sel().add(sublime.Region(result["start"], result["end"]))
        if debug:
          print("startIndex: {0}, endIndex: {1}, type: {2}".format(result["start"], result["end"], result["type"]))
  def run(self, edit, undo=False, debug=True):

    if (undo):
      string = self.view.substr(sublime.Region(0, self.view.size()))
      start = self.view.sel()[0].begin()
      end = self.view.sel()[0].end()
      result = expand_region_handler.undo(string, start, end, self.view.settings())
      if (result):
        self.view.sel().clear()
        self.view.sel().add(sublime.Region(result["start"], result["end"]))
      return

    extension = ""
    if (self.view.file_name()):
      name, fileex = os.path.splitext(self.view.file_name())
      extension = fileex[1:]

    for region in self.view.sel():
      string = self.view.substr(sublime.Region(0, self.view.size()))
      start = region.begin()
      end = region.end()

      result = expand_region_handler.expand(string, start, end, extension, self.view.settings())
      if result:
        self.view.sel().add(sublime.Region(result["start"], result["end"]))
        if debug:
          print("startIndex: {0}, endIndex: {1}, type: {2}".format(result["start"], result["end"], result["type"]))
Ejemplo n.º 3
0
    def run(self, edit, language="", undo=False, debug=True):
        view = self.view
        utils.is_debug_enabled = debug

        if (undo):
            string = view.substr(sublime.Region(0, view.size()))
            start = view.sel()[0].begin()
            end = view.sel()[0].end()
            result = expand_region_handler.undo(string, start, end,
                                                view.settings())
            if (result):
                view.sel().clear()
                view.sel().add(sublime.Region(result["start"], result["end"]))
            return

        if not language:
            language = (_detect_language(view, "ExpandRegion")
                        or _detect_language(view, "ExpandRegionFallback"))
        if debug:
            print("ExpandRegion, ExpandRegion.py, Determined language: '{0}'".
                  format(language))

        new_regions = []
        is_region_expanded = True
        for region in self.view.sel():
            string = self.view.substr(sublime.Region(0, self.view.size()))
            start = region.begin()
            end = region.end()

            result = expand_region_handler.expand(string, start, end, language,
                                                  self.view.settings())
            if result:
                new_regions.append(
                    sublime.Region(result["start"], result["end"]))
                if debug:
                    print(
                        "ExpandRegion, ExpandRegion.py, startIndex: {0}, endIndex: {1}, type: {2}"
                        .format(result["start"], result["end"],
                                result["type"]))
            else:
                # if there is no result, call the built-in sublime text expand_selection to scope command
                is_region_expanded = False

        if is_region_expanded:
            # replace the selections with the new regions
            view.sel().clear()
            for sel in new_regions:
                view.sel().add(sel)

            settings = sublime.load_settings("ExpandRegion.sublime-settings")
            do_force_enable_soft_undo = settings.get(
                "force_soft_undo_integration")
            if do_force_enable_soft_undo:
                _force_enable_soft_undo(view, edit, new_regions)
        else:
            if debug:
                print(
                    "ExpandRegion, ExpandRegion.py, calling Sublime Text expand_selection to scope..."
                )
            view.run_command("expand_selection", {"to": "scope"})
Ejemplo n.º 4
0
    def run(self, edit, language="", undo=False, debug=True):
        view = self.view

        if (undo):
            string = view.substr(sublime.Region(0, view.size()))
            start = view.sel()[0].begin()
            end = view.sel()[0].end()
            result = expand_region_handler.undo(string, start, end,
                                                view.settings())
            if (result):
                view.sel().clear()
                view.sel().add(sublime.Region(result["start"], result["end"]))
            return

        if not language:
            language = (_detect_language(view, "ExpandRegion")
                        or _detect_language(view, "ExpandRegionFallback"))
        if debug:
            print("Determined language: '{0}'".format(language))

        new_regions = []
        for region in self.view.sel():
            string = self.view.substr(sublime.Region(0, self.view.size()))
            start = region.begin()
            end = region.end()

            result = expand_region_handler.expand(string, start, end, language,
                                                  self.view.settings())
            if result:
                new_regions.append(
                    sublime.Region(result["start"], result["end"]))
                if debug:
                    print("startIndex: {0}, endIndex: {1}, type: {2}".format(
                        result["start"], result["end"], result["type"]))
            else:
                # if there is no result, keep the current region
                new_regions.append(region)

        # replace the selections with the new regions
        view.sel().clear()
        for sel in new_regions:
            view.sel().add(sel)

        settings = sublime.load_settings("ExpandRegion.sublime-settings")
        do_force_enable_soft_undo = settings.get("force_soft_undo_integration")
        if do_force_enable_soft_undo:
            _force_enable_soft_undo(view, edit, new_regions)
Ejemplo n.º 5
0
  def run(self, edit, language="", undo=False, debug=True):
    view = self.view

    if (undo):
      string = view.substr(sublime.Region(0, view.size()))
      start = view.sel()[0].begin()
      end = view.sel()[0].end()
      result = expand_region_handler.undo(string, start, end, view.settings())
      if (result):
        view.sel().clear()
        view.sel().add(sublime.Region(result["start"], result["end"]))
      return

    if not language:
      language = (_detect_language(view, "ExpandRegion") or
                  _detect_language(view, "ExpandRegionFallback"))
    if debug:
      print("Determined language: '{0}'".format(language))

    new_regions = []
    for region in self.view.sel():
      string = self.view.substr(sublime.Region(0, self.view.size()))
      start = region.begin()
      end = region.end()

      result = expand_region_handler.expand(string, start, end, language, self.view.settings())
      if result:
        new_regions.append(sublime.Region(result["start"], result["end"]))
        if debug:
          print("startIndex: {0}, endIndex: {1}, type: {2}".format(result["start"], result["end"], result["type"]))
      else:
        # if there is no result, keep the current region
        new_regions.append(region)

    # replace the selections with the new regions
    view.sel().clear()
    for sel in new_regions:
      view.sel().add(sel)

    settings = sublime.load_settings("ExpandRegion.sublime-settings")
    do_force_enable_soft_undo = settings.get("force_soft_undo_integration")
    if do_force_enable_soft_undo:
      _force_enable_soft_undo(view, edit, new_regions)