id:rubikitchさんや、id:IMAKADOさんの記事を読んでanythingの勉強中です。
習作にrubyのインタプリタを実行させるanythingソースを作ってみました。
(defun anything-c-has-print (input) (if (string-match "print\\|puts" input) t nil)) (defun anything-c-ruby-command (command) (if (anything-c-has-print command) command (concat "p " command))) (defvar anything-c-source-ruby '((name . "ruby command") (candidates . (lambda () (start-process "ruby-process" nil "ruby" "-e" (anything-c-ruby-command anything-input)))) (requires-pattern . 3) (delayed) (action . (("Run Ruby" . (lambda (candidate) (switch-to-buffer-other-window (get-buffer-create "*anything result*")) (point-max) (insert (concat (anything-c-ruby-command anything-input) "\n# -- result --\n")) (start-process "ruby-process" "*anything result*" "ruby" "-e" (anything-c-ruby-command anything-input)))))) ) )
1文字打つたびにrubyインタプリタが実行されます。
プログラム入力以外のキータイプが一切いらないので、短いコードの性能を確かめたりするのに便利かもしれません。
動作が重いので、anything.elの情報源を選択する(改訂版)にあるようなanythingソース選択機能を使った方がいいかもしれません。