diff --git a/autoload/zencoding.vim b/autoload/zencoding.vim index 5b6c992..61135ed 100644 --- a/autoload/zencoding.vim +++ b/autoload/zencoding.vim @@ -343,7 +343,8 @@ function! zencoding#expandAbbr(mode) range while part =~ '<.\{-}>' let part = substitute(part, '^.*<.\{-}>', '', '') endwhile - let part = substitute(part, '^.*\s', '', '') + let rtype = len(globpath(&rtp, 'autoload/zencoding/'.type.'.vim')) ? type : 'html' + let part = zencoding#{rtype}#findTokens(part) elseif zencoding#isExtends(type, "css") let part = substitute(part, '^.*[;{]\s*', '', '') endif diff --git a/autoload/zencoding/css.vim b/autoload/zencoding/css.vim index eb12343..c0376e9 100644 --- a/autoload/zencoding/css.vim +++ b/autoload/zencoding/css.vim @@ -1,3 +1,7 @@ +function! zencoding#css#findTokens(str) + return substitute(a:str, '^.*[;{]\s*', '', '') +endfunction + function! zencoding#css#parseIntoTree(abbr, type) let abbr = a:abbr let type = a:type diff --git a/autoload/zencoding/haml.vim b/autoload/zencoding/haml.vim index 45e8e49..55fbd22 100644 --- a/autoload/zencoding/haml.vim +++ b/autoload/zencoding/haml.vim @@ -1,3 +1,7 @@ +function! zencoding#haml#findTokens(str) + return zencoding#html#findTokens(a:str) +endfunction + function! zencoding#haml#parseIntoTree(abbr, type) return zencoding#html#parseIntoTree(a:abbr, a:type) endfunction diff --git a/autoload/zencoding/html.vim b/autoload/zencoding/html.vim index b7be127..e1e7d13 100644 --- a/autoload/zencoding/html.vim +++ b/autoload/zencoding/html.vim @@ -1,3 +1,23 @@ +let s:mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#.]\{-}[a-zA-Z\!][a-zA-Z0-9:_\!\-$]*\|' +\ .'{.\{-}}[ \t\r\n}]*\)\(\%(\%(#{[{}a-zA-Z0-9_\-\$]\+\|' +\ .'#[a-zA-Z0-9_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|' +\ .'\%(\.{[{}a-zA-Z0-9_\-\$]\+\|' +\ .'\.[a-zA-Z0-9_\-\$]\+\)\)*\)\%(\({[^}]\+}\+\)\)\{0,1}\%(\s*\*\s*\([0-9]\+\)\s*\)\{0,1}\(\%(\s*)\%(\s*\*\s*[0-9]\+\s*\)\{0,1}\)*\)' + +function! zencoding#html#findTokens(str) + let str = a:str + while len(str) > 0 + let token = matchstr(str, s:mx.'\s*$') + if token =~ '^\s' + let token = substitute(token, '^\s*', '', '') + let str = str[0 : -len(token)-1] + break + endif + let str = str[0 : -len(token)-1] + endwhile + return a:str[len(str) :-1] +endfunction + function! zencoding#html#parseIntoTree(abbr, type) let abbr = a:abbr let type = a:type @@ -23,11 +43,6 @@ function! zencoding#html#parseIntoTree(abbr, type) let rabbr = substitute(abbr, '\%(+\|^\)\([a-zA-Z][a-zA-Z0-9+]\+\)+\([(){}>]\|$\)', '\="(".zencoding#getExpandos(type, submatch(1)).")".submatch(2)', 'i') endif let abbr = rabbr - let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#.]\{-}[a-zA-Z\!][a-zA-Z0-9:_\!\-$]*\|' - \ .'{.\{-}}[ \t\r\n}]*\)\(\%(\%(#{[{}a-zA-Z0-9_\-\$]\+\|' - \ .'#[a-zA-Z0-9_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|' - \ .'\%(\.{[{}a-zA-Z0-9_\-\$]\+\|' - \ .'\.[a-zA-Z0-9_\-\$]\+\)\)*\)\%(\({[^}]\+}\+\)\)\{0,1}\%(\s*\*\s*\([0-9]\+\)\s*\)\{0,1}\(\%(\s*)\%(\s*\*\s*[0-9]\+\s*\)\{0,1}\)*\)' let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 } let parent = root @@ -35,15 +50,15 @@ function! zencoding#html#parseIntoTree(abbr, type) let pos = [] while len(abbr) " parse line - let match = matchstr(abbr, mx) - let str = substitute(match, mx, '\0', 'ig') - let operator = substitute(match, mx, '\1', 'ig') - let block_start = substitute(match, mx, '\2', 'ig') - let tag_name = substitute(match, mx, '\3', 'ig') - let attributes = substitute(match, mx, '\4', 'ig') - let value = substitute(match, mx, '\5', 'ig') - let multiplier = 0 + substitute(match, mx, '\6', 'ig') - let block_end = substitute(match, mx, '\7', 'ig') + let match = matchstr(abbr, s:mx) + let str = substitute(match, s:mx, '\0', 'ig') + let operator = substitute(match, s:mx, '\1', 'ig') + let block_start = substitute(match, s:mx, '\2', 'ig') + let tag_name = substitute(match, s:mx, '\3', 'ig') + let attributes = substitute(match, s:mx, '\4', 'ig') + let value = substitute(match, s:mx, '\5', 'ig') + let multiplier = 0 + substitute(match, s:mx, '\6', 'ig') + let block_end = substitute(match, s:mx, '\7', 'ig') let important = 0 if len(str) == 0 break diff --git a/autoload/zencoding/slim.vim b/autoload/zencoding/slim.vim index 9c7b952..f333a7c 100644 --- a/autoload/zencoding/slim.vim +++ b/autoload/zencoding/slim.vim @@ -1,3 +1,7 @@ +function! zencoding#slim#findTokens(str) + return zencoding#html#findTokens(a:str) +endfunction + function! zencoding#slim#parseIntoTree(abbr, type) return zencoding#html#parseIntoTree(a:abbr, a:type) endfunction