forked from VimPlug/emmet-vim
resign using recursively call
This commit is contained in:
@@ -1399,15 +1399,17 @@ EOF
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_toggleComment()
|
function! s:zen_toggleComment()
|
||||||
|
let curpos = getpos('.')
|
||||||
|
while 1
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
||||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||||
if content[-2:] == '/>' && s:cursor_in_region(block)
|
if content[-2:] == '/>' && s:point_in_region(curpos[1:2], block)
|
||||||
let comment_region = s:search_region('<!--', '-->')
|
let comment_region = s:search_region('<!--', '-->')
|
||||||
if !s:region_is_valid(comment_region) || !s:cursor_in_region(comment_region)
|
if !s:region_is_valid(comment_region) || !s:point_in_region(curpos[1:2], comment_region)
|
||||||
let content = '<!-- ' . s:get_content(block) . ' -->'
|
let content = '<!-- ' . s:get_content(block) . ' -->'
|
||||||
call s:change_content(block, content)
|
call s:change_content(block, content)
|
||||||
else
|
else
|
||||||
@@ -1415,30 +1417,42 @@ function! s:zen_toggleComment()
|
|||||||
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
|
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
|
||||||
call s:change_content(comment_region, content)
|
call s:change_content(comment_region, content)
|
||||||
endif
|
endif
|
||||||
|
return
|
||||||
else
|
else
|
||||||
if tag_name[0] == '/'
|
if tag_name[0] == '/'
|
||||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
||||||
|
call setpos('.', [0, pos1[0], pos1[1], 0])
|
||||||
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
||||||
else
|
else
|
||||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||||
endif
|
endif
|
||||||
let block = [pos1, pos2]
|
let block = [pos1, pos2]
|
||||||
if s:cursor_in_region(block)
|
if s:point_in_region(curpos[1:2], block)
|
||||||
let comment_region = s:search_region('<!--', '-->')
|
let comment_region = s:search_region('<!--', '-->')
|
||||||
if !s:region_is_valid(comment_region) || !s:cursor_in_region(comment_region)
|
if !s:region_is_valid(comment_region) || !s:point_in_region(curpos[1:2], comment_region)
|
||||||
let content = '<!-- ' . s:get_content(block) . ' -->'
|
let content = '<!-- ' . s:get_content(block) . ' -->'
|
||||||
call s:change_content(block, content)
|
call s:change_content(block, content)
|
||||||
else
|
else
|
||||||
let content = s:get_content(comment_region)
|
let content = s:get_content(block)
|
||||||
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
|
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
|
||||||
call s:change_content(comment_region, content)
|
call s:change_content(block, content)
|
||||||
|
endif
|
||||||
|
return
|
||||||
|
else
|
||||||
|
if block[0][0] > 0
|
||||||
|
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
||||||
|
else
|
||||||
|
call setpos('.', curpos)
|
||||||
|
return
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
call setpos('.', pos)
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_splitJoinTag()
|
function! s:zen_splitJoinTag()
|
||||||
|
let curpos = getpos('.')
|
||||||
|
while 1
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
@@ -1449,31 +1463,37 @@ function! s:zen_splitJoinTag()
|
|||||||
let content = content[:-3] . "></" . tag_name . '>'
|
let content = content[:-3] . "></" . tag_name . '>'
|
||||||
call s:change_content(block, content)
|
call s:change_content(block, content)
|
||||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||||
|
return
|
||||||
else
|
else
|
||||||
if tag_name[0] == '/'
|
if tag_name[0] == '/'
|
||||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
||||||
|
call setpos('.', [0, pos1[0], pos1[1], 0])
|
||||||
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
||||||
else
|
else
|
||||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||||
endif
|
endif
|
||||||
let block = [pos1, pos2]
|
let block = [pos1, pos2]
|
||||||
let content = s:get_content(block)
|
let content = s:get_content(block)
|
||||||
if s:cursor_in_region(block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
if s:point_in_region(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||||
let content = matchstr(content, mx)[:-2] . '/>'
|
let content = matchstr(content, mx)[:-2] . '/>'
|
||||||
call s:change_content(block, content)
|
call s:change_content(block, content)
|
||||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||||
|
return
|
||||||
else
|
else
|
||||||
|
if block[0][0] > 0
|
||||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
||||||
try
|
else
|
||||||
call s:zen_splitJoinTag()
|
call setpos('.', curpos)
|
||||||
catch /E132/
|
return
|
||||||
call setpos('.', pos)
|
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_removeTag()
|
function! s:zen_removeTag()
|
||||||
|
let curpos = getpos('.')
|
||||||
|
while 1
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
@@ -1483,30 +1503,36 @@ function! s:zen_removeTag()
|
|||||||
if content[-2:] == '/>' && s:cursor_in_region(block)
|
if content[-2:] == '/>' && s:cursor_in_region(block)
|
||||||
call s:change_content(block, '')
|
call s:change_content(block, '')
|
||||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||||
|
return
|
||||||
else
|
else
|
||||||
if tag_name[0] == '/'
|
if tag_name[0] == '/'
|
||||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
||||||
|
call setpos('.', [0, pos1[0], pos1[1], 0])
|
||||||
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
||||||
else
|
else
|
||||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||||
endif
|
endif
|
||||||
let block = [pos1, pos2]
|
let block = [pos1, pos2]
|
||||||
let content = s:get_content(block)
|
let content = s:get_content(block)
|
||||||
if s:cursor_in_region(block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
if s:point_in_region(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||||
call s:change_content(block, '')
|
call s:change_content(block, '')
|
||||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||||
|
return
|
||||||
else
|
else
|
||||||
|
if block[0][0] > 0
|
||||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
||||||
try
|
else
|
||||||
call s:zen_removeTag()
|
call setpos('.', curpos)
|
||||||
catch /E132/
|
return
|
||||||
call setpos('.', pos)
|
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_balanceTag(flag)
|
function! s:zen_balanceTag(flag)
|
||||||
|
let curpos = getpos('.')
|
||||||
|
while 1
|
||||||
let pos = getpos('.')
|
let pos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
@@ -1518,6 +1544,7 @@ function! s:zen_balanceTag(flag)
|
|||||||
endif
|
endif
|
||||||
if content[-2:] == '/>' && s:cursor_in_region(block)
|
if content[-2:] == '/>' && s:cursor_in_region(block)
|
||||||
call s:select_region(block)
|
call s:select_region(block)
|
||||||
|
return
|
||||||
else
|
else
|
||||||
if tag_name[0] == '/'
|
if tag_name[0] == '/'
|
||||||
let tag_name = tag_name[1:]
|
let tag_name = tag_name[1:]
|
||||||
@@ -1538,17 +1565,19 @@ function! s:zen_balanceTag(flag)
|
|||||||
endif
|
endif
|
||||||
let block = [pos1, pos2]
|
let block = [pos1, pos2]
|
||||||
let content = s:get_content(block)
|
let content = s:get_content(block)
|
||||||
if s:cursor_in_region(block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
if s:point_in_region(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||||
call s:select_region(block)
|
call s:select_region(block)
|
||||||
|
return
|
||||||
else
|
else
|
||||||
|
if block[0][0] > 0
|
||||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
||||||
try
|
else
|
||||||
call s:zen_balanceTag(a:flag)
|
call setpos('.', curpos)
|
||||||
catch /E132/
|
return
|
||||||
call setpos('.', pos)
|
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_mergeConfig(lhs, rhs)
|
function! s:zen_mergeConfig(lhs, rhs)
|
||||||
|
|||||||
Reference in New Issue
Block a user