Adding ctags integration to UltiSnips

Asked by Gernot Hoeflechner

What do you think of adding a ctags configuration to UltiSnips? This might not
be terribly useful for the creation of actual tag files, but it's kinda cool
when you integrate it with the Tagbar plugin.

Here's a screenshot of what I am talking about:
oi61.tinypic.com/2sbpor5.jpg The bottom part of the screen holds
CtrlPTag output. This is available after actually creating a tags file, you see
that I can fuzzy search all available snippets in the snippets directory.

The split buffer on the right shows the Tagbar plugin. No tag file has to be
created for it, the plugin handles the tag creation in realtime and returns a
nicely sorted list of available snippets in the file I am currently watching.

The actual implementation of it is terribly simple.

I added the following lines to my ~/.ctags file:
--langdef=snippets
--langmap=snippets:.snippets
--regex-snippets=/^snippet (.*)/\1/s,snippet/

And in my vimrc I defined a tagbar related variable:
let g:tagbar_type_snippets = {
      \ 'ctagstype' : 'snippets',
      \ 'kinds' : [
              \ 's:snippets',
      \ ]
\ }

So, we could for sure add this information to the Tagbar wiki at
https://github.com/majutsushi/tagbar/wiki.
We could also add a section in
UltiSnips docs to publish the possibility of doing this.
A further help could be to provide a variable like
g:UltiSnipsTagbarIntegration, which the user can set to 1 and add vim code to
define g:tagbar_type_snippets automatically (unless it's already set etc.)

One would need to handle the addition to the .ctags file manually of course.

I also thought it would be kinda cool to detect and list global snippets as well, but
that's not really easy to do, as global snippets don't really have an
identifier with them (something like a description). On the tags side this
would need exactly to more lines of code to handle.

Possible outcome: Tagbar users can find out about UltiSnips and start using it too :D

Nothing groundbreaking, but probably a nice addition.

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
SirVer (sirver) said :
#1

not a big fan of this proposal. First ctags has no context sensitivity - so inword snippets or only at the beginning of line snippets are always shown. Also there are already excellent solutions for completing snippets (i.e. youcompleteme). This proposal feels like a huge hack to me.

Revision history for this message
Gernot Hoeflechner (1986gh) said :
#2

Hm maybe we are misunderstanding each other, I am actually not proposing using ctags to look up or complete snippets - I agree that's pretty useless and I would never do that.
I only think it's convenient to use the tagbar plugin in snippet files. Tagbar doesn't create a true searchable tag file, it only uses ctags information to parse the contents of your current buffer to display an outline of the file (usually also in a hierarchy of classes etc.). In the case of a snippets file, you'll get a list of all snippets defined in the open snippet file - which is handy when you move around in a big snippet file looking for a particular snippet, or just getting a general idea of what's available, before looking at the actual implemention and so on.

Of course, it's absolutely no must to do anything on UltiSnips' side, I could just add it to the Tagbar wiki and be more than satisfied, unless you don't want UltiSnips mentioned there.

Revision history for this message
Best SirVer (sirver) said :
#3

oh, indeed. I did misunderstand you there.

I think adding this to the tagbar wiki is perfectly fine. I am a little reluctant of adding any code concerning this to UltiSnips since it needs to be maintained and I doubt than many people would benefit from this solution. Not that many people I know are using tagbar.

Revision history for this message
Gernot Hoeflechner (1986gh) said :
#4

Yeah, makes sense, not a good idea to add anything to UltiSnips after thinking about it again. But I'll add it to the wiki :)

Revision history for this message
Gernot Hoeflechner (1986gh) said :
#5

Thanks SirVer, that solved my question.