- Added options head.

This commit is contained in:
Shougo Matsushita
2012-10-21 17:51:07 +09:00
parent 77b3a1950d
commit 87b97cd385
4 changed files with 49 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
"=============================================================================
" FILE: neosnippet.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 19 Oct 2012.
" Last Modified: 21 Oct 2012.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
@@ -226,7 +226,7 @@ function! s:set_snippet_pattern(dict)"{{{
\ 'word' : a:dict.name, 'snip' : a:dict.word,
\ 'description' : a:dict.word,
\ 'menu' : menu_pattern.abbr,
\ 'dup' : 1, 'is_head' : get(a:dict, 'is_head', 0),
\ 'dup' : 1, 'options' : a:dict.options,
\}
return dict
endfunction"}}}
@@ -320,7 +320,8 @@ endfunction"}}}
function! s:load_snippets(snippet, snippets_file)"{{{
let dup_check = {}
let snippet_pattern = { 'word' : '' }
let snippet_pattern = { 'word' : '',
\ 'options' : { 'head' : 0, 'word' : 0 } }
let linenr = 1
@@ -349,7 +350,8 @@ function! s:load_snippets(snippet, snippets_file)"{{{
" Set previous snippet.
call s:set_snippet_dict(snippet_pattern,
\ a:snippet, dup_check, a:snippets_file)
let snippet_pattern = { 'word' : '' }
let snippet_pattern = { 'word' : '',
\ 'options' : { 'head' : 0, 'word' : 0 } }
endif
let snippet_pattern.name =
@@ -377,8 +379,21 @@ function! s:load_snippets(snippet, snippets_file)"{{{
\ '^prev_word\s\+[''"]\zs.*\ze[''"]$')
if prev_word == '^'
" For backward compatibility.
let snippet_pattern.is_head = 1
let snippet_pattern.options.head = 1
else
call neosnippet#util#print_error(
\ 'prev_word must be "^" character.')
endif
elseif line =~ '^options\s\+'
for option in split(matchstr(line,
\ '^options\s\+\zs.*$'), '[,[:space:]]\+')
if !has_key(snippet_pattern.options, option)
call neosnippet#util#print_error(
\ printf('invalid option name : %s is detected.', option)
else
let snippet_pattern.options[option] = 1
endif
endfor
elseif line =~ '^\s'
if snippet_pattern.word != ''
let snippet_pattern.word .= "\n"
@@ -827,7 +842,7 @@ function! neosnippet#get_snippets()"{{{
endfor
if !s:is_beginning_of_line(neosnippet#util#get_cur_text())
call filter(snippets, '!v:val.is_head')
call filter(snippets, '!v:val.options.head')
endif
return snippets

View File

@@ -1,18 +1,18 @@
snippet if
abbr if endif
prev_word '^'
options head
if ${1:condition}
${0}
endif
snippet elseif
prev_word '^'
snippet elseif
options head
elseif ${1:/* condition */}
${0}
snippet ifelse
abbr if else endif
prev_word '^'
options head
if ${1:condition}
${2}
else
@@ -21,14 +21,14 @@ prev_word '^'
snippet for
abbr for in endfor
prev_word '^'
options head
for ${1:var} in ${2:list}
${0}
endfor
snippet while
abbr while endwhile
prev_word '^'
options head
while ${1:condition}
${0}
endwhile
@@ -36,14 +36,14 @@ prev_word '^'
snippet function
abbr func endfunc
alias func
prev_word '^'
options head
function! ${1:func_name}(${2})
${0}
endfunction
snippet try
abbr try endtry
prev_word '^'
options head
try
${1}
catch /${2:pattern}/
@@ -51,28 +51,28 @@ prev_word '^'
endtry
snippet catch
prev_word '^'
options head
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
snippet log
prev_word '^'
options head
echomsg string(${1})
snippet command
abbr command call function
prev_word '^'
options head
command! ${1:command_name} call ${2:func_name}
snippet customlist
abbr customlist complete function
prev_word '^'
options head
function! ${1:func_name}(arglead, cmdline, cursorpos)
return filter(${2:list}, 'stridx(v:val, a:arglead) == 0')
endfunction
snippet augroup
abbr augroup with autocmds
prev_word '^'
options head
augroup ${1}
autocmd!
autocmd ${2:event}