From 45c3baaf23466338d57d629ad3c6283b569d37d9 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 3 Nov 2012 15:35:27 +0900 Subject: [PATCH] - Added regexp syntax. --- autoload/neosnippet.vim | 21 +++++++++++++-------- doc/neosnippet.txt | 11 +++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index 33169c3..0f9bc2b 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -222,8 +222,8 @@ function! s:initialize_snippet(dict, path, line, pattern, name)"{{{ \ 'action__pattern' : a:pattern, 'real_name' : a:name, \} - if has_key(a:dict, 'regex') - let snippet.regex = a:dict.regex + if has_key(a:dict, 'regexp') + let snippet.regexp = a:dict.regexp endif return snippet @@ -453,9 +453,9 @@ function! s:add_snippet_attribute(line, linenr, snippet_dict)"{{{ call neosnippet#util#print_error( \ 'prev_word must be "^" character.') endif - elseif a:line =~ '^regex\s' - let a:snippet_dict.regex = matchstr(a:line, - \ '^regex\s\+[''"]\zs.*\ze[''"]$') + elseif a:line =~ '^regexp\s' + let a:snippet_dict.regexp = matchstr(a:line, + \ '^regexp\s\+[''"]\zs.*\ze[''"]$') elseif a:line =~ '^options\s\+' for option in split(matchstr(a:line, \ '^options\s\+\zs.*$'), '[,[:space:]]\+') @@ -1043,9 +1043,14 @@ function! neosnippet#get_snippets()"{{{ call extend(snippets, s:snippets[filetype], 'keep') endfor - if mode() ==# 'i' && - \ !s:is_beginning_of_line(neosnippet#util#get_cur_text()) - call filter(snippets, '!v:val.options.head') + if mode() ==# 'i' + " Special filters. + let cur_text = neosnippet#util#get_cur_text() + if !s:is_beginning_of_line(cur_text) + call filter(snippets, '!v:val.options.head') + endif + + call filter(snippets, "cur_text =~ get(v:val, 'regexp', '')") endif return snippets diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index a2b0040..c21fa65 100644 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -395,6 +395,16 @@ Snippet Keywords: alias hoge hogera hogehoge < +- regexp [pattern] (optional) + + This snippet expands when it matched by the regexp pattern only. + + Example + +> + regexp '^% ' +< + - options [options] (optional) Options influece the snippet behavior. The possible options are: @@ -677,6 +687,7 @@ CHANGELOG *neosnippet-changelog* - Refactored documentation. - Added :NeoSnippetSource. - Refactored parse routine. +- Added regexp syntax. 2012-11-02 - Added g:neosnippet#enable_snipmate_compatibility option.