From 8b403b945519fd603f2ffad919ee4be1032a24b7 Mon Sep 17 00:00:00 2001 From: moculus Date: Thu, 20 Mar 2008 15:04:04 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- method/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/method/__init__.py b/method/__init__.py index 53634dc..0c4ff8a 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -627,6 +627,22 @@ class WrapParagraph(Method): w.insert_lines(p1, newlines) w.goto(Point(x, y)) +class CountWords(Method): + '''Count the number of words in the document''' + def _execute(self, w, **vargs): + wcount = 0 + pcount = 0 + inp = False + for line in w.buffer.lines: + c = len(line.split()) + if c and not inp: + inp = True + pcount += 1 + elif not c and inp: + inp = False + wcount += c + w.set_error("%d words (%d paragraphs) found in the document" % (wcount, pcount)) + class JustifyRight(Method): '''Justify text with the previous line right from the cursor by whitespace''' def _execute(self, w, **vargs):