diff options
Diffstat (limited to 'Tools/idle/FormatParagraph.py')
-rw-r--r-- | Tools/idle/FormatParagraph.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/Tools/idle/FormatParagraph.py b/Tools/idle/FormatParagraph.py index ea18cc0..c1bc769 100644 --- a/Tools/idle/FormatParagraph.py +++ b/Tools/idle/FormatParagraph.py @@ -14,7 +14,6 @@ # spaces, they will not be considered part of the same block. # * Fancy comments, like this bulleted list, arent handled :-) -import string import re class FormatParagraph: @@ -50,14 +49,14 @@ class FormatParagraph: find_paragraph(text, text.index("insert")) if comment_header: # Reformat the comment lines - convert to text sans header. - lines = string.split(data, "\n") + lines = data.split("\n") lines = map(lambda st, l=len(comment_header): st[l:], lines) - data = string.join(lines, "\n") + data = "\n".join(lines) # Reformat to 70 chars or a 20 char width, whichever is greater. format_width = max(70-len(comment_header), 20) newdata = reformat_paragraph(data, format_width) # re-split and re-insert the comment header. - newdata = string.split(newdata, "\n") + newdata = newdata.split("\n") # If the block ends in a \n, we dont want the comment # prefix inserted after it. (Im not sure it makes sense to # reformat a comment block that isnt made of complete @@ -68,7 +67,7 @@ class FormatParagraph: block_suffix = "\n" newdata = newdata[:-1] builder = lambda item, prefix=comment_header: prefix+item - newdata = string.join(map(builder, newdata), '\n') + block_suffix + newdata = '\n'.join(map(builder, newdata)) + block_suffix else: # Just a normal text format newdata = reformat_paragraph(data) @@ -84,7 +83,7 @@ class FormatParagraph: text.see("insert") def find_paragraph(text, mark): - lineno, col = map(int, string.split(mark, ".")) + lineno, col = map(int, mark.split(".")) line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno) while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line): lineno = lineno + 1 @@ -109,7 +108,7 @@ def find_paragraph(text, mark): return first, last, comment_header, text.get(first, last) def reformat_paragraph(data, limit=70): - lines = string.split(data, "\n") + lines = data.split("\n") i = 0 n = len(lines) while i < n and is_all_white(lines[i]): @@ -130,18 +129,18 @@ def reformat_paragraph(data, limit=70): word = words[j] if not word: continue # Can happen when line ends in whitespace - if len(string.expandtabs(partial + word)) > limit and \ + if len((partial + word).expandtabs()) > limit and \ partial != indent1: - new.append(string.rstrip(partial)) + new.append(partial.rstrip()) partial = indent2 partial = partial + word + " " if j+1 < len(words) and words[j+1] != " ": partial = partial + " " i = i+1 - new.append(string.rstrip(partial)) + new.append(partial.rstrip()) # XXX Should reformat remaining paragraphs as well new.extend(lines[i:]) - return string.join(new, "\n") + return "\n".join(new) def is_all_white(line): return re.match(r"^\s*$", line) is not None |