mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-06 18:54:27 +08:00
balanceTag.
This commit is contained in:
@@ -511,83 +511,8 @@ function! zencoding#removeTag()
|
||||
endfunction
|
||||
|
||||
function! zencoding#balanceTag(flag) range
|
||||
let vblock = zencoding#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
while 1
|
||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
|
||||
let pos1 = searchpos(mx, (a:flag == -2 ? 'nW' : 'bcnW'))
|
||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9:_\-]*\).*$', '\1', '')
|
||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||
if !zencoding#util#regionIsValid(block)
|
||||
break
|
||||
endif
|
||||
if content[-2:] == '/>' && zencoding#util#pointInRegion(curpos[1:2], block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
else
|
||||
if tag_name[0] == '/'
|
||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', a:flag == -2 ? 'nW' : 'bcnW')
|
||||
if pos1[0] == 0
|
||||
break
|
||||
endif
|
||||
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 !zencoding#util#regionIsValid(block)
|
||||
break
|
||||
endif
|
||||
let content = zencoding#util#getContent(block)
|
||||
if a:flag == -2
|
||||
let check = zencoding#util#regionInRegion(vblock, block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||
else
|
||||
let check = zencoding#util#pointInRegion(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||
endif
|
||||
if check
|
||||
if a:flag < 0
|
||||
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]
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
else
|
||||
if zencoding#util#regionIsValid(block)
|
||||
if a:flag == -2
|
||||
if setpos('.', [0, block[0][0]+1, block[0][1], 0]) == -1
|
||||
break
|
||||
endif
|
||||
else
|
||||
if setpos('.', [0, block[0][0]-1, block[0][1], 0]) == -1
|
||||
break
|
||||
endif
|
||||
endif
|
||||
else
|
||||
break
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe "normal! gv"
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
endif
|
||||
let rtype = len(globpath(&rtp, 'autoload/zencoding/lang/'.&ft.'.vim')) ? &ft : 'html'
|
||||
return zencoding#lang#{rtype}#balanceTag(a:flag)
|
||||
endfunction
|
||||
|
||||
function! zencoding#anchorizeURL(flag)
|
||||
|
||||
@@ -87,3 +87,41 @@ function! zencoding#lang#css#toggleComment()
|
||||
call setline('.', line)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#balanceTag(flag) range
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
let block = zencoding#util#getVisualBlock()
|
||||
if !zencoding#util#regionIsValid(block)
|
||||
if a:flag > 0
|
||||
let block = zencoding#util#searchRegion('^', ';')
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
else
|
||||
if a:flag > 0
|
||||
let content = zencoding#util#getContent(block)
|
||||
if content !~ '^{.*}$'
|
||||
let block = zencoding#util#searchRegion('{', '}')
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
else
|
||||
let pos = searchpos('.*;', 'nW')
|
||||
if pos[0] != 0
|
||||
call setpos('.', [0, pos[0], pos[1], 0])
|
||||
let block = zencoding#util#searchRegion('^', ';')
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe "normal! gv"
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -123,3 +123,6 @@ function! zencoding#lang#haml#toggleComment()
|
||||
call setline('.', space . '-# ' . line[len(space):])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#balanceTag(flag) range
|
||||
endfunction
|
||||
|
||||
@@ -493,3 +493,83 @@ function! zencoding#lang#html#toggleComment()
|
||||
endif
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#balanceTag(flag) range
|
||||
let vblock = zencoding#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
while 1
|
||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
|
||||
let pos1 = searchpos(mx, (a:flag == -2 ? 'nW' : 'bcnW'))
|
||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9:_\-]*\).*$', '\1', '')
|
||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||
if !zencoding#util#regionIsValid(block)
|
||||
break
|
||||
endif
|
||||
if content[-2:] == '/>' && zencoding#util#pointInRegion(curpos[1:2], block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
else
|
||||
if tag_name[0] == '/'
|
||||
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', a:flag == -2 ? 'nW' : 'bcnW')
|
||||
if pos1[0] == 0
|
||||
break
|
||||
endif
|
||||
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 !zencoding#util#regionIsValid(block)
|
||||
break
|
||||
endif
|
||||
let content = zencoding#util#getContent(block)
|
||||
if a:flag == -2
|
||||
let check = zencoding#util#regionInRegion(vblock, block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||
else
|
||||
let check = zencoding#util#pointInRegion(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||
endif
|
||||
if check
|
||||
if a:flag < 0
|
||||
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]
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
else
|
||||
if zencoding#util#regionIsValid(block)
|
||||
if a:flag == -2
|
||||
if setpos('.', [0, block[0][0]+1, block[0][1], 0]) == -1
|
||||
break
|
||||
endif
|
||||
else
|
||||
if setpos('.', [0, block[0][0]-1, block[0][1], 0]) == -1
|
||||
break
|
||||
endif
|
||||
endif
|
||||
else
|
||||
break
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe "normal! gv"
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -113,3 +113,6 @@ function! zencoding#lang#slim#toggleComment()
|
||||
call setline('.', space . '/' . line[len(space):])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#balanceTag(flag) range
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user