diff --git a/etype.el b/etype.el new file mode 100644 index 0000000..d1781a4 --- /dev/null +++ b/etype.el @@ -0,0 +1,131 @@ +(require 'cl) + +(defvar etype-score 0) + +(defvar etype-in-game nil) + +(defvar etype-completing-word nil) + +(defvar etype-words nil) + +(defvar etype-timers nil) + +(defvar etype-banned-initials nil) + +(defconst etype-lines-file "etype.lines") + +(defun etype-read-file () + (with-temp-buffer + (insert-file-contents (expand-file-name etype-lines-file default-directory)) + (apply + 'vector + (split-string + (buffer-substring-no-properties (point-min) (point-max)) "\n")))) + +(defun init-game () + (let ((space (make-string fill-column ? ))) + (dotimes (i 30) + (insert space) + (newline)) + (goto-char (point-min)) + (setq etype-in-game t) + ;; Shuffle the vector of etype-words and turn it in to a list. + (setq etype-words (mapcar 'eval (shuffle-vector (etype-read-file)))))) + +(defun etype-fit-word (word) + (let ((space (make-string (+ 1 (length word)) ? ))) + (or (and (looking-at space) (point)) + (search-backward space nil nil) + (search-forward space nil nil)))) + +(defun etype-playing-p () + (string= "Etype" (buffer-name (current-buffer)))) + +(defun etype-search-timers (point) + (first + (remove-if-not + (lambda (timer) + (let ((arg (timer--args timer))) + (and (numberp (first arg)) + (= point (first arg))))) etype-timers))) + +(defun etype-move-word (point) + (message "score: %f" etype-score) + (save-excursion + (when (etype-playing-p) + (goto-char point) + (let* ((word (thing-at-point 'word)) + (len (length word)) + (timer (etype-search-timers point))) + (delete-char len) + (insert (make-string len ? )) + (forward-char (- (+ 1 fill-column) len)) + (let ((point (etype-fit-word word))) + (goto-char point) + (delete-char len) + (insert word) + (setf (timer--args timer) (list (- (point) len)))))))) + +(defun etype-spawn-word () + (save-excursion + (when (etype-playing-p) + (let* ((word (pop etype-words)) + (point (random (- fill-column (length word))))) + (goto-char point) + (setq point (etype-fit-word word)) + (when point + (delete-char (length word)) + (insert word) + (push (run-at-time "5 sec" (+ 1 (random 4)) + 'etype-move-word point) etype-timers)))))) + +(defun etype-loop () + ;; (push (run-at-time "5 sec" 3 'etype-drop) etype-timers) + (push (run-at-time "0 sec" 2 'etype-spawn-word) etype-timers)) + +(defun etype-search-word (key-etyped) + (setq etype-completing-word + (search-forward + (concat " " (single-key-description last-input-event)) nil t))) + +(defun etype-clear-word () + (let* ((len (length (thing-at-point 'word))) + (space (make-string len ? ))) + (backward-word) + (delete-char len) + (insert space) + (goto-char (point-min)) + (incf etype-score (* len 1.5)))) + +(defun etype-continue-word (key-etyped) + (when (looking-at key-etyped) (forward-char)) + (when (looking-at " ") + (etype-clear-word) + (setq visible-cursor) + (setq etype-completing-word nil))) + +(defun etype-catch-input () + (interactive) + (let ((key-etyped (single-key-description last-input-event))) + (if etype-completing-word + (etype-continue-word key-etyped) + (etype-search-word key-etyped)))) + +(defun etype () + (interactive) + (switch-to-buffer "Etype") + (etype-mode) + (init-game) + (etype-loop)) + +(defun etype-cleanup () + (mapc 'cancel-timer etype-timers)) + +(define-derived-mode etype-mode nil "Etype" + "A mode for playing Etype." + (make-local-variable 'etype-words) + (make-local-variable 'etype-timers) + (make-local-variable 'etype-in-game) + (make-local-variable 'etype-completing-word) + (define-key (current-local-map) [remap self-insert-command] 'etype-catch-input) + (add-hook 'kill-buffer-hook 'etype-cleanup)) diff --git a/etype.lines b/etype.lines new file mode 100644 index 0000000..32d5478 --- /dev/null +++ b/etype.lines @@ -0,0 +1,982 @@ +able +about +above +according +account +across +act +action +activities +activity +actually +added +addition +additional +administration +after +again +against +age +ago +ahead +aid +air +all +almost +alone +along +already +also +although +always +am +america +american +among +amount +an +analysis +and +another +answer +anti +any +anyone +anything +apparently +appear +appeared +approach +are +area +areas +arms +army +around +art +as +ask +asked +association +at +attack +attention +audience +available +average +away +back +bad +ball +based +basic +basis +be +beautiful +became +because +become +bed +been +before +began +beginning +behind +being +believe +below +best +better +between +beyond +big +bill +black +blood +blue +board +body +book +born +both +boy +boys +bring +british +brought +brown +building +built +business +but +by +call +called +came +can +cannot +cant +car +care +carried +cars +case +cases +cause +cent +center +central +century +certain +certainly +chance +change +changes +character +charge +chief +child +children +choice +christian +church +city +class +clear +clearly +close +closed +club +co +cold +college +color +come +comes +coming +committee +common +communist +community +company +complete +completely +concerned +conditions +congress +consider +considered +continued +control +corner +corps +cost +costs +could +couldnt +countries +country +county +couple +course +court +covered +cut +daily +dark +data +day +days +de +dead +deal +death +decided +decision +deep +defense +degree +democratic +department +described +design +designed +determined +developed +development +did +didnt +difference +different +difficult +direct +direction +directly +distance +district +do +does +doing +done +dont +door +doubt +down +dr +drive +due +during +each +earlier +early +earth +east +easy +economic +education +effect +effective +effects +effort +efforts +eight +either +elements +else +end +england +english +enough +entire +equipment +especially +established +europe +even +evening +ever +every +everything +evidence +example +except +existence +expect +expected +experience +extent +eye +eyes +face +fact +faith +fall +family +far +farm +father +fear +federal +feed +feel +feeling +feet +felt +few +field +figure +figures +filled +final +finally +find +fine +fire +firm +first +fiscal +five +floor +followed +following +food +foot +for +force +forces +foreign +form +former +forms +forward +found +four +free +freedom +french +friend +friends +from +front +full +function +further +future +game +gave +general +generally +george +get +getting +girl +girls +give +given +gives +glass +go +god +going +gone +good +got +government +great +greater +green +ground +group +groups +growing +growth +gun +had +hair +half +hall +hand +hands +happened +hard +has +have +having +he +head +hear +heard +heart +heavy +held +hell +help +her +here +herself +hes +high +higher +him +himself +his +history +hit +hold +home +hope +horse +hospital +hot +hotel +hour +hours +house +how +however +human +hundred +husband +idea +ideas +if +ill +im +image +immediately +important +in +include +including +income +increase +increased +indeed +individual +industrial +industry +influence +information +inside +instead +interest +international +into +involved +is +island +issue +it +its +itself +ive +job +john +just +justice +keep +kennedy +kept +kind +knew +know +knowledge +known +labor +lack +land +language +large +larger +last +late +later +latter +law +lay +lead +leaders +learned +least +leave +led +left +length +less +let +letter +letters +level +life +light +like +likely +line +lines +list +literature +little +live +lived +living +local +long +longer +look +looked +looking +lost +lot +love +low +lower +made +main +major +make +makes +making +man +manner +mans +many +march +market +married +mass +material +matter +may +maybe +me +mean +meaning +means +medical +meet +meeting +member +members +men +merely +met +method +methods +middle +might +miles +military +million +mind +minutes +miss +modern +moment +money +month +months +moral +more +morning +most +mother +move +moved +movement +moving +mr +mrs +much +music +must +my +myself +name +nation +national +nations +natural +nature +near +nearly +necessary +need +needed +needs +negro +neither +never +new +next +night +no +non +nor +normal +north +not +note +nothing +now +nuclear +number +numbers +obtained +obviously +of +off +office +often +oh +old +on +once +one +ones +only +open +opened +operation +opportunity +or +order +organization +other +others +our +out +outside +over +own +paid +paper +part +particular +particularly +parts +party +passed +past +pattern +pay +peace +people +per +performance +perhaps +period +person +personal +persons +physical +picture +piece +place +placed +plan +plane +planning +plans +plant +play +point +points +police +policy +political +pool +poor +population +position +possible +post +power +present +president +press +pressure +price +principle +private +probably +problem +problems +process +production +products +program +programs +progress +property +provide +provided +public +purpose +put +quality +question +questions +quite +race +radio +ran +range +rate +rather +reached +reaction +read +reading +ready +real +really +reason +received +recent +recently +record +red +religion +religious +remember +report +reported +required +research +respect +responsibility +rest +result +results +return +returned +right +river +road +room +run +running +said +sales +same +sat +saw +say +saying +says +school +schools +science +season +second +secretary +section +see +seem +seemed +seems +seen +self +sense +sent +series +serious +served +service +services +set +seven +several +shall +she +short +shot +should +show +showed +shown +side +similar +simple +simply +since +single +situation +six +size +slowly +small +so +social +society +some +something +sometimes +somewhat +son +soon +sort +sound +south +southern +soviet +space +speak +special +specific +spirit +spring +square +st +staff +stage +stand +standard +start +started +state +statements +states +stay +step +steps +still +stock +stood +stop +stopped +story +straight +street +strength +strong +student +students +study +subject +such +suddenly +summer +sun +support +sure +surface +system +systems +table +take +taken +taking +talk +tax +technical +tell +temperature +ten +term +terms +test +th +than +that +thats +the +their +them +themselves +then +theory +there +therefore +theres +these +they +thing +things +think +thinking +third +thirty +this +those +thought +three +through +through +throughout +thus +time +times +to +today +together +told +too +took +top +total +toward +town +trade +training +treatment +trial +tried +trouble +true +truth +try +trying +turn +turned +twenty +two +type +types +under +understand +understanding +union +united +university +until +up +upon +us +use +used +using +usually +value +values +various +very +view +voice +volume +waiting +walked +wall +want +wanted +war +was +washington +wasnt +water +way +ways +we +week +weeks +well +went +were +west +western +what +whatever +when +where +whether +which +while +white +who +whole +whom +whose +why +wide +wife +will +william +window +wish +with +within +without +woman +women +word +words +work +worked +working +works +world +would +wouldnt +writing +written +wrong +wrote +year +years +yes +yet +york +you +young +your +youre