public
Created

Sublime Text 2 Python plugin to "type" the file that's currently being edited, character by character, for screencasts.

  • Download Gist
TypeFileOut.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import sublime, sublime_plugin
 
BLOCKLEN = 4
 
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.insert(self.edit, self.view.sel()[0].begin(), "".join(totype))
timeout = 10
if "\n" in totype:
timeout = 250
elif " " in totype:
timeout = 80
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.