Home Download Buy Blog Forum Support

livewordcount.py + "since last save" + "in selected"

livewordcount.py + "since last save" + "in selected"

Postby sean on Tue Jan 26, 2010 6:54 am


can someone help me modify the following live wordcount package. i'd like to add two features:
1. show "words since last save: x"
2. show "words in selection: x"

Code: Select all
import sublime, sublimeplugin, re

class liveWordCount(sublimeplugin.Plugin):
   def onModified(self, view):
      sels = view.sel()
      content = view.substr(sublime.Region(0, view.size()))
      sublime.statusMessage("Words: %s" % self.count(content))
   def count(self, content):
      """counts by counting all the start-of-word characters"""
      # regex to find word characters
      wrdRx = re.compile("\w")
      matchingWrd = False
      words = 0;
      for ch in content:
         # test if this char is a word char
         isWrd = wrdRx.match(ch) != None
         if isWrd and not matchingWrd:
            # we're moving into a word from not-a-word
            words = words + 1
            matchingWrd = True
         if not isWrd:
            # go back to not matching words
            matchingWrd = False
      return words

Posts: 14
Joined: Sat Oct 24, 2009 6:36 am

Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 7 guests