Gem which + dired + anything
gem whichでgem名からrequireされるライブラリのファイルパスが引けるので、そのファイルだけじゃなくそのgemのlib/とdiredの手を組ませてみる。
さらにインストール済みのgemをanythingでインクリメンタルに選ぶ。
(defun gem-which (name &optional gem-cmd) "Lookup path of installed gem by kick gem command." (let ((str (shell-command-to-string (format "%s which %s" (or gem-cmd "gem") name)))) (if (string-match "^ERROR:" str) nil (substring str 0 -1)))) (defun gem-dired (name) "Lookup installed gem and open its lib/ diractory." (interactive) (let ((dir (gem-which name))) (if dir (find-file (file-name-directory dir)) (message "Gem not found for `%s'" name)))) (defun gem-list (&optional gem-cmd) "Get installed gems list." (split-string (shell-command-to-string (format "%s list --no-version" (or gem-cmd "gem"))) "\n" t)) (setq anything-c-source-gem-dired '((name . "Gem Dired") (candidates . gem-list) (action . gem-dired))) (defun gem-dired-anything () (interactive) (anything 'anything-c-source-gem-dired))