forked from VimPlug/emmet-vim
fix toggleComment. close #55
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"=============================================================================
|
"=============================================================================
|
||||||
" zencoding.vim
|
" zencoding.vim
|
||||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||||
" Last Change: 17-Jan-2012.
|
" Last Change: 26-Jan-2012.
|
||||||
|
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
@@ -939,6 +939,16 @@ function! zencoding#toggleComment()
|
|||||||
let pos2 = searchpairpos('<'. tag_name[1:] . '>', '', '</' . tag_name[1:] . '>', 'bnW')
|
let pos2 = searchpairpos('<'. tag_name[1:] . '>', '', '</' . tag_name[1:] . '>', 'bnW')
|
||||||
let pos1 = searchpos('>', 'cneW')
|
let pos1 = searchpos('>', 'cneW')
|
||||||
let block = [pos2, pos1]
|
let block = [pos2, pos1]
|
||||||
|
elseif tag_name =~ '/$'
|
||||||
|
if !s:point_in_region(orgpos[1:2], block)
|
||||||
|
" it's broken tree
|
||||||
|
call setpos('.', orgpos)
|
||||||
|
let block = s:search_region('>', '<')
|
||||||
|
let content = '><!-- ' . s:get_content(block)[1:-2] . ' --><'
|
||||||
|
call s:change_content(block, content)
|
||||||
|
silent! call setpos('.', orgpos)
|
||||||
|
return
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
call setpos('.', [0, pos2[0], pos2[1], 0])
|
call setpos('.', [0, pos2[0], pos2[1], 0])
|
||||||
let pos2 = searchpairpos('<'. tag_name . '>', '', '</' . tag_name . '>', 'nW')
|
let pos2 = searchpairpos('<'. tag_name . '>', '', '</' . tag_name . '>', 'nW')
|
||||||
@@ -1265,32 +1275,32 @@ endfunction
|
|||||||
" baz:end
|
" baz:end
|
||||||
" --------------------
|
" --------------------
|
||||||
function! s:change_content(region, content)
|
function! s:change_content(region, content)
|
||||||
let newlines = split(a:content, '\n')
|
let newlines = split(a:content, '\n', 1)
|
||||||
let oldlines = getline(a:region[0][0], a:region[1][0])
|
let oldlines = getline(a:region[0][0], a:region[1][0])
|
||||||
call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
|
call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
|
||||||
silent! exe "delete ".(a:region[1][0] - a:region[0][0])
|
silent! exe "delete ".(a:region[1][0] - a:region[0][0])
|
||||||
if len(newlines) == 0
|
if len(newlines) == 0
|
||||||
let tmp = ''
|
let tmp = ''
|
||||||
if a:region[0][1] > 1
|
if a:region[0][1] >= 1
|
||||||
let tmp = oldlines[0][:a:region[0][1]-2]
|
let tmp = oldlines[0][:a:region[0][1]-2]
|
||||||
endif
|
endif
|
||||||
if a:region[1][1] > 1
|
if a:region[1][1] >= 1
|
||||||
let tmp .= oldlines[-1][a:region[1][1]:]
|
let tmp .= oldlines[-1][a:region[1][1]:]
|
||||||
endif
|
endif
|
||||||
call setline(line('.'), tmp)
|
call setline(line('.'), tmp)
|
||||||
elseif len(newlines) == 1
|
elseif len(newlines) == 1
|
||||||
if a:region[0][1] > 1
|
if a:region[0][1] >= 1
|
||||||
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
|
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
|
||||||
endif
|
endif
|
||||||
if a:region[1][1] > 1
|
if a:region[1][1] >= 1
|
||||||
let newlines[0] .= oldlines[-1][a:region[1][1]:]
|
let newlines[0] .= oldlines[-1][a:region[1][1]:]
|
||||||
endif
|
endif
|
||||||
call setline(line('.'), newlines[0])
|
call setline(line('.'), newlines[0])
|
||||||
else
|
else
|
||||||
if a:region[0][1] > 1
|
if a:region[0][1] >= 1
|
||||||
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
|
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
|
||||||
endif
|
endif
|
||||||
if a:region[1][1] > 1
|
if a:region[1][1] >= 1
|
||||||
let newlines[-1] .= oldlines[-1][a:region[1][1]:]
|
let newlines[-1] .= oldlines[-1][a:region[1][1]:]
|
||||||
endif
|
endif
|
||||||
call setline(line('.'), newlines[0])
|
call setline(line('.'), newlines[0])
|
||||||
@@ -1335,7 +1345,7 @@ endfunction
|
|||||||
" search_region : make region from pattern which is composing start/end
|
" search_region : make region from pattern which is composing start/end
|
||||||
" this function return array of position
|
" this function return array of position
|
||||||
function! s:search_region(start, end)
|
function! s:search_region(start, end)
|
||||||
return [searchpairpos(a:start, '', a:end, 'bcnW'), searchpairpos(a:start, '', a:end, 'nW')]
|
return [searchpairpos(a:start, '', a:end, 'bcnW'), searchpairpos(a:start, '\%#', a:end, 'nW')]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" get_content : get content in region
|
" get_content : get content in region
|
||||||
|
|||||||
Reference in New Issue
Block a user