以下を評価して、
M-x anything-local-gems
すると、インストールされているgemの一覧が出るので、選択すると、 そのgemのlib/を開く。
また、カレントバッファの祖先ディレクトリにGemfileがみつかった場合、bundlerで管理されている方のgemが選択されまうす。
(defvar anything-c-sources-local-gem-file
'((name . "rubygems")
(candidates-in-buffer)
(init . (lambda ()
(let ((gemfile-dir (block 'find-gemfile
(let* ((cur-dir (file-name-directory
(expand-file-name (or (buffer-file-name)
default-directory))))
(cnt 0))
(while (and (< (setq cnt (+ 1 cnt)) 10)
(not (equal cur-dir "/")))
(when (member "Gemfile" (directory-files cur-dir))
(return-from 'find-gemfile cur-dir))
(setq cur-dir (expand-file-name (concat cur-dir "/.."))))
))))
(anything-attrset 'gem-command
(concat (if gemfile-dir
(concat "BUNDLE_GEMFILE=" gemfile-dir "/Gemfile "
"bundle exec ")
"")
"gem 2>/dev/null"))
(unless (anything-candidate-buffer)
(call-process-shell-command (concat (anything-attr 'gem-command) " list")
nil
(anything-candidate-buffer 'local))))))
(action . (lambda (gem-name)
(let ((path (file-name-directory
(shell-command-to-string
(concat (anything-attr 'gem-command) " which "
(replace-regexp-in-string "\s+(.+)$" "" gem-name))))))
(if (and path (file-exists-p path))
(find-file path)
(message "no such file or directory: \"%s\"" path))
)))))
(defun anything-local-gems ()
(interactive)
(anything-other-buffer
'(anything-c-sources-local-gem-file)
"*anything local gems*"
))