Move register_oneshot_snippet function

This commit is contained in:
Shougo Matsushita 2013-11-21 18:14:07 +09:00
parent 038d75ce58
commit 7b1f900912
3 changed files with 29 additions and 29 deletions

View File

@ -284,33 +284,6 @@ function! s:indent_snippet(begin, end) "{{{
endtry endtry
endfunction"}}} 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 = neosnippet#parser#_initialize_snippet_options()
let options.word = 1
let neosnippet.snippets[trigger] = neosnippet#parser#_initialize_snippet(
\ { 'name' : trigger, 'word' : selected_text, 'options' : options },
\ '', 0, '', trigger)
echo 'Registered trigger : ' . trigger
endfunction"}}}
function! neosnippet#_get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) "{{{ function! neosnippet#_get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) "{{{
let pos = getpos('.') let pos = getpos('.')

View File

@ -85,6 +85,33 @@ function! neosnippet#mappings#_clear_select_mode_mappings() "{{{
snoremap <C-h> a<BS> snoremap <C-h> a<BS>
endfunction"}}} endfunction"}}}
function! neosnippet#mappings#_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 = neosnippet#parser#_initialize_snippet_options()
let options.word = 1
let neosnippet.snippets[trigger] = neosnippet#parser#_initialize_snippet(
\ { 'name' : trigger, 'word' : selected_text, 'options' : options },
\ '', 0, '', trigger)
echo 'Registered trigger : ' . trigger
endfunction"}}}
function! s:snippets_expand(cur_text, col) "{{{ function! s:snippets_expand(cur_text, col) "{{{
let cur_word = neosnippet#get_cursor_snippet( let cur_word = neosnippet#get_cursor_snippet(
\ neosnippet#get_snippets(), \ neosnippet#get_snippets(),

View File

@ -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: 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
@ -63,7 +63,7 @@ xnoremap <silent> <Plug>(neosnippet_expand_target)
xnoremap <silent><expr> <Plug>(neosnippet_start_unite_snippet_target) xnoremap <silent><expr> <Plug>(neosnippet_start_unite_snippet_target)
\ unite#sources#snippet_target#start() \ unite#sources#snippet_target#start()
xnoremap <silent> <Plug>(neosnippet_register_oneshot_snippet) xnoremap <silent> <Plug>(neosnippet_register_oneshot_snippet)
\ :<C-u>call neosnippet#register_oneshot_snippet()<CR> \ :<C-u>call neosnippet#mappings#_register_oneshot_snippet()<CR>
inoremap <expr><silent> <Plug>(neosnippet_start_unite_snippet) inoremap <expr><silent> <Plug>(neosnippet_start_unite_snippet)
\ unite#sources#snippet#start_complete() \ unite#sources#snippet#start_complete()