diff options
author | Kurt B. Kaiser <kbk@shore.net> | 2002-09-16 02:22:19 (GMT) |
---|---|---|
committer | Kurt B. Kaiser <kbk@shore.net> | 2002-09-16 02:22:19 (GMT) |
commit | 75e379020eab7d4030fd7df8ff6837c758140a3b (patch) | |
tree | 387e111dbc90ba90a45aac49fbaf52b88e7bf110 | |
parent | 220ecbc731bf600fe977e1721f2f5c1aec7b033c (diff) | |
download | cpython-75e379020eab7d4030fd7df8ff6837c758140a3b.zip cpython-75e379020eab7d4030fd7df8ff6837c758140a3b.tar.gz cpython-75e379020eab7d4030fd7df8ff6837c758140a3b.tar.bz2 |
Merge Py Idle changes:
Rev 1.10 (string methods)
-rw-r--r-- | Lib/idlelib/FormatParagraph.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/Lib/idlelib/FormatParagraph.py b/Lib/idlelib/FormatParagraph.py index cf5e365..eb0e693 100644 --- a/Lib/idlelib/FormatParagraph.py +++ b/Lib/idlelib/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: @@ -42,14 +41,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 @@ -60,7 +59,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) @@ -76,7 +75,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 @@ -101,7 +100,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]): @@ -122,18 +121,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 |