Remove markers

This commit is contained in:
Shougo Matsushita 2017-10-01 22:40:17 +09:00
parent c86a19b06a
commit ddd01d0ee3
15 changed files with 312 additions and 342 deletions

View File

@ -11,15 +11,15 @@ let s:source = {
\ g:neocomplcache_auto_completion_start_length,
\}
function! s:source.initialize() abort "{{{
function! s:source.initialize() abort
" Initialize.
call neocomplcache#set_dictionary_helper(
\ g:neocomplcache_source_rank, 'snippets_complete', 8)
call neocomplcache#set_completion_length('snippets_complete',
\ g:neocomplcache_auto_completion_start_length)
endfunction"}}}
endfunction
function! s:source.get_keyword_pos(cur_text) abort "{{{
function! s:source.get_keyword_pos(cur_text) abort
let cur_word = matchstr(a:cur_text, '\w\+$')
let word_candidates = neocomplcache#keyword_filter(
\ filter(values(neosnippet#helpers#get_snippets()),
@ -29,9 +29,9 @@ function! s:source.get_keyword_pos(cur_text) abort "{{{
endif
return match(a:cur_text, '\S\+$')
endfunction"}}}
endfunction
function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str) abort "{{{
function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str) abort
let list = s:keyword_filter(neosnippet#helpers#get_snippets(), a:cur_keyword_str)
for snippet in list
@ -42,9 +42,9 @@ function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str) abort "{
endfor
return list
endfunction"}}}
endfunction
function! s:keyword_filter(snippets, cur_keyword_str) abort "{{{
function! s:keyword_filter(snippets, cur_keyword_str) abort
" Uniq by real_name.
let dict = {}
@ -65,10 +65,8 @@ function! s:keyword_filter(snippets, cur_keyword_str) abort "{{{
endfor
return values(dict)
endfunction"}}}
endfunction
function! neocomplcache#sources#snippets_complete#define() abort "{{{
function! neocomplcache#sources#snippets_complete#define() abort
return s:source
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -15,7 +15,7 @@ let s:source = {
\ ['matcher_fuzzy'] : ['matcher_head']),
\}
function! s:source.gather_candidates(context) abort "{{{
function! s:source.gather_candidates(context) abort
let snippets = values(neosnippet#helpers#get_completion_snippets())
if matchstr(a:context.input, '\S\+$') !=#
\ matchstr(a:context.input, '\w\+$')
@ -23,9 +23,9 @@ function! s:source.gather_candidates(context) abort "{{{
call filter(snippets, 'v:val.options.word')
endif
return snippets
endfunction"}}}
endfunction
function! s:source.hooks.on_post_filter(context) abort "{{{
function! s:source.hooks.on_post_filter(context) abort
for snippet in a:context.candidates
let snippet.dup = 1
let snippet.menu = neosnippet#util#strwidthpart(
@ -33,10 +33,8 @@ function! s:source.hooks.on_post_filter(context) abort "{{{
endfor
return a:context.candidates
endfunction"}}}
endfunction
function! neocomplete#sources#neosnippet#define() abort "{{{
function! neocomplete#sources#neosnippet#define() abort
return s:source
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,7 +4,7 @@
" License: MIT license
"=============================================================================
" Global options definition. "{{{
" Global options definition.
call neosnippet#util#set_default(
\ 'g:neosnippet#disable_runtime_snippets', {})
call neosnippet#util#set_default(
@ -31,64 +31,62 @@ call neosnippet#util#set_default(
call neosnippet#util#set_default(
\ 'g:neosnippet#_completed_pairs',
\ {'_':{ '(' : ')', '{' : '}', '"' : '"', '[' : ']' }})
"}}}
function! neosnippet#expandable_or_jumpable() abort "{{{
function! neosnippet#expandable_or_jumpable() abort
return neosnippet#mappings#expandable_or_jumpable()
endfunction"}}}
function! neosnippet#expandable() abort "{{{
endfunction
function! neosnippet#expandable() abort
return neosnippet#mappings#expandable()
endfunction"}}}
function! neosnippet#jumpable() abort "{{{
endfunction
function! neosnippet#jumpable() abort
return neosnippet#mappings#jumpable()
endfunction"}}}
function! neosnippet#anonymous(snippet) abort "{{{
endfunction
function! neosnippet#anonymous(snippet) abort
return neosnippet#mappings#_anonymous(a:snippet)
endfunction"}}}
function! neosnippet#expand(trigger) abort "{{{
endfunction
function! neosnippet#expand(trigger) abort
return neosnippet#mappings#_expand(a:trigger)
endfunction"}}}
endfunction
function! neosnippet#get_snippets_directory() abort "{{{
function! neosnippet#get_snippets_directory() abort
return neosnippet#helpers#get_snippets_directory()
endfunction"}}}
function! neosnippet#get_user_snippets_directory() abort "{{{
endfunction
function! neosnippet#get_user_snippets_directory() abort
return copy(neosnippet#variables#snippets_dir())
endfunction"}}}
function! neosnippet#get_runtime_snippets_directory() abort "{{{
endfunction
function! neosnippet#get_runtime_snippets_directory() abort
return copy(neosnippet#variables#runtime_dir())
endfunction"}}}
endfunction
" Get marker patterns.
function! neosnippet#get_placeholder_target_marker_pattern() abort "{{{
function! neosnippet#get_placeholder_target_marker_pattern() abort
return '\%(\\\@<!\|\\\\\zs\)\${\d\+:\(#:\)\?TARGET\%(:.\{-}\)\?\\\@<!}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_pattern() abort "{{{
endfunction
function! neosnippet#get_placeholder_marker_pattern() abort
return '<`\d\+\%(:.\{-}\)\?\\\@<!`>'
endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_pattern() abort "{{{
endfunction
function! neosnippet#get_placeholder_marker_substitute_pattern() abort
return '\%(\\\@<!\|\\\\\zs\)\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_nonzero_pattern() abort "{{{
endfunction
function! neosnippet#get_placeholder_marker_substitute_nonzero_pattern() abort
return '\%(\\\@<!\|\\\\\zs\)\${\([1-9]\d*\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_substitute_zero_pattern() abort "{{{
endfunction
function! neosnippet#get_placeholder_marker_substitute_zero_pattern() abort
return '\%(\\\@<!\|\\\\\zs\)\${\(0\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}}
function! neosnippet#get_placeholder_marker_default_pattern() abort "{{{
endfunction
function! neosnippet#get_placeholder_marker_default_pattern() abort
return '<`\d\+:\zs.\{-}\ze\\\@<!`>'
endfunction"}}}
function! neosnippet#get_sync_placeholder_marker_pattern() abort "{{{
endfunction
function! neosnippet#get_sync_placeholder_marker_pattern() abort
return '<{\d\+\%(:.\{-}\)\?\\\@<!}>'
endfunction"}}}
function! neosnippet#get_sync_placeholder_marker_default_pattern() abort "{{{
endfunction
function! neosnippet#get_sync_placeholder_marker_default_pattern() abort
return '<{\d\+:\zs.\{-}\ze\\\@<!}>'
endfunction"}}}
function! neosnippet#get_mirror_placeholder_marker_pattern() abort "{{{
endfunction
function! neosnippet#get_mirror_placeholder_marker_pattern() abort
return '<|\d\+|>'
endfunction"}}}
function! neosnippet#get_mirror_placeholder_marker_substitute_pattern() abort "{{{
endfunction
function! neosnippet#get_mirror_placeholder_marker_substitute_pattern() abort
return '\\\@<!\$\(\d\+\)'
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,22 +4,22 @@
" License: MIT license
"=============================================================================
" Variables "{{{
" Variables
let s:edit_options = [
\ '-runtime',
\ '-vertical', '-horizontal', '-direction=', '-split',
\]
let s:Cache = neosnippet#util#get_vital().import('System.Cache.Deprecated')
"}}}
function! s:get_list() abort "{{{
function! s:get_list() abort
if !exists('s:List')
let s:List = vital#of('neosnippet').import('Data.List')
endif
return s:List
endfunction"}}}
endfunction
function! neosnippet#commands#_edit(args) abort "{{{
function! neosnippet#commands#_edit(args) abort
if neosnippet#util#is_sudo()
call neosnippet#util#print_error(
\ '"sudo vim" is detected. This feature is disabled.')
@ -72,9 +72,9 @@ function! neosnippet#commands#_edit(args) abort "{{{
execute 'edit' fnameescape(filename)
catch /^Vim\%((\a\+)\)\=:E749/
endtry
endfunction"}}}
endfunction
function! neosnippet#commands#_make_cache(filetype) abort "{{{
function! neosnippet#commands#_make_cache(filetype) abort
call neosnippet#init#check()
let filetype = a:filetype == '' ?
@ -108,17 +108,17 @@ function! neosnippet#commands#_make_cache(filetype) abort "{{{
\ neosnippet#parser#_parse_snippet(filename, trigger)
endfor
endif
endfunction"}}}
endfunction
function! neosnippet#commands#_source(filename) abort "{{{
function! neosnippet#commands#_source(filename) abort
call neosnippet#init#check()
let neosnippet = neosnippet#variables#current_neosnippet()
let neosnippet.snippets = extend(neosnippet.snippets,
\ neosnippet#parser#_parse_snippets(a:filename))
endfunction"}}}
endfunction
function! neosnippet#commands#_clear_markers() abort "{{{
function! neosnippet#commands#_clear_markers() abort
let expand_stack = neosnippet#variables#expand_stack()
" Get patterns and count.
@ -129,15 +129,15 @@ function! neosnippet#commands#_clear_markers() abort "{{{
endif
call neosnippet#view#_clear_markers(expand_stack[-1])
endfunction"}}}
endfunction
" Complete helpers.
function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) abort "{{{
function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) abort
return filter(s:edit_options +
\ neosnippet#commands#_filetype_complete(a:arglead, a:cmdline, a:cursorpos),
\ 'stridx(v:val, a:arglead) == 0')
endfunction"}}}
function! neosnippet#commands#_filetype_complete(arglead, cmdline, cursorpos) abort "{{{
endfunction
function! neosnippet#commands#_filetype_complete(arglead, cmdline, cursorpos) abort
" Dup check.
let ret = {}
for item in map(
@ -151,14 +151,14 @@ function! neosnippet#commands#_filetype_complete(arglead, cmdline, cursorpos) ab
endfor
return sort(keys(ret))
endfunction"}}}
function! neosnippet#commands#_complete_target_snippets(arglead, cmdline, cursorpos) abort "{{{
endfunction
function! neosnippet#commands#_complete_target_snippets(arglead, cmdline, cursorpos) abort
return map(filter(values(neosnippet#helpers#get_snippets()),
\ "stridx(v:val.word, a:arglead) == 0
\ && v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"), 'v:val.word')
endfunction"}}}
endfunction
function! s:initialize_options(options) abort "{{{
function! s:initialize_options(options) abort
let default_options = {
\ 'runtime' : 0,
\ 'vertical' : 0,
@ -175,9 +175,9 @@ function! s:initialize_options(options) abort "{{{
endif
return options
endfunction"}}}
endfunction
function! s:get_snippets_files(path, filetype) abort "{{{
function! s:get_snippets_files(path, filetype) abort
let snippets_files = []
for glob in s:get_list().flatten(
\ map(split(get(g:neosnippet#scope_aliases,
@ -190,8 +190,8 @@ function! s:get_snippets_files(path, filetype) abort "{{{
let snippets_files += split(globpath(a:path, glob), '\n')
endfor
return reverse(s:get_list().uniq(snippets_files))
endfunction"}}}
function! s:get_snippet_files(path, filetype) abort "{{{
endfunction
function! s:get_snippet_files(path, filetype) abort
let snippet_files = []
for glob in s:get_list().flatten(
\ map(split(get(g:neosnippet#scope_aliases,
@ -200,6 +200,4 @@ function! s:get_snippet_files(path, filetype) abort "{{{
let snippet_files += split(globpath(a:path, glob), '\n')
endfor
return reverse(s:get_list().uniq(snippet_files))
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,7 +4,7 @@
" License: MIT license
"=============================================================================
function! neosnippet#handlers#_cursor_moved() abort "{{{
function! neosnippet#handlers#_cursor_moved() abort
let expand_stack = neosnippet#variables#expand_stack()
" Get patterns and count.
@ -18,9 +18,9 @@ function! neosnippet#handlers#_cursor_moved() abort "{{{
\ && line('.') != expand_info.begin_line
call neosnippet#view#_clear_markers(expand_info)
endif
endfunction"}}}
endfunction
function! neosnippet#handlers#_all_clear_markers() abort "{{{
function! neosnippet#handlers#_all_clear_markers() abort
if !&l:modifiable
return
endif
@ -36,9 +36,9 @@ function! neosnippet#handlers#_all_clear_markers() abort "{{{
finally
call setpos('.', pos)
endtry
endfunction"}}}
endfunction
function! neosnippet#handlers#_restore_unnamed_register() abort "{{{
function! neosnippet#handlers#_restore_unnamed_register() abort
let neosnippet = neosnippet#variables#current_neosnippet()
if neosnippet.unnamed_register != ''
@ -46,6 +46,4 @@ function! neosnippet#handlers#_restore_unnamed_register() abort "{{{
let @" = neosnippet.unnamed_register
let neosnippet.unnamed_register = ''
endif
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,7 +4,7 @@
" License: MIT license
"=============================================================================
function! neosnippet#helpers#get_cursor_snippet(snippets, cur_text) abort "{{{
function! neosnippet#helpers#get_cursor_snippet(snippets, cur_text) abort
let cur_word = matchstr(a:cur_text, '\S\+$')
if cur_word != '' && has_key(a:snippets, cur_word)
return cur_word
@ -20,9 +20,9 @@ function! neosnippet#helpers#get_cursor_snippet(snippets, cur_text) abort "{{{
endwhile
return cur_word
endfunction"}}}
endfunction
function! neosnippet#helpers#get_snippets(...) abort "{{{
function! neosnippet#helpers#get_snippets(...) abort
let mode = get(a:000, 0, mode())
call neosnippet#init#check()
@ -51,13 +51,13 @@ function! neosnippet#helpers#get_snippets(...) abort "{{{
endif
return snippets
endfunction"}}}
function! neosnippet#helpers#get_completion_snippets() abort "{{{
endfunction
function! neosnippet#helpers#get_completion_snippets() abort
return filter(neosnippet#helpers#get_snippets(),
\ "!get(v:val.options, 'oneshot', 0)")
endfunction"}}}
endfunction
function! neosnippet#helpers#get_snippets_directory() abort "{{{
function! neosnippet#helpers#get_snippets_directory() abort
let snippets_dir = copy(neosnippet#variables#snippets_dir())
if !get(g:neosnippet#disable_runtime_snippets,
\ neosnippet#helpers#get_filetype(),
@ -66,9 +66,9 @@ function! neosnippet#helpers#get_snippets_directory() abort "{{{
endif
return snippets_dir
endfunction"}}}
endfunction
function! neosnippet#helpers#get_filetype() abort "{{{
function! neosnippet#helpers#get_filetype() abort
" context_filetype.vim installation check.
if !exists('s:exists_context_filetype')
silent! call context_filetype#version()
@ -83,9 +83,9 @@ function! neosnippet#helpers#get_filetype() abort "{{{
endif
return context_filetype
endfunction"}}}
endfunction
function! neosnippet#helpers#get_selected_text(type, ...) abort "{{{
function! neosnippet#helpers#get_selected_text(type, ...) abort
let sel_save = &selection
let &selection = 'inclusive'
let reg_save = @@
@ -109,8 +109,8 @@ function! neosnippet#helpers#get_selected_text(type, ...) abort "{{{
let @@ = reg_save
call setpos('.', pos)
endtry
endfunction"}}}
function! neosnippet#helpers#delete_selected_text(type, ...) abort "{{{
endfunction
function! neosnippet#helpers#delete_selected_text(type, ...) abort
let sel_save = &selection
let &selection = 'inclusive'
let reg_save = @@
@ -132,8 +132,8 @@ function! neosnippet#helpers#delete_selected_text(type, ...) abort "{{{
let @@ = reg_save
call setpos('.', pos)
endtry
endfunction"}}}
function! neosnippet#helpers#substitute_selected_text(type, text) abort "{{{
endfunction
function! neosnippet#helpers#substitute_selected_text(type, text) abort
let sel_save = &selection
let &selection = 'inclusive'
let reg_save = @@
@ -155,30 +155,28 @@ function! neosnippet#helpers#substitute_selected_text(type, text) abort "{{{
let @@ = reg_save
call setpos('.', pos)
endtry
endfunction"}}}
endfunction
function! neosnippet#helpers#vim2json(expr) abort "{{{
function! neosnippet#helpers#vim2json(expr) abort
return has('patch-7.4.1498') ? json_encode(a:expr) : string(a:expr)
endfunction "}}}
function! neosnippet#helpers#json2vim(expr) abort "{{{
endfunction
function! neosnippet#helpers#json2vim(expr) abort
sandbox return has('patch-7.4.1498') ? json_decode(a:expr) : eval(a:expr)
endfunction "}}}
endfunction
function! s:is_beginning_of_line(cur_text) abort "{{{
function! s:is_beginning_of_line(cur_text) abort
let keyword_pattern = '\S\+'
let cur_keyword_str = matchstr(a:cur_text, keyword_pattern.'$')
let line_part = a:cur_text[: -1-len(cur_keyword_str)]
let prev_word_end = matchend(line_part, keyword_pattern)
return prev_word_end <= 0
endfunction"}}}
endfunction
function! s:get_sources_filetypes(filetype) abort "{{{
function! s:get_sources_filetypes(filetype) abort
let filetypes =
\ exists('*context_filetype#get_filetypes') ?
\ context_filetype#get_filetypes(a:filetype) :
\ split(((a:filetype == '') ? 'nothing' : a:filetype), '\.')
return neosnippet#util#uniq(['_'] + filetypes + [a:filetype])
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,28 +4,28 @@
" License: MIT license
"=============================================================================
function! neosnippet#init#_initialize() abort "{{{
function! neosnippet#init#_initialize() abort
let s:is_initialized = 1
call s:initialize_others()
call s:initialize_cache()
endfunction"}}}
endfunction
function! neosnippet#init#check() abort "{{{
function! neosnippet#init#check() abort
if !exists('s:is_initialized')
call neosnippet#init#_initialize()
endif
endfunction"}}}
endfunction
function! s:initialize_cache() abort "{{{
function! s:initialize_cache() abort
" Make cache for _ snippets.
call neosnippet#commands#_make_cache('_')
" Initialize check.
call neosnippet#commands#_make_cache(&filetype)
endfunction"}}}
function! s:initialize_others() abort "{{{
augroup neosnippet "{{{
endfunction
function! s:initialize_others() abort
augroup neosnippet
autocmd!
" Set make cache event.
autocmd FileType *
@ -35,7 +35,7 @@ function! s:initialize_others() abort "{{{
\ call neosnippet#variables#set_snippets({})
autocmd BufEnter *
\ call neosnippet#mappings#_clear_select_mode_mappings()
augroup END"}}}
augroup END
if g:neosnippet#enable_auto_clear_markers
autocmd neosnippet CursorMoved,CursorMovedI *
@ -72,7 +72,7 @@ function! s:initialize_others() abort "{{{
call neosnippet#mappings#_clear_select_mode_mappings()
if g:neosnippet#enable_snipmate_compatibility "{{{
if g:neosnippet#enable_snipmate_compatibility
" For snipMate function.
function! Filename(...) abort
let filename = expand('%:t:r')
@ -84,7 +84,5 @@ function! s:initialize_others() abort "{{{
return substitute(a:1, '$1', filename, 'g')
endif
endfunction
endif"}}}
endfunction"}}}
" vim: foldmethod=marker
endif
endfunction

View File

@ -4,22 +4,22 @@
" License: MIT license
"=============================================================================
function! neosnippet#mappings#expandable_or_jumpable() abort "{{{
function! neosnippet#mappings#expandable_or_jumpable() abort
return neosnippet#mappings#expandable() || neosnippet#mappings#jumpable()
endfunction"}}}
function! neosnippet#mappings#expandable() abort "{{{
endfunction
function! neosnippet#mappings#expandable() abort
" Check snippet trigger.
return neosnippet#mappings#completed_expandable()
\ || neosnippet#helpers#get_cursor_snippet(
\ neosnippet#helpers#get_snippets('i'),
\ neosnippet#util#get_cur_text()) != ''
endfunction"}}}
function! neosnippet#mappings#jumpable() abort "{{{
endfunction
function! neosnippet#mappings#jumpable() abort
" Found snippet placeholder.
return search(neosnippet#get_placeholder_marker_pattern(). '\|'
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0
endfunction"}}}
function! neosnippet#mappings#completed_expandable() abort "{{{
endfunction
function! neosnippet#mappings#completed_expandable() abort
if !s:enabled_completed_snippet()
return 0
endif
@ -28,14 +28,14 @@ function! neosnippet#mappings#completed_expandable() abort "{{{
\ v:completed_item, neosnippet#util#get_cur_text(),
\ neosnippet#util#get_next_text())
return snippet != ''
endfunction"}}}
function! s:enabled_completed_snippet() abort "{{{
endfunction
function! s:enabled_completed_snippet() abort
return exists('v:completed_item')
\ && !empty(v:completed_item)
\ && g:neosnippet#enable_completed_snippet
endfunction"}}}
endfunction
function! neosnippet#mappings#_clear_select_mode_mappings() abort "{{{
function! neosnippet#mappings#_clear_select_mode_mappings() abort
if !g:neosnippet#disable_select_mode_mappings
return
endif
@ -56,9 +56,9 @@ function! neosnippet#mappings#_clear_select_mode_mappings() abort "{{{
snoremap <BS> a<BS>
snoremap <Del> a<BS>
snoremap <C-h> a<BS>
endfunction"}}}
endfunction
function! neosnippet#mappings#_register_oneshot_snippet() abort "{{{
function! neosnippet#mappings#_register_oneshot_snippet() abort
let trigger = input('Please input snippet trigger: ', 'oneshot')
if trigger == ''
return
@ -84,9 +84,9 @@ function! neosnippet#mappings#_register_oneshot_snippet() abort "{{{
\ '', 0, '', trigger)
echo 'Registered trigger : ' . trigger
endfunction"}}}
endfunction
function! neosnippet#mappings#_expand_target() abort "{{{
function! neosnippet#mappings#_expand_target() abort
let trigger = input('Please input snippet trigger: ',
\ '', 'customlist,neosnippet#commands#_complete_target_snippets')
let neosnippet = neosnippet#variables#current_neosnippet()
@ -102,8 +102,8 @@ function! neosnippet#mappings#_expand_target() abort "{{{
endif
call neosnippet#mappings#_expand_target_trigger(trigger)
endfunction"}}}
function! neosnippet#mappings#_expand_target_trigger(trigger) abort "{{{
endfunction
function! neosnippet#mappings#_expand_target_trigger(trigger) abort
let neosnippet = neosnippet#variables#current_neosnippet()
let neosnippet.target = substitute(
\ neosnippet#helpers#get_selected_text(visualmode(), 1), '\n$', '', '')
@ -128,25 +128,25 @@ function! neosnippet#mappings#_expand_target_trigger(trigger) abort "{{{
call cursor(0, col('.') - 1)
stopinsert
endif
endfunction"}}}
endfunction
function! neosnippet#mappings#_anonymous(snippet) abort "{{{
function! neosnippet#mappings#_anonymous(snippet) abort
let [cur_text, col, expr] = neosnippet#mappings#_pre_trigger()
let expr .= printf("\<ESC>:call neosnippet#view#_insert(%s, {}, %s, %d)\<CR>",
\ string(a:snippet), string(cur_text), col)
return expr
endfunction"}}}
function! neosnippet#mappings#_expand(trigger) abort "{{{
endfunction
function! neosnippet#mappings#_expand(trigger) abort
let [cur_text, col, expr] = neosnippet#mappings#_pre_trigger()
let expr .= printf("\<ESC>:call neosnippet#view#_expand(%s, %d, %s)\<CR>",
\ string(cur_text), col, string(a:trigger))
return expr
endfunction"}}}
endfunction
function! s:snippets_expand(cur_text, col) abort "{{{
function! s:snippets_expand(cur_text, col) abort
if s:expand_completed_snippets(a:cur_text, a:col)
return 0
endif
@ -162,8 +162,8 @@ function! s:snippets_expand(cur_text, col) abort "{{{
endif
return 1
endfunction"}}}
function! s:expand_completed_snippets(cur_text, col) abort "{{{
endfunction
function! s:expand_completed_snippets(cur_text, col) abort
if !s:enabled_completed_snippet()
return 0
endif
@ -194,15 +194,15 @@ function! s:expand_completed_snippets(cur_text, col) abort "{{{
call neosnippet#view#_insert(snippet, {}, cur_text, a:col)
return 1
endfunction"}}}
endfunction
function! s:snippets_expand_or_jump(cur_text, col) abort "{{{
function! s:snippets_expand_or_jump(cur_text, col) abort
if s:snippets_expand(a:cur_text, a:col)
call neosnippet#view#_jump('', a:col)
endif
endfunction"}}}
endfunction
function! s:snippets_jump_or_expand(cur_text, col) abort "{{{
function! s:snippets_jump_or_expand(cur_text, col) abort
if search(neosnippet#get_placeholder_marker_pattern(). '\|'
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0
" Found snippet placeholder.
@ -210,13 +210,13 @@ function! s:snippets_jump_or_expand(cur_text, col) abort "{{{
else
return s:snippets_expand(a:cur_text, a:col)
endif
endfunction"}}}
endfunction
function! s:SID_PREFIX() abort "{{{
function! s:SID_PREFIX() abort
return matchstr(expand('<sfile>'), '<SNR>\d\+_\ze\w\+$')
endfunction"}}}
endfunction
function! neosnippet#mappings#_trigger(function) abort "{{{
function! neosnippet#mappings#_trigger(function) abort
let [cur_text, col, expr] = neosnippet#mappings#_pre_trigger()
if !neosnippet#mappings#expandable_or_jumpable()
@ -227,9 +227,9 @@ function! neosnippet#mappings#_trigger(function) abort "{{{
\ a:function, string(cur_text), col)
return expr
endfunction"}}}
endfunction
function! neosnippet#mappings#_pre_trigger() abort "{{{
function! neosnippet#mappings#_pre_trigger() abort
call neosnippet#init#check()
let cur_text = neosnippet#util#get_cur_text()
@ -249,7 +249,7 @@ function! neosnippet#mappings#_pre_trigger() abort "{{{
endif
return [cur_text, col, expr]
endfunction"}}}
endfunction
" Plugin key-mappings.
function! neosnippet#mappings#expand_or_jump_impl() abort
@ -270,5 +270,3 @@ endfunction
function! neosnippet#mappings#jump_impl() abort
return neosnippet#mappings#_trigger('neosnippet#view#_jump')
endfunction
" vim: foldmethod=marker

View File

@ -6,7 +6,7 @@
let s:Cache = neosnippet#util#get_vital().import('System.Cache.Deprecated')
function! neosnippet#parser#_parse_snippets(filename) abort "{{{
function! neosnippet#parser#_parse_snippets(filename) abort
if !filereadable(a:filename)
call neosnippet#util#print_error(
\ printf('snippet file "%s" is not found.', a:filename))
@ -32,8 +32,8 @@ function! neosnippet#parser#_parse_snippets(filename) abort "{{{
endif
return snippets
endfunction"}}}
function! neosnippet#parser#_parse_snippet(filename, trigger) abort "{{{
endfunction
function! neosnippet#parser#_parse_snippet(filename, trigger) abort
if !filereadable(a:filename)
call neosnippet#util#print_error(
\ printf('snippet file "%s" is not found.', a:filename))
@ -48,9 +48,9 @@ function! neosnippet#parser#_parse_snippet(filename, trigger) abort "{{{
return neosnippet#parser#_initialize_snippet(
\ snippet_dict, a:filename, 1, '', a:trigger)
endfunction"}}}
endfunction
function! s:parse(snippets_file) abort "{{{
function! s:parse(snippets_file) abort
let dup_check = {}
let snippet_dict = {}
let linenr = 1
@ -120,9 +120,9 @@ function! s:parse(snippets_file) abort "{{{
endif
return [snippets, sourced]
endfunction"}}}
endfunction
function! s:parse_snippet_name(snippets_file, line, linenr, dup_check) abort "{{{
function! s:parse_snippet_name(snippets_file, line, linenr, dup_check) abort
" Initialize snippet dict.
let snippet_dict = {
\ 'word' : '',
@ -162,9 +162,9 @@ function! s:parse_snippet_name(snippets_file, line, linenr, dup_check) abort "{{
endif
return snippet_dict
endfunction"}}}
endfunction
function! s:add_snippet_attribute(snippets_file, line, linenr, snippet_dict) abort "{{{
function! s:add_snippet_attribute(snippets_file, line, linenr, snippet_dict) abort
" Allow overriding/setting of the description (abbr) of the snippet.
" This will override what was set via the snippet line.
if a:line =~ '^abbr\s'
@ -203,9 +203,9 @@ function! s:add_snippet_attribute(snippets_file, line, linenr, snippet_dict) abo
call neosnippet#util#print_error(
\ printf('Invalid syntax : "%s"', a:line))
endif
endfunction"}}}
endfunction
function! s:set_snippet_dict(snippet_dict, snippets, dup_check, snippets_file) abort "{{{
function! s:set_snippet_dict(snippet_dict, snippets, dup_check, snippets_file) abort
if empty(a:snippet_dict)
return
endif
@ -225,9 +225,9 @@ function! s:set_snippet_dict(snippet_dict, snippets, dup_check, snippets_file) a
let a:snippets[alias] = alias_snippet
let a:dup_check[alias] = alias_snippet
endfor
endfunction"}}}
endfunction
function! neosnippet#parser#_initialize_snippet(dict, path, line, pattern, name) abort "{{{
function! neosnippet#parser#_initialize_snippet(dict, path, line, pattern, name) abort
let a:dict.word = substitute(a:dict.word, '\n\+$', '', '')
if a:dict.word !~ '\n'
\ && a:dict.word !~
@ -265,9 +265,9 @@ function! neosnippet#parser#_initialize_snippet(dict, path, line, pattern, name)
endif
return snippet
endfunction"}}}
endfunction
function! neosnippet#parser#_initialize_snippet_options() abort "{{{
function! neosnippet#parser#_initialize_snippet_options() abort
return {
\ 'head' : 0,
\ 'word' :
@ -275,9 +275,9 @@ function! neosnippet#parser#_initialize_snippet_options() abort "{{{
\ 'indent' : 0,
\ 'oneshot' : 0,
\ }
endfunction"}}}
endfunction
function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, next_text) abort "{{{
function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, next_text) abort
let item = a:completed_item
if strridx(a:cur_text, item.word) != len(a:cur_text) - len(item.word)
@ -376,9 +376,9 @@ function! neosnippet#parser#_get_completed_snippet(completed_item, cur_text, nex
let snippet .= '${' . cnt . '}'
return snippet
endfunction"}}}
endfunction
function! neosnippet#parser#_get_in_paren(key, pair, str) abort "{{{
function! neosnippet#parser#_get_in_paren(key, pair, str) abort
let s = ''
let level = 0
for c in split(a:str, '\zs')
@ -402,9 +402,9 @@ function! neosnippet#parser#_get_in_paren(key, pair, str) abort "{{{
endfor
return ''
endfunction"}}}
endfunction
function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort "{{{
function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort
let outside = ''
let inside = ''
if (a:args != '')
@ -415,5 +415,4 @@ function! neosnippet#parser#_conceal_argument(arg, cnt, args) abort "{{{
endif
endif
return printf('%s${%d:#:%s%s}', outside, a:cnt, inside, escape(a:arg, '{}'))
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,99 +4,99 @@
" License: MIT license
"=============================================================================
function! neosnippet#util#get_vital() abort "{{{
function! neosnippet#util#get_vital() abort
if !exists('s:V')
let s:V = vital#neosnippet#new()
endif
return s:V
endfunction"}}}
function! s:get_prelude() abort "{{{
endfunction
function! s:get_prelude() abort
if !exists('s:Prelude')
let s:Prelude = neosnippet#util#get_vital().import('Prelude')
endif
return s:Prelude
endfunction"}}}
function! s:get_list() abort "{{{
endfunction
function! s:get_list() abort
if !exists('s:List')
let s:List = neosnippet#util#get_vital().import('Data.List')
endif
return s:List
endfunction"}}}
function! s:get_string() abort "{{{
endfunction
function! s:get_string() abort
if !exists('s:String')
let s:String = neosnippet#util#get_vital().import('Data.String')
endif
return s:String
endfunction"}}}
function! s:get_process() abort "{{{
endfunction
function! s:get_process() abort
if !exists('s:Process')
let s:Process = neosnippet#util#get_vital().import('Process')
endif
return s:Process
endfunction"}}}
endfunction
function! neosnippet#util#substitute_path_separator(...) abort "{{{
function! neosnippet#util#substitute_path_separator(...) abort
return call(s:get_prelude().substitute_path_separator, a:000)
endfunction"}}}
function! neosnippet#util#system(...) abort "{{{
endfunction
function! neosnippet#util#system(...) abort
return call(s:get_process().system, a:000)
endfunction"}}}
function! neosnippet#util#has_vimproc(...) abort "{{{
endfunction
function! neosnippet#util#has_vimproc(...) abort
return call(s:get_process().has_vimproc, a:000)
endfunction"}}}
function! neosnippet#util#is_windows(...) abort "{{{
endfunction
function! neosnippet#util#is_windows(...) abort
return call(s:get_prelude().is_windows, a:000)
endfunction"}}}
function! neosnippet#util#is_mac(...) abort "{{{
endfunction
function! neosnippet#util#is_mac(...) abort
return call(s:get_prelude().is_mac, a:000)
endfunction"}}}
function! neosnippet#util#get_last_status(...) abort "{{{
endfunction
function! neosnippet#util#get_last_status(...) abort
return call(s:get_process().get_last_status, a:000)
endfunction"}}}
function! neosnippet#util#escape_pattern(...) abort "{{{
endfunction
function! neosnippet#util#escape_pattern(...) abort
return call(s:get_string().escape_pattern, a:000)
endfunction"}}}
function! neosnippet#util#iconv(...) abort "{{{
endfunction
function! neosnippet#util#iconv(...) abort
return call(s:get_process().iconv, a:000)
endfunction"}}}
function! neosnippet#util#truncate(...) abort "{{{
endfunction
function! neosnippet#util#truncate(...) abort
return call(s:get_string().truncate, a:000)
endfunction"}}}
function! neosnippet#util#strwidthpart(...) abort "{{{
endfunction
function! neosnippet#util#strwidthpart(...) abort
return call(s:get_string().strwidthpart, a:000)
endfunction"}}}
endfunction
function! neosnippet#util#expand(path) abort "{{{
function! neosnippet#util#expand(path) abort
return neosnippet#util#substitute_path_separator(
\ expand(escape(a:path, '*?[]"={}'), 1))
endfunction"}}}
function! neosnippet#util#set_default(var, val, ...) abort "{{{
endfunction
function! neosnippet#util#set_default(var, val, ...) abort
let old_var = get(a:000, 0, '')
if exists(old_var)
let {a:var} = {old_var}
elseif !exists(a:var)
let {a:var} = a:val
endif
endfunction"}}}
function! neosnippet#util#set_dictionary_helper(...) abort "{{{
endfunction
function! neosnippet#util#set_dictionary_helper(...) abort
return call(s:get_prelude().set_dictionary_helper, a:000)
endfunction"}}}
endfunction
function! neosnippet#util#get_cur_text() abort "{{{
function! neosnippet#util#get_cur_text() abort
return
\ (mode() ==# 'i' ? (col('.')-1) : col('.')) >= len(getline('.')) ?
\ getline('.') :
\ matchstr(getline('.'),
\ '^.*\%' . col('.') . 'c' . (mode() ==# 'i' ? '' : '.'))
endfunction"}}}
function! neosnippet#util#get_next_text() abort "{{{
endfunction
function! neosnippet#util#get_next_text() abort
return getline('.')[len(neosnippet#util#get_cur_text()) :]
endfunction"}}}
function! neosnippet#util#print_error(string) abort "{{{
endfunction
function! neosnippet#util#print_error(string) abort
echohl Error | echomsg '[neosnippet] ' . a:string | echohl None
endfunction"}}}
endfunction
function! neosnippet#util#parse_options(args, options_list) abort "{{{
function! neosnippet#util#parse_options(args, options_list) abort
let args = []
let options = {}
for arg in split(a:args, '\%(\\\@<!\s\)\+')
@ -117,9 +117,9 @@ function! neosnippet#util#parse_options(args, options_list) abort "{{{
endfor
return [args, options]
endfunction"}}}
endfunction
function! neosnippet#util#get_buffer_config(
\ filetype, buffer_var, user_var, default_var, ...) abort "{{{
\ filetype, buffer_var, user_var, default_var, ...) abort
let default_val = get(a:000, 0, '')
if exists(a:buffer_var)
@ -131,18 +131,18 @@ function! neosnippet#util#get_buffer_config(
return get({a:user_var}, filetype,
\ get(eval(a:default_var), filetype, default_val))
endfunction"}}}
endfunction
" Sudo check.
function! neosnippet#util#is_sudo() abort "{{{
function! neosnippet#util#is_sudo() abort
return $SUDO_USER != '' && $USER !=# $SUDO_USER
\ && $HOME !=# expand('~'.$USER)
\ && $HOME ==# expand('~'.$SUDO_USER)
endfunction"}}}
endfunction
function! neosnippet#util#option2list(str) abort "{{{
function! neosnippet#util#option2list(str) abort
return type(a:str) == type('') ? split(a:str, '\s*,\s*') : a:str
endfunction"}}}
endfunction
function! neosnippet#util#uniq(list) abort
let list = copy(a:list)
@ -161,5 +161,3 @@ function! neosnippet#util#uniq(list) abort
endwhile
return list
endfunction
" vim: foldmethod=marker

View File

@ -4,7 +4,7 @@
" License: MIT license
"=============================================================================
function! neosnippet#variables#current_neosnippet() abort "{{{
function! neosnippet#variables#current_neosnippet() abort
if !exists('b:neosnippet')
let b:neosnippet = {
\ 'snippets' : {},
@ -17,42 +17,42 @@ function! neosnippet#variables#current_neosnippet() abort "{{{
endif
return b:neosnippet
endfunction"}}}
function! neosnippet#variables#expand_stack() abort "{{{
endfunction
function! neosnippet#variables#expand_stack() abort
if !exists('s:expand_stack')
let s:expand_stack = []
endif
return s:expand_stack
endfunction"}}}
function! neosnippet#variables#pop_expand_stack() abort "{{{
endfunction
function! neosnippet#variables#pop_expand_stack() abort
let s:expand_stack = s:expand_stack[: -2]
endfunction"}}}
function! neosnippet#variables#clear_expand_stack() abort "{{{
endfunction
function! neosnippet#variables#clear_expand_stack() abort
let s:expand_stack = []
endfunction"}}}
function! neosnippet#variables#snippets() abort "{{{
endfunction
function! neosnippet#variables#snippets() abort
if !exists('s:snippets')
let s:snippets= {}
endif
return s:snippets
endfunction"}}}
function! neosnippet#variables#set_snippets(list) abort "{{{
endfunction
function! neosnippet#variables#set_snippets(list) abort
if !exists('s:snippets')
let s:snippets= {}
endif
let s:snippets = a:list
endfunction"}}}
function! neosnippet#variables#snippets_dir() abort "{{{
endfunction
function! neosnippet#variables#snippets_dir() abort
" Set snippets_dir.
let snippets_dir = map(neosnippet#util#option2list(
\ g:neosnippet#snippets_directory),
\ 'neosnippet#util#expand(v:val)')
return map(snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
endfunction"}}}
function! neosnippet#variables#runtime_dir() abort "{{{
endfunction
function! neosnippet#variables#runtime_dir() abort
" Set runtime dir.
let runtime_dir = split(globpath(&runtimepath, 'neosnippets'), '\n')
if empty(runtime_dir) && empty(g:neosnippet#disable_runtime_snippets)
@ -71,8 +71,8 @@ function! neosnippet#variables#runtime_dir() abort "{{{
endif
return map(runtime_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
endfunction"}}}
function! neosnippet#variables#data_dir() abort "{{{
endfunction
function! neosnippet#variables#data_dir() abort
let g:neosnippet#data_directory =
\ substitute(fnamemodify(get(
\ g:, 'neosnippet#data_directory',
@ -84,6 +84,4 @@ function! neosnippet#variables#data_dir() abort "{{{
endif
return g:neosnippet#data_directory
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,7 +4,7 @@
" License: MIT license
"=============================================================================
function! neosnippet#view#_expand(cur_text, col, trigger_name) abort "{{{
function! neosnippet#view#_expand(cur_text, col, trigger_name) abort
let snippets = neosnippet#helpers#get_snippets()
if a:trigger_name == '' || !has_key(snippets, a:trigger_name)
@ -25,8 +25,8 @@ function! neosnippet#view#_expand(cur_text, col, trigger_name) abort "{{{
let cur_text = a:cur_text[: -1-len(a:trigger_name)]
call neosnippet#view#_insert(snippet.snip, snippet.options, cur_text, a:col)
endfunction"}}}
function! neosnippet#view#_insert(snippet, options, cur_text, col) abort "{{{
endfunction
function! neosnippet#view#_insert(snippet, options, cur_text, col) abort
let options = extend(
\ neosnippet#parser#_initialize_snippet_options(),
\ a:options)
@ -105,8 +105,8 @@ function! neosnippet#view#_insert(snippet, options, cur_text, col) abort "{{{
silent! execute begin_line . ',' . end_line . 'foldopen!'
endif
endtry
endfunction"}}}
function! neosnippet#view#_jump(_, col) abort "{{{
endfunction
function! neosnippet#view#_jump(_, col) abort
try
let expand_stack = neosnippet#variables#expand_stack()
@ -148,9 +148,9 @@ function! neosnippet#view#_jump(_, col) abort "{{{
finally
call s:skip_next_auto_completion()
endtry
endfunction"}}}
endfunction
function! s:indent_snippet(begin, end) abort "{{{
function! s:indent_snippet(begin, end) abort
if a:begin > a:end
return
endif
@ -187,9 +187,9 @@ function! s:indent_snippet(begin, end) abort "{{{
let &l:equalprg = equalprg
call setpos('.', pos)
endtry
endfunction"}}}
endfunction
function! neosnippet#view#_get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) abort "{{{
function! neosnippet#view#_get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) abort
let pos = getpos('.')
call cursor(a:begin_line, 0)
@ -227,8 +227,8 @@ function! neosnippet#view#_get_snippet_range(begin_line, begin_patterns, end_lin
call setpos('.', pos)
return [begin, end]
endfunction"}}}
function! neosnippet#view#_search_snippet_range(start, end, cnt, ...) abort "{{{
endfunction
function! neosnippet#view#_search_snippet_range(start, end, cnt, ...) abort
let is_select = get(a:000, 0, 1)
call s:substitute_placeholder_marker(a:start, a:end, a:cnt)
@ -250,8 +250,8 @@ function! neosnippet#view#_search_snippet_range(start, end, cnt, ...) abort "{{{
endfor
return 0
endfunction"}}}
function! neosnippet#view#_search_outof_range(col) abort "{{{
endfunction
function! neosnippet#view#_search_outof_range(col) abort
call s:substitute_placeholder_marker(1, 0, 0)
let pattern = neosnippet#get_placeholder_marker_pattern()
@ -275,8 +275,8 @@ function! neosnippet#view#_search_outof_range(col) abort "{{{
" Not found.
return 0
endfunction"}}}
function! neosnippet#view#_clear_markers(expand_info) abort "{{{
endfunction
function! neosnippet#view#_clear_markers(expand_info) abort
" Search patterns.
let [begin, end] = neosnippet#view#_get_snippet_range(
\ a:expand_info.begin_line,
@ -311,8 +311,8 @@ function! neosnippet#view#_clear_markers(expand_info) abort "{{{
call neosnippet#variables#pop_expand_stack()
endtry
endfunction"}}}
function! s:expand_placeholder(start, end, holder_cnt, line, ...) abort "{{{
endfunction
function! s:expand_placeholder(start, end, holder_cnt, line, ...) abort
let is_select = get(a:000, 0, 1)
let pattern = substitute(neosnippet#get_placeholder_marker_pattern(),
@ -401,8 +401,8 @@ function! s:expand_placeholder(start, end, holder_cnt, line, ...) abort "{{{
else
startinsert!
endif
endfunction"}}}
function! s:expand_target_placeholder(line, col) abort "{{{
endfunction
function! s:expand_target_placeholder(line, col) abort
" Expand target
let neosnippet = neosnippet#variables#current_neosnippet()
let next_line = getline(a:line)[a:col-1 :]
@ -461,8 +461,8 @@ function! s:expand_target_placeholder(line, col) abort "{{{
let neosnippet.target = ''
call neosnippet#view#_jump('', col)
endfunction"}}}
function! s:search_sync_placeholder(start, end, number) abort "{{{
endfunction
function! s:search_sync_placeholder(start, end, number) abort
if a:end == 0
" Search in current buffer.
let cnt = matchstr(getline('.'),
@ -482,8 +482,8 @@ function! s:search_sync_placeholder(start, end, number) abort "{{{
endif
return -1
endfunction"}}}
function! s:substitute_placeholder_marker(start, end, snippet_holder_cnt) abort "{{{
endfunction
function! s:substitute_placeholder_marker(start, end, snippet_holder_cnt) abort
if a:snippet_holder_cnt > 0
let cnt = a:snippet_holder_cnt-1
let sync_marker = substitute(neosnippet#get_sync_placeholder_marker_pattern(),
@ -518,8 +518,8 @@ function! s:substitute_placeholder_marker(start, end, snippet_holder_cnt) abort
\ '\\d\\+', cnt, '')
call setline('.', substitute(getline('.'), sync_marker, sub, ''))
endif
endfunction"}}}
function! s:eval_snippet(snippet_text) abort "{{{
endfunction
function! s:eval_snippet(snippet_text) abort
let snip_word = ''
let prev_match = 0
let match = match(a:snippet_text, '\\\@<!`.\{-}\\\@<!`')
@ -540,8 +540,8 @@ function! s:eval_snippet(snippet_text) abort "{{{
endif
return snip_word
endfunction"}}}
function! s:skip_next_auto_completion() abort "{{{
endfunction
function! s:skip_next_auto_completion() abort
" Skip next auto completion.
let neosnippet = neosnippet#variables#current_neosnippet()
let neosnippet.trigger = 0
@ -552,6 +552,4 @@ function! s:skip_next_auto_completion() abort "{{{
if exists('#deoplete#CompleteDone')
doautocmd deoplete CompleteDone
endif
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,7 +4,7 @@
" License: MIT license
"=============================================================================
function! unite#sources#neosnippet#define() abort "{{{
function! unite#sources#neosnippet#define() abort
let kind = {
\ 'name' : 'neosnippet',
\ 'default_action' : 'expand',
@ -15,7 +15,7 @@ function! unite#sources#neosnippet#define() abort "{{{
call unite#define_kind(kind)
return s:source
endfunction "}}}
endfunction
" neosnippet source.
let s:source = {
@ -24,14 +24,14 @@ let s:source = {
\ 'action_table' : {},
\ }
function! s:source.hooks.on_init(args, context) abort "{{{
function! s:source.hooks.on_init(args, context) abort
let a:context.source__cur_keyword_pos =
\ s:get_keyword_pos(neosnippet#util#get_cur_text())
let a:context.source__snippets =
\ sort(values(neosnippet#helpers#get_completion_snippets()))
endfunction"}}}
endfunction
function! s:source.gather_candidates(args, context) abort "{{{
function! s:source.gather_candidates(args, context) abort
return map(copy(a:context.source__snippets), "{
\ 'word' : v:val.word,
\ 'abbr' : printf('%-50s %s', v:val.word, v:val.menu_abbr),
@ -44,29 +44,29 @@ function! s:source.gather_candidates(args, context) abort "{{{
\ 'source__snip' : v:val.snip,
\ 'source__snip_ref' : v:val,
\ }")
endfunction "}}}
endfunction
" Actions "{{{
" Actions
let s:action_table = {}
let s:action_table.expand = {
\ 'description' : 'expand snippet',
\ }
function! s:action_table.expand.func(candidate) abort "{{{
function! s:action_table.expand.func(candidate) abort
let cur_text = neosnippet#util#get_cur_text()
let cur_keyword_str = matchstr(cur_text, '\S\+$')
let context = unite#get_context()
call neosnippet#view#_expand(
\ cur_text . a:candidate.action__complete_word[len(cur_keyword_str)],
\ context.col, a:candidate.action__complete_word)
endfunction"}}}
endfunction
let s:action_table.preview = {
\ 'description' : 'preview snippet',
\ 'is_selectable' : 1,
\ 'is_quit' : 0,
\ }
function! s:action_table.preview.func(candidates) abort "{{{
function! s:action_table.preview.func(candidates) abort
for snip in a:candidates
echohl String
echo snip.action__complete_word
@ -74,13 +74,13 @@ function! s:action_table.preview.func(candidates) abort "{{{
echo snip.source__snip
echo ' '
endfor
endfunction"}}}
endfunction
let s:action_table.unite__new_candidate = {
\ 'description' : 'add new snippet',
\ 'is_quit' : 1,
\ }
function! s:action_table.unite__new_candidate.func(candidate) abort "{{{
function! s:action_table.unite__new_candidate.func(candidate) abort
let trigger = unite#util#input('Please input snippet trigger: ')
if trigger == ''
echo 'Canceled.'
@ -107,14 +107,14 @@ function! s:action_table.unite__new_candidate.func(candidate) abort "{{{
call cursor(line('$'), 0)
call cursor(0, col('$'))
endfunction"}}}
endfunction
let s:source.action_table = s:action_table
unlet! s:action_table
"}}}
function! unite#sources#neosnippet#start_complete() abort "{{{
function! unite#sources#neosnippet#start_complete() abort
if !exists(':Unite')
call neosnippet#util#print_error(
\ 'unite.vim is not installed.')
@ -125,9 +125,9 @@ function! unite#sources#neosnippet#start_complete() abort "{{{
return unite#start_complete(['neosnippet'],
\ { 'input': neosnippet#util#get_cur_text(), 'buffer_name' : '' })
endfunction "}}}
endfunction
function! s:get_keyword_pos(cur_text) abort "{{{
function! s:get_keyword_pos(cur_text) abort
let cur_keyword_pos = match(a:cur_text, '\S\+$')
if cur_keyword_pos < 0
" Empty string.
@ -135,6 +135,4 @@ function! s:get_keyword_pos(cur_text) abort "{{{
endif
return cur_keyword_pos
endfunction"}}}
" vim: foldmethod=marker
endfunction

View File

@ -4,9 +4,9 @@
" License: MIT license
"=============================================================================
function! unite#sources#neosnippet_file#define() abort "{{{
function! unite#sources#neosnippet_file#define() abort
return [s:source_user, s:source_runtime]
endfunction "}}}
endfunction
" common action table
let s:action_table = {}
@ -15,14 +15,14 @@ let s:action_table.neosnippet_source = {
\ 'is_selectable' : 1,
\ 'is_quit' : 1,
\ }
function! s:action_table.neosnippet_source.func(candidates) abort "{{{
function! s:action_table.neosnippet_source.func(candidates) abort
for candidate in a:candidates
let snippet_name = candidate.action__path
if snippet_name != ''
call neosnippet#commands#_source(snippet_name)
endif
endfor
endfunction"}}}
endfunction
" neosnippet source.
let s:source_user = {
@ -30,23 +30,23 @@ let s:source_user = {
\ 'description' : 'neosnippet user file',
\ 'action_table' : copy(s:action_table),
\ }
function! s:source_user.gather_candidates(args, context) abort "{{{
function! s:source_user.gather_candidates(args, context) abort
return s:get_snippet_candidates(
\ neosnippet#get_user_snippets_directory())
endfunction "}}}
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) abort "{{{
function! s:source_user.action_table.unite__new_candidate.func(candidate) abort
let filename = input(
\ 'New snippet file name: ', neosnippet#helpers#get_filetype())
if filename != ''
call neosnippet#commands#_edit(filename)
endif
endfunction"}}}
endfunction
" neosnippet source.
@ -55,26 +55,26 @@ let s:source_runtime = {
\ 'description' : 'neosnippet runtime file',
\ 'action_table' : copy(s:action_table),
\ }
function! s:source_runtime.gather_candidates(args, context) abort "{{{
function! s:source_runtime.gather_candidates(args, context) abort
return s:get_snippet_candidates(
\ neosnippet#get_runtime_snippets_directory())
endfunction "}}}
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) abort "{{{
function! s:source_runtime.action_table.unite__new_candidate.func(candidate) abort
let filename = input(
\ 'New snippet file name: ', neosnippet#helpers#get_filetype())
if filename != ''
call neosnippet#commands#_edit('-runtime ' . filename)
endif
endfunction"}}}
endfunction
function! s:get_snippet_candidates(dirs) abort "{{{
function! s:get_snippet_candidates(dirs) abort
let _ = []
for directory in a:dirs
let _ += map(split(unite#util#substitute_path_separator(
@ -86,6 +86,4 @@ function! s:get_snippet_candidates(dirs) abort "{{{
endfor
return _
endfunction "}}}
" vim: foldmethod=marker
endfunction

View File

@ -11,7 +11,7 @@ elseif v:version < 704
finish
endif
" Plugin key-mappings. "{{{
" Plugin key-mappings.
inoremap <silent><expr> <Plug>(neosnippet_expand_or_jump)
\ neosnippet#mappings#expand_or_jump_impl()
inoremap <silent><expr> <Plug>(neosnippet_jump_or_expand)
@ -39,13 +39,13 @@ xnoremap <silent> <Plug>(neosnippet_register_oneshot_snippet)
inoremap <expr><silent> <Plug>(neosnippet_start_unite_snippet)
\ unite#sources#neosnippet#start_complete()
"}}}
augroup neosnippet "{{{
augroup neosnippet
autocmd InsertEnter * call neosnippet#init#_initialize()
augroup END"}}}
augroup END
" Commands. "{{{
" Commands.
command! -nargs=? -bar
\ -complete=customlist,neosnippet#commands#_edit_complete
\ NeoSnippetEdit
@ -62,9 +62,6 @@ command! -nargs=1 -bar -complete=file
command! -bar NeoSnippetClearMarkers
\ call neosnippet#commands#_clear_markers()
"}}}
let g:loaded_neosnippet = 1
" __END__
" vim: foldmethod=marker