From d7d138090efa42ac82123dbb1a952753838c7ea0 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Thu, 4 Oct 2012 18:49:16 +0900 Subject: [PATCH] - Changed prev_word behavior. --- autoload/neosnippet.vim | 41 +++++++++++++++-------------------------- doc/neosnippet.txt | 1 + 2 files changed, 16 insertions(+), 26 deletions(-) diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 39e0d77..7ae97cf 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -221,11 +221,9 @@ function! s:set_snippet_pattern(dict)"{{{ \ 'word' : a:dict.name, \ 'snip' : a:dict.word, 'abbr' : a:dict.name, \ 'description' : a:dict.word, - \ 'menu' : menu_pattern . abbr, 'dup' : 1 + \ 'menu' : menu_pattern.abbr, + \ 'dup' : 1, 'is_head' : get(a:dict, 'is_head', 0), \} - if has_key(a:dict, 'prev_word') - let dict.prev_word = a:dict.prev_word - endif return dict endfunction"}}} @@ -370,8 +368,12 @@ function! s:load_snippets(snippet, snippets_file)"{{{ let snippet_pattern.alias = split(matchstr(line, \ '^alias\s\+\zs.*$'), '[,[:space:]]\+') elseif line =~ '^prev_word\s' - let snippet_pattern.prev_word = matchstr(line, + let prev_word = matchstr(line, \ '^prev_word\s\+[''"]\zs.*\ze[''"]$') + if prev_word == '^' + " For backward compatibility. + let snippet_pattern.is_head = 1 + endif elseif line =~ '^\s' if snippet_pattern.word != '' let snippet_pattern.word .= "\n" @@ -404,25 +406,13 @@ function! s:load_snippets(snippet, snippets_file)"{{{ return a:snippet endfunction"}}} -function! s:get_prev_word(cur_keyword_str)"{{{ +function! s:is_beginning_of_line(cur_text)"{{{ let keyword_pattern = '\S\+' - let line_part = neosnippet#util#get_cur_text()[: -1-len(a:cur_keyword_str)] + let cur_keyword_str = matchstr(a:cur_text, keyword_pattern.'$') + let line_part = a:cur_text[: -1-len(cur_keyword_str)] let prev_word_end = matchend(line_part, keyword_pattern) - if prev_word_end > 0 - let word_end = matchend(line_part, keyword_pattern, prev_word_end) - if word_end >= 0 - while word_end >= 0 - let prev_word_end = word_end - let word_end = matchend(line_part, keyword_pattern, prev_word_end) - endwhile - endif - let prev_word = matchstr(line_part[: prev_word_end-1], keyword_pattern . '$') - else - let prev_word = '^' - endif - - return prev_word + return prev_word_end <= 0 endfunction"}}} function! s:get_cursor_snippet(snippets, cur_text)"{{{ let cur_word = matchstr(a:cur_text, '\S\+$') @@ -830,12 +820,11 @@ function! neosnippet#get_snippets()"{{{ endfor call extend(snippets, copy(s:snippets['_']), 'keep') - let cur_keyword_str = matchstr( - \ neosnippet#util#get_cur_text(), '\S\+$') - let prev_word = s:get_prev_word(cur_keyword_str) + if !s:is_beginning_of_line(neosnippet#util#get_cur_text()) + call filter(snippets, '!v:val.is_head') + endif - return filter(snippets, printf("!has_key(v:val, 'prev_word') - \ || v:val.prev_word ==# %s", string(prev_word))) + return snippets endfunction"}}} function! neosnippet#get_snippets_directory()"{{{ let snippets_dir = copy(s:snippets_dir) diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index e00df5f..d55097f 100644 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -413,6 +413,7 @@ CHANGELOG *neosnippet-changelog* - Added scala snip. - Fixed s:get_cursor_snippet(). - Changed g:neosnippet#disable_runtime_snippets behavior. +- Changed prev_word behavior. 2012-10-01 - Deleted neosnippet#force_expandable().