Skip to content

Instantly share code, notes, and snippets.

@miyamuko
Created April 26, 2011 06:32
Show Gist options
  • Save miyamuko/941881 to your computer and use it in GitHub Desktop.
Save miyamuko/941881 to your computer and use it in GitHub Desktop.
どんな人でも瞬時に凄腕ハッカーになれる方法・・・ for #xyzzy
;; どんな人でも瞬時に凄腕ハッカーになれる方法・・・ for #xyzzy
;;
;; * M-x hacker-typer で開始
;; 何かキー入力するたびにすごい勢いでコードを書いていく
;; * C-g で終了
;; * ハックするコードは *hacker-typer-dir* と *hacker-typer-file-pattern*
;; で指定
;;
;; http://duiker101.tk/hackertyper/
;; http://developer.cybozu.co.jp/akky/2011/04/post-a879.html
;; http://www.ideaxidea.com/archives/2011/04/hacker_typer.html
(defvar *hacker-typer-dir* (merge-pathnames "lisp" (si:system-root))
"ハックするソースコードがあるディレクトリ")
(defvar *hacker-typer-file-pattern* "*.l"
"ハックするソースコードの拡張子。複数の拡張子を指定する場合はリストで指定。")
(defvar *hacker-typer-max-input* 3
"キー入力ごとに入力する最大の文字数。
1~この数字までランダムに入力。
値が大きいほどスーパーハカーに見える。")
(defvar-local *hacker-typer-content* nil)
(defvar-local *hacker-typer-buffer* nil)
(defun hacker-typer ()
(interactive)
(let* ((file (choice-hacker-file))
(buf (get-buffer-create (format nil "hacker-~A" (file-namestring file)))))
(set-buffer buf)
(setup-temp-buffer buf)
(insert-file-contents file)
(set-buffer-file-name file)
(ed::find-file-process-params (ed::find-file-scan-params) buf)
(setf *hacker-typer-content* (buffer-substring (point-min) (point-max)))
(erase-buffer buf)
(set-buffer-file-name nil)
(hacker-typer-mode)))
(defun hacker-typer-mode ()
(interactive)
(make-local-variable '*pre-command-hook*)
(add-hook '*pre-command-hook* 'hacker-typer-input)
;; *ime-mode-hook* ってバッファローカルにはできないんだっけ?
(setf *hacker-typer-buffer* t)
(make-local-variable '*ime-mode-hook*)
(add-hook '*ime-mode-hook* 'hacker-typer-disable-ime))
(defun hacker-typer-input ()
(case *this-command*
;; C-g でバッファを閉じる
(quit (kill-buffer (selected-buffer)))
;; C-x k と M-x はそのまま通す
(kill-buffer nil)
(execute-extended-command nil)
;; それ以外のキー入力はハック
(t
(setf *this-command* nil)
(when (string/= *hacker-typer-content* "")
(let* ((count (min (1+ (random *hacker-typer-max-input*))
(length *hacker-typer-content*)))
(hack (substring *hacker-typer-content* 0 count)))
(insert hack)
(setf *hacker-typer-content* (substring *hacker-typer-content* count)))))))
;; IME の on/off は *pre-command-hook* にはこない
(defun hacker-typer-disable-ime ()
(when (and *hacker-typer-buffer*
(get-ime-mode))
(toggle-ime nil)
(hacker-typer-input)
(refresh-screen)))
(defun choice-hacker-file ()
(let ((files (directory *hacker-typer-dir* :wild *hacker-typer-file-pattern*
:absolute t :file-only t :recursive t)))
(nth (random (length files)) files)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment