How to make RSense autocomplete and jump to definitions of a rails project? - ruby-on-rails

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 like Find 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 the M-. 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.

Related

Migrating to Vim from RubyMine - Interpreted Auto completion

Up until last week, I had been using RubyMine for my Rails development. I know it has a vim plugin but I have been working on migrating my development to vim and tmux. I don't want to keep using the mouse and VIM gives me a lot more flexibility. I have found plugins and workarounds for almost all the features I care about except the "interpreted auto complete" functionality in my first screenshot below. RubyMine interprets the whole rails application and offers sorted-by-relevance suggestions (as you can see, it's showing me instance variables and methods for the class in question and the modules it includes) THEN it shows (less relevant) methods available on the Object class. It also shows the method signature when there's one.
Also, in my second screenshot, you can see how RubyMine offers autocompletion for core Ruby classes.
Compare this to the bottommost screenshot. I do have completion but there's no way to find what I'm looking for. I'm using ctags , YouCompleteMe, vim-rails, vim-ruby and I also tried installing eclim to see if it makes a difference.
Is there a plugin I've missed that can enhance my auto completion? It doesn't look like RubyMine is doing something super crazy. pry can give me the same 'power' if it were running in the same 'context'.
First Screenshot (RubyMine interpreted auto complete):
Second Screenshot (RubyMine core Ruby classes auto complete):
Third Screenshot (vim omnifunc + ctags):
Important Note
This solution only works for Ruby 1.9+
I forked 'vim-ruby' at https://github.com/zxiest/vim-ruby and modified it as such:
Method signatures now appear in completion.
I disabled sorting by name for methods.
Plugins and Settings
vim-rails
I'm using vim-rails https://github.com/tpope/vim-rails
supertab
I'm using supertab https://github.com/ervandew/supertab instead of YouCompleteMe (mentioned in my question) although YouCompleteMe is super fast and automatic but there are currently some compatibility issues between my it and my vim-ruby fork.
vim-easytags
I'm using vim-easytags https://github.com/xolox/vim-easytags
Add this to your ~/.vimrc
:set tags=./tags;
:let g:easytags_dynamic_files = 1
Make sure to touch ./tags in your project directory.
Issue :UpdateTags -R **/*.* from vim in order for easytags to generate your tags file.
Remap omnicomplete
In order for omnicomplete to pop up, by default, we have to hit <C-X><C-O>. I remapped this to <C-Space> by inserting the following in my ~/.vimrc:
inoremap <C-#> <C-x><C-o>
I now press tab when I want supertab to complete my code and Ctrl+Space when I want omnicomplete to trigger and show method signatures for me. There's definitely a better way to integrate this (i.e. getting supertab to call omnicomplete after a dot)
And here goes the screenshot! Notice that method sorting being off allowed my custom resize method to appear on top and the signatures now appear in the completion (as well as in the editor when enter is pressed!)

Setting relative path in SublimeLinter's sublimelinter_executable_map

Setup: Portable editions of Sublime Text 2 with its plugin Sublimelinter and node.exe.
sublimelinter_executable_map has to set in a way so that Sublimelinter uses node.exe as JavaScript engine.
Could one do this using a relative path instead of a fully qualified path?
Trying with different forms of relative paths as given in MSDN, the plugin failed to detect node.exe. The console message i got was SublimeLinter: javascript disabled (One of the following JavaScript engines must be installed: node.js, JavaScriptCore)
Your GitHub issue on this topic:
https://github.com/SublimeLinter/SublimeLinter/issues/612
Is a duplicate of these:
https://github.com/SublimeLinter/SublimeLinter/issues/611
https://github.com/SublimeLinter/SublimeLinter/issues/459
This seems to be a hot topic.
I forked the repository and started to code a patch for you, which seems to center around this segment:
https://github.com/SublimeLinter/SublimeLinter/blob/4ef4b2ca08e0224b8af59bf3406c4927432efb94/sublimelinter/modules/base_linter.py#L380
But then, it dawned on me... environment variables. Since this seems to be a prevalent issue with many unsolved requests, it seems that you ought to set the PATH environment variable, and place the location you are looking to be found first, earlier in that variable.
Don't know your Windows version, and the process to set an environment variable will be different for your version, so you ought to experiment with that, and then use that method as the standard for all your environments ( as it seems implied you have more than one to maintain ).
Update: Ruby seems to allow relative paths, but JavaScript does not, because of this section:
https://github.com/SublimeLinter/SublimeLinter/blob/4ef4b2ca08e0224b8af59bf3406c4927432efb94/sublimelinter/modules/base_linter.py#L380
Which hinges on: JAVASCRIPT_ENGINE_WRAPPERS_PATH
So the answer is, unless that code is adapted, no. Relative paths cannot be used for JS.

can i change VIMRUNTIM if i want to move/usr/share/vim/vim71 to other path?

if yes, how to change such variable?
should i modify vimrc? but vimrc is in $VIMTIME, if i changed it, how vim find it?
i maybe have lots copies of VIMRUNTIME, and i hope that i can switch to different VIMRUNTIMEs easily, how to make this done.
anybody here who have ever tried to do this?
btw, there are lots of .vim files inside $VIMRUNTIME, are they all vim plugins? is .vim files all writen in vimscript? what vimscript can do and what it cannot? why not all vim plugins implemented using .vim? since i find some vim plugin also use script language such as perl or python...
The gory details are documented under :help startup, but you rarely need to modify $VIMRUNTIME. You didn't mention why you would want to do this, but it's probably a bad idea.
If you don't want to set the VIMRUNTIME environment variable in the shell from which you launch Vim, you can modify it in a user-specific ~/.vimrc (via :let $VIMRUNTIME = '/path/to/it'), because that one is read before the system-wide configuration.
The runtime files contain the help documents, default configuration, filetype detections and syntax highlightings. You can add your own extensions (e.g. downloads from http://www.vim.org) in ~/.vim/.... As I said, there should be no need to mess with the system-wide runtime; this is managed by your system's package management.

How to load plugins in the new tab in mac vim?

I'm using macvim to code rails project.
I used some plugins, which is specific to rails(like vim-rails) and will be loaded only in a rails' app folder.
After I entered a rails's folder, I run mvim and everything goes fine.
However, when I use command + T to open a new tab. the function of those plugins disabled..seems they are not loaded..
How to load them when I open a new tab?
If these plugins use the similar code to that one fugitive does, then putting something like
augroup LaunchFugitiveForAllBuffers
autocmd!
autocmd BufNew :doautocmd fugitive BufRead .
augroup END
(replace fugitive with actual event group name [1]). You can find this name by either grepping plugin files for BufRead (note: case does not really matter) or walking through the output of au BufRead like I did (there should not be many items). Note that things may be more complicated: for example your plugins attach to Filetype event and changing the above to doautocmd fugitive Filetype ruby may not help. Also note that you can purge out word fugitive at all leaving just a space, but it is potentially destructive operation and can be used only for testing (potentially very destructive in case of Filetype event and some others).
[1] Note: event group, not plugin name. These groups are likely to have the name that is a derivative of plugin name, but they are not forced to be equal to it.
Update: It seems that you need railsPluginDetect group for Tim Pope’s rails plugin. I do not have any rails project so I can’t say this for sure, but autocommand looks very similar to fugitive one. It is better though that you go to plugin bug tracker and add a request there (do not forget to search for an existing one).
Additional informations may be needed but I think that's because the new tab creates an empty virtual buffer.
Because your RoR-related plugins only work in a Rails folder and you are not in a Rails folder -- you are probably in ~, check :pwd to know what the working directory is -- those plugins don't work.

How to rename an existing Grails application

Does anybody know how to (easily) "rename" an existing grails application? I'm running into this because my PaaS provider does not allow me to delete a subscription... So I want to deploy my application under a different name.
Of course, I can do this manually, but I think it might be a useful 'top-level' script (i.e. "grails rename-app newappname")
Manual hints:
When I do a "grails create-app myappname" I can see the myappname exists in the following files (and filenames)... Of course this is done by the create-app script, which replaces #...# tokens in the template. I guess once they are replaced, it's not trivial to do a rename.
./.project: <name>myappname</name>
./application.properties:app.name=myappname
./build.xml:<project xmlns:ivy="antlib:org.apache.ivy.ant" name="myappname" default="test">
./ivy.xml: <info organisation="org.example" module="myappname"/>
./myappname-test.launch:<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="myappname"/>
./myappname.launch:<listEntry value="/myappname"/>
./myappname.launch:<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="myappname" path="1" type="4"/> "/>
./myappname.launch:<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="myappname"/>
./myappname.launch:<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dbase.dir="${project_loc:myappname}" -Dserver.port=8080 -Dgrails.env=development"/>
./myappname.tmproj: <string>myappname.launch</string>
And of course... the top-level directory name is "myappname"
Any hints, or information about ongoing initiatives in this area are welcome
Greetz,
Johan
I had to do this, I renamed my project top level directory to the new name and
edited the application.properties file. There is a line app.name=youroldappname which should be changed.
Actually, you do not even have to rename the directory. You could have a different web-app name.
Hmm, I know it doesn't look fun, but it shouldn't be difficult (just boring) to rename the project directory, then all the files with your project name in them (you can ignore .tmproj unless you use TextMate). Finally, a quick search through all the files for your old project name to replace and you should have it.
Oh! First, if you're using an IDE, you'll want to remove the project from the IDE, then re-import it once you've completed your renaming procedure.
As far as I know, nothing project-specific is stored anywhere except the project directory and below, so it's a very finite set to search, and you only have to do this once (I hope).
Not very elegant, I know, but brute force does have its uses.
I used the brute force Method and it worked for me. Took 5-10 minutes to find all files with the name in it and replace it with the new one. Also Netbeans was ok afterwards. The only thing that changed was the port number which I had to change again.
Just renaming works except when you are using plugins. They will be stored in the $USER_HOME/.grails/$GRAILS_VERSION/projects/OLDNAME folder.
So after renaming your project you "lost" your plugins. I haven't tried renaming the plugin's folder however just installing all your plugin works as well (at least with Google App Engine and gorm-jpa).
If only changing the web app name isn't enough you can try the rough way - make a backup before.
(In workspace folder)
zip -r oldname.zip oldname/
Then, in eclipse/ggts, use
Disable project, Build automatically
Search, File, Containing text : "oldname", Search
Right click on search results, Replace all, ... "newname"
Exit eclipse and rename all folders to the new project name. On Unix/Mac run
find . -name "oldname"
and mv the handful of results to properly reflect the new names.
For me it worked like a charm, but make sure your project name is not a keyword and reasonably unique.

Resources