Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
96115ee4
Commit
96115ee4
authored
Sep 16, 2002
by
Kurt B. Kaiser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge Py Idle changes:
Rev 1.10 (string methods)
parent
543cb977
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
Lib/idlelib/FormatParagraph.py
Lib/idlelib/FormatParagraph.py
+10
-11
No files found.
Lib/idlelib/FormatParagraph.py
View file @
96115ee4
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment