Example #1
0
    def is_global_folded(self):
        """Check if all headlines are folded.
        """
        region, level = headline.find_headline(self.view, 0, \
                                               headline.ANY_LEVEL, True)
        # Treating no heeadline as folded, since unfolded all makes
        # no harm in this situation.
        if is_region_void(region):
            return True

        point = region.a
        # point can be zero
        while (point is not None and region):
            region = headline.region_of_content_of_headline_at_point(self.view, \
                                                                     point)
            if not is_region_void(region):
                point = region.b
            if not self.is_region_totally_folded(region):
                return False
            else:
                region, level = headline.find_headline(self.view, point, \
                                                       headline.ANY_LEVEL, \
                                                       True,
                                                       skip_headline_at_point=True)
                if not is_region_void(region):
                    point = region.a
        return True
Example #2
0
    def is_global_folded(self):
        """Check if all headlines are folded.
        """
        region, level = headline.find_headline(self.view, 0, \
                                               headline.ANY_LEVEL, True)
        # Treating no heeadline as folded, since unfolded all makes
        # no harm in this situation.
        if is_region_void(region):
            return True

        point = region.a
        # point can be zero
        while (point is not None and region):
            region = headline.region_of_content_of_headline_at_point(self.view, \
                                                                     point)
            if not is_region_void(region):
                point = region.b
            if not self.is_region_totally_folded(region):
                return False
            else:
                region, level = headline.find_headline(self.view, point, \
                                                       headline.ANY_LEVEL, \
                                                       True,
                                                       skip_headline_at_point=True)
                if not is_region_void(region):
                    point = region.a
        return True
Example #3
0
    def run(self, edit, forward=True, same_level=True):
        """Move between headlines, forward or backward.

        If same_level is true, only move to headline with the same level
        or higher level.

        """
        new_sel = []
        if same_level:
            level_type = headline.MATCH_PARENT
        else:
            level_type = headline.MATCH_ANY

        for region in self.view.sel():
            if same_level:
                _, level = headline.headline_and_level_at_point(self.view, region.a, search_above_and_down=True)
            else:
                level = headline.ANY_LEVEL

            match_region, _ = headline.find_headline(
                self.view, region.a, level, forward, level_type, skip_headline_at_point=True, skip_folded=True
            )
            if forward:
                if not match_region:
                    size = self.view.size()
                    match_region = sublime.Region(size, size)
            else:
                if not match_region:
                    match_region = sublime.Region(0, 0)
            new_sel.append(sublime.Region(match_region.a, match_region.a))

        self.adjust_view(new_sel)
Example #4
0
    def unfold_yet_fold_subheads(self, region, level):
        """Unfold the region while keeping the subheadlines folded."""
        ## First unfold all
        self.view.unfold(region)
        ## Fold subheads
        child_headline_region, _ = headline.find_headline(self.view, region.a, level, True, \
                                                          headline.MATCH_CHILD)

        while (not is_region_void(child_headline_region) and child_headline_region.b <= region.b):
            child_content_region = headline.region_of_content_of_headline_at_point(self.view,
                                                                                   child_headline_region.a)
            if child_content_region is not None:
                self.view.fold(sublime.Region(child_content_region.a - 1, child_content_region.b))
                search_start_point = child_content_region.b
            else:
                search_start_point = child_headline_region.b

            child_headline_region, _ = headline.find_headline(self.view, \
                                                              search_start_point, level, True, \
                                                              headline.MATCH_CHILD,
                                                              skip_headline_at_point=True)
Example #5
0
    def unfold_yet_fold_subheads(self, region, level):
        """Unfold the region while remembering folded subheadlines. """
        ## First unfold all
        self.view.unfold(region)
        ## Fold subheads
        child_headline_region, _ = headline.find_headline(self.view, region.a, level, True, \
                                                          headline.MATCH_CHILD)

        while (child_headline_region is not None and child_headline_region.b <= region.b):
            child_content_region = headline.region_of_content_of_headline_at_point(self.view,
                                                                                   child_headline_region.a)
            if child_content_region is not None:
                self.view.fold(child_content_region)
                search_start_point = child_content_region.b
            else:
                search_start_point = child_headline_region.b

            child_headline_region, _ = headline.find_headline(self.view, \
                                                              search_start_point, level, True, \
                                                              headline.MATCH_CHILD,
                                                              skip_headline_at_point=True)
    def unfold_yet_fold_subheads(self, region, level):
        """Unfold the region while keeping the subheadlines folded."""
        ## First unfold all
        self.view.unfold(region)
        ## Fold subheads
        child_headline_region, _ = headline.find_headline(self.view, region.a, level, True, \
                                                          headline.MATCH_CHILD)

        while (child_headline_region is not None
               and child_headline_region.b <= region.b):
            child_content_region = headline.region_of_content_of_headline_at_point(
                self.view, child_headline_region.a)
            if child_content_region is not None:
                self.view.fold(child_content_region)
                search_start_point = child_content_region.b
            else:
                search_start_point = child_headline_region.b

            child_headline_region, _ = headline.find_headline(self.view, \
                                                              search_start_point, level, True, \
                                                              headline.MATCH_CHILD,
                                                              skip_headline_at_point=True)
Example #7
0
    def fold_all(self):
        region, level = headline.find_headline(self.view, \
                                               0, \
                                               headline.ANY_LEVEL, \
                                               True)

        # At this point, headline region is sure to exist, otherwise it would be
        # treated as gobal folded. (self.is_global_folded() would return True)
        point = region.a
        # point can be zero
        while (point is not None and region):
            region = headline.region_of_content_of_headline_at_point(self.view, \
                                                                     point)
            if not is_region_void(region):
                point = region.b
                self.view.fold(sublime.Region(region.a - 1, region.b))
            region, level = headline.find_headline(self.view, point, \
                                                   headline.ANY_LEVEL,
                                                   True, \
                                                   skip_headline_at_point=True)
            if not is_region_void(region):
                point = region.a
        self.adjust_cursors_and_view()
Example #8
0
    def fold_all(self):
        region, level = headline.find_headline(self.view, \
                                               0, \
                                               headline.ANY_LEVEL, \
                                               True)

        # At this point, headline region is sure to exist, otherwise it would be
        # treated as gobal folded. (self.is_global_folded() would return True)
        point = region.a
        # point can be zero
        while (point is not None and region):
            region = headline.region_of_content_of_headline_at_point(self.view, \
                                                                     point)
            if not is_region_void(region):
                point = region.b
                self.view.fold(sublime.Region(region.a - 1, region.b))
            region, level = headline.find_headline(self.view, point, \
                                                   headline.ANY_LEVEL,
                                                   True, \
                                                   skip_headline_at_point=True)
            if not is_region_void(region):
                point = region.a
        self.adjust_cursors_and_view()
    def run(self, edit, forward=True, same_level=True):
        """Move between headlines, forward or backward.

        If same_level is true, only move to headline with the same level
        or higher level.

        """
        new_sel = []
        if same_level:
            level_type = headline.MATCH_PARENT
        else:
            level_type = headline.MATCH_ANY

        for region in self.view.sel():
            if same_level:
                _, level = headline.headline_and_level_at_point(self.view,\
                                                                region.a,
                                                                search_above_and_down=True)
            else:
                level = headline.ANY_LEVEL

            match_region, _ = headline.find_headline(self.view, \
                                                     region.a, \
                                                     level, \
                                                     forward, \
                                                     level_type, \
                                                     skip_headline_at_point=True,\
                                                     skip_folded=True)
            if forward:
                if not match_region:
                    size = self.view.size()
                    match_region = sublime.Region(size, size)
            else:
                if not match_region:
                    match_region = sublime.Region(0, 0)
            new_sel.append(sublime.Region(match_region.a, match_region.a))

        self.adjust_view(new_sel)
Example #10
0
    def run(self, edit, forward=True, same_level=True):
        """Move between headlines, forward or backward.

        If same_level is true, only move to headline with the same level
        or higher level.

        """
        new_sel = []
        if same_level:
            level_type = headline.MATCH_PARENT
        else:
            level_type = headline.MATCH_ANY

        for region in self.view.sel():
            if same_level:
                _, level = headline.headline_and_level_at_point(self.view,\
                                                                region.a,
                                                                search_above_and_down=True)
                if level is None:
                    return
            else:
                level = headline.ANY_LEVEL

            match_region, _ = headline.find_headline(self.view, \
                                                     region.a, \
                                                     level, \
                                                     forward, \
                                                     level_type, \
                                                     skip_headline_at_point=True,\
                                                     skip_folded=True)

            if is_region_void(match_region):
                return
            new_sel.append(sublime.Region(match_region.a, match_region.a))

        self.adjust_view(new_sel)