Skip to content

Instantly share code, notes, and snippets.

@alganet
Forked from stuartlangridge/TypeFileOut.py
Last active August 29, 2015 14:26
Show Gist options
  • Save alganet/dcb407fa6ee870e1debd to your computer and use it in GitHub Desktop.
Save alganet/dcb407fa6ee870e1debd to your computer and use it in GitHub Desktop.
Sublime Text 3 Python plugin to "type" the file that's currently being edited, character by character, for screencasts.
import sublime, sublime_plugin
BLOCKLEN = 1
class TypeFileOutCommand(sublime_plugin.TextCommand):
def nextchar(self):
if self.body:
totype = []
while 1:
try:
ch = self.body.pop(0)
except IndexError:
totype.append(ch)
break
totype.append(ch)
if ch in ["\n", " "] or len(totype) > BLOCKLEN:
break
self.view.run_command("insert", {"characters": "".join(totype)})
timeout = 50
if "\n" in totype:
timeout = 300
elif " " in totype:
timeout = 100
sublime.set_timeout(self.nextchar, timeout)
def run(self, edit):
self.edit = edit
# First, read everything in this view
reverything = sublime.Region(0, self.view.size())
self.body = list(self.view.substr(reverything))
self.view.erase(edit, reverything)
sublime.set_timeout(self.nextchar, 2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment