From cc15145429f39b3d3fa2fc15c6b7120e4c9ae2db Mon Sep 17 00:00:00 2001 From: Helder Jorge Rodrigues Inacio Date: Mon, 31 Mar 2014 21:44:31 -0400 Subject: [PATCH 1/3] add unite source --- autoload/unite/sources/ultisnips.vim | 56 ++++++++++++++++++++++++++++ doc/UltiSnips.txt | 10 +++++ 2 files changed, 66 insertions(+) create mode 100644 autoload/unite/sources/ultisnips.vim diff --git a/autoload/unite/sources/ultisnips.vim b/autoload/unite/sources/ultisnips.vim new file mode 100644 index 0000000..30e2d83 --- /dev/null +++ b/autoload/unite/sources/ultisnips.vim @@ -0,0 +1,56 @@ +let s:save_cpo = &cpo +set cpo&vim + +let s:unite_source = { + \ 'name': 'ultisnips', + \ 'hooks': {}, + \ 'action_table': {}, + \ 'default_action': 'expand', + \ } + +let s:unite_source.action_table.preview = { + \ 'description' : 'ultisnips snippets', + \ 'is_quit' : 0, + \ } + +function! s:unite_source.action_table.preview.func(candidate) + " no nice preview at this point, cannot get snippet text + let snippet_preview = a:candidate['word'] + echo snippet_preview +endfunction + +let s:unite_source.action_table.expand = { + \ 'description': 'expand the current snippet', + \ 'is_quit': 1 + \} + +function! s:unite_source.action_table.expand.func(candidate) + let delCurrWord = (getline(".")[col(".")-1] == " ") ? "" : "diw" + exe "normal " . delCurrWord . "a" . a:candidate['trigger'] . " " + call UltiSnips#ExpandSnippet() + return '' +endfunction + +function! s:unite_source.gather_candidates(args, context) + let default_val = {'word': '', 'unite__abbr': '', 'is_dummy': 0, 'source': + \ 'ultisnips', 'unite__is_marked': 0, 'kind': 'command', 'is_matched': 1, + \ 'is_multiline': 0} + let snippet_list = UltiSnips#SnippetsInCurrentScope() + let canditates = [] + for snip in items(snippet_list) + let curr_val = copy(default_val) + let curr_val['word'] = snip[0] . " " . snip[1] + let curr_val['trigger'] = snip[0] + call add(canditates, curr_val) + endfor + return canditates +endfunction + +function! unite#sources#ultisnips#define() + return s:unite_source +endfunction + +"unlet s:unite_source + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index e63eb79..1ae7599 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -1284,6 +1284,16 @@ offers a really nice completion dialogue for snippets. neocomplete - UltiSnips ships with a source for neocomplete and therefore offers out of the box completion dialogue support for it too. +unite - similarly to neocomplete UltiSnips now has a source for unite. +As an example of how you can use the unite source add the following mappings to +your vimrc: + + nnoremap :Unite -start-insert ultisnips + inoremap :Unite -start-insert ultisnips + +Then typing in either insert or normal mode you will get unite interface +with matching snippets. Pressing enter will expand the corresponding snippet. + Supertab - UltiSnips has built-in support for Supertab. Just use a recent enough version of both plugins and will either expand a snippet or defer to Supertab for expansion. From 7bee824db2e80139f0dbeb4437ccc22a599c8bf8 Mon Sep 17 00:00:00 2001 From: Helder Jorge Rodrigues Inacio Date: Thu, 3 Apr 2014 00:00:34 -0400 Subject: [PATCH 2/3] use function to invoqe unite --- doc/UltiSnips.txt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/UltiSnips.txt b/doc/UltiSnips.txt index 1ae7599..1452afe 100644 --- a/doc/UltiSnips.txt +++ b/doc/UltiSnips.txt @@ -236,7 +236,7 @@ vimrc file. > let g:UltiSnipsJumpBackwardTrigger="" UltiSnips will only map the jump triggers while a snippet is active to -interfer as little as possible with other mappings. +interfer as little as possible with other mappings. The default value for g:UltiSnipsJumpBackwardTrigger interferes with the built-in complete function: |i_CTRL-X_CTRL-K|. A workaround is to add the @@ -1285,14 +1285,22 @@ neocomplete - UltiSnips ships with a source for neocomplete and therefore offers out of the box completion dialogue support for it too. unite - similarly to neocomplete UltiSnips now has a source for unite. -As an example of how you can use the unite source add the following mappings to -your vimrc: +As an example of how you can use the unite source add the following function and +mappings to your vimrc: + + function! UltiSnipsCallUnite() + Unite -start-insert -winheight=100 -immediately -no-empty ultisnips + return '' + endfunction + + inoremap =(pumvisible()? "\C-E>":"")=UltiSnipsCallUnite() + nnoremap a=(pumvisible()? "\C-E>":"")=UltiSnipsCallUnite() - nnoremap :Unite -start-insert ultisnips - inoremap :Unite -start-insert ultisnips Then typing in either insert or normal mode you will get unite interface with matching snippets. Pressing enter will expand the corresponding snippet. +If only one snippet matches the text in front of the cursor then it will be +expanded when you press the key. Supertab - UltiSnips has built-in support for Supertab. Just use a recent enough version of both plugins and will either expand a snippet or defer From 77a9d8941f6ac432e8936d29df37b0b7bdbd933d Mon Sep 17 00:00:00 2001 From: Helder Jorge Rodrigues Inacio Date: Sat, 12 Apr 2014 21:02:11 -0400 Subject: [PATCH 3/3] simple test for unite interface --- test.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test.py b/test.py index 0e1de5c..cb7c5b7 100755 --- a/test.py +++ b/test.py @@ -3406,6 +3406,20 @@ class Plugin_Neocomplete_BugTest(_VimTest): vim_config.append('let g:neocomplete#enable_auto_delimiter = 1') vim_config.append('let g:neocomplete#enable_refresh_always = 1') # End: Plugin: Neocomplete #}}} +# Plugin: unite {{{# +class Plugin_unite_BugTest(_VimTest): + plugins = ["Shougo/unite.vim"] + snippets = ("t", "Hello", "", "w") + keys = "iab\\ t=UltiSnipsCallUnite()\n" + wanted = "iab\\ Hello " + + def _extra_options_pre_init(self, vim_config): + vim_config.append(r'set iskeyword+=\\ ') + vim_config.append('function! UltiSnipsCallUnite()') + vim_config.append(' Unite -start-insert -winheight=100 -immediately -no-empty ultisnips') + vim_config.append(' return ""') + vim_config.append('endfunction') +# End: Plugin: unite #}}} # Plugin: Supertab {{{# class Plugin_SuperTab_SimpleTest(_VimTest): plugins = ["ervandew/supertab"]