Skip to content

Instantly share code, notes, and snippets.

@Restuta
Created December 14, 2012 23:23
Show Gist options
  • Save Restuta/4289538 to your computer and use it in GitHub Desktop.
Save Restuta/4289538 to your computer and use it in GitHub Desktop.
Sublime Plugin that does auto-save of the current document when you stop typing. Can be used with LiveReload to remove the need to press Ctrl+S all the time.
import sublime, sublime_plugin, functools
class IdleWatcher(sublime_plugin.EventListener):
pending = 0
def handleTimeout(self, view):
self.pending = self.pending - 1
if self.pending == 0:
self.on_idle(view)
def on_modified(self, view):
self.pending = self.pending + 1
# Ask for handleTimeout to be called in N ms
sublime.set_timeout(functools.partial(self.handleTimeout, view), 800)
def on_idle(self, view):
view.run_command("save")
print "Current document saved"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment