- Improved snippet sources.

This commit is contained in:
Shougo Matsushita 2013-02-17 14:58:57 +09:00
parent 38ba96ea91
commit 8fa2d27f62
3 changed files with 32 additions and 15 deletions

View File

@ -1035,6 +1035,8 @@ function! neosnippet#get_snippets() "{{{
return snippets return snippets
endfunction"}}} endfunction"}}}
function! neosnippet#get_snippets_directory() "{{{ function! neosnippet#get_snippets_directory() "{{{
call s:check_initialize()
let snippets_dir = copy(s:snippets_dir) let snippets_dir = copy(s:snippets_dir)
if !get(g:neosnippet#disable_runtime_snippets, if !get(g:neosnippet#disable_runtime_snippets,
\ neosnippet#get_filetype(), \ neosnippet#get_filetype(),
@ -1045,9 +1047,13 @@ function! neosnippet#get_snippets_directory() "{{{
return snippets_dir return snippets_dir
endfunction"}}} endfunction"}}}
function! neosnippet#get_user_snippets_directory() "{{{ function! neosnippet#get_user_snippets_directory() "{{{
call s:check_initialize()
return copy(s:snippets_dir) return copy(s:snippets_dir)
endfunction"}}} endfunction"}}}
function! neosnippet#get_runtime_snippets_directory() "{{{ function! neosnippet#get_runtime_snippets_directory() "{{{
call s:check_initialize()
return copy(s:runtime_dir) return copy(s:runtime_dir)
endfunction"}}} endfunction"}}}
function! neosnippet#get_filetype() "{{{ function! neosnippet#get_filetype() "{{{

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: neosnippet_file.vim " FILE: neosnippet_file.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 13 Dec 2012. " Last Modified: 17 Feb 2013.
" 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
@ -39,12 +39,8 @@ let s:source_user = {
\ } \ }
function! s:source_user.gather_candidates(args, context) "{{{ function! s:source_user.gather_candidates(args, context) "{{{
let files = s:snip_files(neosnippet#get_user_snippets_directory()) return s:get_snippet_candidates(
return map(files, '{ \ neosnippet#get_user_snippets_directory())
\ "word" : v:val,
\ "action__path" : v:val,
\ "kind" : "file",
\ }')
endfunction "}}} endfunction "}}}
@ -55,17 +51,23 @@ let s:source_runtime = {
\ } \ }
function! s:source_runtime.gather_candidates(args, context) "{{{ function! s:source_runtime.gather_candidates(args, context) "{{{
let files = s:snip_files(neosnippet#get_runtime_snippets_directory()) return s:get_snippet_candidates(
return map(files, '{ \ neosnippet#get_runtime_snippets_directory())
\ "word" : v:val,
\ "action__path" : v:val,
\ "kind" : "file",
\ }')
endfunction "}}} endfunction "}}}
function! s:snip_files(dirs) "{{{ function! s:get_snippet_candidates(dirs) "{{{
return eval(join(map(a:dirs, "split(globpath(v:val, '*.snip'), '\n')"),"+")) 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 _
endfunction "}}} endfunction "}}}

View File

@ -675,6 +675,14 @@ snippet
> >
imap <C-s> <Plug>(neosnippet_start_unite_snippet) imap <C-s> <Plug>(neosnippet_start_unite_snippet)
< <
*neosnippet-unite-source-neosnippet/user*
neosnippet/user
The candidates of the user snippet files.
*neosnippet-unite-source-neosnippet/runtime*
neosnippet/runtime
The candidates of the runtime snippet files.
source actions source actions
snippet *neosnippet-unite-action-snippet* snippet *neosnippet-unite-action-snippet*
@ -722,6 +730,7 @@ CHANGELOG *neosnippet-changelog*
2013-02-17 2013-02-17
- Improved :NeoSnippetEdit. - Improved :NeoSnippetEdit.
- Added neosnippet/runtime and neosnippet/user sources.
2013-02-16 2013-02-16
- Added sh snippet. - Added sh snippet.