From 3d4487111eabd1258241183bfa88b7bfebb9144c Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Thu, 21 Nov 2013 18:25:37 +0900 Subject: [PATCH] Add helpers file --- autoload/neosnippet.vim | 17 ----------- autoload/neosnippet/helpers.vim | 51 ++++++++++++++++++++++++++++++++ autoload/neosnippet/init.vim | 2 +- autoload/neosnippet/mappings.vim | 26 +++------------- 4 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 autoload/neosnippet/helpers.vim diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index e852a61..78ee10f 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -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() diff --git a/autoload/neosnippet/helpers.vim b/autoload/neosnippet/helpers.vim new file mode 100644 index 0000000..fdff32a --- /dev/null +++ b/autoload/neosnippet/helpers.vim @@ -0,0 +1,51 @@ +"============================================================================= +" FILE: helpers.vim +" AUTHOR: Shougo Matsushita +" 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 diff --git a/autoload/neosnippet/init.vim b/autoload/neosnippet/init.vim index bdde10c..d294cbc 100644 --- a/autoload/neosnippet/init.vim +++ b/autoload/neosnippet/init.vim @@ -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 diff --git a/autoload/neosnippet/mappings.vim b/autoload/neosnippet/mappings.vim index 670d0d3..ce02224 100644 --- a/autoload/neosnippet/mappings.vim +++ b/autoload/neosnippet/mappings.vim @@ -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