- Deleted s:get_cursor_keyword_snippet().

This commit is contained in:
Shougo Matsushita 2012-09-30 17:30:21 +09:00
parent 1747ce4581
commit 67b59e9a1b
3 changed files with 28 additions and 21 deletions

View File

@ -52,7 +52,7 @@ function! s:initialize()"{{{
\ + s:runtime_dir \ + s:runtime_dir
endif endif
for dir in split(g:neocomplcache_snippets_dir, '\s*,\s*') for dir in split(g:neosnippet#snippets_directory, '\s*,\s*')
let dir = neosnippet#util#expand(dir) let dir = neosnippet#util#expand(dir)
if !isdirectory(dir) if !isdirectory(dir)
call mkdir(dir, 'p') call mkdir(dir, 'p')
@ -134,7 +134,7 @@ function! s:doc_dict.search(cur_text)"{{{
let snippets = neosnippet#get_snippets() let snippets = neosnippet#get_snippets()
let cur_word = s:get_cursor_keyword_snippet(snippets, a:cur_text) let cur_word = s:get_cursor_snippet(snippets, a:cur_text)
if cur_word == '' if cur_word == ''
return [] return []
endif endif
@ -167,8 +167,7 @@ function! neosnippet#force_expandable()"{{{
let cur_text = neosnippet#util#get_cur_text(1) let cur_text = neosnippet#util#get_cur_text(1)
" Found snippet trigger. " Found snippet trigger.
return s:get_cursor_keyword_snippet(snippets, cur_text) != '' return s:get_cursor_snippet(snippets, cur_text) != ''
\ || s:get_cursor_snippet(snippets, cur_text) != ''
endfunction"}}} endfunction"}}}
function! neosnippet#jumpable()"{{{ function! neosnippet#jumpable()"{{{
" Found snippet placeholder. " Found snippet placeholder.
@ -323,11 +322,11 @@ function! s:load_snippets(snippet, snippets_file)"{{{
" Check for duplicated names. " Check for duplicated names.
if has_key(dup_check, snippet_pattern.name) if has_key(dup_check, snippet_pattern.name)
call neocomplcache#print_error( call neosnippet#util#print_error(
\ 'Warning: ' . a:snippets_file . ':' \ 'Warning: ' . a:snippets_file . ':'
\ . linenr . ': duplicated snippet name `' \ . linenr . ': duplicated snippet name `'
\ . snippet_pattern.name . '`') \ . snippet_pattern.name . '`')
call neocomplcache#print_error( call neosnippet#util#print_error(
\ 'Please delete this snippet name before.') \ 'Please delete this snippet name before.')
endif endif
elseif has_key(snippet_pattern, 'name') elseif has_key(snippet_pattern, 'name')
@ -372,21 +371,25 @@ function! s:load_snippets(snippet, snippets_file)"{{{
return a:snippet return a:snippet
endfunction"}}} endfunction"}}}
function! s:get_cursor_keyword_snippet(snippets, cur_text)"{{{ function! s:get_prev_word(cur_keyword_str)"{{{
let cur_word = matchstr(a:cur_text, let keyword_pattern = '\S\+'
\ neocomplcache#get_keyword_pattern_end().'\|\h\w*\W\+$') let line_part = neocomplcache#get_cur_text()[: -1-len(a:cur_keyword_str)]
let prev_word_end = matchend(line_part, keyword_pattern)
" Check prev_word. if prev_word_end > 0
let prev_word = neocomplcache#get_prev_word(cur_word) let word_end = matchend(line_part, keyword_pattern, prev_word_end)
let pattern = printf('(!has_key(v:val, "prev_word") || v:val.prev_word ==# %s)', if word_end >= 0
\ string(prev_word)) while word_end >= 0
let prev_word_end = word_end
let dict = filter(copy(a:snippets), pattern) let word_end = matchend(line_part, keyword_pattern, prev_word_end)
if !has_key(dict, cur_word) endwhile
let cur_word = ''
endif endif
return cur_word let prev_word = matchstr(line_part[: prev_word_end-1], keyword_pattern . '$')
else
let prev_word = '^'
endif
return prev_word
endfunction"}}} endfunction"}}}
function! s:get_cursor_snippet(snippets, cur_text)"{{{ function! s:get_cursor_snippet(snippets, cur_text)"{{{
let cur_word = matchstr(a:cur_text, '\S\+$') let cur_word = matchstr(a:cur_text, '\S\+$')
@ -405,7 +408,7 @@ function! s:snippets_force_expand(cur_text, col)"{{{
\ a:cur_text, a:col, cur_word) \ a:cur_text, a:col, cur_word)
endfunction"}}} endfunction"}}}
function! s:snippets_expand_or_jump(cur_text, col)"{{{ function! s:snippets_expand_or_jump(cur_text, col)"{{{
let cur_word = s:get_cursor_keyword_snippet( let cur_word = s:get_cursor_snippet(
\ neosnippet#get_snippets(), \ neosnippet#get_snippets(),
\ a:cur_text) \ a:cur_text)
if cur_word == '' if cur_word == ''
@ -424,7 +427,7 @@ function! s:snippets_expand_or_jump(cur_text, col)"{{{
endif endif
endfunction"}}} endfunction"}}}
function! s:snippets_jump_or_expand(cur_text, col)"{{{ function! s:snippets_jump_or_expand(cur_text, col)"{{{
let cur_word = s:get_cursor_keyword_snippet( let cur_word = s:get_cursor_snippet(
\ neosnippet#get_snippets(), a:cur_text) \ neosnippet#get_snippets(), a:cur_text)
if search(s:get_placeholder_marker_pattern(). '\|' if search(s:get_placeholder_marker_pattern(). '\|'
\ .s:get_sync_placeholder_marker_pattern(), 'nw') > 0 \ .s:get_sync_placeholder_marker_pattern(), 'nw') > 0
@ -837,7 +840,7 @@ function! s:SID_PREFIX()"{{{
endfunction"}}} endfunction"}}}
function! s:trigger(function)"{{{ function! s:trigger(function)"{{{
let cur_text = neocomplcache#get_cur_text(1) let cur_text = neosnippet#util#get_cur_text(1)
let col = col('.') let col = col('.')
if mode() !=# 'i' if mode() !=# 'i'

View File

@ -80,6 +80,9 @@ function! neosnippet#util#get_cur_text()"{{{
\ matchstr(getline('.'), \ matchstr(getline('.'),
\ '^.*\%' . col('.') . 'c' . (mode() ==# 'i' ? '' : '.')) \ '^.*\%' . col('.') . 'c' . (mode() ==# 'i' ? '' : '.'))
endfunction"}}} endfunction"}}}
function! neosnippet#util#print_error(string)"{{{
echohl Error | echomsg a:string | echohl None
endfunction"}}}
let &cpo = s:save_cpo let &cpo = s:save_cpo
unlet s:save_cpo unlet s:save_cpo

View File

@ -324,6 +324,7 @@ CHANGELOG *neosnippet-changelog*
- Vitalized. - Vitalized.
- Deleted neocomplcache#util functions. - Deleted neocomplcache#util functions.
- Refactored variables. - Refactored variables.
- Deleted s:get_cursor_keyword_snippet().
2012-09-27 2012-09-27
- Ver.3 development is started. - Ver.3 development is started.