- Added <Plug>(neosnippet_start_unite_snippet_target).
This commit is contained in:
parent
2d5fccac52
commit
32eca05280
@ -617,7 +617,7 @@ function! neosnippet#expand_target()"{{{
|
|||||||
let neosnippet = neosnippet#get_current_neosnippet()
|
let neosnippet = neosnippet#get_current_neosnippet()
|
||||||
if !has_key(neosnippet#get_snippets(), trigger) ||
|
if !has_key(neosnippet#get_snippets(), trigger) ||
|
||||||
\ neosnippet#get_snippets()[trigger].snip !~#
|
\ neosnippet#get_snippets()[trigger].snip !~#
|
||||||
\ s:get_placeholder_target_marker_pattern()
|
\ neosnippet#get_placeholder_target_marker_pattern()
|
||||||
if trigger != ''
|
if trigger != ''
|
||||||
echo 'The trigger is invalid.'
|
echo 'The trigger is invalid.'
|
||||||
endif
|
endif
|
||||||
@ -628,18 +628,21 @@ function! neosnippet#expand_target()"{{{
|
|||||||
|
|
||||||
let neosnippet.target = substitute(
|
let neosnippet.target = substitute(
|
||||||
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
|
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
|
||||||
call neosnippet#delete_selected_text(visualmode(), 1)
|
|
||||||
|
|
||||||
let base_indent = matchstr(neosnippet.target, '^\s*')
|
let base_indent = matchstr(neosnippet.target, '^\s*')
|
||||||
|
|
||||||
" Delete base_indent.
|
" Delete base_indent.
|
||||||
let neosnippet.target = substitute(neosnippet.target,
|
let neosnippet.target = substitute(neosnippet.target,
|
||||||
\'^' . base_indent, '', 'g')
|
\'^' . base_indent, '', 'g')
|
||||||
|
|
||||||
call setline('.', base_indent . trigger)
|
call neosnippet#substitute_selected_text(visualmode(),
|
||||||
startinsert!
|
\ base_indent)
|
||||||
|
|
||||||
call neosnippet#expand(getline('.'), col('$'), trigger)
|
" startinsert!
|
||||||
|
" let start = getpos("'<")
|
||||||
|
" call cursor(0, start[2]+len(base_indent . trigger)-1)
|
||||||
|
|
||||||
|
call neosnippet#expand(neosnippet#util#get_cur_text(),
|
||||||
|
\ col('.'), trigger)
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! s:indent_snippet(begin, end)"{{{
|
function! s:indent_snippet(begin, end)"{{{
|
||||||
if a:begin > a:end
|
if a:begin > a:end
|
||||||
@ -1005,7 +1008,8 @@ function! neosnippet#get_snippets()"{{{
|
|||||||
call extend(snippets, s:snippets[filetype], 'keep')
|
call extend(snippets, s:snippets[filetype], 'keep')
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
if !s:is_beginning_of_line(neosnippet#util#get_cur_text())
|
if mode() ==# 'i' &&
|
||||||
|
\ !s:is_beginning_of_line(neosnippet#util#get_cur_text())
|
||||||
call filter(snippets, '!v:val.options.head')
|
call filter(snippets, '!v:val.options.head')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -1054,10 +1058,10 @@ endfunction"}}}
|
|||||||
function! neosnippet#complete_target_snippets(arglead, cmdline, cursorpos)"{{{
|
function! neosnippet#complete_target_snippets(arglead, cmdline, cursorpos)"{{{
|
||||||
return map(filter(values(neosnippet#get_snippets()),
|
return map(filter(values(neosnippet#get_snippets()),
|
||||||
\ "stridx(v:val.word, a:arglead) == 0
|
\ "stridx(v:val.word, a:arglead) == 0
|
||||||
\ && v:val.snip =~# s:get_placeholder_target_marker_pattern()"), 'v:val.word')
|
\ && v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"), 'v:val.word')
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:get_placeholder_target_marker_pattern()"{{{
|
function! neosnippet#get_placeholder_target_marker_pattern()"{{{
|
||||||
return '\${\d\+:TARGET\%(:.\{-}\)\?\\\@<!}'
|
return '\${\d\+:TARGET\%(:.\{-}\)\?\\\@<!}'
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! s:get_placeholder_marker_pattern()"{{{
|
function! s:get_placeholder_marker_pattern()"{{{
|
||||||
@ -1156,6 +1160,21 @@ function! neosnippet#delete_selected_text(type, ...)"{{{
|
|||||||
call setpos('.', pos)
|
call setpos('.', pos)
|
||||||
endtry
|
endtry
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
function! neosnippet#substitute_selected_text(type, text)"{{{
|
||||||
|
let sel_save = &selection
|
||||||
|
let &selection = 'inclusive'
|
||||||
|
let reg_save = @@
|
||||||
|
let pos = getpos('.')
|
||||||
|
|
||||||
|
try
|
||||||
|
" Invoked from Visual mode, use '< and '> marks.
|
||||||
|
silent exe "normal! `<" . a:type . "`>s" . a:text
|
||||||
|
finally
|
||||||
|
let &selection = sel_save
|
||||||
|
let @@ = reg_save
|
||||||
|
call setpos('.', pos)
|
||||||
|
endtry
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
function! neosnippet#clear_select_mode_mappings()"{{{
|
function! neosnippet#clear_select_mode_mappings()"{{{
|
||||||
if !g:neosnippet#disable_select_mode_mappings
|
if !g:neosnippet#disable_select_mode_mappings
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: snippet.vim
|
" FILE: snippet.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 21 Oct 2012.
|
" Last Modified: 31 Oct 2012.
|
||||||
" License: MIT license {{{
|
" License: MIT license {{{
|
||||||
" Permission is hereby granted, free of charge, to any person obtaining
|
" Permission is hereby granted, free of charge, to any person obtaining
|
||||||
" a copy of this software and associated documentation files (the
|
" a copy of this software and associated documentation files (the
|
||||||
@ -56,7 +56,7 @@ function! s:source.hooks.on_init(args, context) "{{{
|
|||||||
let a:context.source__cur_keyword_pos =
|
let a:context.source__cur_keyword_pos =
|
||||||
\ s:get_keyword_pos(neosnippet#util#get_cur_text())
|
\ s:get_keyword_pos(neosnippet#util#get_cur_text())
|
||||||
let a:context.source__snippets =
|
let a:context.source__snippets =
|
||||||
\ sort(values(neosnippet#get_snippets()), 's:compare_words')
|
\ sort(values(neosnippet#get_snippets()))
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:source.gather_candidates(args, context) "{{{
|
function! s:source.gather_candidates(args, context) "{{{
|
||||||
@ -168,12 +168,10 @@ function! unite#sources#snippet#start_complete() "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
return unite#start_complete(['snippet'],
|
return unite#start_complete(['snippet'],
|
||||||
\ { 'input': neosnippet#util#get_cur_text() })
|
\ { 'input': neosnippet#util#get_cur_text(),
|
||||||
|
\ 'buffer_name' : 'snippet' })
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:compare_words(i1, i2)"{{{
|
|
||||||
return a:i1.menu - a:i2.menu
|
|
||||||
endfunction"}}}
|
|
||||||
function! s:get_keyword_pos(cur_text)"{{{
|
function! s:get_keyword_pos(cur_text)"{{{
|
||||||
let cur_keyword_pos = match(a:cur_text, '\S\+$')
|
let cur_keyword_pos = match(a:cur_text, '\S\+$')
|
||||||
if cur_keyword_pos < 0
|
if cur_keyword_pos < 0
|
||||||
|
137
autoload/unite/sources/snippet_target.vim
Normal file
137
autoload/unite/sources/snippet_target.vim
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
"=============================================================================
|
||||||
|
" FILE: snippet_target.vim
|
||||||
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
|
" Last Modified: 31 Oct 2012.
|
||||||
|
" License: MIT license {{{
|
||||||
|
" Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
" a copy of this software and associated documentation files (the
|
||||||
|
" "Software"), to deal in the Software without restriction, including
|
||||||
|
" without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
" distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
" permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
" the following conditions:
|
||||||
|
"
|
||||||
|
" The above copyright notice and this permission notice shall be included
|
||||||
|
" in all copies or substantial portions of the Software.
|
||||||
|
"
|
||||||
|
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
" }}}
|
||||||
|
"=============================================================================
|
||||||
|
|
||||||
|
let s:save_cpo = &cpo
|
||||||
|
set cpo&vim
|
||||||
|
|
||||||
|
function! unite#sources#snippet_target#define() "{{{
|
||||||
|
if !exists('*unite#version') || unite#version() < 150
|
||||||
|
echoerr 'Your unite.vim is too old.'
|
||||||
|
return []
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:source
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
let s:source = {
|
||||||
|
\ 'name': 'snippet/target',
|
||||||
|
\ 'hooks' : {},
|
||||||
|
\ 'default_action' : 'select',
|
||||||
|
\ 'action_table' : {},
|
||||||
|
\ 'is_listed' : 0,
|
||||||
|
\ }
|
||||||
|
|
||||||
|
function! s:source.hooks.on_init(args, context) "{{{
|
||||||
|
let a:context.source__bufnr = bufnr('%')
|
||||||
|
let a:context.source__linenr = line('.')
|
||||||
|
|
||||||
|
let a:context.source__snippets =
|
||||||
|
\ sort(filter(values(neosnippet#get_snippets()),
|
||||||
|
\ "v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"))
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
|
function! s:source.gather_candidates(args, context) "{{{
|
||||||
|
let list = []
|
||||||
|
for keyword in a:context.source__snippets
|
||||||
|
let dict = {
|
||||||
|
\ 'word' : keyword.word,
|
||||||
|
\ 'abbr' : printf('%-50s %s', keyword.word, keyword.menu),
|
||||||
|
\ 'source__menu' : keyword.menu,
|
||||||
|
\ 'source__snip' : keyword.snip,
|
||||||
|
\ 'source__context' : a:context,
|
||||||
|
\ }
|
||||||
|
|
||||||
|
call add(list, dict)
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return list
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
" Actions"{{{
|
||||||
|
let s:source.action_table.select = {
|
||||||
|
\ 'description' : 'select targetted snippet',
|
||||||
|
\ }
|
||||||
|
function! s:source.action_table.select.func(candidate)"{{{
|
||||||
|
let context = a:candidate.source__context
|
||||||
|
if bufnr('%') != context.source__bufnr ||
|
||||||
|
\ line('.') != context.source__linenr
|
||||||
|
" Ignore.
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let neosnippet = neosnippet#get_current_neosnippet()
|
||||||
|
|
||||||
|
let neosnippet.target = substitute(
|
||||||
|
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
|
||||||
|
let base_indent = matchstr(neosnippet.target, '^\s*')
|
||||||
|
|
||||||
|
" Delete base_indent.
|
||||||
|
let neosnippet.target = substitute(neosnippet.target,
|
||||||
|
\'^' . base_indent, '', 'g')
|
||||||
|
|
||||||
|
call neosnippet#substitute_selected_text(visualmode(),
|
||||||
|
\ base_indent)
|
||||||
|
|
||||||
|
call cursor(0, getpos("'<")[2])
|
||||||
|
|
||||||
|
call neosnippet#expand(neosnippet#util#get_cur_text(),
|
||||||
|
\ col('.'), a:candidate.word)
|
||||||
|
endfunction"}}}
|
||||||
|
"}}}
|
||||||
|
|
||||||
|
function! unite#sources#snippet_target#start() "{{{
|
||||||
|
if !exists(':Unite')
|
||||||
|
call neosnippet#util#print_error(
|
||||||
|
\ 'unite.vim is not installed.')
|
||||||
|
call neosnippet#util#print_error(
|
||||||
|
\ 'Please install unite.vim Ver.1.5 or above.')
|
||||||
|
return ''
|
||||||
|
elseif unite#version() < 300
|
||||||
|
call neosnippet#util#print_error(
|
||||||
|
\ 'Your unite.vim is too old.')
|
||||||
|
call neosnippet#util#print_error(
|
||||||
|
\ 'Please install unite.vim Ver.3.0 or above.')
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
return unite#start_complete(['snippet/target'],
|
||||||
|
\ { 'buffer_name' : 'snippet/target' })
|
||||||
|
endfunction "}}}
|
||||||
|
|
||||||
|
function! s:get_keyword_pos(cur_text)"{{{
|
||||||
|
let cur_keyword_pos = match(a:cur_text, '\S\+$')
|
||||||
|
if cur_keyword_pos < 0
|
||||||
|
" Empty string.
|
||||||
|
return len(a:cur_text)
|
||||||
|
endif
|
||||||
|
|
||||||
|
return cur_keyword_pos
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
|
let &cpo = s:save_cpo
|
||||||
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
" vim: foldmethod=marker
|
@ -238,9 +238,9 @@ s_<Plug>(neosnippet_jump)
|
|||||||
|
|
||||||
i_<Plug>(neosnippet_start_unite_snippet)
|
i_<Plug>(neosnippet_start_unite_snippet)
|
||||||
*i_<Plug>(neosnippet_start_unite_snippet)*
|
*i_<Plug>(neosnippet_start_unite_snippet)*
|
||||||
Starts the unite snippet source. You can expand a snippet by the
|
Starts the unite snippet source. You can expand a snippet by the
|
||||||
unite interface. Note: The plug-in |unite.vim| is required for
|
unite interface.
|
||||||
that feature.
|
Note: The plug-in |unite.vim| is required for that feature.
|
||||||
|
|
||||||
*<Plug>(neocomplcache_start_unite_snippet)*
|
*<Plug>(neocomplcache_start_unite_snippet)*
|
||||||
Note: |<Plug>(neocomplcache_start_unite_snippet)| is an obsolete
|
Note: |<Plug>(neocomplcache_start_unite_snippet)| is an obsolete
|
||||||
@ -250,6 +250,12 @@ x_<Plug>(neosnippet_expand_target)
|
|||||||
*x_<Plug>(neosnippet_expand_target)*
|
*x_<Plug>(neosnippet_expand_target)*
|
||||||
Expand the input trigger by a selected target text.
|
Expand the input trigger by a selected target text.
|
||||||
|
|
||||||
|
x_<Plug>(neosnippet_start_unite_snippet_target)
|
||||||
|
*x_<Plug>(neosnippet_start_unite_snippet_target)*
|
||||||
|
Expand the input trigger by a selected target text by the
|
||||||
|
unite interface.
|
||||||
|
Note: The plug-in |unite.vim| is required for that feature.
|
||||||
|
|
||||||
x_<Plug>(neosnippet_register_oneshot_snippet)
|
x_<Plug>(neosnippet_register_oneshot_snippet)
|
||||||
*x_<Plug>(neosnippet_register_oneshot_snippet)*
|
*x_<Plug>(neosnippet_register_oneshot_snippet)*
|
||||||
Register oneshot snippet in the current buffer.
|
Register oneshot snippet in the current buffer.
|
||||||
@ -619,6 +625,7 @@ CHANGELOG *neosnippet-changelog*
|
|||||||
|
|
||||||
2012-10-31
|
2012-10-31
|
||||||
- Improved indent_snippet().
|
- Improved indent_snippet().
|
||||||
|
- Added <Plug>(neosnippet_start_unite_snippet_target).
|
||||||
|
|
||||||
2012-10-30
|
2012-10-30
|
||||||
- Implemented commented placeholder.
|
- Implemented commented placeholder.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: neosnippet.vim
|
" FILE: neosnippet.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 30 Oct 2012.
|
" Last Modified: 31 Oct 2012.
|
||||||
" License: MIT license {{{
|
" License: MIT license {{{
|
||||||
" Permission is hereby granted, free of charge, to any person obtaining
|
" Permission is hereby granted, free of charge, to any person obtaining
|
||||||
" a copy of this software and associated documentation files (the
|
" a copy of this software and associated documentation files (the
|
||||||
@ -77,6 +77,8 @@ smap <silent> <Plug>(neocomplcache_snippets_force_jump)
|
|||||||
|
|
||||||
xnoremap <silent> <Plug>(neosnippet_expand_target)
|
xnoremap <silent> <Plug>(neosnippet_expand_target)
|
||||||
\ :<C-u>call neosnippet#expand_target()<CR>
|
\ :<C-u>call neosnippet#expand_target()<CR>
|
||||||
|
xnoremap <silent><expr> <Plug>(neosnippet_start_unite_snippet_target)
|
||||||
|
\ unite#sources#snippet_target#start()
|
||||||
xnoremap <silent> <Plug>(neosnippet_register_oneshot_snippet)
|
xnoremap <silent> <Plug>(neosnippet_register_oneshot_snippet)
|
||||||
\ :<C-u>call neosnippet#register_oneshot_snippet()<CR>
|
\ :<C-u>call neosnippet#register_oneshot_snippet()<CR>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user