- Added options head.
This commit is contained in:
parent
77b3a1950d
commit
87b97cd385
@ -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
|
||||
|
@ -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}
|
||||
|
@ -299,7 +299,7 @@ Example:
|
||||
>
|
||||
snippet if
|
||||
abbr if endif
|
||||
prev_word '^'
|
||||
options head
|
||||
if ${1:condition}
|
||||
${2}
|
||||
endif
|
||||
@ -307,7 +307,9 @@ Example:
|
||||
snippet {snippet_name} syntax is the snippet name.
|
||||
abbr {abbr_name} is the completion abbrevation (same to completion "abbr"
|
||||
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
|
||||
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.
|
||||
>
|
||||
snippet hoge
|
||||
prev_word '^'
|
||||
options head
|
||||
`expand("%")`
|
||||
<
|
||||
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
|
||||
abbr if endif
|
||||
prev_word '^'
|
||||
options head
|
||||
if ${1:condition}
|
||||
${2}
|
||||
endif
|
||||
@ -399,8 +401,8 @@ But must escape inner "}". "\" is eacape sequence.
|
||||
<
|
||||
In following snippet, you must escape "}" twice.
|
||||
>
|
||||
snippet catch
|
||||
prev_word '^'
|
||||
snippet catch
|
||||
options head
|
||||
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
|
||||
<
|
||||
Because ${1:} substitutes the pattern to "/${2:pattern: empty, E484,
|
||||
@ -440,6 +442,9 @@ snippet *neosnippet-unite-action-snippet*
|
||||
==============================================================================
|
||||
CHANGELOG *neosnippet-changelog*
|
||||
|
||||
2012-10-21
|
||||
- Added options head.
|
||||
|
||||
2012-10-19
|
||||
- Fixed syntax highlight.
|
||||
- Improved documentation.
|
||||
|
@ -43,7 +43,8 @@ syn match SnippetVariable '\$\d\+' contained
|
||||
syn match SnippetComment '^#.*$'
|
||||
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 SnippetStatementName '^snippet\s.*$' contains=SnippetName,SnippetKeyword
|
||||
syn match SnippetName '\s\+.*$' contained
|
||||
@ -57,6 +58,7 @@ syn match SnippetStatementDelete '^delete\s.*$' contains=SnippetDelete,Sn
|
||||
syn match SnippetDelete '\s\+.*$' contained
|
||||
syn match SnippetStatementAlias '^alias\s.*$' contains=SnippetAlias,SnippetKeyword
|
||||
syn match SnippetAlias '\s\+.*$' contained
|
||||
syn match SnippetStatementOptions '^options\s.*$' contains=SnippetOption,SnippetKeyword
|
||||
|
||||
hi def link SnippetKeyword Statement
|
||||
hi def link SnippetPrevWord String
|
||||
@ -69,6 +71,7 @@ hi def link SnippetVariable Special
|
||||
hi def link SnippetComment Comment
|
||||
hi def link SnippetInclude PreProc
|
||||
hi def link SnippetDelete PreProc
|
||||
hi def link SnippetOption PreProc
|
||||
hi def link SnippetAlias Identifier
|
||||
hi def link SnippetEscape Special
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user