##// END OF EJS Templates
minirst: unindent "if True" block in filtersections()
Yuya Nishihara -
r39342:9fe97e67 default
parent child Browse files
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 name == section:
694 if lastparents != parents:
695 if lastparents != parents:
695 llen = len(lastparents)
696 llen = len(lastparents)
696 plen = len(parents)
697 plen = len(parents)
697 if llen and llen != plen:
698 if llen and llen != plen:
698 collapse = False
699 collapse = False
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 parent = parents[j]
702 if (j >= llen or
703 if (j >= llen or
703 lastparents[j] != parent):
704 lastparents[j] != parent):
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 blocks.append(sec[0])
707 blocks.append(sec[-1])
708 blocks.append(sec[-1])
708 if s:
709 if s:
709 synthetic.append(s)
710 synthetic.append(s)
711
710
712 lastparents = parents[:]
711 lastparents = parents[:]
713 blocks.extend(b)
712 blocks.extend(b)
714
713
715 ## Also show all subnested sections
714 ## Also show all subnested sections
716 while i + 1 < len(sections) and sections[i + 1][1] > nest:
715 while i + 1 < len(sections) and sections[i + 1][1] > nest:
717 i += 1
716 i += 1
718 blocks.extend(sections[i][2])
717 blocks.extend(sections[i][2])
719 i += 1
718 i += 1
720 if collapse:
719 if collapse:
721 synthetic.reverse()
720 synthetic.reverse()
722 for s in synthetic:
721 for s in synthetic:
723 path = [blocks[syn]['lines'][0] for syn in s]
722 path = [blocks[syn]['lines'][0] for syn in s]
724 real = s[-1] + 2
723 real = s[-1] + 2
725 realline = blocks[real]['lines']
724 realline = blocks[real]['lines']
726 realline[0] = ('"%s"' %
725 realline[0] = ('"%s"' %
727 '.'.join(path + [realline[0]]).replace('"', ''))
726 '.'.join(path + [realline[0]]).replace('"', ''))
728 del blocks[s[0]:real]
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