mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-08 11:34:46 +08:00
expandos
This commit is contained in:
@@ -681,9 +681,9 @@ let s:zen_settings = {
|
|||||||
\ 'optgroup': 'optgroup>option',
|
\ 'optgroup': 'optgroup>option',
|
||||||
\ 'optg': 'optgroup>option'
|
\ 'optg': 'optgroup>option'
|
||||||
\ },
|
\ },
|
||||||
\ 'empty_elements': ['area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param', 'embed', 'keygen', 'command'],
|
\ 'empty_elements': 'area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,keygen,command',
|
||||||
\ 'block_elements': 'address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,link,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul,h1,h2,h3,h4,h5,h6',
|
\ 'block_elements': 'address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,link,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul,h1,h2,h3,h4,h5,h6',
|
||||||
\ 'inline_elements': 'a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var'
|
\ 'inline_elements': 'a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var',
|
||||||
\ },
|
\ },
|
||||||
\ 'xsl': {
|
\ 'xsl': {
|
||||||
\ 'default_attributes': {
|
\ 'default_attributes': {
|
||||||
@@ -723,13 +723,21 @@ let s:zen_settings = {
|
|||||||
\ }
|
\ }
|
||||||
\}
|
\}
|
||||||
|
|
||||||
|
function! s:zen_expandos(key, type)
|
||||||
|
if has_key(s:zen_settings[a:type]['expandos'], a:key)
|
||||||
|
return s:zen_settings[a:type]['expandos'][a:key]
|
||||||
|
else
|
||||||
|
return a:key
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:zen_parseIntoTree(abbr, type)
|
function! s:zen_parseIntoTree(abbr, type)
|
||||||
let abbr = a:abbr
|
let abbr = a:abbr
|
||||||
let type = a:type
|
let type = a:type
|
||||||
if len(type) == 0 | let type = 'html' | endif
|
if len(type) == 0 | let type = 'html' | endif
|
||||||
|
|
||||||
" TODO : expandos
|
" TODO : expandos
|
||||||
"let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)\+$', '\=zen_settings[type][''expandos''][submatch(1)]', 'i')
|
let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)\+$', '\=s:zen_expandos(submatch(1), type)', 'i')
|
||||||
|
|
||||||
let mx = '\([\+>]\)\{-}\([a-z][a-z0-9:\!\-]*\)\(#[0-9A-Za-z_\-\$]\+\)\{0,1}\(\%(\.[0-9A-Za-z_\-\$]\+\)*\)\%(\*\([0-9]\+\)\)\{0,1}'
|
let mx = '\([\+>]\)\{-}\([a-z][a-z0-9:\!\-]*\)\(#[0-9A-Za-z_\-\$]\+\)\{0,1}\(\%(\.[0-9A-Za-z_\-\$]\+\)*\)\%(\*\([0-9]\+\)\)\{0,1}'
|
||||||
let last = {}
|
let last = {}
|
||||||
@@ -746,11 +754,28 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
if multiplier <= 0
|
if multiplier <= 0
|
||||||
let multiplier = 1
|
let multiplier = 1
|
||||||
endif
|
endif
|
||||||
|
if has_key(s:zen_settings[type]['aliases'], tag_name)
|
||||||
|
let tag_name = s:zen_settings[type]['aliases'][tag_name]
|
||||||
|
endif
|
||||||
let current = { 'name': '', 'attr':[], 'child': [], 'snippet': '', 'multiplier': 1 }
|
let current = { 'name': '', 'attr':[], 'child': [], 'snippet': '', 'multiplier': 1 }
|
||||||
if has_key(s:zen_settings[type]['snippets'], tag_name)
|
if has_key(s:zen_settings[type]['snippets'], tag_name)
|
||||||
let current['snippet'] = s:zen_settings[type]['snippets'][tag_name]
|
let current['snippet'] = s:zen_settings[type]['snippets'][tag_name]
|
||||||
else
|
else
|
||||||
let current['name'] = tag_name
|
let current['name'] = tag_name
|
||||||
|
if has_key(s:zen_settings[type]['default_attributes'], tag_name)
|
||||||
|
if type(s:zen_settings[type]['default_attributes'][tag_name]) == 4
|
||||||
|
let a = s:zen_settings[type]['default_attributes'][tag_name]
|
||||||
|
for k in keys(a)
|
||||||
|
call add(current['attr'], {'name': k, 'value': a[k]})
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
for a in s:zen_settings[type]['default_attributes'][tag_name]
|
||||||
|
for k in keys(a)
|
||||||
|
call add(current['attr'], {'name': k, 'value': a[k]})
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
if len(id)
|
if len(id)
|
||||||
call add(current['attr'], {'name': 'id', 'value': id[1:]})
|
call add(current['attr'], {'name': 'id', 'value': id[1:]})
|
||||||
@@ -812,10 +837,14 @@ function! s:zen_toString(...)
|
|||||||
let inner = substitute(inner, "\t$", "", 'g')
|
let inner = substitute(inner, "\t$", "", 'g')
|
||||||
let str .= ">\n\t" . inner . "</" . current['name'] . ">\n"
|
let str .= ">\n\t" . inner . "</" . current['name'] . ">\n"
|
||||||
else
|
else
|
||||||
if match(s:zen_settings[type]['empty_elements'], '^'.current['name'].'$') >= 0
|
if stridx(','.s:zen_settings[type]['empty_elements'].',', ','.current['name'].',') != -1
|
||||||
let str .= " />\n"
|
let str .= " />\n"
|
||||||
else
|
else
|
||||||
let str .= "></" . current['name'] . ">\n"
|
if stridx(','.s:zen_settings[type]['block_elements'].',', ','.current['name'].',') != -1 && len(current['child'])
|
||||||
|
let str .= ">\n</" . current['name'] . ">\n"
|
||||||
|
else
|
||||||
|
let str .= "></" . current['name'] . ">\n"
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
@@ -837,26 +866,31 @@ endfunction
|
|||||||
function! s:zen_expand()
|
function! s:zen_expand()
|
||||||
let line = getline('.')[:col('.')]
|
let line = getline('.')[:col('.')]
|
||||||
let line = matchstr(line, '\(\S*\)$')
|
let line = matchstr(line, '\(\S*\)$')
|
||||||
let expand = s:zen_toString(s:zen_parseIntoTree(line, '')['child'][0])
|
let items = s:zen_parseIntoTree(line, '')['child']
|
||||||
|
let expand = len(items) ? s:zen_toString(items[0]) : ''
|
||||||
if len(expand)
|
if len(expand)
|
||||||
if expand !~ '|'
|
if expand !~ '|'
|
||||||
let expand .= '|'
|
let expand .= '|'
|
||||||
endif
|
endif
|
||||||
silent! exe "normal! d".(len(line)-1)."h"
|
let expand = repeat("\<c-h>", len(line)) . expand
|
||||||
silent! put! =expand
|
return expand
|
||||||
call search('|', 'b')
|
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ZenExpand(abbr, type)
|
function! ZenExpand(abbr, type)
|
||||||
return s:toString(s:parseIntoTree(a:abbr, a:type)['child'][0])
|
let items = s:zen_parseIntoTree(a:abbr, a:type)['child']
|
||||||
|
if len(items) | return s:zen_toString(items[0]) | endif
|
||||||
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
inoremap <plug>ZenCodingExpand <c-r>=<sid>zen_expand()<cr><del>
|
inoremap <plug>ZenCodingExpand <c-r>=<sid>zen_expand()<cr><esc>?\|<cr><del>a
|
||||||
imap <c-z>, <plug>ZenCodingExpand
|
imap <c-z>, <plug>ZenCodingExpand
|
||||||
|
|
||||||
" test
|
" test
|
||||||
"echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '')
|
"echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '')
|
||||||
|
"echo ZenExpand('ol>li*2', '')
|
||||||
|
"echo ZenExpand('a', '')
|
||||||
|
"echo ZenExpand('obj', '')
|
||||||
"echo ZenExpand('cc:ie6>p+blockquote#sample$.so.many.classes*2', '')
|
"echo ZenExpand('cc:ie6>p+blockquote#sample$.so.many.classes*2', '')
|
||||||
"echo ZenExpand('tm>if>div.message', '')
|
"echo ZenExpand('tm>if>div.message', '')
|
||||||
|
|||||||
Reference in New Issue
Block a user