Last active
December 10, 2016 11:35
-
-
Save howardabrams/b5dc2082bcce46fdc9b8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; I would like a function that inserts a phrase or paragraph into a | |
;; buffer, but that it is looks like it is being typed. This means to | |
;; have a slight, but random time delay between each letter. Calling | |
;; `sit-for' is sufficient for short sentences (around 140 | |
;; characters), but anything longer makes the display look like it | |
;; hangs until some event, and then the entire results are displayed. | |
;; | |
;; Ideas or thoughts on what to look for? | |
(defun insert-typewriter (str) | |
"Insert STR into the current buffer as if you were typing it by hand." | |
(interactive "s") | |
(dolist (ch (string-to-list str)) | |
(insert ch) | |
(sit-for (/ 1.0 (+ 10 (random 80))) nil))) | |
;; This works well: | |
(insert-typewriter "Hello, how the hell are you doing today?") | |
;; But this is really fun to watch: | |
(insert-typewriter "Lorem ipsum dolor sit amet, consectetur | |
adipiscing elit, sed do eiusmod tempor incididunt ut labore et | |
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud | |
exercitation ullamco laboris nisi ut aliquip ex ea commodo | |
consequat. Duis aute irure dolor in reprehenderit in voluptate | |
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint | |
occaecat cupidatat non proident, sunt in culpa qui officia | |
deserunt mollit anim id est laborum. | |
Sed ut perspiciatis unde omnis iste natus error sit voluptatem | |
accusantium doloremque laudantium, totam rem aperiam, eaque ipsa | |
quae ab illo inventore veritatis et quasi architecto beatae vitae | |
dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas | |
sit aspernatur aut odit aut fugit, sed quia consequuntur magni | |
dolores eos qui ratione voluptatem sequi nesciunt. Neque porro | |
quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, | |
adipisci velit, sed quia non numquam eius modi tempora incidunt | |
ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad | |
minima veniam, quis nostrum exercitationem ullam corporis | |
suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? | |
Quis autem vel eum iure reprehenderit qui in ea voluptate velit | |
esse quam nihil molestiae consequatur, vel illum qui dolorem eum | |
fugiat quo voluptas nulla pariatur?") |
Ah! But of course! The sit-for
function, when given a 0
was the culprit! I will edit the gist in case anyone else comes along looking for something similarly silly. Thanks for the help!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool! the string-empty-p wasn't defined for me. maybe fix.