Show More
@@ -680,52 +680,51 b' def format(text, width=80, indent=0, kee' | |||||
680 | def filtersections(blocks, section): |
|
680 | def filtersections(blocks, section): | |
681 | """Select parsed blocks under the specified section""" |
|
681 | """Select parsed blocks under the specified section""" | |
682 | parents = [] |
|
682 | parents = [] | |
683 | if True: |
|
683 | sections = getsections(blocks) | |
684 | sections = getsections(blocks) |
|
684 | blocks = [] | |
685 | blocks = [] |
|
685 | i = 0 | |
686 | i = 0 |
|
686 | lastparents = [] | |
687 | lastparents = [] |
|
687 | synthetic = [] | |
688 | synthetic = [] |
|
688 | collapse = True | |
689 | collapse = True |
|
689 | while i < len(sections): | |
690 | while i < len(sections): |
|
690 | name, nest, b = sections[i] | |
691 | name, nest, b = sections[i] |
|
691 | del parents[nest:] | |
692 | del parents[nest:] |
|
692 | parents.append(i) | |
693 | parents.append(i) |
|
693 | if name == section: | |
694 |
if |
|
694 | if lastparents != parents: | |
695 |
|
|
695 | llen = len(lastparents) | |
696 |
|
|
696 | plen = len(parents) | |
697 |
plen |
|
697 | if llen and llen != plen: | |
698 |
|
|
698 | collapse = False | |
699 |
|
|
699 | s = [] | |
700 | s = [] |
|
700 | for j in pycompat.xrange(3, plen - 1): | |
701 | for j in pycompat.xrange(3, plen - 1): |
|
701 | parent = parents[j] | |
702 |
|
|
702 | if (j >= llen or | |
703 |
|
|
703 | lastparents[j] != parent): | |
704 |
|
|
704 | s.append(len(blocks)) | |
705 | s.append(len(blocks)) |
|
705 | sec = sections[parent][2] | |
706 | sec = sections[parent][2] |
|
706 | blocks.append(sec[0]) | |
707 |
|
|
707 | blocks.append(sec[-1]) | |
708 | blocks.append(sec[-1]) |
|
708 | if s: | |
709 |
|
|
709 | synthetic.append(s) | |
710 | synthetic.append(s) |
|
|||
711 |
|
710 | |||
712 |
|
|
711 | lastparents = parents[:] | |
713 |
|
|
712 | blocks.extend(b) | |
714 |
|
713 | |||
715 |
|
|
714 | ## Also show all subnested sections | |
716 |
|
|
715 | while i + 1 < len(sections) and sections[i + 1][1] > nest: | |
717 |
|
|
716 | i += 1 | |
718 |
|
|
717 | blocks.extend(sections[i][2]) | |
719 |
|
|
718 | i += 1 | |
720 |
|
|
719 | if collapse: | |
721 |
|
|
720 | synthetic.reverse() | |
722 |
|
|
721 | for s in synthetic: | |
723 |
|
|
722 | path = [blocks[syn]['lines'][0] for syn in s] | |
724 |
|
|
723 | real = s[-1] + 2 | |
725 |
|
|
724 | realline = blocks[real]['lines'] | |
726 |
|
|
725 | realline[0] = ('"%s"' % | |
727 |
|
|
726 | '.'.join(path + [realline[0]]).replace('"', '')) | |
728 |
|
|
727 | del blocks[s[0]:real] | |
729 |
|
728 | |||
730 | return blocks |
|
729 | return blocks | |
731 |
|
730 |
General Comments 0
You need to be logged in to leave comments.
Login now