Add helpers file
This commit is contained in:
parent
3e60de00a3
commit
3d4487111e
@ -56,23 +56,6 @@ function! s:is_beginning_of_line(cur_text) "{{{
|
|||||||
|
|
||||||
return prev_word_end <= 0
|
return prev_word_end <= 0
|
||||||
endfunction"}}}
|
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) "{{{
|
function! neosnippet#jump(cur_text, col) "{{{
|
||||||
call s:skip_next_auto_completion()
|
call s:skip_next_auto_completion()
|
||||||
|
51
autoload/neosnippet/helpers.vim
Normal file
51
autoload/neosnippet/helpers.vim
Normal 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
|
@ -188,7 +188,7 @@ function! s:doc_dict.search(cur_text) "{{{
|
|||||||
|
|
||||||
let snippets = neosnippet#get_snippets()
|
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 == ''
|
if cur_word == ''
|
||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
|
@ -32,7 +32,7 @@ function! neosnippet#mappings#expandable_or_jumpable() "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#mappings#expandable() "{{{
|
function! neosnippet#mappings#expandable() "{{{
|
||||||
" Check snippet trigger.
|
" Check snippet trigger.
|
||||||
return neosnippet#get_cursor_snippet(
|
return neosnippet#helpers#get_cursor_snippet(
|
||||||
\ neosnippet#get_snippets(), neosnippet#util#get_cur_text()) != ''
|
\ neosnippet#get_snippets(), neosnippet#util#get_cur_text()) != ''
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! neosnippet#mappings#jumpable() "{{{
|
function! neosnippet#mappings#jumpable() "{{{
|
||||||
@ -41,24 +41,6 @@ function! neosnippet#mappings#jumpable() "{{{
|
|||||||
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0
|
\ .neosnippet#get_sync_placeholder_marker_pattern(), 'nw') > 0
|
||||||
endfunction"}}}
|
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() "{{{
|
function! neosnippet#mappings#_clear_select_mode_mappings() "{{{
|
||||||
if !g:neosnippet#disable_select_mode_mappings
|
if !g:neosnippet#disable_select_mode_mappings
|
||||||
return
|
return
|
||||||
@ -113,7 +95,7 @@ function! neosnippet#mappings#_register_oneshot_snippet() "{{{
|
|||||||
endfunction"}}}
|
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#helpers#get_cursor_snippet(
|
||||||
\ neosnippet#get_snippets(),
|
\ neosnippet#get_snippets(),
|
||||||
\ a:cur_text)
|
\ a:cur_text)
|
||||||
|
|
||||||
@ -122,7 +104,7 @@ function! s:snippets_expand(cur_text, col) "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:snippets_expand_or_jump(cur_text, col) "{{{
|
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)
|
\ neosnippet#get_snippets(), a:cur_text)
|
||||||
|
|
||||||
if cur_word != ''
|
if cur_word != ''
|
||||||
@ -135,7 +117,7 @@ function! s:snippets_expand_or_jump(cur_text, col) "{{{
|
|||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:snippets_jump_or_expand(cur_text, col) "{{{
|
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)
|
\ neosnippet#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
|
||||||
|
Loading…
Reference in New Issue
Block a user