How to make RSense autocomplete and jump to definitions of a rails project?
I switched from netbeans to emacs and I am pretty happy with the change. The thing I am missing the most is autocompletion and jump to definitions. In order to get this I have installed Rsense. It works fine for the gems code, though, I cannot jump-to-definitions of my Rails project nor开发者_运维百科 autocomplete according to the methods I defined.
I tried to add my project's load path to Rsense's load_path configuration, though, it still doesn't work.
Does anyone know how to get this working?
You can use tags for browsing through files and jumping directly to function definitions. I use Exuberant Ctags (its got Ruby support). You can download it from here.
I am assuming that you are working on windows. Getting the tags to work initially on windows is a pain especially if you are using emacs for the first time.
These are the steps I followed:
- Install Cygwin from here.
- Include the cygwin\bin\ folder in your environment variable
PATH
. E.g. here - Install exhuberant ctags. Note that emacs may sometime have a built in ctags. Later on you will have to use the
ctags
command in cygwin to create tags. At that time you may encounter some errors in case it uses the ctags in emacs instead of exuberant ctag. - Once you have installed ctags, add that to the environmental variable
PATH
as well. - If you have a small project with relatively lesser number of files (<500). So you just need a single global TAGS file. For that open cygwin, change your directory to the root directory of your project and type in the command
ctags -R -e
Check this out for other approaches - Your tags file will be created. It will be named "TAGS" and will be present in the root directory of your project.
- Next open emacs, and browse through the code. In case you come across a function and want to jump to its definition, put your cursor on the function name and press
M-.
your minibuffer should then show something likeFind tag (default <function-name>):
Press Enter and voila!!! you are magically transported to the function definition!!! Note: You may have to specify the TAGS file the first time you use theM-.
This needs to be done only once after emacs startup. You can also modify your .emacs file to take in the TAGS file automatically on startup.
Refer to this and this for more info for tags related commands in emacs.
Until now, I have been using rtags to jump to definitions. It's not perfect, but it does the trick in many cases.
精彩评论