Add helpers file

This commit is contained in:
Shougo Matsushita 2013-11-21 18:25:37 +09:00
parent 3e60de00a3
commit 3d4487111e
4 changed files with 56 additions and 40 deletions

View File

@ -56,23 +56,6 @@ function! s:is_beginning_of_line(cur_text) "{{{
return prev_word_end <= 0
endfunction"}}}
function! neosnippet#get_cursor_snippet(snippets, cur_text) "{{{
let cur_word = matchstr(a:cur_text, '\S\+$')
if cur_word != '' && has_key(a:snippets, cur_word)
return cur_word
endif
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
return cur_word
endfunction"}}}
function! neosnippet#jump(cur_text, col) "{{{
call s:skip_next_auto_completion()

View File

@ -0,0 +1,51 @@
"=============================================================================
" FILE: helpers.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 21 Nov 2013.
" 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
function! neosnippet#helpers#get_cursor_snippet(snippets, cur_text) "{{{
let cur_word = matchstr(a:cur_text, '\S\+$')
if cur_word != '' && has_key(a:snippets, cur_word)
return cur_word
endif
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
return cur_word
endfunction"}}}
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: foldmethod=marker

View File

@ -188,7 +188,7 @@ function! s:doc_dict.search(cur_text) "{{{
let snippets = neosnippet#get_snippets()
let cur_word = neosnippet#get_cursor_snippet(snippets, a:cur_text)
let cur_word = neosnippet#helpers#get_cursor_snippet(snippets, a:cur_text)
if cur_word == ''
return []
endif

View File

@ -32,7 +32,7 @@ function! neosnippet#mappings#expandable_or_jumpable() "{{{
endfunction"}}}
function! neosnippet#mappings#expandable() "{{{
" Check snippet trigger.
return neosnippet#get_cursor_snippet(
return neosnippet#helpers#get_cursor_snippet(
\ neosnippet#get_snippets(), neosnippet#util#get_cur_text()) != ''
endfunction"}}}
function! neosnippet#mappings#jumpable() "{{{
@ -41,24 +41,6 @@ function! neosnippet#mappings#jumpable() "{{{
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0
endfunction"}}}
function! neosnippet#mappings#_get_cursor_snippet(snippets, cur_text) "{{{
let cur_word = matchstr(a:cur_text, '\S\+$')
if cur_word != '' && has_key(a:snippets, cur_word)
return cur_word
endif
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
return cur_word
endfunction"}}}
function! neosnippet#mappings#_clear_select_mode_mappings() "{{{
if !g:neosnippet#disable_select_mode_mappings
return
@ -113,7 +95,7 @@ function! neosnippet#mappings#_register_oneshot_snippet() "{{{
endfunction"}}}
function! s:snippets_expand(cur_text, col) "{{{
let cur_word = neosnippet#get_cursor_snippet(
let cur_word = neosnippet#helpers#get_cursor_snippet(
\ neosnippet#get_snippets(),
\ a:cur_text)
@ -122,7 +104,7 @@ function! s:snippets_expand(cur_text, col) "{{{
endfunction"}}}
function! s:snippets_expand_or_jump(cur_text, col) "{{{
let cur_word = neosnippet#get_cursor_snippet(
let cur_word = neosnippet#helpers#get_cursor_snippet(
\ neosnippet#get_snippets(), a:cur_text)
if cur_word != ''
@ -135,7 +117,7 @@ function! s:snippets_expand_or_jump(cur_text, col) "{{{
endfunction"}}}
function! s:snippets_jump_or_expand(cur_text, col) "{{{
let cur_word = neosnippet#get_cursor_snippet(
let cur_word = neosnippet#helpers#get_cursor_snippet(
\ neosnippet#get_snippets(), a:cur_text)
if search(neosnippet#get_placeholder_marker_pattern(). '\|'
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0