mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-10 12:31:50 +08:00
resign using recursively call
This commit is contained in:
269
zencoding.vim
269
zencoding.vim
@@ -1399,33 +1399,17 @@ EOF
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_toggleComment()
|
function! s:zen_toggleComment()
|
||||||
let pos = getpos('.')
|
let curpos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
while 1
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos = getpos('.')
|
||||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||||
if content[-2:] == '/>' && s:cursor_in_region(block)
|
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
||||||
let comment_region = s:search_region('<!--', '-->')
|
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||||
if !s:region_is_valid(comment_region) || !s:cursor_in_region(comment_region)
|
if content[-2:] == '/>' && s:point_in_region(curpos[1:2], block)
|
||||||
let content = '<!-- ' . s:get_content(block) . ' -->'
|
|
||||||
call s:change_content(block, content)
|
|
||||||
else
|
|
||||||
let content = s:get_content(comment_region)
|
|
||||||
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
|
|
||||||
call s:change_content(comment_region, content)
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
if tag_name[0] == '/'
|
|
||||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
|
||||||
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
|
||||||
else
|
|
||||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
|
||||||
endif
|
|
||||||
let block = [pos1, pos2]
|
|
||||||
if s:cursor_in_region(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
|
||||||
@@ -1433,122 +1417,167 @@ 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
|
||||||
|
if tag_name[0] == '/'
|
||||||
|
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')
|
||||||
|
else
|
||||||
|
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||||
|
endif
|
||||||
|
let block = [pos1, pos2]
|
||||||
|
if s:point_in_region(curpos[1:2], block)
|
||||||
|
let comment_region = s:search_region('<!--', '-->')
|
||||||
|
if !s:region_is_valid(comment_region) || !s:point_in_region(curpos[1:2], comment_region)
|
||||||
|
let content = '<!-- ' . s:get_content(block) . ' -->'
|
||||||
|
call s:change_content(block, content)
|
||||||
|
else
|
||||||
|
let content = s:get_content(block)
|
||||||
|
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
|
||||||
|
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
|
endwhile
|
||||||
call setpos('.', pos)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_splitJoinTag()
|
function! s:zen_splitJoinTag()
|
||||||
let pos = getpos('.')
|
let curpos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
while 1
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos = getpos('.')
|
||||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||||
if content[-2:] == '/>' && s:cursor_in_region(block)
|
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
||||||
let content = content[:-3] . "></" . tag_name . '>'
|
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||||
call s:change_content(block, content)
|
if content[-2:] == '/>' && s:cursor_in_region(block)
|
||||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
let content = content[:-3] . "></" . tag_name . '>'
|
||||||
else
|
|
||||||
if tag_name[0] == '/'
|
|
||||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
|
||||||
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
|
||||||
else
|
|
||||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
|
||||||
endif
|
|
||||||
let block = [pos1, pos2]
|
|
||||||
let content = s:get_content(block)
|
|
||||||
if s:cursor_in_region(block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
|
||||||
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
|
||||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
if tag_name[0] == '/'
|
||||||
try
|
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
||||||
call s:zen_splitJoinTag()
|
call setpos('.', [0, pos1[0], pos1[1], 0])
|
||||||
catch /E132/
|
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
||||||
call setpos('.', pos)
|
else
|
||||||
endtry
|
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||||
|
endif
|
||||||
|
let block = [pos1, pos2]
|
||||||
|
let content = s:get_content(block)
|
||||||
|
if s:point_in_region(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||||
|
let content = matchstr(content, mx)[:-2] . '/>'
|
||||||
|
call s:change_content(block, content)
|
||||||
|
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||||
|
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
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_removeTag()
|
function! s:zen_removeTag()
|
||||||
let pos = getpos('.')
|
let curpos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
while 1
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos = getpos('.')
|
||||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||||
if content[-2:] == '/>' && s:cursor_in_region(block)
|
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
||||||
call s:change_content(block, '')
|
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
if content[-2:] == '/>' && s:cursor_in_region(block)
|
||||||
else
|
|
||||||
if tag_name[0] == '/'
|
|
||||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
|
||||||
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
|
||||||
else
|
|
||||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
|
||||||
endif
|
|
||||||
let block = [pos1, pos2]
|
|
||||||
let content = s:get_content(block)
|
|
||||||
if s:cursor_in_region(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
|
||||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
if tag_name[0] == '/'
|
||||||
try
|
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
|
||||||
call s:zen_removeTag()
|
call setpos('.', [0, pos1[0], pos1[1], 0])
|
||||||
catch /E132/
|
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
||||||
call setpos('.', pos)
|
else
|
||||||
endtry
|
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||||
|
endif
|
||||||
|
let block = [pos1, pos2]
|
||||||
|
let content = s:get_content(block)
|
||||||
|
if s:point_in_region(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||||
|
call s:change_content(block, '')
|
||||||
|
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||||
|
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
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_balanceTag(flag)
|
function! s:zen_balanceTag(flag)
|
||||||
let pos = getpos('.')
|
let curpos = getpos('.')
|
||||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
while 1
|
||||||
let pos1 = searchpos(mx, 'bcnW')
|
let pos = getpos('.')
|
||||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9]*\)[^>]*>'
|
||||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
let pos1 = searchpos(mx, 'bcnW')
|
||||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||||
if !s:region_is_valid(block)
|
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9]*\).*$', '\1', '')
|
||||||
return
|
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||||
endif
|
if !s:region_is_valid(block)
|
||||||
if content[-2:] == '/>' && s:cursor_in_region(block)
|
return
|
||||||
call s:select_region(block)
|
|
||||||
else
|
|
||||||
if tag_name[0] == '/'
|
|
||||||
let tag_name = tag_name[1:]
|
|
||||||
let pos1 = searchpos('<' . tag_name . '[^a-zA-Z0-9]*[^>]*>', 'bcnW')
|
|
||||||
let mx = '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
|
||||||
endif
|
endif
|
||||||
if a:flag
|
if content[-2:] == '/>' && s:cursor_in_region(block)
|
||||||
let l = getline(pos1[0])
|
|
||||||
let content = matchstr(l[pos1[1]-1:], mx)
|
|
||||||
if pos1[1] + len(content) > len(l)
|
|
||||||
let pos1[0] += 1
|
|
||||||
else
|
|
||||||
let pos1[1] += len(content)
|
|
||||||
endif
|
|
||||||
let pos2 = searchpos('\(\n\|.\)</' . tag_name . '>', 'cnW')
|
|
||||||
else
|
|
||||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
|
||||||
endif
|
|
||||||
let block = [pos1, pos2]
|
|
||||||
let content = s:get_content(block)
|
|
||||||
if s:cursor_in_region(block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
|
||||||
call s:select_region(block)
|
call s:select_region(block)
|
||||||
|
return
|
||||||
else
|
else
|
||||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
if tag_name[0] == '/'
|
||||||
try
|
let tag_name = tag_name[1:]
|
||||||
call s:zen_balanceTag(a:flag)
|
let pos1 = searchpos('<' . tag_name . '[^a-zA-Z0-9]*[^>]*>', 'bcnW')
|
||||||
catch /E132/
|
let mx = '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||||
call setpos('.', pos)
|
endif
|
||||||
endtry
|
if a:flag
|
||||||
|
let l = getline(pos1[0])
|
||||||
|
let content = matchstr(l[pos1[1]-1:], mx)
|
||||||
|
if pos1[1] + len(content) > len(l)
|
||||||
|
let pos1[0] += 1
|
||||||
|
else
|
||||||
|
let pos1[1] += len(content)
|
||||||
|
endif
|
||||||
|
let pos2 = searchpos('\(\n\|.\)</' . tag_name . '>', 'cnW')
|
||||||
|
else
|
||||||
|
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||||
|
endif
|
||||||
|
let block = [pos1, pos2]
|
||||||
|
let content = s:get_content(block)
|
||||||
|
if s:point_in_region(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||||
|
call s:select_region(block)
|
||||||
|
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
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_mergeConfig(lhs, rhs)
|
function! s:zen_mergeConfig(lhs, rhs)
|
||||||
|
|||||||
Reference in New Issue
Block a user