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 return _speller
def free(): def free():
if _speller: if _speller:
_speller.close() _speller.stop()
class Speller(object): class Speller(object):
def __init__(self, cmd='ispell'): def __init__(self, cmd='ispell'):

View File

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

View File

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

View File

@ -76,6 +76,9 @@ class Text(mode.Fundamental):
extensions=['.txt'] extensions=['.txt']
grammar = TextGrammar grammar = TextGrammar
actions = [LearnWord, TextInsertSpace, TextWrapParagraph] actions = [LearnWord, TextInsertSpace, TextWrapParagraph]
config = {
'text.margin': 78,
}
def __init__(self, w): def __init__(self, w):
mode.Fundamental.__init__(self, w) mode.Fundamental.__init__(self, w)
self.add_bindings('learn-word', ('C-c l',)) 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_email': ('cyan', 'default', 'bold'),
'text2_url': ('green', 'default', 'bold'), 'text2_url': ('green', 'default', 'bold'),
} }
config = {}
install = Text2.install install = Text2.install