Created
June 7, 2013 13:09
-
-
Save sachac/5729122 to your computer and use it in GitHub Desktop.
Modified version of https://github.com/thesoftwarebin/the-emacs-software-bin/blob/master/teletype.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun teletype-char (c short-pause long-pause) | |
(let ((med-pause (/ (+ long-pause (* 2 short-pause)) 3.0))) | |
(cond | |
((equal c ?.) | |
(insert (char-to-string c)) | |
(sit-for long-pause)) | |
((equal c ?,) | |
(insert (char-to-string c)) | |
(sit-for med-pause)) | |
((equal c ?\n) | |
(sit-for med-pause) (insert (char-to-string c)) | |
(sit-for med-pause)) | |
(t | |
(insert (char-to-string c)) | |
(sit-for short-pause))))) | |
(defun teletype-text (str short-pause long-pause) | |
(mapcar | |
(lambda (strchar) | |
(teletype-char strchar short-pause long-pause)) | |
(string-to-list str))) | |
(defun teletype-demo (pause-between-keys pause-between-rows buffer-title text) | |
"Print characters with a pause between each character." | |
(switch-to-buffer (get-buffer-create buffer-title)) | |
(erase-buffer) | |
(teletype-text text pause-between-keys pause-between-rows)) | |
(defun teletype-run-demo () | |
"Demonstrate teletyping." | |
(interactive) | |
(teletype-demo | |
0.1 | |
0.5 | |
"Emacs teletype demo" | |
(concat | |
"Hello Emacs user,\n\n" | |
" teletype-like printing can be useful to\n" | |
"keep the user focused on a brief tutorial.\n\n" | |
" You are currently reading at 10 cps, with\n" | |
"pauses of 0.5 sec at punctuation and newlines.\n" | |
" If this demo annoys you, stop it with C-g.\n\n" | |
" To run your own demo, you may load teletype.el and\n" | |
"execute the following LISP function:\n\n" | |
" (teletype-demo 0.1 0.5 demo-title all-your-text)\n\n" | |
"Future improvements could be:\n\n" | |
" - read text from file\n" | |
" - a resumable \"pause\" key\n" | |
" - support for text coloring\n" | |
" - support for typewriter sound (tick-tick-tick)\n" | |
" - configurable regexps for pauses (so for example you\n" | |
" don't have to ... wait so long at the ellipsys\n" | |
" triple dots)\n\n" | |
" Hope you enjoyed, regards.\n\n" | |
" The Software Bin\n" | |
" http://github.com/thesoftwarebin\n"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment