- Renamed commands.

This commit is contained in:
Shougo Matsushita 2012-09-30 19:10:25 +09:00
parent f065035e7f
commit e3fa0bbf64
5 changed files with 145 additions and 58 deletions

View File

@ -40,18 +40,6 @@ function! s:source.initialize()"{{{
\ g:neocomplcache_auto_completion_start_length)
endfunction"}}}
function! s:source.finalize()"{{{
delcommand NeoComplCacheEditSnippets
delcommand NeoComplCacheEditRuntimeSnippets
delcommand NeoComplCacheCachingSnippets
hi clear NeoComplCacheExpandSnippets
if neocomplcache#exists_echodoc()
call echodoc#unregister('snippets_complete')
endif
endfunction"}}}
function! s:source.get_keyword_pos(cur_text)"{{{
return match(a:cur_text, '\S\+$')
endfunction"}}}
@ -63,7 +51,7 @@ function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str)"{{{
\ neosnippet#get_filetype())
if !has_key(all_snippets, filetype)
" Caching snippets.
call neosnippet#caching_snippets(filetype)
call neosnippet#make_cache(filetype)
endif
endfor

View File

@ -36,6 +36,13 @@ call neosnippet#util#set_default('g:neosnippet#disable_select_mode_mappings',
\ 0, 'g:neocomplcache_disable_select_mode_mappings')
"}}}
" Variables "{{{
let s:neosnippet_options = [
\ '-runtime',
\ '-vertical', '-horizontal', '-direction=', '-split',
\]
"}}}
function! s:initialize()"{{{
" Initialize.
let s:snippets_expand_stack = []
@ -101,7 +108,7 @@ function! s:initialize()"{{{
endif"}}}
" Caching _ snippets.
call neosnippet#caching_snippets('_')
call neosnippet#make_cache('_')
" Initialize check.
call neosnippet#caching()
@ -166,7 +173,7 @@ function! neosnippet#jumpable()"{{{
endfunction"}}}
function! neosnippet#caching()"{{{
call neosnippet#caching_snippets(&filetype)
call neosnippet#make_cache(&filetype)
endfunction"}}}
function! s:set_snippet_dict(snippet_pattern, snippet_dict, dup_check, snippets_file)"{{{
@ -219,25 +226,30 @@ function! s:set_snippet_pattern(dict)"{{{
return dict
endfunction"}}}
function! neosnippet#edit_snippets(filetype, isruntime)"{{{
let filetype = a:filetype
function! neosnippet#edit_snippets(args)"{{{
let [args, options] = neosnippet#util#parse_options(
\ a:args, s:neosnippet_options)
let filetype = get(args, 0, '')
if filetype == ''
let filetype = neosnippet#get_filetype()
endif
let options = s:initialize_options(options)
if options.runtime && empty(s:runtime_dir)
\ || !options.runtime && empty(s:snippets_dir)
return
endif
" Edit snippet file.
if a:isruntime
if empty(s:runtime_dir)
return
endif
let filename = (options.runtime ? s:runtime_dir[0] : s:snippets_dir[-1])
\ .'/'.filetype.'.snip'
let filename = s:runtime_dir[0].'/'.filetype.'.snip'
else
if empty(s:snippets_dir)
return
endif
let filename = s:snippets_dir[-1].'/'.filetype.'.snip'
if options.split
" Split window.
execute options.direction
\ (options.vertical ? 'vnew' : 'new')
endif
if filereadable(filename)
@ -249,7 +261,26 @@ function! neosnippet#edit_snippets(filetype, isruntime)"{{{
endif
endfunction"}}}
function! neosnippet#caching_snippets(filetype)"{{{
function! s:initialize_options(options)"{{{
let default_options = {
\ 'runtime' : 0,
\ 'vertical' : 0,
\ 'direction' : 'belowleft',
\ 'split' : 0,
\ }
let options = extend(default_options, a:options)
" Complex initializer.
if has_key(options, 'horizontal')
" Disable vertically.
let context.vertical = 0
endif
return options
endfunction"}}}
function! neosnippet#make_cache(filetype)"{{{
let filetype = a:filetype == '' ?
\ &filetype : a:filetype
if filetype ==# ''
@ -782,7 +813,7 @@ endfunction"}}}
function! neosnippet#get_snippets()"{{{
if !has_key(s:snippets, '_')
" Caching _ snippets.
call neosnippet#caching_snippets('_')
call neosnippet#make_cache('_')
endif
" Get buffer filetype.
@ -808,6 +839,10 @@ function! s:get_sources_list(snippets, filetype)"{{{
\ neocomplcache#get_sources_list(a:snippets, a:filetype) : a:filetype
endfunction"}}}
function! neosnippet#edit_complete(arglead, cmdline, cursorpos)"{{{
return filter(s:neosnippet_options + neosnippet#filetype_complete(
\ a:arglead, a:cmdline, a:cursorpos), 'stridx(v:val, a:arglead) == 0')
endfunction"}}}
" Complete filetype helper.
function! neosnippet#filetype_complete(arglead, cmdline, cursorpos)"{{{
" Dup check.

View File

@ -84,6 +84,30 @@ function! neosnippet#util#print_error(string)"{{{
echohl Error | echomsg a:string | echohl None
endfunction"}}}
function! neosnippet#util#parse_options(args, options_list)"{{{
let args = []
let options = {}
for arg in split(a:args, '\%(\\\@<!\s\)\+')
let arg = substitute(arg, '\\\( \)', '\1', 'g')
let matched_list = filter(copy(a:options_list),
\ 'stridx(arg, v:val) == 0')
for option in matched_list
let key = substitute(substitute(option, '-', '_', 'g'), '=$', '', '')[1:]
let options[key] = (option =~ '=$') ?
\ arg[len(option) :] : 1
break
endfor
if empty(matched_list)
call add(args, arg)
endif
endfor
return [args, options]
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -58,34 +58,65 @@ INTERFACE *neosnippet-interface*
------------------------------------------------------------------------------
COMMANDS *neosnippet-commands*
:NeoComplCacheCachingSnippets [filetype]
*:NeoComplCacheCachingSnippets*
:NeoSnippetMakeCache [filetype]
*:NeoSnippetMakeCache*
Makes cache of [filetype] snippets. It automatically selects
current buffer's filetype unless you specify [filetype].
:NeoComplCacheEditSnippets [filetype]
*:NeoSnippetMakeCache-options*
{options} are options for the command. You may give the
following parameters for a option; you must escape with "\"
when it contains spaces.
*neosnippet-edit-options-vertical*
-vertical
Splits window vertically.
*neosnippet-edit-options-horizontal*
-horizontal
Splits window horizontally.
The behavior is undefined when both options are defined.
*neosnippet-edit-options-direction*
-direction={direction}
Defines split position rule. The default value is "belowleft".
*neosnippet-edit-options-split*
-split
Split buffer.
*neosnippet-edit-options-runtime*
-runtime
Edit runtime snippets instead of user snippets.
*:NeoComplCacheCachingSnippets*
Note: |:NeoComplCacheCachingSnippets| is obsolute name.
:NeoSnippetEdit [{options}] [filetype]
*:NeoSnippetEdit*
Opens [filetype] snippets to edit. It automatically selects
current buffer's filetype unless you specify [filetype].
If [filetype] snippet file doesn't exist, it creates one
automatically.
It edits a snippet file in |g:neosnippet#snippets_directory|
with precedence.
Re-make cache will be done automatically when you save the
file.
*:NeoComplCacheEditSnippets*
Opens [filetype] snippets to edit. It automatically selects
current buffer's filetype unless you specify [filetype].
Note: |:NeoComplCacheEditSnippets| is obsolute name.
If [filetype] snippet file doesn't exist, it creates one
automatically.
:NeoComplCacheEdit -runtime [filetype]
This command edits a snippet file in
|g:neosnippet#snippets_directory| with precedence.
Re-cache will be done automatically when you save the file.
It edits a runtime snippet file with neosnippet.
Re-make cache will be done automatically when you save the
file.
:NeoComplCacheEditRuntimeSnippets [filetype]
*:NeoComplCacheEditRuntimeSnippets*
Opens [filetype] snippets to edit. It automatically selects
current buffer's filetype unless you specify [filetype].
If [filetype] snippet file doesn't exist, it creates one
automatically.
This command edits a runtime snippet file with
snippets_complete. Re-cache will be done automatically when
you save the file.
Note: |:NeoComplCacheEditRuntimeSnippets| is obsolute name.
------------------------------------------------------------------------------
VARIABLES *neosnippet-variables*
@ -274,8 +305,8 @@ Eval snippet feature is available.
prev_word '^'
`expand("%")`
<
If you use |:NeoComplCacheEditSnippets| command for easy snippet editing, the
file will be loaded automatically when you save the file.
If you use |:NeoSnippetEdit| command for easy snippet editing, the file will
be loaded automatically when you save the file.
Neosnippet doesn't map snippet-expand key by default. If you want to use
snippet feature, you can define below mappings in your .vimrc:
@ -369,6 +400,7 @@ CHANGELOG *neosnippet-changelog*
- Improved filetype complete.
- Improved documentation.
- Changed neocomplcache source behavior.
- Renamed commands.
2012-09-27
- Ver.3 development is started.

View File

@ -88,15 +88,23 @@ augroup neosnippet"{{{
augroup END"}}}
" Commands."{{{
command! -nargs=? -complete=customlist,neosnippet#edit_complete
\ NeoSnippetEdit
\ call neosnippet#edit_snippets(<q-args>)
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)
\ NeoSnippetMakeCache
\ call neosnippet#make_cache(<q-args>)
command! -nargs=? -complete=customlist,neosnippet#filetype_complete
\ NeoComplCacheCachingSnippets
\ call neosnippet#caching_snippets(<q-args>)
\ NeoSnippetMakeCache <args>
command! -nargs=? -complete=customlist,neosnippet#filetype_complete
\ NeoComplCacheEditSnippets
\ NeoSnippetEdit <args>
command! -nargs=? -complete=customlist,neosnippet#filetype_complete
\ NeoComplCacheEditRuntimeSnippets
\ NeoSnippetEdit -runtime <args>
"}}}
let g:loaded_neosnippet = 1