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