Sublime Forum

WordCount Package: strip comment lines from count

#1

Hello,

I’m using the WordCount package (https://github.com/titoBouzout/WordCount ) in ST3. I’d like to strip comments from the word count in certain files (e.g. lines starting with % in plain text files). I’ve tried, for example:

{
"strip": {
    "plain text": [
        "%.*$"
    ],
    "Plain Text": [
        "%.*$"
    ]
}
}

any ideas? Thanks.

0 Likes

#2

Well without knowing exactly how WordCount does its processing there might be some nuance to it. Have you tried anchoring it to the start of a line like "^%.*$"? Also, is there a reason to have multiple entries with different capitalizations?

0 Likes

#3

Hey Remi,

Yes, I tried anchoring to the start of the line as you mention. The reason for the different capitalization is that the settings file mentions to use lowercase for the file type, but I tried both just in case.

Thanks.

0 Likes

#4

At first blush, this seems to work OK for me with the settings that you mentioned in your post above.

With the default settings, the plain text file on the left reports as ten words:

With the setting you provided above, it starts reporting as only five words as I would expect:

That said, the entirety of the WordCount.sublime-settings here is purely default except for changing the strip setting, so potentially some of the other settings may in some way interfere with it working if you’ve modified them.

There are also a few problems with the package, so that may be getting in your way. For example it doesn’t seem to detect when the syntax in the view changes, so for example changing the syntax to HTML keeps the word count as five until you make a modification, then it remains at ten when you switch back to Plain Text until you make a further modification.

As such, you may need to modify the file to get it to notice that the count has updated.

I also noticed that it stopped working for a while, and my console was filling up with many of this error message:

KeyError: 'count'
Traceback (most recent call last):
  File "WordCount in /home/tmartin/local/sublime_text_3_sandbox/Data/Installed Packages/WordCount.sublime-package", line 295, in <lambda>
  File "WordCount in /home/tmartin/local/sublime_text_3_sandbox/Data/Installed Packages/WordCount.sublime-package", line 132, in run

The referenced line of code is for the update of the status line for the word count, where it’s accessing a dictionary which spontaneously no longer has the required count view setting to track the word count. It’s communicating with a background thread of some sort, so there may be some sort of syncronization issue.

In any case, I would also check the console output (View > Show Console) to see if it’s doing that or not. I didn’t spend much time trying to reproduce whatever it was I did that made it angry, so it may just have been the syntax changing.

1 Like

#5

Thanks for your help on this.

I did see those errors appearing (although not consistently) when I open the console. I can’t make it work even when using the settings exactly as you put them in your settings file.

I guess this plugin no longer works. Are you using ST2 or ST3? Looks like you’re on Linux.

0 Likes

#6

I remove and installed the package again, and this showed up:

reloading plugin WordCount.WordCount
reloading settings Packages/WordCount/WordCount.sublime-settings
Exception in thread Thread-4:
Traceback (most recent call last):
  File "./python3.3/threading.py", line 901, in _bootstrap_inner
  File "./python3.3/threading.py", line 858, in run
  File "WordCount in /Users/cmoffat/Library/Application Support/Sublime Text 3/Installed Packages/WordCount.sublime-package", line 294, in word_count_loop
AttributeError: 'NoneType' object has no attribute 'running'

Maybe part of the problem?

0 Likes

#7

Sorry for the delay in response here, it’s been a busy couple of days.

The test above was with the latest development release of Sublime 3 under Linux, in a sandbox environment with only this package installed.

However, I can replicate those results using a similarly sandboxed portable Windows and MacOS version as well:

So on the face of it it seems like regardless of the weird errors it generates into the console periodically, at some level it should be doing what you want it to.

Possibly there may be some other package interfering with it so it might be worth trying it in a clean environment like I did here and see if it works, and then add packages in to see what might break it.

0 Likes

#8

Hi,

I appreciate your thoughts on this. I tried a clean environment as you suggested, but still no luck. It just seems broken with my setup.

0 Likes