- Added get_selected_text().
This commit is contained in:
parent
d4870c9987
commit
c1cfe686ad
@ -858,6 +858,15 @@ function! s:eval_snippet(snippet_text)"{{{
|
|||||||
|
|
||||||
return snip_word
|
return snip_word
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
function! neosnippet#get_current_neosnippet()"{{{
|
||||||
|
if !exists('b:neosnippet')
|
||||||
|
let b:neosnippet = {
|
||||||
|
\ 'selected_text' : '',
|
||||||
|
\}
|
||||||
|
endif
|
||||||
|
|
||||||
|
return b:neosnippet
|
||||||
|
endfunction"}}}
|
||||||
function! neosnippet#get_snippets()"{{{
|
function! neosnippet#get_snippets()"{{{
|
||||||
let snippets = {}
|
let snippets = {}
|
||||||
for filetype in s:get_sources_filetypes(neosnippet#get_filetype())
|
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 cur_text = neosnippet#util#get_cur_text()
|
||||||
|
|
||||||
let col = col('.')
|
let col = col('.')
|
||||||
|
let expr = ''
|
||||||
if mode() !=# 'i'
|
if mode() !=# 'i'
|
||||||
" Fix column.
|
" Fix column.
|
||||||
let col += 2
|
let col += 2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return printf("\<ESC>:call %s(%s,%d)\<CR>",
|
" Get selected text.
|
||||||
|
let neosnippet = neosnippet#get_current_neosnippet()
|
||||||
|
if mode() ==# 's' && neosnippet.selected_text =~ '^#:'
|
||||||
|
let expr .= "a\<BS>"
|
||||||
|
endif
|
||||||
|
|
||||||
|
let expr .= printf("\<ESC>:call %s(%s,%d)\<CR>",
|
||||||
\ a:function, string(cur_text), col)
|
\ a:function, string(cur_text), col)
|
||||||
|
|
||||||
|
return expr
|
||||||
endfunction"}}}
|
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! `[\<C-V>`]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()"{{{
|
function! neosnippet#clear_select_mode_mappings()"{{{
|
||||||
if !g:neosnippet#disable_select_mode_mappings
|
if !g:neosnippet#disable_select_mode_mappings
|
||||||
return
|
return
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
snippet if
|
snippet if
|
||||||
abbr if endif
|
abbr if endif
|
||||||
options head
|
options head
|
||||||
if ${1:condition}
|
if ${1:#:condition}
|
||||||
${0}
|
${0}
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ options head
|
|||||||
snippet ifelse
|
snippet ifelse
|
||||||
abbr if else endif
|
abbr if else endif
|
||||||
options head
|
options head
|
||||||
if ${1:condition}
|
if ${1:#:condition}
|
||||||
${2}
|
${2}
|
||||||
else
|
else
|
||||||
${3}
|
${3}
|
||||||
@ -22,14 +22,14 @@ options head
|
|||||||
snippet for
|
snippet for
|
||||||
abbr for in endfor
|
abbr for in endfor
|
||||||
options head
|
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
|
||||||
options head
|
options head
|
||||||
while ${1:condition}
|
while ${1:#:condition}
|
||||||
${0}
|
${0}
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ snippet function
|
|||||||
abbr func endfunc
|
abbr func endfunc
|
||||||
alias func
|
alias func
|
||||||
options head
|
options head
|
||||||
function! ${1:func_name}(${2})
|
function! ${1:#:func_name}(${2})
|
||||||
${0}
|
${0}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ abbr try endtry
|
|||||||
options head
|
options head
|
||||||
try
|
try
|
||||||
${1}
|
${1}
|
||||||
catch /${2:pattern}/
|
catch /${2:#:pattern}/
|
||||||
${3}
|
${3}
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ options head
|
|||||||
|
|
||||||
snippet catch
|
snippet catch
|
||||||
options head
|
options head
|
||||||
catch ${1:/${2:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
|
catch ${1:/${2:#:pattern: empty, E484, Vim(cmdname):{errmsg\\}\}/}
|
||||||
|
|
||||||
snippet echomsg
|
snippet echomsg
|
||||||
alias log
|
alias log
|
||||||
@ -72,13 +72,13 @@ options head
|
|||||||
snippet command
|
snippet command
|
||||||
abbr command call function
|
abbr command call function
|
||||||
options head
|
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
|
||||||
options head
|
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
|
||||||
@ -86,13 +86,13 @@ abbr augroup with autocmds
|
|||||||
options head
|
options head
|
||||||
augroup ${1}
|
augroup ${1}
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd ${2:event}
|
autocmd ${2:#:event}
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
snippet redir
|
snippet redir
|
||||||
abbr redir => var
|
abbr redir => var
|
||||||
options head
|
options head
|
||||||
redir => ${1}
|
redir => ${1:#:var}
|
||||||
${2:}
|
${2:}
|
||||||
redir END
|
redir END
|
||||||
|
|
||||||
|
@ -458,6 +458,7 @@ CHANGELOG *neosnippet-changelog*
|
|||||||
- Improved parse of snippets file.
|
- Improved parse of snippets file.
|
||||||
- Improved syntax of markers.
|
- Improved syntax of markers.
|
||||||
- Improved clear select mode mappings.
|
- Improved clear select mode mappings.
|
||||||
|
- Added get_selected_text().
|
||||||
|
|
||||||
2012-10-28
|
2012-10-28
|
||||||
- Improved snipMate compatibility.
|
- Improved snipMate compatibility.
|
||||||
|
@ -55,6 +55,8 @@ inoremap <silent><expr> <Plug>(neosnippet_jump)
|
|||||||
snoremap <silent><expr> <Plug>(neosnippet_jump)
|
snoremap <silent><expr> <Plug>(neosnippet_jump)
|
||||||
\ neosnippet#jump_impl()
|
\ neosnippet#jump_impl()
|
||||||
|
|
||||||
|
" <C-v>:call neosnippet#get_selected_text(visualmode(), 1)<CR><C-v>
|
||||||
|
|
||||||
imap <silent> <Plug>(neocomplcache_snippets_expand)
|
imap <silent> <Plug>(neocomplcache_snippets_expand)
|
||||||
\ <Plug>(neosnippet_expand_or_jump)
|
\ <Plug>(neosnippet_expand_or_jump)
|
||||||
smap <silent> <Plug>(neocomplcache_snippets_expand)
|
smap <silent> <Plug>(neocomplcache_snippets_expand)
|
||||||
@ -62,7 +64,7 @@ smap <silent> <Plug>(neocomplcache_snippets_expand)
|
|||||||
imap <silent> <Plug>(neocomplcache_snippets_jump)
|
imap <silent> <Plug>(neocomplcache_snippets_jump)
|
||||||
\ <Plug>(neosnippet_jump_or_expand)
|
\ <Plug>(neosnippet_jump_or_expand)
|
||||||
smap <silent> <Plug>(neocomplcache_snippets_jump)
|
smap <silent> <Plug>(neocomplcache_snippets_jump)
|
||||||
\ <Plug>(neosnippet_jump_or_expand)
|
\ <Plug>(neosnippet_expand_or_jump)
|
||||||
imap <silent> <Plug>(neocomplcache_snippets_force_expand)
|
imap <silent> <Plug>(neocomplcache_snippets_force_expand)
|
||||||
\ <Plug>(neosnippet_expand)
|
\ <Plug>(neosnippet_expand)
|
||||||
smap <silent> <Plug>(neocomplcache_snippets_force_expand)
|
smap <silent> <Plug>(neocomplcache_snippets_force_expand)
|
||||||
|
@ -33,47 +33,50 @@ elseif exists("b:current_syntax")
|
|||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
syn region SnippetPrevWord start=+'+ end=+'+ contained
|
syn region neosnippetPrevWord start=+'+ end=+'+ contained
|
||||||
syn region SnippetPrevWord start=+"+ end=+"+ contained
|
syn region neosnippetPrevWord start=+"+ end=+"+ contained
|
||||||
syn region SnippetEval start=+\\\@<!`+ end=+\\\@<!`+ contained
|
syn region neosnippetEval start=+\\\@<!`+ end=+\\\@<!`+ contained
|
||||||
syn match SnippetWord '^\s\+.*$' contains=
|
syn match neosnippetWord '^\s\+.*$' contains=
|
||||||
\SnippetEval,SnippetExpand,SnippetEscape,SnippetVariable
|
\neosnippetEval,neosnippetPlaceHolder,neosnippetEscape,neosnippetVariable
|
||||||
syn match SnippetExpand '\${\d\+\%(:.\{-}\)\?\\\@<!}' contained
|
syn match neosnippetPlaceHolder '\${\d\+\%(:.\{-}\)\?\\\@<!}'
|
||||||
syn match SnippetVariable '\$\d\+' contained
|
\ contained contains=neosnippetPlaceHolderComment
|
||||||
syn match SnippetComment '^#.*$'
|
syn match neosnippetVariable '\$\d\+' contained
|
||||||
syn match SnippetEscape '\\[`]' contained
|
syn match neosnippetComment '^#.*$'
|
||||||
|
syn match neosnippetEscape '\\[`]' contained
|
||||||
|
|
||||||
syn match SnippetKeyword '^\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\)' contained
|
syn match neosnippetKeyword '^\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\)' contained
|
||||||
syn keyword SnippetOption head word contained
|
syn keyword neosnippetOption head word contained
|
||||||
syn match SnippetPrevWords '^prev_word\s\+.*$' contains=SnippetPrevWord,SnippetKeyword
|
syn match neosnippetPrevWords '^prev_word\s\+.*$' contains=neosnippetPrevWord,neosnippetKeyword
|
||||||
syn match SnippetStatementName '^snippet\s.*$' contains=SnippetName,SnippetKeyword
|
syn match neosnippetStatementName '^snippet\s.*$' contains=neosnippetName,neosnippetKeyword
|
||||||
syn match SnippetName '\s\+.*$' contained
|
syn match neosnippetName '\s\+.*$' contained
|
||||||
syn match SnippetStatementAbbr '^abbr\s.*$' contains=SnippetAbbr,SnippetKeyword
|
syn match neosnippetStatementAbbr '^abbr\s.*$' contains=neosnippetAbbr,neosnippetKeyword
|
||||||
syn match SnippetAbbr '\s\+.*$' contained
|
syn match neosnippetAbbr '\s\+.*$' contained
|
||||||
syn match SnippetStatementRank '^rank\s.*$' contains=SnippetRank,SnippetKeyword
|
syn match neosnippetStatementRank '^rank\s.*$' contains=neosnippetRank,neosnippetKeyword
|
||||||
syn match SnippetRank '\s\+\d\+$' contained
|
syn match neosnippetRank '\s\+\d\+$' contained
|
||||||
syn match SnippetStatementInclude '^include\s.*$' contains=SnippetInclude,SnippetKeyword
|
syn match neosnippetStatementInclude '^include\s.*$' contains=neosnippetInclude,neosnippetKeyword
|
||||||
syn match SnippetInclude '\s\+.*$' contained
|
syn match neosnippetInclude '\s\+.*$' contained
|
||||||
syn match SnippetStatementDelete '^delete\s.*$' contains=SnippetDelete,SnippetKeyword
|
syn match neosnippetStatementDelete '^delete\s.*$' contains=neosnippetDelete,neosnippetKeyword
|
||||||
syn match SnippetDelete '\s\+.*$' contained
|
syn match neosnippetDelete '\s\+.*$' contained
|
||||||
syn match SnippetStatementAlias '^alias\s.*$' contains=SnippetAlias,SnippetKeyword
|
syn match neosnippetStatementAlias '^alias\s.*$' contains=neosnippetAlias,neosnippetKeyword
|
||||||
syn match SnippetAlias '\s\+.*$' contained
|
syn match neosnippetAlias '\s\+.*$' contained
|
||||||
syn match SnippetStatementOptions '^options\s.*$' contains=SnippetOption,SnippetKeyword
|
syn match neosnippetStatementOptions '^options\s.*$' contains=neosnippetOption,neosnippetKeyword
|
||||||
|
syn match neosnippetPlaceHolderComment '{\d\+:\zs#:.\{-}\ze\\\@<!}' contained
|
||||||
|
|
||||||
hi def link SnippetKeyword Statement
|
hi def link neosnippetKeyword Statement
|
||||||
hi def link SnippetPrevWord String
|
hi def link neosnippetPrevWord String
|
||||||
hi def link SnippetName Identifier
|
hi def link neosnippetName Identifier
|
||||||
hi def link SnippetAbbr Normal
|
hi def link neosnippetAbbr Normal
|
||||||
hi def link SnippetEval Type
|
hi def link neosnippetEval Type
|
||||||
hi def link SnippetWord String
|
hi def link neosnippetWord String
|
||||||
hi def link SnippetExpand Special
|
hi def link neosnippetPlaceHolder Special
|
||||||
hi def link SnippetVariable Special
|
hi def link neosnippetPlaceHolderComment Comment
|
||||||
hi def link SnippetComment Comment
|
hi def link neosnippetVariable Special
|
||||||
hi def link SnippetInclude PreProc
|
hi def link neosnippetComment Comment
|
||||||
hi def link SnippetDelete PreProc
|
hi def link neosnippetInclude PreProc
|
||||||
hi def link SnippetOption PreProc
|
hi def link neosnippetDelete PreProc
|
||||||
hi def link SnippetAlias Identifier
|
hi def link neosnippetOption PreProc
|
||||||
hi def link SnippetEscape Special
|
hi def link neosnippetAlias Identifier
|
||||||
|
hi def link neosnippetEscape Special
|
||||||
|
|
||||||
let b:current_syntax = "snippet"
|
let b:current_syntax = "snippet"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user