2012-10-31 05:50:50 +00:00
|
|
|
"=============================================================================
|
|
|
|
" FILE: snippet_target.vim
|
|
|
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
2013-11-21 09:40:40 +00:00
|
|
|
" Last Modified: 21 Nov 2013.
|
2012-10-31 05:50:50 +00:00
|
|
|
" 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 =
|
2013-11-21 09:40:40 +00:00
|
|
|
\ sort(filter(values(neosnippet#helpers#get_snippets()),
|
2012-10-31 05:50:50 +00:00
|
|
|
\ "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 = {
|
2013-03-05 13:57:03 +00:00
|
|
|
\ 'word' : printf('%-50s %s', keyword.word, keyword.menu_abbr),
|
2012-11-02 02:19:46 +00:00
|
|
|
\ 'source__trigger' : keyword.word,
|
2013-03-05 13:57:03 +00:00
|
|
|
\ 'source__menu' : keyword.menu_abbr,
|
2012-10-31 05:50:50 +00:00
|
|
|
\ 'source__snip' : keyword.snip,
|
|
|
|
\ 'source__context' : a:context,
|
|
|
|
\ }
|
|
|
|
|
|
|
|
call add(list, dict)
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return list
|
|
|
|
endfunction "}}}
|
|
|
|
|
2012-12-13 08:34:20 +00:00
|
|
|
" Actions "{{{
|
2012-10-31 05:50:50 +00:00
|
|
|
let s:source.action_table.select = {
|
|
|
|
\ 'description' : 'select targetted snippet',
|
|
|
|
\ }
|
2012-12-13 08:34:20 +00:00
|
|
|
function! s:source.action_table.select.func(candidate) "{{{
|
2012-10-31 05:50:50 +00:00
|
|
|
let context = a:candidate.source__context
|
|
|
|
if bufnr('%') != context.source__bufnr ||
|
|
|
|
\ line('.') != context.source__linenr
|
|
|
|
" Ignore.
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-11-21 09:54:04 +00:00
|
|
|
call neosnippet#mappings#_expand_target_trigger(a:candidate.source__trigger)
|
2012-10-31 05:50:50 +00:00
|
|
|
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 "}}}
|
|
|
|
|
2012-12-13 08:34:20 +00:00
|
|
|
function! s:get_keyword_pos(cur_text) "{{{
|
2012-10-31 05:50:50 +00:00
|
|
|
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
|