- Added options head.
This commit is contained in:
parent
77b3a1950d
commit
87b97cd385
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: neosnippet.vim
|
" FILE: neosnippet.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 19 Oct 2012.
|
" Last Modified: 21 Oct 2012.
|
||||||
" License: MIT license {{{
|
" License: MIT license {{{
|
||||||
" Permission is hereby granted, free of charge, to any person obtaining
|
" Permission is hereby granted, free of charge, to any person obtaining
|
||||||
" a copy of this software and associated documentation files (the
|
" 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,
|
\ 'word' : a:dict.name, 'snip' : a:dict.word,
|
||||||
\ 'description' : a:dict.word,
|
\ 'description' : a:dict.word,
|
||||||
\ 'menu' : menu_pattern.abbr,
|
\ 'menu' : menu_pattern.abbr,
|
||||||
\ 'dup' : 1, 'is_head' : get(a:dict, 'is_head', 0),
|
\ 'dup' : 1, 'options' : a:dict.options,
|
||||||
\}
|
\}
|
||||||
return dict
|
return dict
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
@ -320,7 +320,8 @@ endfunction"}}}
|
|||||||
|
|
||||||
function! s:load_snippets(snippet, snippets_file)"{{{
|
function! s:load_snippets(snippet, snippets_file)"{{{
|
||||||
let dup_check = {}
|
let dup_check = {}
|
||||||
let snippet_pattern = { 'word' : '' }
|
let snippet_pattern = { 'word' : '',
|
||||||
|
\ 'options' : { 'head' : 0, 'word' : 0 } }
|
||||||
|
|
||||||
let linenr = 1
|
let linenr = 1
|
||||||
|
|
||||||
@ -349,7 +350,8 @@ function! s:load_snippets(snippet, snippets_file)"{{{
|
|||||||
" Set previous snippet.
|
" Set previous snippet.
|
||||||
call s:set_snippet_dict(snippet_pattern,
|
call s:set_snippet_dict(snippet_pattern,
|
||||||
\ a:snippet, dup_check, a:snippets_file)
|
\ a:snippet, dup_check, a:snippets_file)
|
||||||
let snippet_pattern = { 'word' : '' }
|
let snippet_pattern = { 'word' : '',
|
||||||
|
\ 'options' : { 'head' : 0, 'word' : 0 } }
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let snippet_pattern.name =
|
let snippet_pattern.name =
|
||||||
@ -377,8 +379,21 @@ function! s:load_snippets(snippet, snippets_file)"{{{
|
|||||||
\ '^prev_word\s\+[''"]\zs.*\ze[''"]$')
|
\ '^prev_word\s\+[''"]\zs.*\ze[''"]$')
|
||||||
if prev_word == '^'
|
if prev_word == '^'
|
||||||
" For backward compatibility.
|
" 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
|
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'
|
elseif line =~ '^\s'
|
||||||
if snippet_pattern.word != ''
|
if snippet_pattern.word != ''
|
||||||
let snippet_pattern.word .= "\n"
|
let snippet_pattern.word .= "\n"
|
||||||
@ -827,7 +842,7 @@ function! neosnippet#get_snippets()"{{{
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
if !s:is_beginning_of_line(neosnippet#util#get_cur_text())
|
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
|
endif
|
||||||
|
|
||||||
return snippets
|
return snippets
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
snippet if
|
snippet if
|
||||||
abbr if endif
|
abbr if endif
|
||||||
prev_word '^'
|
options head
|
||||||
if ${1:condition}
|
if ${1:condition}
|
||||||
${0}
|
${0}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
snippet elseif
|
snippet elseif
|
||||||
prev_word '^'
|
options head
|
||||||
elseif ${1:/* condition */}
|
elseif ${1:/* condition */}
|
||||||
${0}
|
${0}
|
||||||
|
|
||||||
snippet ifelse
|
snippet ifelse
|
||||||
abbr if else endif
|
abbr if else endif
|
||||||
prev_word '^'
|
options head
|
||||||
if ${1:condition}
|
if ${1:condition}
|
||||||
${2}
|
${2}
|
||||||
else
|
else
|
||||||
@ -21,14 +21,14 @@ prev_word '^'
|
|||||||
|
|
||||||
snippet for
|
snippet for
|
||||||
abbr for in endfor
|
abbr for in endfor
|
||||||
prev_word '^'
|
options head
|
||||||
for ${1:var} in ${2:list}
|
for ${1:var} in ${2:list}
|
||||||
${0}
|
${0}
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
snippet while
|
snippet while
|
||||||
abbr while endwhile
|
abbr while endwhile
|
||||||
prev_word '^'
|
options head
|
||||||
while ${1:condition}
|
while ${1:condition}
|
||||||
${0}
|
${0}
|
||||||
endwhile
|
endwhile
|
||||||
@ -36,14 +36,14 @@ prev_word '^'
|
|||||||
snippet function
|
snippet function
|
||||||
abbr func endfunc
|
abbr func endfunc
|
||||||
alias func
|
alias func
|
||||||
prev_word '^'
|
options head
|
||||||
function! ${1:func_name}(${2})
|
function! ${1:func_name}(${2})
|
||||||
${0}
|
${0}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
snippet try
|
snippet try
|
||||||
abbr try endtry
|
abbr try endtry
|
||||||
prev_word '^'
|
options head
|
||||||
try
|
try
|
||||||
${1}
|
${1}
|
||||||
catch /${2:pattern}/
|
catch /${2:pattern}/
|
||||||
@ -51,28 +51,28 @@ prev_word '^'
|
|||||||
endtry
|
endtry
|
||||||
|
|
||||||
snippet catch
|
snippet catch
|
||||||
prev_word '^'
|
options head
|
||||||
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
|
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
|
||||||
|
|
||||||
snippet log
|
snippet log
|
||||||
prev_word '^'
|
options head
|
||||||
echomsg string(${1})
|
echomsg string(${1})
|
||||||
|
|
||||||
snippet command
|
snippet command
|
||||||
abbr command call function
|
abbr command call function
|
||||||
prev_word '^'
|
options head
|
||||||
command! ${1:command_name} call ${2:func_name}
|
command! ${1:command_name} call ${2:func_name}
|
||||||
|
|
||||||
snippet customlist
|
snippet customlist
|
||||||
abbr customlist complete function
|
abbr customlist complete function
|
||||||
prev_word '^'
|
options head
|
||||||
function! ${1:func_name}(arglead, cmdline, cursorpos)
|
function! ${1:func_name}(arglead, cmdline, cursorpos)
|
||||||
return filter(${2:list}, 'stridx(v:val, a:arglead) == 0')
|
return filter(${2:list}, 'stridx(v:val, a:arglead) == 0')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
snippet augroup
|
snippet augroup
|
||||||
abbr augroup with autocmds
|
abbr augroup with autocmds
|
||||||
prev_word '^'
|
options head
|
||||||
augroup ${1}
|
augroup ${1}
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd ${2:event}
|
autocmd ${2:event}
|
||||||
|
@ -299,7 +299,7 @@ Example:
|
|||||||
>
|
>
|
||||||
snippet if
|
snippet if
|
||||||
abbr if endif
|
abbr if endif
|
||||||
prev_word '^'
|
options head
|
||||||
if ${1:condition}
|
if ${1:condition}
|
||||||
${2}
|
${2}
|
||||||
endif
|
endif
|
||||||
@ -307,7 +307,9 @@ Example:
|
|||||||
snippet {snippet_name} syntax is the snippet name.
|
snippet {snippet_name} syntax is the snippet name.
|
||||||
abbr {abbr_name} is the completion abbrevation (same to completion "abbr"
|
abbr {abbr_name} is the completion abbrevation (same to completion "abbr"
|
||||||
key).
|
key).
|
||||||
prev_word '^' means this snippet is enabled only in line head.
|
|
||||||
|
"options head" means this snippet is enabled only in line head.
|
||||||
|
Note: prev_word '^' is duplicated keyword.
|
||||||
|
|
||||||
By the way, it is warned that the snippet name was already defined by other
|
By the way, it is warned that the snippet name was already defined by other
|
||||||
snippet file. If you want to overwrite it explicitly, please use:
|
snippet file. If you want to overwrite it explicitly, please use:
|
||||||
@ -331,7 +333,7 @@ If you want to include a whole filetype directory snippets.
|
|||||||
Eval snippet feature is available.
|
Eval snippet feature is available.
|
||||||
>
|
>
|
||||||
snippet hoge
|
snippet hoge
|
||||||
prev_word '^'
|
options head
|
||||||
`expand("%")`
|
`expand("%")`
|
||||||
<
|
<
|
||||||
Note: You want to use backticks in snippet, you must escape backticks.
|
Note: You want to use backticks in snippet, you must escape backticks.
|
||||||
@ -354,7 +356,7 @@ Placeholder feature is available. The string after ":" is default value.
|
|||||||
>
|
>
|
||||||
snippet if
|
snippet if
|
||||||
abbr if endif
|
abbr if endif
|
||||||
prev_word '^'
|
options head
|
||||||
if ${1:condition}
|
if ${1:condition}
|
||||||
${2}
|
${2}
|
||||||
endif
|
endif
|
||||||
@ -399,8 +401,8 @@ But must escape inner "}". "\" is eacape sequence.
|
|||||||
<
|
<
|
||||||
In following snippet, you must escape "}" twice.
|
In following snippet, you must escape "}" twice.
|
||||||
>
|
>
|
||||||
snippet catch
|
snippet catch
|
||||||
prev_word '^'
|
options head
|
||||||
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
|
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
|
||||||
<
|
<
|
||||||
Because ${1:} substitutes the pattern to "/${2:pattern: empty, E484,
|
Because ${1:} substitutes the pattern to "/${2:pattern: empty, E484,
|
||||||
@ -440,6 +442,9 @@ snippet *neosnippet-unite-action-snippet*
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
CHANGELOG *neosnippet-changelog*
|
CHANGELOG *neosnippet-changelog*
|
||||||
|
|
||||||
|
2012-10-21
|
||||||
|
- Added options head.
|
||||||
|
|
||||||
2012-10-19
|
2012-10-19
|
||||||
- Fixed syntax highlight.
|
- Fixed syntax highlight.
|
||||||
- Improved documentation.
|
- Improved documentation.
|
||||||
|
@ -43,7 +43,8 @@ syn match SnippetVariable '\$\d\+' contained
|
|||||||
syn match SnippetComment '^#.*$'
|
syn match SnippetComment '^#.*$'
|
||||||
syn match SnippetEscape '\\[`]' contained
|
syn match SnippetEscape '\\[`]' contained
|
||||||
|
|
||||||
syn match SnippetKeyword '^\%(include\|snippet\|abbr\|prev_word\|delete\|alias\)' contained
|
syn match SnippetKeyword '^\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\)' contained
|
||||||
|
syn keyword SnippetOption head word contained
|
||||||
syn match SnippetPrevWords '^prev_word\s\+.*$' contains=SnippetPrevWord,SnippetKeyword
|
syn match SnippetPrevWords '^prev_word\s\+.*$' contains=SnippetPrevWord,SnippetKeyword
|
||||||
syn match SnippetStatementName '^snippet\s.*$' contains=SnippetName,SnippetKeyword
|
syn match SnippetStatementName '^snippet\s.*$' contains=SnippetName,SnippetKeyword
|
||||||
syn match SnippetName '\s\+.*$' contained
|
syn match SnippetName '\s\+.*$' contained
|
||||||
@ -57,6 +58,7 @@ syn match SnippetStatementDelete '^delete\s.*$' contains=SnippetDelete,Sn
|
|||||||
syn match SnippetDelete '\s\+.*$' contained
|
syn match SnippetDelete '\s\+.*$' contained
|
||||||
syn match SnippetStatementAlias '^alias\s.*$' contains=SnippetAlias,SnippetKeyword
|
syn match SnippetStatementAlias '^alias\s.*$' contains=SnippetAlias,SnippetKeyword
|
||||||
syn match SnippetAlias '\s\+.*$' contained
|
syn match SnippetAlias '\s\+.*$' contained
|
||||||
|
syn match SnippetStatementOptions '^options\s.*$' contains=SnippetOption,SnippetKeyword
|
||||||
|
|
||||||
hi def link SnippetKeyword Statement
|
hi def link SnippetKeyword Statement
|
||||||
hi def link SnippetPrevWord String
|
hi def link SnippetPrevWord String
|
||||||
@ -69,6 +71,7 @@ hi def link SnippetVariable Special
|
|||||||
hi def link SnippetComment Comment
|
hi def link SnippetComment Comment
|
||||||
hi def link SnippetInclude PreProc
|
hi def link SnippetInclude PreProc
|
||||||
hi def link SnippetDelete PreProc
|
hi def link SnippetDelete PreProc
|
||||||
|
hi def link SnippetOption PreProc
|
||||||
hi def link SnippetAlias Identifier
|
hi def link SnippetAlias Identifier
|
||||||
hi def link SnippetEscape Special
|
hi def link SnippetEscape Special
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user