Once (or twice) upon a time you just have to look at the source code of a gem. Maybe you remember where your gems are located. Maybe you use RVM or Bundler to help you find them. But you know that your mojo will grow like potatoes if you do it directly in your editor (read ‘Emacs’).
The other day I thought the same and in 10 minutes (read ‘1 hour’) hacked a
M-x find-gem command. Just remember that it is using Bundler and your Gemfile has to be in your current directory. Feel free to fork and fix those limitations though!
NOTE: Maybe I am wrong but the internetz told me that you have to make your own trimming function in Emacs. I am a lazy person though, so I used the one that Xah wrote. Kudos to Raimon for cleaning up the code and
It was after that amusing one hour of eLisp coding when I realized that Pry would get me directly to the source of a method and integrating it might have been even simpler. If anyone did that, please let me know!
EDIT 1: After some days of using the script, we’ve found that having to navigate to the root directory of your project is a bit tedious if you really use that feature a lot, so we’ve hacked a way to navigate to the root of your rails project in a nifty way. The following code will find the root of the project for you.
Note that it’s a higher order function that is not bound just to find a root directory in git, but you can pass it a lambda and member-directory will return the first directory that returns non-nil for the lambda passed to it.
And to use our new pathfinder from our “old” find-gem, we just have to bind default-directory
EDIT 2: To mimic the above code using Pry, you only have to write
gem-cd rails and then open Emacs or other wicked editor by
.emacsclient . &. There. Alias it for more karma points.