Back to index

python3.2  3.2.2
Classes | Functions
idlelib.FormatParagraph Namespace Reference

Classes

class  FormatParagraph

Functions

def find_paragraph
def reformat_paragraph
def is_all_white
def get_indent
def get_comment_header

Function Documentation

def idlelib.FormatParagraph.find_paragraph (   text,
  mark 
)

Definition at line 80 of file FormatParagraph.py.

00080 
00081 def find_paragraph(text, mark):
00082     lineno, col = map(int, mark.split("."))
00083     line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
00084     while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
00085         lineno = lineno + 1
00086         line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
00087     first_lineno = lineno
00088     comment_header = get_comment_header(line)
00089     comment_header_len = len(comment_header)
00090     while get_comment_header(line)==comment_header and \
00091               not is_all_white(line[comment_header_len:]):
00092         lineno = lineno + 1
00093         line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
00094     last = "%d.0" % lineno
00095     # Search back to beginning of paragraph
00096     lineno = first_lineno - 1
00097     line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
00098     while lineno > 0 and \
00099               get_comment_header(line)==comment_header and \
00100               not is_all_white(line[comment_header_len:]):
00101         lineno = lineno - 1
00102         line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
00103     first = "%d.0" % (lineno+1)
00104     return first, last, comment_header, text.get(first, last)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 146 of file FormatParagraph.py.

00146 
00147 def get_comment_header(line):
00148     m = re.match(r"^(\s*#*)", line)
00149     if m is None: return ""
00150     return m.group(1)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 143 of file FormatParagraph.py.

00143 
00144 def get_indent(line):
00145     return re.match(r"^(\s*)", line).group()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 140 of file FormatParagraph.py.

00140 
00141 def is_all_white(line):
00142     return re.match(r"^\s*$", line) is not None

Here is the call graph for this function:

Here is the caller graph for this function:

def idlelib.FormatParagraph.reformat_paragraph (   data,
  limit 
)

Definition at line 105 of file FormatParagraph.py.

00105 
00106 def reformat_paragraph(data, limit):
00107     lines = data.split("\n")
00108     i = 0
00109     n = len(lines)
00110     while i < n and is_all_white(lines[i]):
00111         i = i+1
00112     if i >= n:
00113         return data
00114     indent1 = get_indent(lines[i])
00115     if i+1 < n and not is_all_white(lines[i+1]):
00116         indent2 = get_indent(lines[i+1])
00117     else:
00118         indent2 = indent1
00119     new = lines[:i]
00120     partial = indent1
00121     while i < n and not is_all_white(lines[i]):
00122         # XXX Should take double space after period (etc.) into account
00123         words = re.split("(\s+)", lines[i])
00124         for j in range(0, len(words), 2):
00125             word = words[j]
00126             if not word:
00127                 continue # Can happen when line ends in whitespace
00128             if len((partial + word).expandtabs()) > limit and \
00129                partial != indent1:
00130                 new.append(partial.rstrip())
00131                 partial = indent2
00132             partial = partial + word + " "
00133             if j+1 < len(words) and words[j+1] != " ":
00134                 partial = partial + " "
00135         i = i+1
00136     new.append(partial.rstrip())
00137     # XXX Should reformat remaining paragraphs as well
00138     new.extend(lines[i:])
00139     return "\n".join(new)

Here is the call graph for this function:

Here is the caller graph for this function: