- Added options word.

This commit is contained in:
Shougo Matsushita 2012-10-21 18:03:10 +09:00
parent 87b97cd385
commit 15e014ca10
4 changed files with 30 additions and 2 deletions

View File

@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" FILE: snippets_complete.vim " FILE: snippets_complete.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
@ -41,6 +41,14 @@ function! s:source.initialize()"{{{
endfunction"}}} endfunction"}}}
function! s:source.get_keyword_pos(cur_text)"{{{ function! s:source.get_keyword_pos(cur_text)"{{{
let cur_word = matchstr(a:cur_text, '\w\+$')
let word_candidates = neocomplcache#keyword_filter(
\ filter(values(neosnippet#get_snippets()),
\ 'v:val.options.word'), cur_word)
if !empty(word_candidates)
return match(a:cur_text, '\w\+$')
endif
return match(a:cur_text, '\S\+$') return match(a:cur_text, '\S\+$')
endfunction"}}} endfunction"}}}

View File

@ -435,9 +435,15 @@ function! s:is_beginning_of_line(cur_text)"{{{
return prev_word_end <= 0 return prev_word_end <= 0
endfunction"}}} endfunction"}}}
function! s:get_cursor_snippet(snippets, cur_text)"{{{ function! s:get_cursor_snippet(snippets, cur_text)"{{{
let cur_word = matchstr(a:cur_text, '\w\+$')
if cur_word != '' &&
\ has_key(a:snippets, cur_word) && a:snippets[cur_word].options.word
return cur_word
endif
let cur_word = matchstr(a:cur_text, '\S\+$') let cur_word = matchstr(a:cur_text, '\S\+$')
return has_key(a:snippets, cur_word) ? cur_word : '' return cur_word != '' && has_key(a:snippets, cur_word) ? cur_word : ''
endfunction"}}} endfunction"}}}
function! s:snippets_expand(cur_text, col)"{{{ function! s:snippets_expand(cur_text, col)"{{{
let cur_word = s:get_cursor_snippet( let cur_word = s:get_cursor_snippet(

View File

@ -1,16 +1,20 @@
# Global snippets # Global snippets
snippet date snippet date
options word
`strftime("%d %b %Y")` `strftime("%d %b %Y")`
snippet date_full snippet date_full
alias df alias df
options word
`strftime("%Y-%m-%dT%H:%M:%S")` `strftime("%Y-%m-%dT%H:%M:%S")`
snippet date_day snippet date_day
alias dd alias dd
options word
`strftime("%Y-%m-%d")` `strftime("%Y-%m-%d")`
snippet date_time snippet date_time
alias dt alias dt
options word
`strftime("%H:%M:%S")` `strftime("%H:%M:%S")`

View File

@ -418,6 +418,15 @@ languages' indent files can not work very well (e.g.: PHP, Python).
${2:// code...} ${2:// code...}
} }
< <
"options word" means this snippet is expanded by word boundary.
Note: The trigger must be word(digits or alphabet characters or "_")
characters.
>
snippet date
options word
`strftime("%d %b %Y")`
<
============================================================================== ==============================================================================
UNITE SOURCES *neosnippet-unite-sources* UNITE SOURCES *neosnippet-unite-sources*
@ -444,6 +453,7 @@ CHANGELOG *neosnippet-changelog*
2012-10-21 2012-10-21
- Added options head. - Added options head.
- Added options word.
2012-10-19 2012-10-19
- Fixed syntax highlight. - Fixed syntax highlight.