diff --git a/method/__init__.py b/method/__init__.py index 3b02b08..4069362 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -853,17 +853,11 @@ class WrapParagraph2(Method): # translate our cursor according to the line breaks we just did. (x, y) = oldc.xy() k = 0 - while k < len(newlines) and x > len(newlines[k]): + while k < len(newlines) - 1 and x > len(newlines[k]): x = x - len(newlines[k]) - 1 y += 1 k += 1 - # if our cursor is on a new line (past all the newlines) then we should - # be inserting another line so that we preserve the spacing of the - # document. - if k == len(newlines): - newlines.append('') - # kill the old paragraph region, insert the new, and goto the new cursor w.kill(p1, Point(len(w.buffer.lines[i-1]), i-1)) w.insert_lines(p1, newlines) diff --git a/mode/mutt.py b/mode/mutt.py index 702e425..6d36642 100644 --- a/mode/mutt.py +++ b/mode/mutt.py @@ -40,16 +40,11 @@ class Mutt(mode.Fundamental): self.add_action_and_bindings(MuttWrapParagraph(), ('M-q',)) self.add_action_and_bindings(MuttInsertSpace(), ('SPACE',)) -class MuttWrapLine(method.WrapLine): - limit = 72 - class MuttWrapParagraph(method.WrapParagraph2): - wrapper = MuttWrapLine limit = 72 empty_re = re.compile('^(?: *>.*| *)$') class MuttInsertSpace(mode.text.TextInsertSpace): - limit = 72 wrapper = MuttWrapParagraph install = Mutt.install diff --git a/mode/text.py b/mode/text.py index c5399a8..25f7ed0 100644 --- a/mode/text.py +++ b/mode/text.py @@ -52,16 +52,17 @@ class Text(mode.Fundamental): self.add_action_and_bindings(TextInsertSpace(), ('SPACE',)) self.add_action_and_bindings(method.WrapParagraph2(), ('M-q',)) +class TextWrapParagraph(method.WrapParagraph2): + pass + class TextInsertSpace(method.Method): - limit = 80 - #wrapper = method.WrapParagraph - wrapper = method.WrapParagraph2 + wrapper = TextWrapParagraph def execute(self, w, **vargs): - w.insert_string_at_cursor(' ') cursor = w.logical_cursor() i = cursor.y - if len(w.buffer.lines[i]) > self.limit: + if len(w.buffer.lines[i]) > self.wrapper.limit: self.wrapper().execute(w) + w.insert_string_at_cursor(' ') class LearnWord(method.Method): def execute(self, w, **vargs):