[Idle-dev] CVS: idle FormatParagraph.py,1.4,1.5
Kurt B. Kaiser
kbk@users.sourceforge.net
Sun, 15 Sep 2002 19:22:22 -0700
Update of /cvsroot/idlefork/idle
In directory usw-pr-cvs1:/tmp/cvs-serv28330
Modified Files:
FormatParagraph.py
Log Message:
Merge Py Idle changes:
Rev 1.10 (string methods)
Index: FormatParagraph.py
===================================================================
RCS file: /cvsroot/idlefork/idle/FormatParagraph.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** FormatParagraph.py 19 Jan 2002 10:41:51 -0000 1.4
--- FormatParagraph.py 16 Sep 2002 02:22:19 -0000 1.5
***************
*** 15,19 ****
# * Fancy comments, like this bulleted list, arent handled :-)
- import string
import re
--- 15,18 ----
***************
*** 43,54 ****
if comment_header:
# Reformat the comment lines - convert to text sans header.
! lines = string.split(data, "\n")
lines = map(lambda st, l=len(comment_header): st[l:], lines)
! data = string.join(lines, "\n")
# 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")
# If the block ends in a \n, we dont want the comment
# prefix inserted after it. (Im not sure it makes sense to
--- 42,53 ----
if comment_header:
# Reformat the comment lines - convert to text sans header.
! lines = data.split("\n")
lines = map(lambda st, l=len(comment_header): st[l:], lines)
! 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 = 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
***************
*** 61,65 ****
newdata = newdata[:-1]
builder = lambda item, prefix=comment_header: prefix+item
! newdata = string.join(map(builder, newdata), '\n') + block_suffix
else:
# Just a normal text format
--- 60,64 ----
newdata = newdata[:-1]
builder = lambda item, prefix=comment_header: prefix+item
! newdata = '\n'.join(map(builder, newdata)) + block_suffix
else:
# Just a normal text format
***************
*** 77,81 ****
def find_paragraph(text, mark):
! lineno, col = map(int, string.split(mark, "."))
line = text.get("%d.0" % lineno, "%d.0 lineend" % lineno)
while text.compare("%d.0" % lineno, "<", "end") and is_all_white(line):
--- 76,80 ----
def find_paragraph(text, 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):
***************
*** 102,106 ****
def reformat_paragraph(data, limit=70):
! lines = string.split(data, "\n")
i = 0
n = len(lines)
--- 101,105 ----
def reformat_paragraph(data, limit=70):
! lines = data.split("\n")
i = 0
n = len(lines)
***************
*** 123,129 ****
if not word:
continue # Can happen when line ends in whitespace
! if len(string.expandtabs(partial + word)) > limit and \
partial != indent1:
! new.append(string.rstrip(partial))
partial = indent2
partial = partial + word + " "
--- 122,128 ----
if not word:
continue # Can happen when line ends in whitespace
! if len((partial + word).expandtabs()) > limit and \
partial != indent1:
! new.append(partial.rstrip())
partial = indent2
partial = partial + word + " "
***************
*** 131,138 ****
partial = partial + " "
i = i+1
! new.append(string.rstrip(partial))
# XXX Should reformat remaining paragraphs as well
new.extend(lines[i:])
! return string.join(new, "\n")
def is_all_white(line):
--- 130,137 ----
partial = partial + " "
i = i+1
! new.append(partial.rstrip())
# XXX Should reformat remaining paragraphs as well
new.extend(lines[i:])
! return "\n".join(new)
def is_all_white(line):