Add g:neosnippet#enable_auto_clear_markers option

This commit is contained in:
Shougo Matsushita 2015-12-19 10:00:57 +09:00
parent de5a7e284d
commit 12ebafeb81
6 changed files with 58 additions and 45 deletions

View File

@ -43,6 +43,8 @@ call neosnippet#util#set_default(
\ 'g:neosnippet#enable_conceal_markers', 1)
call neosnippet#util#set_default(
\ 'g:neosnippet#enable_complete_done', 0)
call neosnippet#util#set_default(
\ 'g:neosnippet#enable_auto_clear_markers', 1)
"}}}
function! neosnippet#expandable_or_jumpable() "{{{

View File

@ -142,42 +142,7 @@ function! neosnippet#commands#_clear_markers() "{{{
return
endif
let expand_info = expand_stack[-1]
" Search patterns.
let [begin, end] = neosnippet#view#_get_snippet_range(
\ expand_info.begin_line,
\ expand_info.begin_patterns,
\ expand_info.end_line,
\ expand_info.end_patterns)
let mode = mode()
let pos = getpos('.')
" Found snippet.
let found = 0
try
while neosnippet#view#_search_snippet_range(
\ begin, end, expand_info.holder_cnt, 0)
" Next count.
let expand_info.holder_cnt += 1
let found = 1
endwhile
" Search placeholder 0.
if neosnippet#view#_search_snippet_range(begin, end, 0)
let found = 1
endif
finally
if found && mode !=# 'i'
stopinsert
endif
call setpos('.', pos)
call neosnippet#variables#clear_expand_stack()
endtry
call neosnippet#view#_clear_markers(expand_info[-1])
endfunction"}}}
" Complete helpers.

View File

@ -97,7 +97,7 @@ function! neosnippet#handlers#_cursor_moved() "{{{
let expand_info = expand_stack[-1]
if expand_info.begin_line == expand_info.end_line
\ && line('.') != expand_info.begin_line
call neosnippet#commands#_clear_markers()
call neosnippet#view#_clear_markers(expand_info)
endif
endfunction"}}}
@ -105,15 +105,14 @@ function! neosnippet#handlers#_all_clear_markers() "{{{
let pos = getpos('.')
try
" Search out of range.
while neosnippet#view#_search_outof_range(col('.'))
while !empty(neosnippet#variables#expand_stack())
call neosnippet#view#_clear_markers(
\ neosnippet#variables#expand_stack()[-1])
endwhile
finally
stopinsert
call setpos('.', pos)
call neosnippet#variables#clear_expand_stack()
endtry
endfunction"}}}

View File

@ -57,12 +57,15 @@ function! s:initialize_others() "{{{
\ call neosnippet#variables#set_snippets({})
autocmd BufEnter *
\ call neosnippet#mappings#_clear_select_mode_mappings()
autocmd CursorMoved,CursorMovedI *
\ call neosnippet#handlers#_cursor_moved()
autocmd BufWritePre *
\ call neosnippet#handlers#_all_clear_markers()
augroup END"}}}
if g:neosnippet#enable_auto_clear_markers
autocmd neosnippet CursorMoved,CursorMovedI *
\ call neosnippet#handlers#_cursor_moved()
autocmd neosnippet BufWritePre *
\ call neosnippet#handlers#_all_clear_markers()
endif
if exists('v:completed_item')
autocmd neosnippet CompleteDone *
\ call neosnippet#handlers#_complete_done()

View File

@ -297,6 +297,42 @@ function! neosnippet#view#_search_outof_range(col) "{{{
" Not found.
return 0
endfunction"}}}
function! neosnippet#view#_clear_markers(expand_info) "{{{
" Search patterns.
let [begin, end] = neosnippet#view#_get_snippet_range(
\ a:expand_info.begin_line,
\ a:expand_info.begin_patterns,
\ a:expand_info.end_line,
\ a:expand_info.end_patterns)
let mode = mode()
let pos = getpos('.')
" Found snippet.
let found = 0
try
while neosnippet#view#_search_snippet_range(
\ begin, end, a:expand_info.holder_cnt, 0)
" Next count.
let a:expand_info.holder_cnt += 1
let found = 1
endwhile
" Search placeholder 0.
if neosnippet#view#_search_snippet_range(begin, end, 0)
let found = 1
endif
finally
if found && mode !=# 'i'
stopinsert
endif
call setpos('.', pos)
call neosnippet#variables#pop_expand_stack()
endtry
endfunction"}}}
function! s:expand_placeholder(start, end, holder_cnt, line, ...) "{{{
let is_select = get(a:000, 0, 1)

View File

@ -232,6 +232,14 @@ g:neosnippet#enable_complete_done
The default value is 0.
*g:neosnippet#enable_auto_clear_markers*
g:neosnippet#enable_auto_clear_markers
If this variable is not 0, neosnippet will clear the markers
in the buffer when |BufWritePost|, |CursorMoved| and
|CursorMovedI| autocmd.
The default value is 1.
*g:neosnippet#scope_aliases*
g:neosnippet#scope_aliases
It is a dictionary that associating certain filetypes with