Skip to content

Instantly share code, notes, and snippets.

@Arc0re
Created August 20, 2016 13:45
Show Gist options
  • Save Arc0re/5a79160cd85c007b981046054e03a177 to your computer and use it in GitHub Desktop.
Save Arc0re/5a79160cd85c007b981046054e03a177 to your computer and use it in GitHub Desktop.
Sublime Text 3 plugin to display total line count of a file.
import sublime, sublime_plugin, time
last_change = time.time()
update_interval = 1.5 # s
class DisplayLineCount(sublime_plugin.EventListener):
def update_line_count(self, view):
line_count = view.rowcol(view.size())[0] + 1
view.set_status("line_count", "{0} lines".format(line_count))
def on_modified(self, view):
global last_change
current_change = time.time()
# Check if we haven't embedded the change in the last update
if current_change > last_change + update_interval:
last_change = current_change
sublime.set_timeout(lambda: self.update_line_count(view),
int(update_interval * 1000))
on_post_save_async = update_line_count
on_modified_async = update_line_count
on_activated_async = update_line_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment