- Added regexp syntax.

This commit is contained in:
Shougo Matsushita 2012-11-03 15:35:27 +09:00
parent ff8b6f19c3
commit 45c3baaf23
2 changed files with 24 additions and 8 deletions

View File

@ -222,8 +222,8 @@ function! s:initialize_snippet(dict, path, line, pattern, name)"{{{
\ 'action__pattern' : a:pattern, 'real_name' : a:name, \ 'action__pattern' : a:pattern, 'real_name' : a:name,
\} \}
if has_key(a:dict, 'regex') if has_key(a:dict, 'regexp')
let snippet.regex = a:dict.regex let snippet.regexp = a:dict.regexp
endif endif
return snippet return snippet
@ -453,9 +453,9 @@ function! s:add_snippet_attribute(line, linenr, snippet_dict)"{{{
call neosnippet#util#print_error( call neosnippet#util#print_error(
\ 'prev_word must be "^" character.') \ 'prev_word must be "^" character.')
endif endif
elseif a:line =~ '^regex\s' elseif a:line =~ '^regexp\s'
let a:snippet_dict.regex = matchstr(a:line, let a:snippet_dict.regexp = matchstr(a:line,
\ '^regex\s\+[''"]\zs.*\ze[''"]$') \ '^regexp\s\+[''"]\zs.*\ze[''"]$')
elseif a:line =~ '^options\s\+' elseif a:line =~ '^options\s\+'
for option in split(matchstr(a:line, for option in split(matchstr(a:line,
\ '^options\s\+\zs.*$'), '[,[:space:]]\+') \ '^options\s\+\zs.*$'), '[,[:space:]]\+')
@ -1043,9 +1043,14 @@ function! neosnippet#get_snippets()"{{{
call extend(snippets, s:snippets[filetype], 'keep') call extend(snippets, s:snippets[filetype], 'keep')
endfor endfor
if mode() ==# 'i' && if mode() ==# 'i'
\ !s:is_beginning_of_line(neosnippet#util#get_cur_text()) " Special filters.
call filter(snippets, '!v:val.options.head') 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 endif
return snippets return snippets

View File

@ -395,6 +395,16 @@ Snippet Keywords:
alias hoge hogera hogehoge alias hoge hogera hogehoge
< <
- regexp [pattern] (optional)
This snippet expands when it matched by the regexp pattern only.
Example
>
regexp '^% '
<
- options [options] (optional) - options [options] (optional)
Options influece the snippet behavior. The possible options are: Options influece the snippet behavior. The possible options are:
@ -677,6 +687,7 @@ CHANGELOG *neosnippet-changelog*
- Refactored documentation. - Refactored documentation.
- Added :NeoSnippetSource. - Added :NeoSnippetSource.
- Refactored parse routine. - Refactored parse routine.
- Added regexp syntax.
2012-11-02 2012-11-02
- Added g:neosnippet#enable_snipmate_compatibility option. - Added g:neosnippet#enable_snipmate_compatibility option.