Last active
July 1, 2021 07:35
-
-
Save EyalAr/8383050 to your computer and use it in GitHub Desktop.
Count words in selection - plugin for Sublime Text 3.
Full blog post: http://eyalarubas.com/count-words-in-sublime-text-3.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime, sublime_plugin, re | |
class CountWordsInSelectionCommand(sublime_plugin.EventListener): | |
def on_selection_modified(self, view): | |
''' | |
listen to event 'on_selection_modified' and count words in all selected | |
regions when invoked. | |
''' | |
# clear status bar if nothing is selected | |
if len(view.sel()) == 1 and view.sel()[0].size() == 0: | |
view.set_status("words_in_selection", "") | |
return | |
count = 0 | |
for region in view.sel(): | |
for i in range(region.begin(), region.end()): | |
if view.classify(i) & sublime.CLASS_WORD_START: | |
count += 1 | |
view.set_status("words_in_selection", "{} words".format(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment