diff --git a/autoload/neosnippet.vim b/autoload/neosnippet.vim index d85df69..40c510d 100644 --- a/autoload/neosnippet.vim +++ b/autoload/neosnippet.vim @@ -858,6 +858,15 @@ function! s:eval_snippet(snippet_text)"{{{ return snip_word endfunction"}}} +function! neosnippet#get_current_neosnippet()"{{{ + if !exists('b:neosnippet') + let b:neosnippet = { + \ 'selected_text' : '', + \} + endif + + return b:neosnippet +endfunction"}}} function! neosnippet#get_snippets()"{{{ let snippets = {} for filetype in s:get_sources_filetypes(neosnippet#get_filetype()) @@ -942,15 +951,49 @@ function! s:trigger(function)"{{{ let cur_text = neosnippet#util#get_cur_text() let col = col('.') + let expr = '' if mode() !=# 'i' " Fix column. let col += 2 endif - return printf("\:call %s(%s,%d)\", + " Get selected text. + let neosnippet = neosnippet#get_current_neosnippet() + if mode() ==# 's' && neosnippet.selected_text =~ '^#:' + let expr .= "a\" + endif + + let expr .= printf("\:call %s(%s,%d)\", \ a:function, string(cur_text), col) + + return expr endfunction"}}} +function! neosnippet#get_selected_text(type, ...) + let sel_save = &selection + let &selection = 'inclusive' + let reg_save = @@ + + try + " Invoked from Visual mode, use '< and '> marks. + if a:0 + silent exe "normal! `<" . a:type . "`>y" + elseif a:type == 'line' + silent exe "normal! '[V']y" + elseif a:type == 'block' + silent exe "normal! `[\`]y" + else + silent exe "normal! `[v`]y" + endif + + let neosnippet = neosnippet#get_current_neosnippet() + let neosnippet.selected_text = @@ + finally + let &selection = sel_save + let @@ = reg_save + endtry +endfunction + function! neosnippet#clear_select_mode_mappings()"{{{ if !g:neosnippet#disable_select_mode_mappings return diff --git a/autoload/neosnippet/snippets/vim.snip b/autoload/neosnippet/snippets/vim.snip index 87b49d0..c10be1b 100644 --- a/autoload/neosnippet/snippets/vim.snip +++ b/autoload/neosnippet/snippets/vim.snip @@ -1,7 +1,7 @@ snippet if abbr if endif options head - if ${1:condition} + if ${1:#:condition} ${0} endif @@ -13,7 +13,7 @@ options head snippet ifelse abbr if else endif options head - if ${1:condition} + if ${1:#:condition} ${2} else ${3} @@ -22,14 +22,14 @@ options head snippet for abbr for in endfor options head - for ${1:var} in ${2:list} + for ${1:#:var} in ${2:#:list} ${0} endfor snippet while abbr while endwhile options head - while ${1:condition} + while ${1:#:condition} ${0} endwhile @@ -37,7 +37,7 @@ snippet function abbr func endfunc alias func options head - function! ${1:func_name}(${2}) + function! ${1:#:func_name}(${2}) ${0} endfunction @@ -46,7 +46,7 @@ abbr try endtry options head try ${1} - catch /${2:pattern}/ + catch /${2:#:pattern}/ ${3} endtry @@ -62,7 +62,7 @@ options head snippet catch options head - catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/} + catch ${1:/${2:#:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/} snippet echomsg alias log @@ -72,13 +72,13 @@ options head snippet command abbr command call function options head - command! ${1:command_name} call ${2:func_name} + command! ${1:#:command_name} call ${2:#:func_name} snippet customlist abbr customlist complete function options head - function! ${1:func_name}(arglead, cmdline, cursorpos) - return filter(${2:list}, 'stridx(v:val, a:arglead) == 0') + function! ${1:#:func_name}(arglead, cmdline, cursorpos) + return filter(${2:#:list}, 'stridx(v:val, a:arglead) == 0') endfunction snippet augroup @@ -86,13 +86,13 @@ abbr augroup with autocmds options head augroup ${1} autocmd! - autocmd ${2:event} + autocmd ${2:#:event} augroup END snippet redir abbr redir => var options head - redir => ${1} + redir => ${1:#:var} ${2:} redir END diff --git a/doc/neosnippet.txt b/doc/neosnippet.txt index a35fb4d..d788725 100644 --- a/doc/neosnippet.txt +++ b/doc/neosnippet.txt @@ -458,6 +458,7 @@ CHANGELOG *neosnippet-changelog* - Improved parse of snippets file. - Improved syntax of markers. - Improved clear select mode mappings. +- Added get_selected_text(). 2012-10-28 - Improved snipMate compatibility. diff --git a/plugin/neosnippet.vim b/plugin/neosnippet.vim index df6cdcd..75718bd 100644 --- a/plugin/neosnippet.vim +++ b/plugin/neosnippet.vim @@ -55,6 +55,8 @@ inoremap (neosnippet_jump) snoremap (neosnippet_jump) \ neosnippet#jump_impl() +" :call neosnippet#get_selected_text(visualmode(), 1) + imap (neocomplcache_snippets_expand) \ (neosnippet_expand_or_jump) smap (neocomplcache_snippets_expand) @@ -62,7 +64,7 @@ smap (neocomplcache_snippets_expand) imap (neocomplcache_snippets_jump) \ (neosnippet_jump_or_expand) smap (neocomplcache_snippets_jump) - \ (neosnippet_jump_or_expand) + \ (neosnippet_expand_or_jump) imap (neocomplcache_snippets_force_expand) \ (neosnippet_expand) smap (neocomplcache_snippets_force_expand) diff --git a/syntax/snippet.vim b/syntax/snippet.vim index c657ed5..d825488 100644 --- a/syntax/snippet.vim +++ b/syntax/snippet.vim @@ -33,47 +33,50 @@ elseif exists("b:current_syntax") finish endif -syn region SnippetPrevWord start=+'+ end=+'+ contained -syn region SnippetPrevWord start=+"+ end=+"+ contained -syn region SnippetEval start=+\\\@