neosnippet.vim/autoload/neosnippet.vim

1225 lines
35 KiB
VimL
Raw Normal View History

2012-09-27 15:42:34 +00:00
"=============================================================================
" FILE: neosnippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
2012-11-01 02:18:58 +00:00
" Last Modified: 01 Nov 2012.
2012-09-27 15:42:34 +00:00
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================
let s:save_cpo = &cpo
set cpo&vim
2012-09-30 08:17:31 +00:00
" Global options definition."{{{
call neosnippet#util#set_default(
\ 'g:neosnippet#disable_runtime_snippets', {})
call neosnippet#util#set_default(
\ 'g:neosnippet#snippets_directory',
2012-09-30 08:17:31 +00:00
\ '', 'g:neocomplcache_snippets_dir')
call neosnippet#util#set_default(
\ 'g:neosnippet#disable_select_mode_mappings',
\ 1, 'g:neocomplcache_disable_select_mode_mappings')
2012-09-30 08:17:31 +00:00
"}}}
2012-09-30 10:10:25 +00:00
" Variables "{{{
let s:neosnippet_options = [
\ '-runtime',
\ '-vertical', '-horizontal', '-direction=', '-split',
\]
"}}}
2012-09-27 15:42:34 +00:00
function! s:initialize()"{{{
" Initialize.
let s:snippets_expand_stack = []
if get(g:, 'neocomplcache_snippets_disable_runtime_snippets', 0)
" Set for backward compatibility.
let g:neosnippet#disable_runtime_snippets._ = 1
endif
" Set runtime dir.
2012-09-27 15:42:34 +00:00
let s:runtime_dir = split(globpath(&runtimepath,
2012-09-30 08:04:46 +00:00
\ 'autoload/neosnippet/snippets'), '\n')
let s:runtime_dir += (exists('g:snippets_dir') ?
\ split(g:snippets_dir, '\s*,\s*')
\ : split(globpath(&runtimepath, 'snippets'), '\n'))
call map(s:runtime_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
2012-09-27 15:42:34 +00:00
" Set snippets_dir.
let s:snippets_dir = []
for dir in split(g:neosnippet#snippets_directory, '\s*,\s*')
2012-09-30 08:17:31 +00:00
let dir = neosnippet#util#expand(dir)
if !isdirectory(dir)
call mkdir(dir, 'p')
endif
call add(s:snippets_dir, dir)
endfor
2012-09-27 15:42:34 +00:00
call map(s:snippets_dir, 'substitute(v:val, "[\\\\/]$", "", "")')
augroup neosnippet
2012-10-29 02:32:38 +00:00
autocmd BufNewFile,BufRead,Syntax *
2012-10-29 02:27:22 +00:00
\ execute 'syntax match neosnippetExpandSnippets'
\ "'".s:get_placeholder_marker_pattern(). '\|'
\ .s:get_sync_placeholder_marker_pattern().'\|'
\ .s:get_mirror_placeholder_marker_pattern()."'"
2012-10-29 02:27:22 +00:00
\ 'containedin=ALL oneline'
if has('conceal')
2012-10-29 02:32:38 +00:00
autocmd BufNewFile,BufRead,Syntax *
2012-10-29 02:27:22 +00:00
\ syntax region neosnippetConcealExpandSnippets
\ matchgroup=neosnippetExpandSnippets
\ start='<`\d\+:\=\|<{\d\+:\=\|<|'
\ end='`>\|}>\||>'
\ containedin=ALL
2012-10-29 02:27:22 +00:00
\ concealends oneline
endif
augroup END
doautocmd neosnippet BufRead
2012-09-27 15:42:34 +00:00
2012-09-30 08:17:31 +00:00
hi def link neosnippetExpandSnippets Special
2012-09-27 15:42:34 +00:00
" Caching _ snippets.
2012-09-30 10:10:25 +00:00
call neosnippet#make_cache('_')
2012-09-27 15:42:34 +00:00
" Initialize check.
call neosnippet#caching()
2012-09-30 08:17:31 +00:00
if get(g:, 'loaded_echodoc', 0)
2012-09-27 15:42:34 +00:00
call echodoc#register('snippets_complete', s:doc_dict)
endif
endfunction"}}}
" For echodoc."{{{
let s:doc_dict = {
2012-09-30 08:17:31 +00:00
\ 'name' : 'neosnippet',
2012-09-27 15:42:34 +00:00
\ 'rank' : 100,
\ 'filetypes' : {},
\ }
function! s:doc_dict.search(cur_text)"{{{
if mode() !=# 'i'
return []
endif
let snippets = neosnippet#get_snippets()
let cur_word = s:get_cursor_snippet(snippets, a:cur_text)
2012-09-27 15:42:34 +00:00
if cur_word == ''
return []
endif
let snip = snippets[cur_word]
let ret = []
call add(ret, { 'text' : snip.word, 'highlight' : 'String' })
call add(ret, { 'text' : ' ' })
call add(ret, { 'text' : snip.menu, 'highlight' : 'Special' })
return ret
endfunction"}}}
"}}}
function! neosnippet#expandable()"{{{
let ret = 0
let snippets = neosnippet#get_snippets()
let cur_text = neosnippet#util#get_cur_text()
" Check snippet trigger.
if s:get_cursor_snippet(snippets, cur_text) != ''
2012-09-27 15:42:34 +00:00
let ret += 1
endif
" Check jumpable.
2012-09-27 15:42:34 +00:00
if neosnippet#jumpable()
let ret += 2
endif
return ret
endfunction"}}}
function! neosnippet#jumpable()"{{{
" Found snippet placeholder.
return search(s:get_placeholder_marker_pattern(). '\|'
\ .s:get_sync_placeholder_marker_pattern(), 'nw') > 0
endfunction"}}}
function! neosnippet#caching()"{{{
2012-09-30 10:10:25 +00:00
call neosnippet#make_cache(&filetype)
2012-09-27 15:42:34 +00:00
endfunction"}}}
2012-10-19 09:31:55 +00:00
function! neosnippet#recaching()"{{{
let s:snippets = {}
endfunction"}}}
2012-10-29 02:22:37 +00:00
function! s:set_snippet_dict(snippet_dict, snippets, dup_check, snippets_file)"{{{
if empty(a:snippet_dict)
2012-09-27 15:42:34 +00:00
return
endif
2012-10-29 02:22:37 +00:00
let action_pattern = '^snippet\s\+' . a:snippet_dict.name . '$'
let snippet = s:initialize_snippet(
\ a:snippet_dict, a:snippets_file,
\ a:snippet_dict.linenr, action_pattern,
\ a:snippet_dict.name)
let a:snippets[a:snippet_dict.name] = snippet
let a:dup_check[a:snippet_dict.name] = snippet
2012-09-27 15:42:34 +00:00
2012-10-29 02:22:37 +00:00
for alias in get(a:snippet_dict, 'alias', [])
let alias_snippet = copy(snippet)
let alias_snippet.word = alias
2012-09-27 15:42:34 +00:00
2012-10-29 20:18:59 +00:00
let a:snippets[alias] = alias_snippet
2012-10-29 02:22:37 +00:00
let a:dup_check[alias] = alias_snippet
2012-09-27 15:42:34 +00:00
endfor
endfunction"}}}
2012-10-29 02:22:37 +00:00
function! s:initialize_snippet(dict, path, line, pattern, name)"{{{
2012-09-27 15:42:34 +00:00
let a:dict.word = substitute(a:dict.word, '\n$', '', '')
if a:dict.word !~
\ s:get_placeholder_marker_substitute_pattern()
" Add placeholder.
let a:dict.word .= '${0}'
endif
2012-09-27 15:42:34 +00:00
let menu_pattern = (a:dict.word =~
2012-10-18 07:31:45 +00:00
\ s:get_placeholder_marker_substitute_pattern()
\ . '.*' . s:get_placeholder_marker_substitute_pattern()) ?
2012-09-27 15:42:34 +00:00
\ '<Snip> ' : '[Snip] '
2012-10-28 09:47:26 +00:00
if !has_key(a:dict, 'abbr') || a:dict.abbr == ''
" Set default abbr.
let abbr = substitute(a:dict.word,
2012-09-27 15:42:34 +00:00
\ s:get_placeholder_marker_pattern(). '\|'.
\ s:get_mirror_placeholder_marker_pattern().
2012-10-28 09:47:26 +00:00
\ '\|\s\+\|\n', ' ', 'g')
else
let abbr = a:dict.abbr
endif
2012-09-27 15:42:34 +00:00
let dict = {
2012-10-16 23:19:37 +00:00
\ 'word' : a:dict.name, 'snip' : a:dict.word,
2012-09-27 15:42:34 +00:00
\ 'description' : a:dict.word,
2012-10-04 09:49:16 +00:00
\ 'menu' : menu_pattern.abbr,
2012-10-21 08:51:07 +00:00
\ 'dup' : 1, 'options' : a:dict.options,
2012-10-29 02:22:37 +00:00
\ 'action__path' : a:path, 'action__line' : a:line,
\ 'action__pattern' : a:pattern, 'real_name' : a:name,
2012-09-27 15:42:34 +00:00
\}
return dict
endfunction"}}}
function! s:initialize_snippet_options()"{{{
return { 'head' : 0, 'word' : 0, 'indent' : 0 }
endfunction"}}}
2012-09-27 15:42:34 +00:00
2012-09-30 10:10:25 +00:00
function! neosnippet#edit_snippets(args)"{{{
let [args, options] = neosnippet#util#parse_options(
\ a:args, s:neosnippet_options)
let filetype = get(args, 0, '')
2012-09-30 08:33:50 +00:00
if filetype == ''
let filetype = neosnippet#get_filetype()
2012-09-27 15:42:34 +00:00
endif
2012-09-30 10:10:25 +00:00
let options = s:initialize_options(options)
2012-09-27 15:42:34 +00:00
2012-09-30 10:10:25 +00:00
if options.runtime && empty(s:runtime_dir)
\ || !options.runtime && empty(s:snippets_dir)
return
endif
2012-09-27 15:42:34 +00:00
2012-09-30 10:10:25 +00:00
" Edit snippet file.
2012-10-04 03:35:07 +00:00
let snippet_dir = (options.runtime ? s:runtime_dir[0] : s:snippets_dir[-1])
let filename = snippet_dir .'/'.filetype
if isdirectory(filename)
" Edit in snippet directory.
let filename .= '/'.filetype
endif
if filename !~ '\.snip*$'
let filename .= '.snip'
endif
2012-09-30 10:10:25 +00:00
if options.split
" Split window.
execute options.direction
2012-10-27 03:20:00 +00:00
\ (options.vertical ? 'vsplit' : 'split')
2012-09-27 15:42:34 +00:00
endif
2012-10-06 11:18:15 +00:00
try
edit `=filename`
catch /^Vim\%((\a\+)\)\=:E749/
endtry
2012-09-27 15:42:34 +00:00
endfunction"}}}
2012-09-30 10:10:25 +00:00
function! s:initialize_options(options)"{{{
let default_options = {
\ 'runtime' : 0,
\ 'vertical' : 0,
\ 'direction' : 'below',
2012-09-30 10:10:25 +00:00
\ 'split' : 0,
\ }
let options = extend(default_options, a:options)
" Complex initializer.
if has_key(options, 'horizontal')
" Disable vertically.
2012-10-04 06:37:13 +00:00
let options.vertical = 0
2012-09-30 10:10:25 +00:00
endif
return options
endfunction"}}}
function! neosnippet#make_cache(filetype)"{{{
2012-09-27 15:42:34 +00:00
let filetype = a:filetype == '' ?
\ &filetype : a:filetype
2012-09-30 08:45:41 +00:00
if filetype ==# ''
let filetype = 'nothing'
endif
2012-09-27 15:42:34 +00:00
2012-10-19 09:31:55 +00:00
if has_key(s:snippets, filetype)
return
endif
let snippets_dir = neosnippet#get_snippets_directory()
2012-09-27 15:42:34 +00:00
let snippet = {}
let snippets_files =
\ split(globpath(join(snippets_dir, ','),
2012-09-27 15:42:34 +00:00
\ filetype . '.snip*'), '\n')
\ + split(globpath(join(snippets_dir, ','),
2012-09-27 15:42:34 +00:00
\ filetype . '_*.snip*'), '\n')
\ + split(globpath(join(snippets_dir, ','),
2012-10-19 07:07:15 +00:00
\ filetype . '/**/*.snip*'), '\n')
for snippets_file in reverse(snippets_files)
2012-10-29 02:22:37 +00:00
call s:parse_snippets_file(snippet, snippets_file)
2012-09-27 15:42:34 +00:00
endfor
let s:snippets[filetype] = snippet
endfunction"}}}
2012-10-29 02:22:37 +00:00
function! s:parse_snippets_file(snippets, snippets_file)"{{{
2012-09-27 15:42:34 +00:00
let dup_check = {}
2012-10-29 02:22:37 +00:00
let snippet_dict = {}
2012-09-27 15:42:34 +00:00
let linenr = 1
for line in readfile(a:snippets_file)
if line =~ '^\h\w*.*\s$'
" Delete spaces.
let line = substitute(line, '\s\+$', '', '')
endif
if line =~ '^include'
" Include snippets.
let snippet_file = matchstr(line, '^include\s\+\zs.*$')
for snippets_file in split(globpath(join(
\ neosnippet#get_snippets_directory(), ','),
2012-09-27 15:42:34 +00:00
\ snippet_file), '\n')
2012-10-29 02:22:37 +00:00
call s:parse_snippets_file(a:snippets, snippets_file)
2012-09-27 15:42:34 +00:00
endfor
elseif line =~ '^delete\s'
let name = matchstr(line, '^delete\s\+\zs.*$')
2012-10-29 02:22:37 +00:00
if name != '' && has_key(a:snippets, name)
call filter(a:snippets, 'v:val.real_name !=# name')
2012-09-27 15:42:34 +00:00
endif
elseif line =~ '^snippet\s'
2012-10-29 02:22:37 +00:00
if !empty(snippet_dict)
2012-09-27 15:42:34 +00:00
" Set previous snippet.
2012-10-29 02:22:37 +00:00
call s:set_snippet_dict(snippet_dict,
\ a:snippets, dup_check, a:snippets_file)
2012-09-27 15:42:34 +00:00
endif
2012-10-29 02:22:37 +00:00
" Initialize snippet dict.
let snippet_dict = { 'word' : '', 'linenr' : linenr,
\ 'options' : s:initialize_snippet_options() }
2012-10-29 02:22:37 +00:00
2012-10-28 05:25:52 +00:00
" Try using the name without the description (abbr).
2012-10-29 02:22:37 +00:00
let snippet_dict.name = matchstr(line, '^snippet\s\+\zs\S\+')
2012-10-28 05:25:52 +00:00
" Fall back to using the name and description (abbr) combined.
" SnipMate snippets may have duplicate names, but different
" descriptions (abbrs).
2012-11-01 02:29:37 +00:00
let description = matchstr(line, '^snippet\s\+\zs.*$')
if description !=# snippet_dict.name
" Convert description.
let snippet_dict.name =
\ substitute(description, '\W\+', '_', 'g')
2012-10-28 05:25:52 +00:00
endif
" Collect the description (abbr) of the snippet, if set on snippet line.
" This is for compatibility with SnipMate-style snippets.
2012-10-29 02:22:37 +00:00
let snippet_dict.abbr = matchstr(line, '^snippet\s\+\S\+\s\+\zs.*$')
2012-09-27 15:42:34 +00:00
" Check for duplicated names.
2012-10-29 02:22:37 +00:00
if has_key(dup_check, snippet_dict.name)
let dup = dup_check[snippet_dict.name]
call neosnippet#util#print_error(printf(
\ 'Warning: %s:%d is overriding `%s` from %s:%d',
\ a:snippets_file, linenr, snippet_dict.name,
\ dup.action__path, dup.action__line))
call neosnippet#util#print_error(printf(
\ 'Please rename the snippet name or use `delete %s`.',
\ snippet_dict.name))
2012-09-27 15:42:34 +00:00
endif
2012-10-29 02:22:37 +00:00
elseif !empty(snippet_dict)
" Allow overriding/setting of the description (abbr) of the snippet.
" This will override what was set via the snippet line.
2012-09-27 15:42:34 +00:00
if line =~ '^abbr\s'
2012-10-29 02:22:37 +00:00
let snippet_dict.abbr = matchstr(line, '^abbr\s\+\zs.*$')
2012-09-27 15:42:34 +00:00
elseif line =~ '^alias\s'
2012-10-29 02:22:37 +00:00
let snippet_dict.alias = split(matchstr(line,
2012-09-27 15:42:34 +00:00
\ '^alias\s\+\zs.*$'), '[,[:space:]]\+')
elseif line =~ '^prev_word\s'
2012-10-04 09:49:16 +00:00
let prev_word = matchstr(line,
2012-09-27 15:42:34 +00:00
\ '^prev_word\s\+[''"]\zs.*\ze[''"]$')
2012-10-04 09:49:16 +00:00
if prev_word == '^'
" For backward compatibility.
2012-10-29 02:22:37 +00:00
let snippet_dict.options.head = 1
2012-10-21 08:51:07 +00:00
else
call neosnippet#util#print_error(
\ 'prev_word must be "^" character.')
2012-10-04 09:49:16 +00:00
endif
2012-10-21 08:51:07 +00:00
elseif line =~ '^options\s\+'
for option in split(matchstr(line,
\ '^options\s\+\zs.*$'), '[,[:space:]]\+')
2012-10-29 02:22:37 +00:00
if !has_key(snippet_dict.options, option)
2012-10-21 08:51:07 +00:00
call neosnippet#util#print_error(
2012-10-21 12:07:57 +00:00
\ printf('invalid option name : %s is detected.', option))
2012-10-21 08:51:07 +00:00
else
2012-10-29 02:22:37 +00:00
let snippet_dict.options[option] = 1
2012-10-21 08:51:07 +00:00
endif
endfor
2012-09-27 15:42:34 +00:00
elseif line =~ '^\s'
2012-10-29 02:22:37 +00:00
if snippet_dict.word != ''
let snippet_dict.word .= "\n"
2012-09-27 15:42:34 +00:00
else
" Substitute Tab character.
let line = substitute(line, '^\t', '', '')
endif
2012-10-29 02:22:37 +00:00
let snippet_dict.word .=
2012-09-27 15:42:34 +00:00
\ matchstr(line, '^ *\zs.*$')
elseif line =~ '^$'
" Blank line.
2012-10-29 02:22:37 +00:00
let snippet_dict.word .= "\n"
2012-09-27 15:42:34 +00:00
endif
endif
let linenr += 1
endfor
2012-10-29 02:22:37 +00:00
if !empty(snippet_dict)
" Set previous snippet.
call s:set_snippet_dict(snippet_dict,
\ a:snippets, dup_check, a:snippets_file)
endif
2012-09-27 15:42:34 +00:00
2012-10-29 02:22:37 +00:00
return a:snippets
2012-09-27 15:42:34 +00:00
endfunction"}}}
2012-10-04 09:49:16 +00:00
function! s:is_beginning_of_line(cur_text)"{{{
let keyword_pattern = '\S\+'
2012-10-04 09:49:16 +00:00
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)
2012-09-27 15:42:34 +00:00
2012-10-04 09:49:16 +00:00
return prev_word_end <= 0
2012-09-27 15:42:34 +00:00
endfunction"}}}
function! s:get_cursor_snippet(snippets, cur_text)"{{{
2012-10-21 11:48:02 +00:00
let cur_word = matchstr(a:cur_text, '\S\+$')
if cur_word != '' && has_key(a:snippets, cur_word)
return cur_word
2012-10-21 09:03:10 +00:00
endif
2012-10-21 11:48:02 +00:00
while cur_word != ''
if has_key(a:snippets, cur_word) &&
\ a:snippets[cur_word].options.word
return cur_word
endif
let cur_word = substitute(cur_word, '^\%(\w\+\|\W\)', '', '')
endwhile
2012-09-27 15:42:34 +00:00
2012-10-21 11:48:02 +00:00
return cur_word
2012-09-27 15:42:34 +00:00
endfunction"}}}
2012-10-30 09:54:07 +00:00
2012-10-04 01:22:35 +00:00
function! s:snippets_expand(cur_text, col)"{{{
2012-09-27 15:42:34 +00:00
let cur_word = s:get_cursor_snippet(
\ neosnippet#get_snippets(),
\ a:cur_text)
call neosnippet#expand(
\ a:cur_text, a:col, cur_word)
endfunction"}}}
2012-10-29 23:03:53 +00:00
function! neosnippet#jump(cur_text, col)"{{{
2012-10-04 01:22:35 +00:00
" Get patterns and count.
if empty(s:snippets_expand_stack)
return s:search_outof_range(a:col)
endif
let expand_info = s:snippets_expand_stack[-1]
" Search patterns.
let [begin, end] = s:get_snippet_range(
\ expand_info.begin_line,
\ expand_info.begin_patterns,
\ expand_info.end_line,
\ expand_info.end_patterns)
if s:search_snippet_range(begin, end, expand_info.holder_cnt)
" Next count.
let expand_info.holder_cnt += 1
return 1
endif
" Search placeholder 0.
if s:search_snippet_range(begin, end, 0)
return 1
endif
" Not found.
let s:snippets_expand_stack = s:snippets_expand_stack[: -2]
return s:search_outof_range(a:col)
endfunction"}}}
2012-09-27 15:42:34 +00:00
function! s:snippets_expand_or_jump(cur_text, col)"{{{
let cur_word = s:get_cursor_snippet(
2012-10-04 05:28:37 +00:00
\ neosnippet#get_snippets(), a:cur_text)
2012-09-27 15:42:34 +00:00
if cur_word != ''
" Found snippet trigger.
call neosnippet#expand(
\ a:cur_text, a:col, cur_word)
else
2012-10-29 23:03:53 +00:00
call neosnippet#jump(a:cur_text, a:col)
2012-09-27 15:42:34 +00:00
endif
endfunction"}}}
function! s:snippets_jump_or_expand(cur_text, col)"{{{
let cur_word = s:get_cursor_snippet(
2012-09-27 15:42:34 +00:00
\ neosnippet#get_snippets(), a:cur_text)
if search(s:get_placeholder_marker_pattern(). '\|'
\ .s:get_sync_placeholder_marker_pattern(), 'nw') > 0
" Found snippet placeholder.
2012-10-29 23:03:53 +00:00
call neosnippet#jump(a:cur_text, a:col)
2012-09-27 15:42:34 +00:00
else
call neosnippet#expand(
\ a:cur_text, a:col, cur_word)
endif
endfunction"}}}
function! neosnippet#expand(cur_text, col, trigger_name)"{{{
2012-10-29 22:38:37 +00:00
let snippets = neosnippet#get_snippets()
if a:trigger_name == '' || !has_key(snippets, a:trigger_name)
2012-09-27 15:42:34 +00:00
let pos = getpos('.')
let pos[2] = len(a:cur_text)+1
call setpos('.', pos)
if pos[2] < col('$')
startinsert
else
startinsert!
endif
return
endif
let snippet = snippets[a:trigger_name]
let cur_text = a:cur_text[: -1-len(a:trigger_name)]
let snip_word = snippet.snip
if snip_word =~ '\\\@<!`.*\\\@<!`'
let snip_word = s:eval_snippet(snip_word)
endif
" Substitute escaped `.
let snip_word = substitute(snip_word, '\\`', '`', 'g')
" Substitute markers.
let snip_word = substitute(snip_word,
\ s:get_placeholder_marker_substitute_pattern(),
\ '<`\1`>', 'g')
let snip_word = substitute(snip_word,
\ s:get_mirror_placeholder_marker_substitute_pattern(),
\ '<|\1|>', 'g')
" Insert snippets.
let next_line = getline('.')[a:col-1 :]
let snippet_lines = split(snip_word, '\n', 1)
if empty(snippet_lines)
return
endif
let begin_line = line('.')
let end_line = line('.') + len(snippet_lines) - 1
let snippet_lines[0] = cur_text . snippet_lines[0]
let next_col = len(snippet_lines[-1]) + 1
let snippet_lines[-1] = snippet_lines[-1] . next_line
if has('folding')
let foldmethod = &l:foldmethod
let &l:foldmethod = 'manual'
endif
2012-10-28 09:58:55 +00:00
try
call setline('.', snippet_lines[0])
if len(snippet_lines) > 1
call append('.', snippet_lines[1:])
endif
2012-09-27 15:42:34 +00:00
2012-10-31 02:10:56 +00:00
if begin_line != end_line || snippet.options.indent
call s:indent_snippet(begin_line, end_line)
endif
2012-10-28 09:58:55 +00:00
let begin_patterns = (begin_line > 1) ?
\ [getline(begin_line - 1)] : []
let end_patterns = (end_line < line('$')) ?
\ [getline(end_line + 1)] : []
call add(s:snippets_expand_stack, {
\ 'begin_line' : begin_line,
\ 'begin_patterns' : begin_patterns,
\ 'end_line' : end_line,
\ 'end_patterns' : end_patterns,
\ 'holder_cnt' : 1,
\ })
if snip_word =~ s:get_placeholder_marker_pattern()
2012-10-29 23:03:53 +00:00
call neosnippet#jump(a:cur_text, a:col)
2012-10-28 09:58:55 +00:00
endif
finally
if has('folding')
let &l:foldmethod = foldmethod
silent! execute begin_line . ',' . end_line . 'foldopen!'
endif
endtry
2012-09-27 15:42:34 +00:00
let &l:iminsert = 0
let &l:imsearch = 0
endfunction"}}}
2012-10-29 22:38:37 +00:00
function! neosnippet#expand_target()"{{{
let trigger = input('Please input snippet trigger: ',
2012-10-29 23:03:53 +00:00
\ '', 'customlist,neosnippet#complete_target_snippets')
2012-10-29 22:38:37 +00:00
let neosnippet = neosnippet#get_current_neosnippet()
2012-10-29 23:03:53 +00:00
if !has_key(neosnippet#get_snippets(), trigger) ||
\ neosnippet#get_snippets()[trigger].snip !~#
\ neosnippet#get_placeholder_target_marker_pattern()
if trigger != ''
echo 'The trigger is invalid.'
endif
2012-10-29 22:38:37 +00:00
let neosnippet.target = ''
return
endif
let neosnippet.target = substitute(
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
let base_indent = matchstr(neosnippet.target, '^\s*')
" Delete base_indent.
let neosnippet.target = substitute(neosnippet.target,
\'^' . base_indent, '', 'g')
call neosnippet#substitute_selected_text(visualmode(),
\ base_indent)
2012-10-29 22:38:37 +00:00
call neosnippet#expand(neosnippet#util#get_cur_text(),
\ col('.'), trigger)
2012-10-29 22:38:37 +00:00
endfunction"}}}
2012-09-27 15:42:34 +00:00
function! s:indent_snippet(begin, end)"{{{
if a:begin > a:end
return
endif
2012-09-27 15:42:34 +00:00
let equalprg = &l:equalprg
let pos = getpos('.')
2012-10-30 14:53:35 +00:00
let neosnippet = neosnippet#get_current_neosnippet()
2012-10-06 07:22:36 +00:00
try
setlocal equalprg=
2012-09-27 15:42:34 +00:00
2012-10-06 08:56:10 +00:00
" Check use of indent plugin.
2012-10-30 14:53:35 +00:00
if neosnippet.target == '' && getline(a:begin+1) !~ '^\t\+'
2012-10-06 08:56:10 +00:00
" Indent begin line.
call cursor(a:begin, 0)
silent normal! ==
endif
2012-09-27 15:42:34 +00:00
2012-10-06 07:22:36 +00:00
let base_indent = matchstr(getline(a:begin), '^\s\+')
for line_nr in range(a:begin+1, a:end)
call cursor(line_nr, 0)
if getline('.') =~ '^\t\+'
" Delete head tab character.
let current_line = substitute(getline('.'), '^\t', '', '')
if &l:expandtab && current_line =~ '^\t\+'
" Expand tab.
cal setline('.', substitute(current_line,
\ '^\t\+', base_indent . repeat(' ', &shiftwidth *
\ len(matchstr(current_line, '^\t\+'))), ''))
elseif line_nr != a:begin
call setline('.', base_indent . current_line)
endif
else
silent normal! ==
endif
endfor
finally
let &l:equalprg = equalprg
call setpos('.', pos)
endtry
2012-09-27 15:42:34 +00:00
endfunction"}}}
function! neosnippet#register_oneshot_snippet()"{{{
let trigger = input('Please input snippet trigger: ', 'oneshot')
if trigger == ''
return
endif
let selected_text = substitute(
\ neosnippet#get_selected_text(visualmode(), 1), '\n$', '', '')
call neosnippet#delete_selected_text(visualmode(), 1)
let base_indent = matchstr(selected_text, '^\s*')
" Delete base_indent.
let selected_text = substitute(selected_text,
\'^' . base_indent, '', 'g')
let neosnippet = neosnippet#get_current_neosnippet()
let options = s:initialize_snippet_options()
let options.word = 1
let neosnippet.snippets[trigger] = s:initialize_snippet(
\ { 'name' : trigger, 'word' : selected_text, 'options' : options },
\ '', 0, '', trigger)
echo 'Registered trigger : ' . trigger
endfunction"}}}
2012-09-27 15:42:34 +00:00
function! s:get_snippet_range(begin_line, begin_patterns, end_line, end_patterns)"{{{
let pos = getpos('.')
call cursor(a:begin_line, 0)
if empty(a:begin_patterns)
let begin = line('.') - 50
else
let [begin, _] = searchpos('^' . neosnippet#util#escape_pattern(
2012-09-27 15:42:34 +00:00
\ a:begin_patterns[0]) . '$', 'bnW')
if begin <= 0
let begin = line('.') - 50
endif
endif
if begin <= 0
let begin = 1
endif
call cursor(a:end_line, 0)
if empty(a:end_patterns)
let end = line('.') + 50
else
let [end, _] = searchpos('^' . neosnippet#util#escape_pattern(
2012-09-27 15:42:34 +00:00
\ a:end_patterns[0]) . '$', 'nW')
if end <= 0
let end = line('.') + 50
endif
endif
if end > line('$')
let end = line('$')
endif
call setpos('.', pos)
return [begin, end]
endfunction"}}}
function! s:search_snippet_range(start, end, cnt)"{{{
call s:substitute_placeholder_marker(a:start, a:end, a:cnt)
2012-11-01 02:18:58 +00:00
" Search marker pattern.
let pattern = substitute(s:get_placeholder_marker_pattern(),
\ '\\d\\+', a:cnt, '')
2012-09-27 15:42:34 +00:00
for line in filter(range(a:start, a:end),
\ 'getline(v:val) =~ pattern')
call s:expand_placeholder(a:start, a:end, a:cnt, line)
return 1
endfor
return 0
endfunction"}}}
function! s:search_outof_range(col)"{{{
call s:substitute_placeholder_marker(1, 0, 0)
let pattern = s:get_placeholder_marker_pattern()
if search(pattern, 'w') > 0
2012-10-06 08:16:56 +00:00
call s:expand_placeholder(line('.'), 0, '\\d\\+', line('.'))
2012-09-27 15:42:34 +00:00
return 1
endif
let pos = getpos('.')
if a:col == 1
let pos[2] = 1
call setpos('.', pos)
startinsert
2012-11-01 02:18:58 +00:00
elseif a:col >= col('$')
2012-09-27 15:42:34 +00:00
startinsert!
else
let pos[2] = a:col+1
call setpos('.', pos)
startinsert
endif
" Not found.
return 0
endfunction"}}}
function! s:expand_placeholder(start, end, holder_cnt, line)"{{{
let pattern = substitute(s:get_placeholder_marker_pattern(),
\ '\\d\\+', a:holder_cnt, '')
let current_line = getline(a:line)
let match = match(current_line, pattern)
2012-10-29 22:38:37 +00:00
let neosnippet = neosnippet#get_current_neosnippet()
2012-09-27 15:42:34 +00:00
let default_pattern = substitute(
\ s:get_placeholder_marker_default_pattern(),
\ '\\d\\+', a:holder_cnt, '')
let default = substitute(
2012-10-29 22:38:37 +00:00
\ matchstr(current_line, default_pattern),
\ '\\\ze[^\\]', '', 'g')
if default =~ '^TARGET\>' && neosnippet.target != ''
let default = ''
let is_target = 1
else
let is_target = 0
endif
2012-11-01 02:26:40 +00:00
let default = substitute(default, '^TARGET:\?', '', '')
2012-10-29 20:09:50 +00:00
let neosnippet.selected_text = default
2012-09-27 15:42:34 +00:00
" Substitute marker.
let default = substitute(default,
\ s:get_placeholder_marker_substitute_pattern(),
\ '<`\1`>', 'g')
let default = substitute(default,
\ s:get_mirror_placeholder_marker_substitute_pattern(),
\ '<|\1|>', 'g')
let default_len = len(default)
let pos = getpos('.')
let pos[1] = a:line
let pos[2] = match+1
let cnt = s:search_sync_placeholder(a:start, a:end, a:holder_cnt)
2012-11-01 02:18:58 +00:00
if cnt >= 0
2012-09-27 15:42:34 +00:00
let pattern = substitute(s:get_placeholder_marker_pattern(),
\ '\\d\\+', cnt, '')
call setline(a:line, substitute(current_line, pattern,
\ '<{'.cnt.':'.escape(default, '\').'}>', ''))
let pos[2] += len('<{'.cnt.':')
else
" Substitute holder.
call setline(a:line,
\ substitute(current_line, pattern, escape(default, '\'), ''))
endif
call setpos('.', pos)
2012-10-29 22:38:37 +00:00
if is_target
" Expand target
return s:expand_target_placeholder(a:line, match+1)
endif
2012-09-27 15:42:34 +00:00
if default_len > 0
" Select default value.
let len = default_len-1
if &l:selection == 'exclusive'
let len += 1
endif
stopinsert
execute 'normal! v'. repeat('l', len) . "\<C-g>"
elseif pos[2] < col('$')
startinsert
else
startinsert!
endif
endfunction"}}}
2012-10-29 22:38:37 +00:00
function! s:expand_target_placeholder(line, col)"{{{
" Expand target
let neosnippet = neosnippet#get_current_neosnippet()
let next_line = getline(a:line)[a:col-1 :]
let target_lines = split(neosnippet.target, '\n', 1)
let cur_text = getline(a:line)[: a:col-2]
let target_lines[0] = cur_text . target_lines[0]
let next_col = len(target_lines[-1]) + 1
let target_lines[-1] = target_lines[-1] . next_line
let begin_line = a:line
let end_line = a:line + len(target_lines) - 1
if has('folding')
let foldmethod = &l:foldmethod
let &l:foldmethod = 'manual'
endif
try
let base_indent = matchstr(cur_text, '^\s\+')
2012-10-29 22:38:37 +00:00
call setline(a:line, target_lines[0])
if len(target_lines) > 1
call append(a:line, map(target_lines[1:],
\ 'base_indent . v:val'))
2012-10-29 22:38:37 +00:00
endif
call cursor(end_line, 0)
if next_line != ''
startinsert
else
startinsert!
endif
finally
if has('folding')
let &l:foldmethod = foldmethod
silent! execute begin_line . ',' . end_line . 'foldopen!'
endif
endtry
let neosnippet.target = ''
2012-10-29 23:03:53 +00:00
call neosnippet#jump(neosnippet#util#get_cur_text(), col('.'))
2012-10-29 22:38:37 +00:00
endfunction"}}}
2012-09-27 15:42:34 +00:00
function! s:search_sync_placeholder(start, end, number)"{{{
if a:end == 0
" Search in current buffer.
let cnt = matchstr(getline('.'),
\ substitute(s:get_placeholder_marker_pattern(),
\ '\\d\\+', '\\zs\\d\\+\\ze', ''))
return search(substitute(
\ s:get_mirror_placeholder_marker_pattern(),
2012-11-01 02:26:40 +00:00
\ '\\d\\+', cnt, ''), 'nw') > 0 ? cnt : -1
2012-09-27 15:42:34 +00:00
endif
let pattern = substitute(
\ s:get_mirror_placeholder_marker_pattern(),
\ '\\d\\+', a:number, '')
for line in filter(range(a:start, a:end),
\ 'getline(v:val) =~ pattern')
return a:number
endfor
2012-11-01 02:26:40 +00:00
return -1
2012-09-27 15:42:34 +00:00
endfunction"}}}
function! s:substitute_placeholder_marker(start, end, snippet_holder_cnt)"{{{
2012-11-01 02:18:58 +00:00
if a:snippet_holder_cnt > 0
2012-09-27 15:42:34 +00:00
let cnt = a:snippet_holder_cnt-1
let sync_marker = substitute(s:get_sync_placeholder_marker_pattern(),
\ '\\d\\+', cnt, '')
let mirror_marker = substitute(
\ s:get_mirror_placeholder_marker_pattern(),
\ '\\d\\+', cnt, '')
let line = a:start
for line in range(a:start, a:end)
if getline(line) =~ sync_marker
let sub = escape(matchstr(getline(line),
\ substitute(s:get_sync_placeholder_marker_default_pattern(),
\ '\\d\\+', cnt, '')), '/\')
silent execute printf('%d,%ds/' . mirror_marker . '/%s/'
\ . (&gdefault ? '' : 'g'), a:start, a:end, sub)
call setline(line, substitute(getline(line), sync_marker, sub, ''))
endif
endfor
elseif search(s:get_sync_placeholder_marker_pattern(), 'wb') > 0
let sub = escape(matchstr(getline('.'),
\ s:get_sync_placeholder_marker_default_pattern()), '/\')
let cnt = matchstr(getline('.'),
\ substitute(s:get_sync_placeholder_marker_pattern(),
\ '\\d\\+', '\\zs\\d\\+\\ze', ''))
silent execute printf('%%s/' . mirror_marker . '/%s/'
\ . (&gdefault ? 'g' : ''), sub)
let sync_marker = substitute(s:get_sync_placeholder_marker_pattern(),
\ '\\d\\+', cnt, '')
let mirror_marker = substitute(
\ s:get_mirror_placeholder_marker_pattern(),
\ '\\d\\+', cnt, '')
call setline('.', substitute(getline('.'), sync_marker, sub, ''))
endif
endfunction"}}}
function! s:eval_snippet(snippet_text)"{{{
let snip_word = ''
let prev_match = 0
let match = match(a:snippet_text, '\\\@<!`.\{-}\\\@<!`')
while match >= 0
if match - prev_match > 0
let snip_word .= a:snippet_text[prev_match : match - 1]
endif
let prev_match = matchend(a:snippet_text,
\ '\\\@<!`.\{-}\\\@<!`', match)
2012-10-25 01:50:25 +00:00
let snip_word .= eval(
2012-10-19 09:38:52 +00:00
\ a:snippet_text[match+1 : prev_match - 2])
2012-09-27 15:42:34 +00:00
let match = match(a:snippet_text, '\\\@<!`.\{-}\\\@<!`', prev_match)
endwhile
if prev_match >= 0
let snip_word .= a:snippet_text[prev_match :]
endif
return snip_word
endfunction"}}}
2012-10-29 10:27:18 +00:00
function! neosnippet#get_current_neosnippet()"{{{
if !exists('b:neosnippet')
let b:neosnippet = {
\ 'snippets' : {},
2012-10-29 10:27:18 +00:00
\ 'selected_text' : '',
2012-10-29 22:38:37 +00:00
\ 'target' : '',
2012-10-29 10:27:18 +00:00
\}
endif
return b:neosnippet
endfunction"}}}
2012-09-27 15:42:34 +00:00
function! neosnippet#get_snippets()"{{{
let neosnippet = neosnippet#get_current_neosnippet()
let snippets = copy(neosnippet.snippets)
2012-10-19 09:31:55 +00:00
for filetype in s:get_sources_filetypes(neosnippet#get_filetype())
call neosnippet#make_cache(filetype)
call extend(snippets, s:snippets[filetype], 'keep')
2012-09-27 15:42:34 +00:00
endfor
if mode() ==# 'i' &&
\ !s:is_beginning_of_line(neosnippet#util#get_cur_text())
2012-10-21 08:51:07 +00:00
call filter(snippets, '!v:val.options.head')
2012-10-04 09:49:16 +00:00
endif
2012-10-04 01:22:35 +00:00
2012-10-04 09:49:16 +00:00
return snippets
2012-09-27 15:42:34 +00:00
endfunction"}}}
2012-09-30 09:13:49 +00:00
function! neosnippet#get_snippets_directory()"{{{
let snippets_dir = copy(s:snippets_dir)
if !get(g:neosnippet#disable_runtime_snippets,
\ neosnippet#get_filetype(),
\ get(g:neosnippet#disable_runtime_snippets, '_', 0))
let snippets_dir += s:runtime_dir
endif
return snippets_dir
2012-09-27 15:42:34 +00:00
endfunction"}}}
2012-09-30 08:33:50 +00:00
function! neosnippet#get_filetype()"{{{
return exists('*neocomplcache#get_context_filetype') ?
\ neocomplcache#get_context_filetype(1) : &filetype
endfunction"}}}
2012-10-19 09:31:55 +00:00
function! s:get_sources_filetypes(filetype)"{{{
return (exists('*neocomplcache#get_source_filetypes') ?
\ neocomplcache#get_source_filetypes(a:filetype) :
\ [a:filetype]) + ['_']
2012-09-30 08:45:41 +00:00
endfunction"}}}
2012-09-30 10:10:25 +00:00
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"}}}
2012-09-30 08:45:41 +00:00
" 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"}}}
2012-10-29 23:03:53 +00:00
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')
2012-10-29 22:38:37 +00:00
endfunction"}}}
2012-09-27 15:42:34 +00:00
function! neosnippet#get_placeholder_target_marker_pattern()"{{{
2012-10-29 23:03:53 +00:00
return '\${\d\+:TARGET\%(:.\{-}\)\?\\\@<!}'
endfunction"}}}
2012-09-27 15:42:34 +00:00
function! s:get_placeholder_marker_pattern()"{{{
return '<`\d\+\%(:.\{-}\)\?\\\@<!`>'
endfunction"}}}
function! s:get_placeholder_marker_substitute_pattern()"{{{
return '\${\(\d\+\%(:.\{-}\)\?\\\@<!\)}'
endfunction"}}}
function! s:get_placeholder_marker_default_pattern()"{{{
return '<`\d\+:\zs.\{-}\ze\\\@<!`>'
endfunction"}}}
function! s:get_sync_placeholder_marker_pattern()"{{{
return '<{\d\+\%(:.\{-}\)\?\\\@<!}>'
endfunction"}}}
function! s:get_sync_placeholder_marker_default_pattern()"{{{
return '<{\d\+:\zs.\{-}\ze\\\@<!}>'
endfunction"}}}
function! s:get_mirror_placeholder_marker_pattern()"{{{
return '<|\d\+|>'
endfunction"}}}
function! s:get_mirror_placeholder_marker_substitute_pattern()"{{{
return '\$\(\d\+\)'
endfunction"}}}
function! s:SID_PREFIX()"{{{
return matchstr(expand('<sfile>'), '<SNR>\d\+_')
endfunction"}}}
function! s:trigger(function)"{{{
2012-09-30 08:34:34 +00:00
let cur_text = neosnippet#util#get_cur_text()
2012-09-27 15:42:34 +00:00
let col = col('.')
2012-10-29 10:27:18 +00:00
let expr = ''
2012-09-27 15:42:34 +00:00
if mode() !=# 'i'
" Fix column.
let col += 2
endif
2012-10-29 10:27:18 +00:00
" Get selected text.
let neosnippet = neosnippet#get_current_neosnippet()
if mode() ==# 's' && neosnippet.selected_text =~ '^#:'
let expr .= "a\<BS>"
endif
let expr .= printf("\<ESC>:call %s(%s,%d)\<CR>",
2012-09-27 15:42:34 +00:00
\ a:function, string(cur_text), col)
2012-10-29 10:27:18 +00:00
return expr
2012-09-27 15:42:34 +00:00
endfunction"}}}
2012-10-29 22:38:37 +00:00
function! neosnippet#get_selected_text(type, ...)"{{{
2012-10-29 10:27:18 +00:00
let sel_save = &selection
let &selection = 'inclusive'
let reg_save = @@
2012-10-29 20:09:50 +00:00
let pos = getpos('.')
2012-10-29 10:27:18 +00:00
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
2012-10-29 22:38:37 +00:00
return @@
2012-10-29 10:27:18 +00:00
finally
let &selection = sel_save
let @@ = reg_save
2012-10-29 20:09:50 +00:00
call setpos('.', pos)
2012-10-29 10:27:18 +00:00
endtry
2012-10-29 22:38:37 +00:00
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 == 'line'
silent exe "normal! '[V']d"
elseif a:type == 'block'
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.
silent exe "normal! `<" . a:type . "`>s" . a:text
finally
let &selection = sel_save
let @@ = reg_save
call setpos('.', pos)
endtry
endfunction"}}}
2012-10-29 10:27:18 +00:00
2012-10-29 03:28:33 +00:00
function! neosnippet#clear_select_mode_mappings()"{{{
if !g:neosnippet#disable_select_mode_mappings
return
endif
redir => mappings
silent! smap
redir END
for line in map(filter(split(mappings, '\n'),
2012-10-27 09:06:46 +00:00
\ "v:val !~# 'neosnippet\\|neocomplcache_snippets'"),
\ "substitute(v:val, '<NL>', '<C-J>', 'g')")
let map = matchstr(line, '^\a*\s*\zs\S\+')
let map = substitute(map, '<NL>', '<C-j>', 'g')
silent! execute 'sunmap' map
silent! execute 'sunmap <buffer>' map
endfor
2012-10-29 03:28:33 +00:00
" Define default select mode mappings.
snoremap <CR> a<BS>
snoremap <BS> a<BS>
snoremap <Del> a<BS>
snoremap <C-h> a<BS>
snoremap <right> <ESC>a
snoremap <left> <ESC>bi
endfunction"}}}
2012-09-27 15:42:34 +00:00
" Plugin key-mappings.
function! neosnippet#expand_or_jump_impl()
return s:trigger(s:SID_PREFIX().'snippets_expand_or_jump')
endfunction
function! neosnippet#jump_or_expand_impl()
return s:trigger(s:SID_PREFIX().'snippets_jump_or_expand')
endfunction
function! neosnippet#expand_impl()
2012-10-04 01:22:35 +00:00
return s:trigger(s:SID_PREFIX().'snippets_expand')
2012-09-27 15:42:34 +00:00
endfunction
function! neosnippet#jump_impl()
2012-10-30 09:54:07 +00:00
return s:trigger('neosnippet#jump')
2012-09-27 15:42:34 +00:00
endfunction
if !exists('s:snippets')
let s:snippets = {}
call s:initialize()
endif
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker