2013-02-17 05:20:34 +00:00
|
|
|
"=============================================================================
|
|
|
|
" FILE: neosnippet_file.vim
|
2017-06-15 00:11:15 +00:00
|
|
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
|
2017-06-15 00:04:27 +00:00
|
|
|
" License: MIT license
|
2013-02-17 05:20:34 +00:00
|
|
|
"=============================================================================
|
|
|
|
|
2016-02-08 12:48:14 +00:00
|
|
|
function! unite#sources#neosnippet_file#define() abort "{{{
|
2013-02-17 05:20:34 +00:00
|
|
|
return [s:source_user, s:source_runtime]
|
|
|
|
endfunction "}}}
|
|
|
|
|
2013-09-01 10:19:22 +00:00
|
|
|
" common action table
|
|
|
|
let s:action_table = {}
|
|
|
|
let s:action_table.neosnippet_source = {
|
|
|
|
\ 'description' : 'neosnippet_source file',
|
|
|
|
\ 'is_selectable' : 1,
|
|
|
|
\ 'is_quit' : 1,
|
|
|
|
\ }
|
2016-02-08 12:48:14 +00:00
|
|
|
function! s:action_table.neosnippet_source.func(candidates) abort "{{{
|
2013-09-01 10:19:22 +00:00
|
|
|
for candidate in a:candidates
|
|
|
|
let snippet_name = candidate.action__path
|
|
|
|
if snippet_name != ''
|
2013-11-19 07:19:33 +00:00
|
|
|
call neosnippet#commands#_source(snippet_name)
|
2013-09-01 10:19:22 +00:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfunction"}}}
|
|
|
|
|
2013-02-17 05:20:34 +00:00
|
|
|
" neosnippet source.
|
|
|
|
let s:source_user = {
|
|
|
|
\ 'name': 'neosnippet/user',
|
|
|
|
\ 'description' : 'neosnippet user file',
|
2013-09-01 10:19:22 +00:00
|
|
|
\ 'action_table' : copy(s:action_table),
|
2013-02-17 05:20:34 +00:00
|
|
|
\ }
|
2016-02-08 12:48:14 +00:00
|
|
|
function! s:source_user.gather_candidates(args, context) abort "{{{
|
2013-02-17 05:58:57 +00:00
|
|
|
return s:get_snippet_candidates(
|
|
|
|
\ neosnippet#get_user_snippets_directory())
|
2013-02-17 05:20:34 +00:00
|
|
|
endfunction "}}}
|
|
|
|
|
2013-02-17 07:11:21 +00:00
|
|
|
let s:source_user.action_table.unite__new_candidate = {
|
|
|
|
\ 'description' : 'create new user snippet',
|
|
|
|
\ 'is_invalidate_cache' : 1,
|
|
|
|
\ 'is_quit' : 1,
|
|
|
|
\ }
|
2016-02-08 12:48:14 +00:00
|
|
|
function! s:source_user.action_table.unite__new_candidate.func(candidate) abort "{{{
|
2013-02-17 07:11:21 +00:00
|
|
|
let filename = input(
|
2013-11-21 09:40:40 +00:00
|
|
|
\ 'New snippet file name: ', neosnippet#helpers#get_filetype())
|
2013-02-17 07:11:21 +00:00
|
|
|
if filename != ''
|
2013-11-19 07:19:33 +00:00
|
|
|
call neosnippet#commands#_edit(filename)
|
2013-02-17 07:11:21 +00:00
|
|
|
endif
|
|
|
|
endfunction"}}}
|
|
|
|
|
2013-02-17 05:20:34 +00:00
|
|
|
|
|
|
|
" neosnippet source.
|
|
|
|
let s:source_runtime = {
|
|
|
|
\ 'name': 'neosnippet/runtime',
|
|
|
|
\ 'description' : 'neosnippet runtime file',
|
2013-09-01 10:19:22 +00:00
|
|
|
\ 'action_table' : copy(s:action_table),
|
2013-02-17 05:20:34 +00:00
|
|
|
\ }
|
2016-02-08 12:48:14 +00:00
|
|
|
function! s:source_runtime.gather_candidates(args, context) abort "{{{
|
2013-02-17 05:58:57 +00:00
|
|
|
return s:get_snippet_candidates(
|
|
|
|
\ neosnippet#get_runtime_snippets_directory())
|
2013-02-17 05:20:34 +00:00
|
|
|
endfunction "}}}
|
|
|
|
|
2013-02-17 07:11:21 +00:00
|
|
|
let s:source_runtime.action_table.unite__new_candidate = {
|
|
|
|
\ 'description' : 'create new runtime snippet',
|
|
|
|
\ 'is_invalidate_cache' : 1,
|
|
|
|
\ 'is_quit' : 1,
|
|
|
|
\ }
|
2016-02-08 12:48:14 +00:00
|
|
|
function! s:source_runtime.action_table.unite__new_candidate.func(candidate) abort "{{{
|
2013-02-17 07:11:21 +00:00
|
|
|
let filename = input(
|
2013-11-21 09:40:40 +00:00
|
|
|
\ 'New snippet file name: ', neosnippet#helpers#get_filetype())
|
2013-02-17 07:11:21 +00:00
|
|
|
if filename != ''
|
2013-11-19 07:19:33 +00:00
|
|
|
call neosnippet#commands#_edit('-runtime ' . filename)
|
2013-02-17 07:11:21 +00:00
|
|
|
endif
|
|
|
|
endfunction"}}}
|
|
|
|
|
2013-02-17 05:20:34 +00:00
|
|
|
|
2016-02-08 12:48:14 +00:00
|
|
|
function! s:get_snippet_candidates(dirs) abort "{{{
|
2013-02-17 05:58:57 +00:00
|
|
|
let _ = []
|
|
|
|
for directory in a:dirs
|
|
|
|
let _ += map(split(unite#util#substitute_path_separator(
|
|
|
|
\ globpath(directory, '**/*.snip*')), '\n'), "{
|
|
|
|
\ 'word' : v:val[len(directory)+1 :],
|
|
|
|
\ 'action__path' : v:val,
|
|
|
|
\ 'kind' : 'file',
|
|
|
|
\ }")
|
|
|
|
endfor
|
|
|
|
|
|
|
|
return _
|
2013-02-17 05:20:34 +00:00
|
|
|
endfunction "}}}
|
|
|
|
|
|
|
|
" vim: foldmethod=marker
|