Skip to content

Instantly share code, notes, and snippets.

@pwaldhauer
Forked from stuartlangridge/TypeFileOut.py
Created May 14, 2014 12:54
Show Gist options
  • Save pwaldhauer/45082050e37dae8301de to your computer and use it in GitHub Desktop.
Save pwaldhauer/45082050e37dae8301de to your computer and use it in GitHub Desktop.
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))
line = self.view.line_height()
left, old_top = self.view.viewport_position()
top = old_top + line;
self.view.set_viewport_position((left, top))
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)
@pwaldhauer
Copy link
Author

Now with scrolling, wow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment