bugs about wrapping

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-11-10 19:58:12 +00:00
parent f8680694b3
commit 86af2469d4
5 changed files with 20 additions and 8 deletions

View File

@ -15,7 +15,7 @@ def get_speller():
return _speller
def free():
if _speller:
_speller.close()
_speller.stop()
class Speller(object):
def __init__(self, cmd='ispell'):

View File

@ -576,9 +576,9 @@ class WrapLine(Method):
w.goto(Point(x, y))
class WrapParagraph(Method):
limit = 80
valid_re = re.compile('^( *)([^ ].*)$')
empty_re = regex.whitespace
limit = 80
valid_re = re.compile('^( *)([^ ].*)$')
empty_re = regex.whitespace
def _execute(self, w, **vargs):
limit = util.get_margin_limit(w, self.limit)
@ -587,7 +587,7 @@ class WrapParagraph(Method):
p1 = oldc = w.logical_cursor()
cur_offset = 0
m = self.valid_re.match(w.buffer.lines[p1.y])
m = self.valid_re.match(w.buffer.lines[p1.y])
if not m:
# the line was empty
return
@ -601,7 +601,7 @@ class WrapParagraph(Method):
if i > 1 and w.buffer.lines[i] and not w.buffer.lines[i].startswith(' '):
while i > 1 and w.buffer.lines[i - 1] and not w.buffer.lines[i - 1].startswith(' '):
i -= 1
p1 = Point(0, i)
p1 = Point(0, i)
# get the first line; strip it, and put it in our new lines list.
s1 = w.buffer.lines[p1.y][p1.x:]
@ -630,6 +630,8 @@ class WrapParagraph(Method):
# stringify our paragraph
s = " ".join(lines)
#raise Exception, '%r %r' % (limit, s)
# ok, so now we need to find the line breaks
newlines = []
while s:
@ -658,6 +660,8 @@ class WrapParagraph(Method):
y += 1
k += 1
#assert len(newlines), 'fooga: %r %r' % (limit, s)
# kill the old paragraph region, insert the new, and goto the new cursor
w.delete(p1, Point(len(w.buffer.lines[i-1]), i-1))
w.insert_lines(p1, newlines)

View File

@ -44,10 +44,11 @@ class RSTGrammar(Grammar):
]
class RstInsertSpace(TextInsertSpace):
limit = 75
class RstWrapParagraph(method.WrapParagraph):
limit = 75
class RstInsertSpace(TextInsertSpace):
limit = 75
wrapper = RstWrapParagraph
class RST(mode.Fundamental):
modename = 'RST'
@ -99,6 +100,9 @@ class RST(mode.Fundamental):
}
actions = [RstInsertSpace, RstWrapParagraph]
config = {
'rst.margin': 75,
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('rst-insert-space', ('SPACE',))

View File

@ -76,6 +76,9 @@ class Text(mode.Fundamental):
extensions=['.txt']
grammar = TextGrammar
actions = [LearnWord, TextInsertSpace, TextWrapParagraph]
config = {
'text.margin': 78,
}
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.add_bindings('learn-word', ('C-c l',))

View File

@ -21,5 +21,6 @@ class Text2(mode.text.Text):
'text2_email': ('cyan', 'default', 'bold'),
'text2_url': ('green', 'default', 'bold'),
}
config = {}
install = Text2.install