Move many helper functions
This commit is contained in:
parent
3d4487111e
commit
212609b1e3
@ -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: 04 Jun 2013.
|
" Last Modified: 21 Nov 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
|
||||||
@ -47,7 +47,7 @@ endfunction"}}}
|
|||||||
function! s:source.get_keyword_pos(cur_text) "{{{
|
function! s:source.get_keyword_pos(cur_text) "{{{
|
||||||
let cur_word = matchstr(a:cur_text, '\w\+$')
|
let cur_word = matchstr(a:cur_text, '\w\+$')
|
||||||
let word_candidates = neocomplcache#keyword_filter(
|
let word_candidates = neocomplcache#keyword_filter(
|
||||||
\ filter(values(neosnippet#get_snippets()),
|
\ filter(values(neosnippet#helpers#get_snippets()),
|
||||||
\ 'v:val.options.word'), cur_word)
|
\ 'v:val.options.word'), cur_word)
|
||||||
if !empty(word_candidates)
|
if !empty(word_candidates)
|
||||||
return match(a:cur_text, '\w\+$')
|
return match(a:cur_text, '\w\+$')
|
||||||
@ -57,7 +57,7 @@ function! s:source.get_keyword_pos(cur_text) "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str) "{{{
|
function! s:source.get_complete_words(cur_keyword_pos, cur_keyword_str) "{{{
|
||||||
let list = s:keyword_filter(neosnippet#get_snippets(), a:cur_keyword_str)
|
let list = s:keyword_filter(neosnippet#helpers#get_snippets(), a:cur_keyword_str)
|
||||||
|
|
||||||
for snippet in list
|
for snippet in list
|
||||||
let snippet.dup = 1
|
let snippet.dup = 1
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: neosnippet.vim
|
" FILE: neosnippet.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 05 Jun 2013.
|
" Last Modified: 21 Nov 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
|
||||||
@ -41,7 +41,7 @@ function! s:source.hooks.on_init(context) "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:source.gather_candidates(context) "{{{
|
function! s:source.gather_candidates(context) "{{{
|
||||||
return values(neosnippet#get_snippets())
|
return values(neosnippet#helpers#get_snippets())
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:source.hooks.on_post_filter(context) "{{{
|
function! s:source.hooks.on_post_filter(context) "{{{
|
||||||
|
@ -48,15 +48,6 @@ function! neosnippet#jumpable() "{{{
|
|||||||
return neosnippet#mappings#jumpable()
|
return neosnippet#mappings#jumpable()
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:is_beginning_of_line(cur_text) "{{{
|
|
||||||
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"}}}
|
|
||||||
|
|
||||||
function! neosnippet#jump(cur_text, col) "{{{
|
function! neosnippet#jump(cur_text, col) "{{{
|
||||||
call s:skip_next_auto_completion()
|
call s:skip_next_auto_completion()
|
||||||
|
|
||||||
@ -94,7 +85,7 @@ endfunction"}}}
|
|||||||
function! neosnippet#expand(cur_text, col, trigger_name) "{{{
|
function! neosnippet#expand(cur_text, col, trigger_name) "{{{
|
||||||
call s:skip_next_auto_completion()
|
call s:skip_next_auto_completion()
|
||||||
|
|
||||||
let snippets = neosnippet#get_snippets()
|
let snippets = neosnippet#helpers#get_snippets()
|
||||||
|
|
||||||
if a:trigger_name == '' || !has_key(snippets, a:trigger_name)
|
if a:trigger_name == '' || !has_key(snippets, a:trigger_name)
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
@ -196,10 +187,10 @@ function! neosnippet#expand(cur_text, col, trigger_name) "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#expand_target() "{{{
|
function! neosnippet#expand_target() "{{{
|
||||||
let trigger = input('Please input snippet trigger: ',
|
let trigger = input('Please input snippet trigger: ',
|
||||||
\ '', 'customlist,neosnippet#complete_target_snippets')
|
\ '', 'customlist,neosnippet#commands#_complete_target_snippets')
|
||||||
let neosnippet = neosnippet#variables#current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
if !has_key(neosnippet#get_snippets(), trigger) ||
|
if !has_key(neosnippet#helpers#get_snippets(), trigger) ||
|
||||||
\ neosnippet#get_snippets()[trigger].snip !~#
|
\ neosnippet#helpers#get_snippets()[trigger].snip !~#
|
||||||
\ neosnippet#get_placeholder_target_marker_pattern()
|
\ neosnippet#get_placeholder_target_marker_pattern()
|
||||||
if trigger != ''
|
if trigger != ''
|
||||||
echo 'The trigger is invalid.'
|
echo 'The trigger is invalid.'
|
||||||
@ -214,12 +205,12 @@ endfunction"}}}
|
|||||||
function! neosnippet#expand_target_trigger(trigger) "{{{
|
function! neosnippet#expand_target_trigger(trigger) "{{{
|
||||||
let neosnippet = neosnippet#variables#current_neosnippet()
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
let neosnippet.target = substitute(
|
let neosnippet.target = substitute(
|
||||||
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
|
\ neosnippet#helpers#get_selected_text(visualmode(), 1), '\n$', '', '')
|
||||||
|
|
||||||
let line = getpos("'<")[1]
|
let line = getpos("'<")[1]
|
||||||
let col = getpos("'<")[2]
|
let col = getpos("'<")[2]
|
||||||
|
|
||||||
call neosnippet#delete_selected_text(visualmode())
|
call neosnippet#helpers#delete_selected_text(visualmode())
|
||||||
|
|
||||||
call cursor(line, col)
|
call cursor(line, col)
|
||||||
|
|
||||||
@ -540,51 +531,9 @@ function! s:eval_snippet(snippet_text) "{{{
|
|||||||
|
|
||||||
return snip_word
|
return snip_word
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#variables#current_neosnippet() "{{{
|
|
||||||
if !exists('b:neosnippet')
|
|
||||||
let b:neosnippet = {
|
|
||||||
\ 'snippets' : {},
|
|
||||||
\ 'selected_text' : '',
|
|
||||||
\ 'target' : '',
|
|
||||||
\ 'trigger' : 0,
|
|
||||||
\}
|
|
||||||
endif
|
|
||||||
|
|
||||||
return b:neosnippet
|
|
||||||
endfunction"}}}
|
|
||||||
function! neosnippet#get_snippets() "{{{
|
|
||||||
call neosnippet#init#check()
|
|
||||||
|
|
||||||
let neosnippet = neosnippet#variables#current_neosnippet()
|
|
||||||
let snippets = copy(neosnippet.snippets)
|
|
||||||
for filetype in s:get_sources_filetypes(neosnippet#get_filetype())
|
|
||||||
call neosnippet#commands#_make_cache(filetype)
|
|
||||||
call extend(snippets,
|
|
||||||
\ neosnippet#variables#snippets()[filetype], 'keep')
|
|
||||||
endfor
|
|
||||||
|
|
||||||
let cur_text = neosnippet#util#get_cur_text()
|
|
||||||
|
|
||||||
if mode() ==# 'i'
|
|
||||||
" Special filters.
|
|
||||||
if !s:is_beginning_of_line(cur_text)
|
|
||||||
call filter(snippets, '!v:val.options.head')
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
call filter(snippets, "cur_text =~# get(v:val, 'regexp', '')")
|
|
||||||
|
|
||||||
return snippets
|
|
||||||
endfunction"}}}
|
|
||||||
function! neosnippet#get_snippets_directory() "{{{
|
function! neosnippet#get_snippets_directory() "{{{
|
||||||
let snippets_dir = copy(neosnippet#variables#snippets_dir())
|
return neosnippet#helpers#get_snippets_directory()
|
||||||
if !get(g:neosnippet#disable_runtime_snippets,
|
|
||||||
\ neosnippet#get_filetype(),
|
|
||||||
\ get(g:neosnippet#disable_runtime_snippets, '_', 0))
|
|
||||||
let snippets_dir += neosnippet#variables#runtime_dir()
|
|
||||||
endif
|
|
||||||
|
|
||||||
return snippets_dir
|
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#get_user_snippets_directory() "{{{
|
function! neosnippet#get_user_snippets_directory() "{{{
|
||||||
return copy(neosnippet#variables#snippets_dir())
|
return copy(neosnippet#variables#snippets_dir())
|
||||||
@ -592,57 +541,6 @@ endfunction"}}}
|
|||||||
function! neosnippet#get_runtime_snippets_directory() "{{{
|
function! neosnippet#get_runtime_snippets_directory() "{{{
|
||||||
return copy(neosnippet#variables#runtime_dir())
|
return copy(neosnippet#variables#runtime_dir())
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#get_filetype() "{{{
|
|
||||||
if !exists('s:exists_context_filetype')
|
|
||||||
" context_filetype.vim installation check.
|
|
||||||
try
|
|
||||||
call context_filetype#version()
|
|
||||||
let s:exists_context_filetype = 1
|
|
||||||
catch
|
|
||||||
let s:exists_context_filetype = 0
|
|
||||||
endtry
|
|
||||||
endif
|
|
||||||
|
|
||||||
let context_filetype =
|
|
||||||
\ s:exists_context_filetype ?
|
|
||||||
\ context_filetype#get_filetype() : &filetype
|
|
||||||
if context_filetype == ''
|
|
||||||
let context_filetype = 'nothing'
|
|
||||||
endif
|
|
||||||
|
|
||||||
return context_filetype
|
|
||||||
endfunction"}}}
|
|
||||||
function! s:get_sources_filetypes(filetype) "{{{
|
|
||||||
let filetypes =
|
|
||||||
\ exists('*neocomplete#get_source_filetypes') ?
|
|
||||||
\ neocomplete#get_source_filetypes(a:filetype) :
|
|
||||||
\ exists('*neocomplcache#get_source_filetypes') ?
|
|
||||||
\ neocomplcache#get_source_filetypes(a:filetype) :
|
|
||||||
\ [(a:filetype == '') ? 'nothing' : a:filetype]
|
|
||||||
return filetypes + ['_']
|
|
||||||
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! neosnippet#complete_target_snippets(arglead, cmdline, cursorpos) "{{{
|
|
||||||
return map(filter(values(neosnippet#get_snippets()),
|
|
||||||
\ "stridx(v:val.word, a:arglead) == 0
|
|
||||||
\ && v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"), 'v:val.word')
|
|
||||||
endfunction"}}}
|
|
||||||
|
|
||||||
" Get marker patterns.
|
" Get marker patterns.
|
||||||
function! neosnippet#get_placeholder_target_marker_pattern() "{{{
|
function! neosnippet#get_placeholder_target_marker_pattern() "{{{
|
||||||
@ -670,78 +568,6 @@ function! neosnippet#get_mirror_placeholder_marker_substitute_pattern() "{{{
|
|||||||
return '\$\(\d\+\)'
|
return '\$\(\d\+\)'
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! neosnippet#get_selected_text(type, ...) "{{{
|
|
||||||
let sel_save = &selection
|
|
||||||
let &selection = 'inclusive'
|
|
||||||
let reg_save = @@
|
|
||||||
let pos = getpos('.')
|
|
||||||
|
|
||||||
try
|
|
||||||
" Invoked from Visual mode, use '< and '> marks.
|
|
||||||
if a:0
|
|
||||||
silent exe "normal! `<" . a:type . "`>y"
|
|
||||||
elseif a:type == 'line'
|
|
||||||
silent exe "normal! '[V']y"
|
|
||||||
elseif a:type == 'block'
|
|
||||||
silent exe "normal! `[\<C-v>`]y"
|
|
||||||
else
|
|
||||||
silent exe "normal! `[v`]y"
|
|
||||||
endif
|
|
||||||
|
|
||||||
return @@
|
|
||||||
finally
|
|
||||||
let &selection = sel_save
|
|
||||||
let @@ = reg_save
|
|
||||||
call setpos('.', pos)
|
|
||||||
endtry
|
|
||||||
endfunction"}}}
|
|
||||||
function! neosnippet#delete_selected_text(type, ...) "{{{
|
|
||||||
let sel_save = &selection
|
|
||||||
let &selection = 'inclusive'
|
|
||||||
let reg_save = @@
|
|
||||||
let pos = getpos('.')
|
|
||||||
|
|
||||||
try
|
|
||||||
" Invoked from Visual mode, use '< and '> marks.
|
|
||||||
if a:0
|
|
||||||
silent exe "normal! `<" . a:type . "`>d"
|
|
||||||
elseif a:type ==# 'V'
|
|
||||||
silent exe "normal! `[V`]s"
|
|
||||||
elseif a:type ==# "\<C-v>"
|
|
||||||
silent exe "normal! `[\<C-v>`]d"
|
|
||||||
else
|
|
||||||
silent exe "normal! `[v`]d"
|
|
||||||
endif
|
|
||||||
finally
|
|
||||||
let &selection = sel_save
|
|
||||||
let @@ = reg_save
|
|
||||||
call setpos('.', pos)
|
|
||||||
endtry
|
|
||||||
endfunction"}}}
|
|
||||||
function! neosnippet#substitute_selected_text(type, text) "{{{
|
|
||||||
let sel_save = &selection
|
|
||||||
let &selection = 'inclusive'
|
|
||||||
let reg_save = @@
|
|
||||||
let pos = getpos('.')
|
|
||||||
|
|
||||||
try
|
|
||||||
" Invoked from Visual mode, use '< and '> marks.
|
|
||||||
if a:0
|
|
||||||
silent exe "normal! `<" . a:type . "`>s" . a:text
|
|
||||||
elseif a:type ==# 'V'
|
|
||||||
silent exe "normal! '[V']hs" . a:text
|
|
||||||
elseif a:type ==# "\<C-v>"
|
|
||||||
silent exe "normal! `[\<C-v>`]s" . a:text
|
|
||||||
else
|
|
||||||
silent exe "normal! `[v`]s" . a:text
|
|
||||||
endif
|
|
||||||
finally
|
|
||||||
let &selection = sel_save
|
|
||||||
let @@ = reg_save
|
|
||||||
call setpos('.', pos)
|
|
||||||
endtry
|
|
||||||
endfunction"}}}
|
|
||||||
|
|
||||||
function! s:skip_next_auto_completion() "{{{
|
function! s:skip_next_auto_completion() "{{{
|
||||||
" Skip next auto completion.
|
" Skip next auto completion.
|
||||||
if exists('*neocomplcache#skip_next_complete')
|
if exists('*neocomplcache#skip_next_complete')
|
||||||
|
@ -48,7 +48,7 @@ function! neosnippet#commands#_edit(args) "{{{
|
|||||||
|
|
||||||
let filetype = get(args, 0, '')
|
let filetype = get(args, 0, '')
|
||||||
if filetype == ''
|
if filetype == ''
|
||||||
let filetype = neosnippet#get_filetype()
|
let filetype = neosnippet#helpers#get_filetype()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let options = s:initialize_options(options)
|
let options = s:initialize_options(options)
|
||||||
@ -99,7 +99,7 @@ function! neosnippet#commands#_make_cache(filetype) "{{{
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let snippets_dir = neosnippet#get_snippets_directory()
|
let snippets_dir = neosnippet#helpers#get_snippets_directory()
|
||||||
let snippet = {}
|
let snippet = {}
|
||||||
let snippets_files =
|
let snippets_files =
|
||||||
\ split(globpath(join(snippets_dir, ','),
|
\ split(globpath(join(snippets_dir, ','),
|
||||||
@ -123,11 +123,32 @@ function! neosnippet#commands#_source(filename) "{{{
|
|||||||
call neosnippet#parser#_parse(neosnippet.snippets, a:filename)
|
call neosnippet#parser#_parse(neosnippet.snippets, a:filename)
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
" Complete helpers.
|
||||||
function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) "{{{
|
function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) "{{{
|
||||||
return filter(s:edit_options +
|
return filter(s:edit_options +
|
||||||
\ neosnippet#filetype_complete(a:arglead, a:cmdline, a:cursorpos),
|
\ neosnippet#commands#_filetype_complete(a:arglead, a:cmdline, a:cursorpos),
|
||||||
\ 'stridx(v:val, a:arglead) == 0')
|
\ 'stridx(v:val, a:arglead) == 0')
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
function! neosnippet#commands#_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! neosnippet#commands#_complete_target_snippets(arglead, cmdline, cursorpos) "{{{
|
||||||
|
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"}}}
|
||||||
|
|
||||||
function! s:initialize_options(options) "{{{
|
function! s:initialize_options(options) "{{{
|
||||||
let default_options = {
|
let default_options = {
|
||||||
|
@ -45,6 +45,154 @@ function! neosnippet#helpers#get_cursor_snippet(snippets, cur_text) "{{{
|
|||||||
return cur_word
|
return cur_word
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
function! neosnippet#helpers#get_snippets() "{{{
|
||||||
|
call neosnippet#init#check()
|
||||||
|
|
||||||
|
let neosnippet = neosnippet#variables#current_neosnippet()
|
||||||
|
let snippets = copy(neosnippet.snippets)
|
||||||
|
for filetype in s:get_sources_filetypes(neosnippet#helpers#get_filetype())
|
||||||
|
call neosnippet#commands#_make_cache(filetype)
|
||||||
|
call extend(snippets,
|
||||||
|
\ neosnippet#variables#snippets()[filetype], 'keep')
|
||||||
|
endfor
|
||||||
|
|
||||||
|
let cur_text = neosnippet#util#get_cur_text()
|
||||||
|
|
||||||
|
if mode() ==# 'i'
|
||||||
|
" Special filters.
|
||||||
|
if !s:is_beginning_of_line(cur_text)
|
||||||
|
call filter(snippets, '!v:val.options.head')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
call filter(snippets, "cur_text =~# get(v:val, 'regexp', '')")
|
||||||
|
|
||||||
|
return snippets
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
|
function! neosnippet#helpers#get_snippets_directory() "{{{
|
||||||
|
let snippets_dir = copy(neosnippet#variables#snippets_dir())
|
||||||
|
if !get(g:neosnippet#disable_runtime_snippets,
|
||||||
|
\ neosnippet#helpers#get_filetype(),
|
||||||
|
\ get(g:neosnippet#disable_runtime_snippets, '_', 0))
|
||||||
|
let snippets_dir += neosnippet#variables#runtime_dir()
|
||||||
|
endif
|
||||||
|
|
||||||
|
return snippets_dir
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
|
function! neosnippet#helpers#get_filetype() "{{{
|
||||||
|
if !exists('s:exists_context_filetype')
|
||||||
|
" context_filetype.vim installation check.
|
||||||
|
try
|
||||||
|
call context_filetype#version()
|
||||||
|
let s:exists_context_filetype = 1
|
||||||
|
catch
|
||||||
|
let s:exists_context_filetype = 0
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
|
|
||||||
|
let context_filetype =
|
||||||
|
\ s:exists_context_filetype ?
|
||||||
|
\ context_filetype#get_filetype() : &filetype
|
||||||
|
if context_filetype == ''
|
||||||
|
let context_filetype = 'nothing'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return context_filetype
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
|
function! neosnippet#helpers#get_selected_text(type, ...) "{{{
|
||||||
|
let sel_save = &selection
|
||||||
|
let &selection = 'inclusive'
|
||||||
|
let reg_save = @@
|
||||||
|
let pos = getpos('.')
|
||||||
|
|
||||||
|
try
|
||||||
|
" Invoked from Visual mode, use '< and '> marks.
|
||||||
|
if a:0
|
||||||
|
silent exe "normal! `<" . a:type . "`>y"
|
||||||
|
elseif a:type == 'line'
|
||||||
|
silent exe "normal! '[V']y"
|
||||||
|
elseif a:type == 'block'
|
||||||
|
silent exe "normal! `[\<C-v>`]y"
|
||||||
|
else
|
||||||
|
silent exe "normal! `[v`]y"
|
||||||
|
endif
|
||||||
|
|
||||||
|
return @@
|
||||||
|
finally
|
||||||
|
let &selection = sel_save
|
||||||
|
let @@ = reg_save
|
||||||
|
call setpos('.', pos)
|
||||||
|
endtry
|
||||||
|
endfunction"}}}
|
||||||
|
function! neosnippet#helpers#delete_selected_text(type, ...) "{{{
|
||||||
|
let sel_save = &selection
|
||||||
|
let &selection = 'inclusive'
|
||||||
|
let reg_save = @@
|
||||||
|
let pos = getpos('.')
|
||||||
|
|
||||||
|
try
|
||||||
|
" Invoked from Visual mode, use '< and '> marks.
|
||||||
|
if a:0
|
||||||
|
silent exe "normal! `<" . a:type . "`>d"
|
||||||
|
elseif a:type ==# 'V'
|
||||||
|
silent exe "normal! `[V`]s"
|
||||||
|
elseif a:type ==# "\<C-v>"
|
||||||
|
silent exe "normal! `[\<C-v>`]d"
|
||||||
|
else
|
||||||
|
silent exe "normal! `[v`]d"
|
||||||
|
endif
|
||||||
|
finally
|
||||||
|
let &selection = sel_save
|
||||||
|
let @@ = reg_save
|
||||||
|
call setpos('.', pos)
|
||||||
|
endtry
|
||||||
|
endfunction"}}}
|
||||||
|
function! neosnippet#helpers#substitute_selected_text(type, text) "{{{
|
||||||
|
let sel_save = &selection
|
||||||
|
let &selection = 'inclusive'
|
||||||
|
let reg_save = @@
|
||||||
|
let pos = getpos('.')
|
||||||
|
|
||||||
|
try
|
||||||
|
" Invoked from Visual mode, use '< and '> marks.
|
||||||
|
if a:0
|
||||||
|
silent exe "normal! `<" . a:type . "`>s" . a:text
|
||||||
|
elseif a:type ==# 'V'
|
||||||
|
silent exe "normal! '[V']hs" . a:text
|
||||||
|
elseif a:type ==# "\<C-v>"
|
||||||
|
silent exe "normal! `[\<C-v>`]s" . a:text
|
||||||
|
else
|
||||||
|
silent exe "normal! `[v`]s" . a:text
|
||||||
|
endif
|
||||||
|
finally
|
||||||
|
let &selection = sel_save
|
||||||
|
let @@ = reg_save
|
||||||
|
call setpos('.', pos)
|
||||||
|
endtry
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
|
function! s:is_beginning_of_line(cur_text) "{{{
|
||||||
|
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"}}}
|
||||||
|
|
||||||
|
function! s:get_sources_filetypes(filetype) "{{{
|
||||||
|
let filetypes =
|
||||||
|
\ exists('*neocomplete#get_source_filetypes') ?
|
||||||
|
\ neocomplete#get_source_filetypes(a:filetype) :
|
||||||
|
\ exists('*neocomplcache#get_source_filetypes') ?
|
||||||
|
\ neocomplcache#get_source_filetypes(a:filetype) :
|
||||||
|
\ [(a:filetype == '') ? 'nothing' : a:filetype]
|
||||||
|
return filetypes + ['_']
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
unlet s:save_cpo
|
unlet s:save_cpo
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ function! s:doc_dict.search(cur_text) "{{{
|
|||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let snippets = neosnippet#get_snippets()
|
let snippets = neosnippet#helpers#get_snippets()
|
||||||
|
|
||||||
let cur_word = neosnippet#helpers#get_cursor_snippet(snippets, a:cur_text)
|
let cur_word = neosnippet#helpers#get_cursor_snippet(snippets, a:cur_text)
|
||||||
if cur_word == ''
|
if cur_word == ''
|
||||||
|
@ -33,7 +33,7 @@ endfunction"}}}
|
|||||||
function! neosnippet#mappings#expandable() "{{{
|
function! neosnippet#mappings#expandable() "{{{
|
||||||
" Check snippet trigger.
|
" Check snippet trigger.
|
||||||
return neosnippet#helpers#get_cursor_snippet(
|
return neosnippet#helpers#get_cursor_snippet(
|
||||||
\ neosnippet#get_snippets(), neosnippet#util#get_cur_text()) != ''
|
\ neosnippet#helpers#get_snippets(), neosnippet#util#get_cur_text()) != ''
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#mappings#jumpable() "{{{
|
function! neosnippet#mappings#jumpable() "{{{
|
||||||
" Found snippet placeholder.
|
" Found snippet placeholder.
|
||||||
@ -74,8 +74,8 @@ function! neosnippet#mappings#_register_oneshot_snippet() "{{{
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let selected_text = substitute(
|
let selected_text = substitute(
|
||||||
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
|
\ neosnippet#helpers#get_selected_text(visualmode(), 1), '\n$', '', '')
|
||||||
call neosnippet#delete_selected_text(visualmode(), 1)
|
call neosnippet#helpers#delete_selected_text(visualmode(), 1)
|
||||||
|
|
||||||
let base_indent = matchstr(selected_text, '^\s*')
|
let base_indent = matchstr(selected_text, '^\s*')
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ endfunction"}}}
|
|||||||
|
|
||||||
function! s:snippets_expand(cur_text, col) "{{{
|
function! s:snippets_expand(cur_text, col) "{{{
|
||||||
let cur_word = neosnippet#helpers#get_cursor_snippet(
|
let cur_word = neosnippet#helpers#get_cursor_snippet(
|
||||||
\ neosnippet#get_snippets(),
|
\ neosnippet#helpers#get_snippets(),
|
||||||
\ a:cur_text)
|
\ a:cur_text)
|
||||||
|
|
||||||
call neosnippet#expand(
|
call neosnippet#expand(
|
||||||
@ -105,7 +105,7 @@ endfunction"}}}
|
|||||||
|
|
||||||
function! s:snippets_expand_or_jump(cur_text, col) "{{{
|
function! s:snippets_expand_or_jump(cur_text, col) "{{{
|
||||||
let cur_word = neosnippet#helpers#get_cursor_snippet(
|
let cur_word = neosnippet#helpers#get_cursor_snippet(
|
||||||
\ neosnippet#get_snippets(), a:cur_text)
|
\ neosnippet#helpers#get_snippets(), a:cur_text)
|
||||||
|
|
||||||
if cur_word != ''
|
if cur_word != ''
|
||||||
" Found snippet trigger.
|
" Found snippet trigger.
|
||||||
@ -118,7 +118,7 @@ endfunction"}}}
|
|||||||
|
|
||||||
function! s:snippets_jump_or_expand(cur_text, col) "{{{
|
function! s:snippets_jump_or_expand(cur_text, col) "{{{
|
||||||
let cur_word = neosnippet#helpers#get_cursor_snippet(
|
let cur_word = neosnippet#helpers#get_cursor_snippet(
|
||||||
\ neosnippet#get_snippets(), a:cur_text)
|
\ neosnippet#helpers#get_snippets(), a:cur_text)
|
||||||
if search(neosnippet#get_placeholder_marker_pattern(). '\|'
|
if search(neosnippet#get_placeholder_marker_pattern(). '\|'
|
||||||
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0
|
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0
|
||||||
" Found snippet placeholder.
|
" Found snippet placeholder.
|
||||||
|
@ -52,7 +52,7 @@ function! neosnippet#parser#_parse(snippets, snippets_file) "{{{
|
|||||||
let filename = matchstr(line, '^include\s\+\zs.*$')
|
let filename = matchstr(line, '^include\s\+\zs.*$')
|
||||||
|
|
||||||
for snippets_file in split(globpath(join(
|
for snippets_file in split(globpath(join(
|
||||||
\ neosnippet#get_snippets_directory(), ','),
|
\ neosnippet#helpers#get_snippets_directory(), ','),
|
||||||
\ filename), '\n')
|
\ filename), '\n')
|
||||||
call neosnippet#parser#_parse(a:snippets, snippets_file)
|
call neosnippet#parser#_parse(a:snippets, snippets_file)
|
||||||
endfor
|
endfor
|
||||||
|
@ -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: 19 Nov 2013.
|
" Last Modified: 21 Nov 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
|
||||||
@ -65,7 +65,7 @@ let s:source_user.action_table.unite__new_candidate = {
|
|||||||
\ }
|
\ }
|
||||||
function! s:source_user.action_table.unite__new_candidate.func(candidate) "{{{
|
function! s:source_user.action_table.unite__new_candidate.func(candidate) "{{{
|
||||||
let filename = input(
|
let filename = input(
|
||||||
\ 'New snippet file name: ', neosnippet#get_filetype())
|
\ 'New snippet file name: ', neosnippet#helpers#get_filetype())
|
||||||
if filename != ''
|
if filename != ''
|
||||||
call neosnippet#commands#_edit(filename)
|
call neosnippet#commands#_edit(filename)
|
||||||
endif
|
endif
|
||||||
@ -90,7 +90,7 @@ let s:source_runtime.action_table.unite__new_candidate = {
|
|||||||
\ }
|
\ }
|
||||||
function! s:source_runtime.action_table.unite__new_candidate.func(candidate) "{{{
|
function! s:source_runtime.action_table.unite__new_candidate.func(candidate) "{{{
|
||||||
let filename = input(
|
let filename = input(
|
||||||
\ 'New snippet file name: ', neosnippet#get_filetype())
|
\ 'New snippet file name: ', neosnippet#helpers#get_filetype())
|
||||||
if filename != ''
|
if filename != ''
|
||||||
call neosnippet#commands#_edit('-runtime ' . filename)
|
call neosnippet#commands#_edit('-runtime ' . filename)
|
||||||
endif
|
endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: snippet.vim
|
" FILE: snippet.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 11 Jul 2013.
|
" Last Modified: 21 Nov 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
|
||||||
@ -51,7 +51,7 @@ function! s:source.hooks.on_init(args, context) "{{{
|
|||||||
let a:context.source__cur_keyword_pos =
|
let a:context.source__cur_keyword_pos =
|
||||||
\ s:get_keyword_pos(neosnippet#util#get_cur_text())
|
\ s:get_keyword_pos(neosnippet#util#get_cur_text())
|
||||||
let a:context.source__snippets =
|
let a:context.source__snippets =
|
||||||
\ sort(values(neosnippet#get_snippets()))
|
\ sort(values(neosnippet#helpers#get_snippets()))
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:source.gather_candidates(args, context) "{{{
|
function! s:source.gather_candidates(args, context) "{{{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: snippet_target.vim
|
" FILE: snippet_target.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 05 Mar 2013.
|
" Last Modified: 21 Nov 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
|
||||||
@ -49,7 +49,7 @@ function! s:source.hooks.on_init(args, context) "{{{
|
|||||||
let a:context.source__linenr = line('.')
|
let a:context.source__linenr = line('.')
|
||||||
|
|
||||||
let a:context.source__snippets =
|
let a:context.source__snippets =
|
||||||
\ sort(filter(values(neosnippet#get_snippets()),
|
\ sort(filter(values(neosnippet#helpers#get_snippets()),
|
||||||
\ "v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"))
|
\ "v:val.snip =~# neosnippet#get_placeholder_target_marker_pattern()"))
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ snoremap <silent><expr> <Plug>(neosnippet_jump)
|
|||||||
\ neosnippet#mappings#jump_impl()
|
\ neosnippet#mappings#jump_impl()
|
||||||
|
|
||||||
xnoremap <silent> <Plug>(neosnippet_get_selected_text)
|
xnoremap <silent> <Plug>(neosnippet_get_selected_text)
|
||||||
\ :call neosnippet#get_selected_text(visualmode(), 1)<CR>
|
\ :call neosnippet#helpers#get_selected_text(visualmode(), 1)<CR>
|
||||||
|
|
||||||
xnoremap <silent> <Plug>(neosnippet_expand_target)
|
xnoremap <silent> <Plug>(neosnippet_expand_target)
|
||||||
\ :<C-u>call neosnippet#expand_target()<CR>
|
\ :<C-u>call neosnippet#expand_target()<CR>
|
||||||
@ -78,7 +78,7 @@ command! -nargs=? -complete=customlist,neosnippet#commands#_edit_complete
|
|||||||
\ NeoSnippetEdit
|
\ NeoSnippetEdit
|
||||||
\ call neosnippet#commands#_edit(<q-args>)
|
\ call neosnippet#commands#_edit(<q-args>)
|
||||||
|
|
||||||
command! -nargs=? -complete=customlist,neosnippet#filetype_complete
|
command! -nargs=? -complete=customlist,neosnippet#commands#_filetype_complete
|
||||||
\ NeoSnippetMakeCache
|
\ NeoSnippetMakeCache
|
||||||
\ call neosnippet#commands#_make_cache(<q-args>)
|
\ call neosnippet#commands#_make_cache(<q-args>)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user