From b0d0bb1a6cbda939efa6a9791c7117a14f86daa6 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 17 Feb 2013 16:11:21 +0900 Subject: [PATCH] - Added unite__new_candidate action. --- autoload/neosnippet.vim | 4 +++- autoload/unite/sources/neosnippet_file.vim | 28 ++++++++++++++++++++++ doc/neosnippet.txt | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 1b46221..2042f0d 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -212,6 +212,7 @@ function! neosnippet#edit_snippets(args) "{{{ \ get(neosnippet#get_user_snippets_directory(), -1, '')) if snippet_dir == '' + call neosnippet#util#print_error('Snippet directory is not found.') return endif @@ -1058,7 +1059,8 @@ function! neosnippet#get_runtime_snippets_directory() "{{{ endfunction"}}} function! neosnippet#get_filetype() "{{{ return exists('*neocomplcache#get_context_filetype') ? - \ neocomplcache#get_context_filetype(1) : &filetype + \ neocomplcache#get_context_filetype(1) : + \ (&filetype == '' ? 'nothing' : &filetype) endfunction"}}} function! s:get_sources_filetypes(filetype) "{{{ return (exists('*neocomplcache#get_source_filetypes') ? diff --git a/autoload/unite/sources/neosnippet_file.vim b/autoload/unite/sources/neosnippet_file.vim index 6977d54..77acfff 100644 --- a/autoload/unite/sources/neosnippet_file.vim +++ b/autoload/unite/sources/neosnippet_file.vim @@ -36,6 +36,7 @@ endfunction "}}} let s:source_user = { \ 'name': 'neosnippet/user', \ 'description' : 'neosnippet user file', + \ 'action_table' : {}, \ } function! s:source_user.gather_candidates(args, context) "{{{ @@ -43,11 +44,25 @@ function! s:source_user.gather_candidates(args, context) "{{{ \ neosnippet#get_user_snippets_directory()) endfunction "}}} +let s:source_user.action_table.unite__new_candidate = { + \ 'description' : 'create new user snippet', + \ 'is_invalidate_cache' : 1, + \ 'is_quit' : 1, + \ } +function! s:source_user.action_table.unite__new_candidate.func(candidate) "{{{ + let filename = input( + \ 'New snippet file name: ', neosnippet#get_filetype()) + if filename != '' + call neosnippet#edit_snippets(filename) + endif +endfunction"}}} + " neosnippet source. let s:source_runtime = { \ 'name': 'neosnippet/runtime', \ 'description' : 'neosnippet runtime file', + \ 'action_table' : {}, \ } function! s:source_runtime.gather_candidates(args, context) "{{{ @@ -55,6 +70,19 @@ function! s:source_runtime.gather_candidates(args, context) "{{{ \ neosnippet#get_runtime_snippets_directory()) endfunction "}}} +let s:source_runtime.action_table.unite__new_candidate = { + \ 'description' : 'create new runtime snippet', + \ 'is_invalidate_cache' : 1, + \ 'is_quit' : 1, + \ } +function! s:source_runtime.action_table.unite__new_candidate.func(candidate) "{{{ + let filename = input( + \ 'New snippet file name: ', neosnippet#get_filetype()) + if filename != '' + call neosnippet#edit_snippets('-runtime ' . filename) + endif +endfunction"}}} + function! s:get_snippet_candidates(dirs) "{{{ let _ = [] diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index 89066c0..b514c99 100755 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -731,6 +731,7 @@ CHANGELOG *neosnippet-changelog* 2013-02-17 - Improved :NeoSnippetEdit. - Added neosnippet/runtime and neosnippet/user sources. +- Added unite__new_candidate action. 2013-02-16 - Added sh snippet.