From 86af2469d4cb404976a6e32e52543cb96b6f317e Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 10 Nov 2008 19:58:12 +0000 Subject: [PATCH] bugs about wrapping --HG-- branch : pmacs2 --- ispell.py | 2 +- method/__init__.py | 14 +++++++++----- mode/rst.py | 8 ++++++-- mode/text.py | 3 +++ mode/text2.py | 1 + 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ispell.py b/ispell.py index ce3591b..eb40d0b 100644 --- a/ispell.py +++ b/ispell.py @@ -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'): diff --git a/method/__init__.py b/method/__init__.py index eee7a70..f3da555 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -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) diff --git a/mode/rst.py b/mode/rst.py index 87e88bc..c1f6607 100644 --- a/mode/rst.py +++ b/mode/rst.py @@ -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',)) diff --git a/mode/text.py b/mode/text.py index f7b7248..912c66b 100644 --- a/mode/text.py +++ b/mode/text.py @@ -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',)) diff --git a/mode/text2.py b/mode/text2.py index e0080d3..5d7dd3f 100644 --- a/mode/text2.py +++ b/mode/text2.py @@ -21,5 +21,6 @@ class Text2(mode.text.Text): 'text2_email': ('cyan', 'default', 'bold'), 'text2_url': ('green', 'default', 'bold'), } + config = {} install = Text2.install