- Improved filetype complete.

This commit is contained in:
Shougo Matsushita 2012-09-30 17:45:41 +09:00
parent d5e1a678d4
commit 0739b9b12e
4 changed files with 48 additions and 24 deletions

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: snippets_complete.vim " FILE: snippets_complete.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com> " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 28 Sep 2012. " Last Modified: 30 Sep 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
@ -53,11 +53,13 @@ endfunction"}}}
function! s:source.get_keyword_list(cur_keyword_str)"{{{ function! s:source.get_keyword_list(cur_keyword_str)"{{{
let all_snippets = neosnippet#get_snippets() let all_snippets = neosnippet#get_snippets()
let filetype = neocomplcache#get_context_filetype() for filetype in neocomplcache#get_source_filetypes(
if !has_key(all_snippets, filetype) \ neosnippet#get_filetype())
if !has_key(s:snippets, filetype)
" Caching snippets. " Caching snippets.
call neosnippet#caching_snippets(filetype) call neosnippet#caching_snippets(filetype)
endif endif
endfor
return s:keyword_filter(neocomplcache#dup_filter( return s:keyword_filter(neocomplcache#dup_filter(
\ values(all_snippets)), a:cur_keyword_str) \ values(all_snippets)), a:cur_keyword_str)

View File

@ -85,16 +85,6 @@ function! s:initialize()"{{{
hi def link neosnippetExpandSnippets Special hi def link neosnippetExpandSnippets Special
command! -nargs=? -complete=customlist,neocomplcache#filetype_complete
\ NeoComplCacheEditSnippets
\ call s:edit_snippets(<q-args>, 0)
command! -nargs=? -complete=customlist,neocomplcache#filetype_complete
\ NeoComplCacheEditRuntimeSnippets
\ call s:edit_snippets(<q-args>, 1)
command! -nargs=? -complete=customlist,neocomplcache#filetype_complete
\ NeoComplCacheCachingSnippets
\ call neosnippet#caching_snippets(<q-args>)
" Select mode mappings."{{{ " Select mode mappings."{{{
if g:neosnippet#disable_select_mode_mappings if g:neosnippet#disable_select_mode_mappings
snoremap <CR> a<BS> snoremap <CR> a<BS>
@ -176,12 +166,7 @@ function! neosnippet#jumpable()"{{{
endfunction"}}} endfunction"}}}
function! neosnippet#caching()"{{{ function! neosnippet#caching()"{{{
for filetype in neocomplcache#get_source_filetypes( call neosnippet#caching_snippets(&filetype)
\ neosnippet#get_filetype())
if !has_key(s:snippets, filetype)
call neosnippet#caching_snippets(filetype)
endif
endfor
endfunction"}}} endfunction"}}}
function! s:set_snippet_dict(snippet_pattern, snippet_dict, dup_check, snippets_file)"{{{ function! s:set_snippet_dict(snippet_pattern, snippet_dict, dup_check, snippets_file)"{{{
@ -234,7 +219,7 @@ function! s:set_snippet_pattern(dict)"{{{
return dict return dict
endfunction"}}} endfunction"}}}
function! s:edit_snippets(filetype, isruntime)"{{{ function! neosnippet#edit_snippets(filetype, isruntime)"{{{
let filetype = a:filetype let filetype = a:filetype
if filetype == '' if filetype == ''
let filetype = neosnippet#get_filetype() let filetype = neosnippet#get_filetype()
@ -267,6 +252,9 @@ endfunction"}}}
function! neosnippet#caching_snippets(filetype)"{{{ function! neosnippet#caching_snippets(filetype)"{{{
let filetype = a:filetype == '' ? let filetype = a:filetype == '' ?
\ &filetype : a:filetype \ &filetype : a:filetype
if filetype ==# ''
let filetype = 'nothing'
endif
let snippet = {} let snippet = {}
let snippets_files = let snippets_files =
@ -801,7 +789,7 @@ function! neosnippet#get_snippets()"{{{
let filetype = neosnippet#get_filetype() let filetype = neosnippet#get_filetype()
let snippets = {} let snippets = {}
for source in neocomplcache#get_sources_list(s:snippets, filetype) for source in s:get_sources_list(s:snippets, filetype)
call extend(snippets, source, 'keep') call extend(snippets, source, 'keep')
endfor endfor
call extend(snippets, copy(s:snippets['_']), 'keep') call extend(snippets, copy(s:snippets['_']), 'keep')
@ -815,6 +803,27 @@ function! neosnippet#get_filetype()"{{{
return exists('*neocomplcache#get_context_filetype') ? return exists('*neocomplcache#get_context_filetype') ?
\ neocomplcache#get_context_filetype(1) : &filetype \ neocomplcache#get_context_filetype(1) : &filetype
endfunction"}}} endfunction"}}}
function! s:get_sources_list(snippets, filetype)"{{{
return exists('*neocomplcache#get_sources_list') ?
\ neocomplcache#get_sources_list(a:snippets, a:filetype) : a:filetype
endfunction"}}}
" Complete filetype helper.
function! neosnippet#filetype_complete(arglead, cmdline, cursorpos)"{{{
" Dup check.
let ret = {}
for item in map(
\ split(globpath(&runtimepath, 'syntax/*.vim'), '\n') +
\ split(globpath(&runtimepath, 'indent/*.vim'), '\n') +
\ split(globpath(&runtimepath, 'ftplugin/*.vim'), '\n')
\ , 'fnamemodify(v:val, ":t:r")')
if !has_key(ret, item) && item =~ '^'.a:arglead
let ret[item] = 1
endif
endfor
return sort(keys(ret))
endfunction"}}}
function! s:get_placeholder_marker_pattern()"{{{ function! s:get_placeholder_marker_pattern()"{{{
return '<`\d\+\%(:.\{-}\)\?\\\@<!`>' return '<`\d\+\%(:.\{-}\)\?\\\@<!`>'

View File

@ -326,6 +326,7 @@ CHANGELOG *neosnippet-changelog*
- Refactored variables. - Refactored variables.
- Deleted s:get_cursor_keyword_snippet(). - Deleted s:get_cursor_keyword_snippet().
- Improved for filetype. - Improved for filetype.
- Improved filetype complete.
2012-09-27 2012-09-27
- Ver.3 development is started. - Ver.3 development is started.

View File

@ -82,6 +82,18 @@ augroup neosnippet"{{{
\ call neosnippet#caching_snippets(expand('<afile>:t:r')) \ call neosnippet#caching_snippets(expand('<afile>:t:r'))
augroup END"}}} augroup END"}}}
" Commands."{{{
command! -nargs=? -complete=customlist,neosnippet#filetype_complete
\ NeoComplCacheEditSnippets
\ call neosnippet#edit_snippets(<q-args>, 0)
command! -nargs=? -complete=customlist,neosnippet#filetype_complete
\ NeoComplCacheEditRuntimeSnippets
\ call neosnippet#edit_snippets(<q-args>, 1)
command! -nargs=? -complete=customlist,neosnippet#filetype_complete
\ NeoComplCacheCachingSnippets
\ call neosnippet#caching_snippets(<q-args>)
"}}}
let g:loaded_neosnippet = 1 let g:loaded_neosnippet = 1
let &cpo = s:save_cpo let &cpo = s:save_cpo