parameters: (self)
return_statement: return outPara
docstring: Reflow the current paragraph, respecting the paragraph lead and
          hanging indentation levels.
  
          The algorithm also respects trailing '+' signs that indicate embedded newlines,
          and will not reflow a very long word immediately after a bullet point.
  
          Just return the paragraph unchanged if the -noflow argument was
          given.
docstring_summary: Reflow the current paragraph, respecting the paragraph lead and
          hanging indentation levels.
docstring_tokens: Reflow the current paragraph respecting the paragraph lead and hanging indentation levels .
function: def reflowPara(self):
          """Reflow the current paragraph, respecting the paragraph lead and
          hanging indentation levels.
  
          The algorithm also respects trailing '+' signs that indicate embedded newlines,
          and will not reflow a very long word immediately after a bullet point.
  
          Just return the paragraph unchanged if the -noflow argument was
          given."""
          if not self.reflow:
              return self.para
  
          logDiag('reflowPara lead indent = ', self.leadIndent,
                  'hangIndent =', self.hangIndent,
                  'para:', self.para[0], end='')
  
          # Total words processed (we care about the *first* word vs. others)
          wordCount = 0
  
          # Tracks the *previous* word processed. It must not be empty.
          prevWord = ' '
  
          # Track the previous line and paragraph being indented, if any
          outLine = None
          outPara = []
  
          for line in self.para:
              line = line.rstrip()
              words = line.split()
  
              # logDiag('reflowPara: input line =', line)
              numWords = len(words) - 1
  
              for i in range(0, numWords + 1):
                  word = words[i]
                  wordLen = len(word)
                  wordCount += 1
  
                  endEscape = False
                  if i == numWords and word == '+':
                      # Trailing ' +' must stay on the same line
                      endEscape = word
                      # logDiag('reflowPara last word of line =', word, 'prevWord =', prevWord, 'endEscape =', endEscape)
                  else:
                      pass
                      # logDiag('reflowPara wordCount =', wordCount, 'word =', word, 'prevWord =', prevWord)
  
                  if wordCount == 1:
                      # The first word of the paragraph is treated specially.
                      # The loop logic becomes trickier if all this code is
                      # done prior to looping over lines and words, so all the
                      # setup logic is done here.
  
                      outPara = []
                      outLine = ''.ljust(self.leadIndent) + word
                      outLineLen = self.leadIndent + wordLen
  
                      # If the paragraph begins with a bullet point, generate
                      # a hanging indent level if there is not one already.
                      if beginBullet.match(self.para[0]):
                          bulletPoint = True
                          if len(self.para) > 1:
                              logDiag('reflowPara first line matches bullet point',
                                      'but indent already hanging @ input line',
                                      self.lineNumber)
                          else:
                              logDiag('reflowPara first line matches bullet point -'
                                      'single line, assuming hangIndent @ input line',
                                      self.lineNumber)
                              self.hangIndent = outLineLen + 1
                      else:
                          bulletPoint = False
                  else:
                      # Possible actions to take with this word
                      #
                      # addWord - add word to current line
                      # closeLine - append line and start a new (null) one
                      # startLine - add word to a new line
  
                      # Default behavior if all the tests below fail is to add
                      # this word to the current line, and keep accumulating
                      # that line.
                      (addWord, closeLine, startLine) = (True, False, False)
  
                      # How long would this line be if the word were added?
                      newLen = outLineLen + 1 + wordLen
  
                      # Are we on the first word following a bullet point?
                      firstBullet = (wordCount == 2 and bulletPoint)
  
                      if endEscape:
                          # If the new word ends the input line with ' +',
                          # add it to the current line.
  
                          (addWord, closeLine, startLine) = (True, True, False)
                      elif self.vuidAnchor(word):
                          # If the new word is a Valid Usage anchor, break the
                          # line afterwards. Note that this should only happen
                          # immediately after a bullet point, but we do not
                          # currently check for this.
                          (addWord, closeLine, startLine) = (True, True, False)
                      elif newLen > self.margin:
                          if firstBullet:
                              # If the word follows a bullet point, add it to
                              # the current line no matter its length.
  
                              (addWord, closeLine, startLine) = (True, True, False)
                          elif beginBullet.match(word + ' '):
                              # If the word *is* a bullet point, add it to
                              # the current line no matter its length.
                              # This avoids an innocent inline '-' or '*'
                              # turning into a bogus bullet point.
  
                              (addWord, closeLine, startLine) = (True, True, False)
                          else:
                              # The word overflows, so add it to a new line.
  
                              (addWord, closeLine, startLine) = (False, True, True)
                      elif (self.breakPeriod and
                            (wordCount > 2 or not firstBullet) and
                            self.endSentence(prevWord)):
                          # If the previous word ends a sentence and
                          # breakPeriod is set, start a new line.
                          # The complicated logic allows for leading bullet
                          # points which are periods (implicitly numbered lists).
                          # @@@ But not yet for explicitly numbered lists.
  
                          (addWord, closeLine, startLine) = (False, True, True)
  
                      # Add a word to the current line
                      if addWord:
                          if outLine:
                              outLine += ' ' + word
                              outLineLen = newLen
                          else:
                              # Fall through to startLine case if there is no
                              # current line yet.
                              startLine = True
  
                      # Add current line to the output paragraph. Force
                      # starting a new line, although we do not yet know if it
                      # will ever have contents.
                      if closeLine:
                          if outLine:
                              outPara.append(outLine + '\n')
                              outLine = None
  
                      # Start a new line and add a word to it
                      if startLine:
                          outLine = ''.ljust(self.hangIndent) + word
                          outLineLen = self.hangIndent + wordLen
  
                  # Track the previous word, for use in breaking at end of
                  # a sentence
                  prevWord = word
  
          # Add this line to the output paragraph.
          if outLine:
              outPara.append(outLine + '\n')
  
          return outPara
function_tokens: def reflowPara ( self ) : if not self . reflow : return self . para logDiag ( 'reflowPara lead indent = ' , self . leadIndent , 'hangIndent =' , self . hangIndent , 'para:' , self . para [ 0 ] , end = '' ) # Total words processed (we care about the *first* word vs. others) wordCount = 0 # Tracks the *previous* word processed. It must not be empty. prevWord = ' ' # Track the previous line and paragraph being indented, if any outLine = None outPara = [ ] for line in self . para : line = line . rstrip ( ) words = line . split ( ) # logDiag('reflowPara: input line =', line) numWords = len ( words ) - 1 for i in range ( 0 , numWords + 1 ) : word = words [ i ] wordLen = len ( word ) wordCount += 1 endEscape = False if i == numWords and word == '+' : # Trailing ' +' must stay on the same line endEscape = word # logDiag('reflowPara last word of line =', word, 'prevWord =', prevWord, 'endEscape =', endEscape) else : pass # logDiag('reflowPara wordCount =', wordCount, 'word =', word, 'prevWord =', prevWord) if wordCount == 1 : # The first word of the paragraph is treated specially. # The loop logic becomes trickier if all this code is # done prior to looping over lines and words, so all the # setup logic is done here. outPara = [ ] outLine = '' . ljust ( self . leadIndent ) + word outLineLen = self . leadIndent + wordLen # If the paragraph begins with a bullet point, generate # a hanging indent level if there is not one already. if beginBullet . match ( self . para [ 0 ] ) : bulletPoint = True if len ( self . para ) > 1 : logDiag ( 'reflowPara first line matches bullet point' , 'but indent already hanging @ input line' , self . lineNumber ) else : logDiag ( 'reflowPara first line matches bullet point -' 'single line, assuming hangIndent @ input line' , self . lineNumber ) self . hangIndent = outLineLen + 1 else : bulletPoint = False else : # Possible actions to take with this word # # addWord - add word to current line # closeLine - append line and start a new (null) one # startLine - add word to a new line # Default behavior if all the tests below fail is to add # this word to the current line, and keep accumulating # that line. ( addWord , closeLine , startLine ) = ( True , False , False ) # How long would this line be if the word were added? newLen = outLineLen + 1 + wordLen # Are we on the first word following a bullet point? firstBullet = ( wordCount == 2 and bulletPoint ) if endEscape : # If the new word ends the input line with ' +', # add it to the current line. ( addWord , closeLine , startLine ) = ( True , True , False ) elif self . vuidAnchor ( word ) : # If the new word is a Valid Usage anchor, break the # line afterwards. Note that this should only happen # immediately after a bullet point, but we do not # currently check for this. ( addWord , closeLine , startLine ) = ( True , True , False ) elif newLen > self . margin : if firstBullet : # If the word follows a bullet point, add it to # the current line no matter its length. ( addWord , closeLine , startLine ) = ( True , True , False ) elif beginBullet . match ( word + ' ' ) : # If the word *is* a bullet point, add it to # the current line no matter its length. # This avoids an innocent inline '-' or '*' # turning into a bogus bullet point. ( addWord , closeLine , startLine ) = ( True , True , False ) else : # The word overflows, so add it to a new line. ( addWord , closeLine , startLine ) = ( False , True , True ) elif ( self . breakPeriod and ( wordCount > 2 or not firstBullet ) and self . endSentence ( prevWord ) ) : # If the previous word ends a sentence and # breakPeriod is set, start a new line. # The complicated logic allows for leading bullet # points which are periods (implicitly numbered lists). # @@@ But not yet for explicitly numbered lists. ( addWord , closeLine , startLine ) = ( False , True , True ) # Add a word to the current line if addWord : if outLine : outLine += ' ' + word outLineLen = newLen else : # Fall through to startLine case if there is no # current line yet. startLine = True # Add current line to the output paragraph. Force # starting a new line, although we do not yet know if it # will ever have contents. if closeLine : if outLine : outPara . append ( outLine + '\n' ) outLine = None # Start a new line and add a word to it if startLine : outLine = '' . ljust ( self . hangIndent ) + word outLineLen = self . hangIndent + wordLen # Track the previous word, for use in breaking at end of # a sentence prevWord = word # Add this line to the output paragraph. if outLine : outPara . append ( outLine + '\n' ) return outPara