Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conflict with Ultisnips #145

Closed
regedarek opened this issue Mar 6, 2012 · 12 comments
Closed

conflict with Ultisnips #145

regedarek opened this issue Mar 6, 2012 · 12 comments

Comments

@regedarek
Copy link

http://stackoverflow.com/questions/9556230/how-to-set-manualy-color-of-params-and-redirect-to-in-vim#comment12127893_9556230

My filetype is ruby.rails and when i cheange it to set filetype=ruby syntax works.
But then my ultisnips dont recognize rails snippets, how to compare this two things??

@tpope
Copy link
Owner

tpope commented Mar 6, 2012

The problem is that every snippets plugin insists that file types are the only valid grouping for snippets. This leads to the bizarre creation of a "rails" pseudo-filetype. See #134 for my stance on that.

That being said, if someone wants to go to the trouble of working around it in rails.vim, I won't object. Basically, you need to change conditionals like

if &filetype == 'ruby'

to be like

if &filetype =~# '^ruby\>'

Make sure you get all of them though. Start with a search for \<ruby\>.

@regedarek
Copy link
Author

Thx Tim :)

@SirVer
Copy link

SirVer commented Mar 6, 2012

Tim, I am the author of UltiSnips. I am interested in a better way to group snippets beside filetypes to avoid this clutch. Do you have a suggestion? One could add a Vim Variable (a dictionary maybe) that rails.vim could set or modify and that ultisnips would understand - but this would be a specific hack for UltiSnips. Do you have a better suggestion?

@tpope
Copy link
Owner

tpope commented Mar 6, 2012

@SirVer I feel like the ideal solution is just a command that defines a snippet for the current buffer. Much like how abbreviations work. If you wanted to define an abbreviation for all Ruby files, you'd do

autocmd FileType ruby abbrev <buffer> AR ActiveRecord

Doing it in in Rails projects, then, is a simple switch to a rails.vim autocommand:

autocmd User Rails abbrev <buffer> AR ActiveRecord

I guess the problem here is that snippets tend to be multiple lines, and thus much harder to adapt to a Vim command syntax. Given this constraint, I feel like the best compromise solution is instead some sort of command to load a bundle of snippets into the current buffer independent of file type. That would enable a simple decoupling.

autocmd User Rails UltiSnipsLoad rails

Hell, I'd have no objection to dispatching that from rails.vim automatically.

Bonus orthogonal idea: ability to load from an arbitrary path. This would enable project specific snippets. For example:

autocmd User Fugitive UltiSnipsLoad `=fugitive#repo().tree('.project.snippets')`

@SirVer
Copy link

SirVer commented Mar 8, 2012

Right, I added a bug report for this idea in the ultisnips bug tracker [1]. I think I prefer a buffer local variable, similar to a vim option - so it will be possible to also associate a priority order with the filetypes. Note that project specific snippets are already supported, but a naming convention must be followed [2]. Thanks for your ideas Tim! I will let you know when I have implemented this in UltiSnips.

[1] https://bugs.launchpad.net/ultisnips/+bug/950033
[2] https://answers.launchpad.net/ultisnips/+question/187062

@tpope
Copy link
Owner

tpope commented Mar 9, 2012

Sounds good. I hope you'll consider a wrapper command though. If I do

if &filetype =~# '^ruby\>'
  let b:UtilSnips_Filetypes = ['ruby', 'rails']
endif

I'll be potentially clobbering the user's preferences, and if I do

if &filetype =~# '^ruby\>' && exists('b:UltiSnips_Filtetypes')
  let b:UtilSnips_Filetypes += ['rails']
endif

I'll be potentially duplicating 'rails' in b:UtilSnips_Filetypes, particularly on reloads.

@SirVer
Copy link

SirVer commented Mar 10, 2012

I will keep this in mind.

@SirVer
Copy link

SirVer commented Apr 1, 2012

Tim, I just pushed this fix. There is now a new command defined in UltiSnips. I think vim-rails should call it like this

:UltiSnipsAddFiletypes rails.ruby

for each rails buffer. It will make sure that rails and ruby snippets are considered when expanding and rails snippets will have a higher priority (read: can overwrite) ruby snippets. Also, UltiSnipsEdit will open rails.snippets by default for editing. Would you mind adding this to rails.vim?

@tpope
Copy link
Owner

tpope commented Apr 1, 2012

I can give it a go. Surely I can just do :UtilsSnipsAddFiletypes rails in ruby files, right?

Calling them Filetypes still feels wrong, but it's a dissonance I'm willing to tolerate. :)

@SirVer
Copy link

SirVer commented Apr 1, 2012

I can give it a go. Surely I can just do :UtilsSnipsAddFiletypes rails in ruby files, right?
Yep. Though it should not be needed as the UltiSnips also reacts on the
FileType autocommand. But it does no harm at all

@tpope tpope reopened this Apr 1, 2012
@tpope tpope closed this as completed in 28ba552 Apr 1, 2012
@tpope
Copy link
Owner

tpope commented Apr 1, 2012

Done and done.

@SirVer
Copy link

SirVer commented Apr 2, 2012

Cool, thanks Tim!

dennisjbell pushed a commit to RubidiumStudios/vim-rails that referenced this issue Jun 18, 2012
ajzafar added a commit to garbas/vim-snipmate that referenced this issue Mar 22, 2014
This is like the UltiSnipsLoad command that came out of
<tpope/vim-rails#145>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants