Fix #199 add :NeoSnippetClearMarkers command
This commit is contained in:
parent
f657404c22
commit
38a24ec1db
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: commands.vim
|
" FILE: commands.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 21 Nov 2013.
|
" Last Modified: 25 Dec 2013.
|
||||||
" 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
|
||||||
@ -123,6 +123,49 @@ function! neosnippet#commands#_source(filename) "{{{
|
|||||||
call neosnippet#parser#_parse(neosnippet.snippets, a:filename)
|
call neosnippet#parser#_parse(neosnippet.snippets, a:filename)
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
|
function! neosnippet#commands#_clear_markers() "{{{
|
||||||
|
let expand_stack = neosnippet#variables#expand_stack()
|
||||||
|
|
||||||
|
" Get patterns and count.
|
||||||
|
if empty(expand_stack)
|
||||||
|
\ || neosnippet#variables#current_neosnippet().trigger
|
||||||
|
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 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
|
||||||
|
stopinsert
|
||||||
|
endif
|
||||||
|
|
||||||
|
call setpos('.', pos)
|
||||||
|
endtry
|
||||||
|
endfunction"}}}
|
||||||
|
|
||||||
" Complete helpers.
|
" Complete helpers.
|
||||||
function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) "{{{
|
function! neosnippet#commands#_edit_complete(arglead, cmdline, cursorpos) "{{{
|
||||||
return filter(s:edit_options +
|
return filter(s:edit_options +
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: view.vim
|
" FILE: view.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 22 Nov 2013.
|
" Last Modified: 25 Dec 2013.
|
||||||
" 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
|
||||||
@ -142,19 +142,20 @@ function! neosnippet#view#_jump(cur_text, col) "{{{
|
|||||||
|
|
||||||
let expand_info = expand_stack[-1]
|
let expand_info = expand_stack[-1]
|
||||||
" Search patterns.
|
" Search patterns.
|
||||||
let [begin, end] = s:get_snippet_range(
|
let [begin, end] = neosnippet#view#_get_snippet_range(
|
||||||
\ expand_info.begin_line,
|
\ expand_info.begin_line,
|
||||||
\ expand_info.begin_patterns,
|
\ expand_info.begin_patterns,
|
||||||
\ expand_info.end_line,
|
\ expand_info.end_line,
|
||||||
\ expand_info.end_patterns)
|
\ expand_info.end_patterns)
|
||||||
if s:search_snippet_range(begin, end, expand_info.holder_cnt)
|
if neosnippet#view#_search_snippet_range(
|
||||||
|
\ begin, end, expand_info.holder_cnt)
|
||||||
" Next count.
|
" Next count.
|
||||||
let expand_info.holder_cnt += 1
|
let expand_info.holder_cnt += 1
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Search placeholder 0.
|
" Search placeholder 0.
|
||||||
if s:search_snippet_range(begin, end, 0)
|
if neosnippet#view#_search_snippet_range(begin, end, 0)
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -174,41 +175,11 @@ function! neosnippet#view#_on_insert_leave() "{{{
|
|||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let expand_info = expand_stack[-1]
|
if expand_stack[-1].begin_line != expand_stack[-1].end_line
|
||||||
|
|
||||||
if expand_info.begin_line != expand_info.end_line
|
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Search patterns.
|
call neosnippet#commands#_clear_markers()
|
||||||
let [begin, end] = s:get_snippet_range(
|
|
||||||
\ expand_info.begin_line,
|
|
||||||
\ expand_info.begin_patterns,
|
|
||||||
\ expand_info.end_line,
|
|
||||||
\ expand_info.end_patterns)
|
|
||||||
|
|
||||||
let pos = getpos('.')
|
|
||||||
|
|
||||||
" Found snippet.
|
|
||||||
let found = 0
|
|
||||||
try
|
|
||||||
while s: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 s:search_snippet_range(begin, end, 0)
|
|
||||||
let found = 1
|
|
||||||
endif
|
|
||||||
finally
|
|
||||||
if found
|
|
||||||
stopinsert
|
|
||||||
endif
|
|
||||||
|
|
||||||
call setpos('.', pos)
|
|
||||||
endtry
|
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:indent_snippet(begin, end) "{{{
|
function! s:indent_snippet(begin, end) "{{{
|
||||||
@ -253,7 +224,7 @@ function! s:indent_snippet(begin, end) "{{{
|
|||||||
endtry
|
endtry
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
|
|
||||||
function! s:get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) "{{{
|
function! neosnippet#view#_get_snippet_range(begin_line, begin_patterns, end_line, end_patterns) "{{{
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
|
|
||||||
call cursor(a:begin_line, 0)
|
call cursor(a:begin_line, 0)
|
||||||
@ -287,7 +258,7 @@ function! s:get_snippet_range(begin_line, begin_patterns, end_line, end_patterns
|
|||||||
call setpos('.', pos)
|
call setpos('.', pos)
|
||||||
return [begin, end]
|
return [begin, end]
|
||||||
endfunction"}}}
|
endfunction"}}}
|
||||||
function! s:search_snippet_range(start, end, cnt, ...) "{{{
|
function! neosnippet#view#_search_snippet_range(start, end, cnt, ...) "{{{
|
||||||
let is_select = get(a:000, 0, 1)
|
let is_select = get(a:000, 0, 1)
|
||||||
call s:substitute_placeholder_marker(a:start, a:end, a:cnt)
|
call s:substitute_placeholder_marker(a:start, a:end, a:cnt)
|
||||||
|
|
||||||
|
@ -71,7 +71,6 @@ COMMANDS *neosnippet-commands*
|
|||||||
|
|
||||||
*:NeoSnippetMakeCache*
|
*:NeoSnippetMakeCache*
|
||||||
:NeoSnippetMakeCache [filetype]
|
:NeoSnippetMakeCache [filetype]
|
||||||
|
|
||||||
Creates a cache for the snippets of the given [filetype]. It
|
Creates a cache for the snippets of the given [filetype]. It
|
||||||
automatically chooses the current buffer's file type unless you
|
automatically chooses the current buffer's file type unless you
|
||||||
specify another one by [filetype].
|
specify another one by [filetype].
|
||||||
@ -120,10 +119,15 @@ COMMANDS *neosnippet-commands*
|
|||||||
|
|
||||||
*:NeoSnippetSource*
|
*:NeoSnippetSource*
|
||||||
:NeoSnippetSource [filename]
|
:NeoSnippetSource [filename]
|
||||||
|
|
||||||
Load the snippets of a [filetype].
|
Load the snippets of a [filetype].
|
||||||
Note: The loaded snippets are enabled in current buffer only.
|
Note: The loaded snippets are enabled in current buffer only.
|
||||||
|
|
||||||
|
*:NeoSnippetClearMarkers*
|
||||||
|
:NeoSnippetClearMarkers
|
||||||
|
Clear current markers.
|
||||||
|
Note: If you delete markers, you cannot jump to next
|
||||||
|
placeholder.
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
VARIABLES *neosnippet-variables*
|
VARIABLES *neosnippet-variables*
|
||||||
|
|
||||||
@ -725,5 +729,9 @@ Q: I want to add snippets dynamically.
|
|||||||
|
|
||||||
A: You can use |:NeoSnippetSource| for it.
|
A: You can use |:NeoSnippetSource| for it.
|
||||||
|
|
||||||
|
Q: I want to delete markers in multiline snippet.
|
||||||
|
|
||||||
|
A: You can use |:NeoSnippetClearMarkers| command.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
vim:tw=78:ts=8:ft=help:norl:noet:fen:noet:
|
vim:tw=78:ts=8:ft=help:norl:noet:fen:noet:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" FILE: neosnippet.vim
|
" FILE: neosnippet.vim
|
||||||
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
|
||||||
" Last Modified: 21 Nov 2013.
|
" Last Modified: 25 Dec 2013.
|
||||||
" 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
|
||||||
@ -85,6 +85,9 @@ command! -nargs=? -complete=customlist,neosnippet#commands#_filetype_complete
|
|||||||
command! -nargs=1 -complete=file
|
command! -nargs=1 -complete=file
|
||||||
\ NeoSnippetSource
|
\ NeoSnippetSource
|
||||||
\ call neosnippet#commands#_source(<q-args>)
|
\ call neosnippet#commands#_source(<q-args>)
|
||||||
|
|
||||||
|
command! NeoSnippetClearMarkers
|
||||||
|
\ call neosnippet#commands#_clear_markers()
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
let g:loaded_neosnippet = 1
|
let g:loaded_neosnippet = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user