The count of '(((a#foo + a#bar)*2)*3)' should be 12.

This commit is contained in:
mattn
2010-02-26 21:26:29 +09:00
parent 8a0a160996
commit d987123e70
2 changed files with 93 additions and 85 deletions

View File

@@ -2,7 +2,7 @@
" File: zencoding.vim " File: zencoding.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 26-Feb-2010. " Last Change: 26-Feb-2010.
" Version: 0.25 " Version: 0.26
" WebPage: http://github.com/mattn/zencoding-vim " WebPage: http://github.com/mattn/zencoding-vim
" Description: vim plugins for HTML and CSS hi-speed coding. " Description: vim plugins for HTML and CSS hi-speed coding.
" SeeAlso: http://code.google.com/p/zen-coding/ " SeeAlso: http://code.google.com/p/zen-coding/
@@ -61,7 +61,7 @@
" \ } " \ }
" \} " \}
" "
" You can set language attribute in html using zen_settings['lang']. " You can set language attribute in html using 'zen_settings.lang'.
" "
" GetLatestVimScripts: 2981 1 :AutoInstall: zencoding.vim " GetLatestVimScripts: 2981 1 :AutoInstall: zencoding.vim
" script type: plugin " script type: plugin
@@ -814,8 +814,8 @@ let s:zen_settings = {
function! s:zen_expandos(key, type) function! s:zen_expandos(key, type)
if has_key(s:zen_settings[a:type], 'expandos') if has_key(s:zen_settings[a:type], 'expandos')
if has_key(s:zen_settings[a:type]['expandos'], a:key) if has_key(s:zen_settings[a:type].expandos, a:key)
return s:zen_settings[a:type]['expandos'][a:key] return s:zen_settings[a:type].expandos[a:key]
endif endif
endif endif
return a:key return a:key
@@ -830,7 +830,7 @@ function! s:zen_parseIntoTree(abbr, type)
endif endif
let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)+\([()]\|$\)', '\="(".s:zen_expandos(submatch(1), type).")".submatch(2)', 'i') let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)+\([()]\|$\)', '\="(".s:zen_expandos(submatch(1), type).")".submatch(2)', 'i')
let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#]\{-}[a-z][a-z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#[0-9A-Za-z_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|\%(\.[0-9A-Za-z_\-\$]\+\)\)*\)\%(\({[^}]\+}\)\)\{0,1}\%(\*\([0-9]\+\)\)\{0,1}\s*\()\+\)\{0,1}\%(\*\([0-9]\+\)\)\{0,1}' let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#]\{-}[a-z][a-z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#[0-9A-Za-z_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|\%(\.[0-9A-Za-z_\-\$]\+\)\)*\)\%(\({[^}]\+}\)\)\{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 } let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
let parent = root let parent = root
let last = root let last = root
@@ -845,7 +845,6 @@ function! s:zen_parseIntoTree(abbr, type)
let value = substitute(match, mx, '\5', 'ig') let value = substitute(match, mx, '\5', 'ig')
let multiplier = 0 + substitute(match, mx, '\6', 'ig') let multiplier = 0 + substitute(match, mx, '\6', 'ig')
let block_end = substitute(match, mx, '\7', 'ig') let block_end = substitute(match, mx, '\7', 'ig')
let multiplier_block = 0 + substitute(match, mx, '\8', 'ig')
if len(str) == 0 if len(str) == 0
break break
endif endif
@@ -854,29 +853,28 @@ function! s:zen_parseIntoTree(abbr, type)
let tag_name = 'div' let tag_name = 'div'
endif endif
if multiplier <= 0 | let multiplier = 1 | endif if multiplier <= 0 | let multiplier = 1 | endif
if multiplier_block <= 0 | let multiplier_block = 1 | endif
if has_key(s:zen_settings[type], 'aliases') if has_key(s:zen_settings[type], 'aliases')
if has_key(s:zen_settings[type]['aliases'], tag_name) if has_key(s:zen_settings[type].aliases, tag_name)
let tag_name = s:zen_settings[type]['aliases'][tag_name] let tag_name = s:zen_settings[type].aliases[tag_name]
endif endif
endif endif
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 } let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
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'] = substitute(tag_name, ':.*$', '', '') let current.name = substitute(tag_name, ':.*$', '', '')
if has_key(s:zen_settings[type], 'default_attributes') if has_key(s:zen_settings[type], 'default_attributes')
let default_attributes = s:zen_settings[type]['default_attributes'] let default_attributes = s:zen_settings[type].default_attributes
if has_key(default_attributes, tag_name) if has_key(default_attributes, tag_name)
if type(default_attributes[tag_name]) == 4 if type(default_attributes[tag_name]) == 4
let a = default_attributes[tag_name] let a = default_attributes[tag_name]
for k in keys(a) for k in keys(a)
let current['attr'][k] = len(a[k]) ? a[k] : '|' let current.attr[k] = len(a[k]) ? a[k] : '|'
endfor endfor
else else
for a in default_attributes[tag_name] for a in default_attributes[tag_name]
for k in keys(a) for k in keys(a)
let current['attr'][k] = len(a[k]) ? a[k] : '|' let current.attr[k] = len(a[k]) ? a[k] : '|'
endfor endfor
endfor endfor
endif endif
@@ -891,44 +889,44 @@ function! s:zen_parseIntoTree(abbr, type)
break break
endif endif
if item[0] == '#' if item[0] == '#'
let current['attr']['id'] = item[1:] let current.attr.id = item[1:]
endif endif
if item[0] == '.' if item[0] == '.'
let current['attr']['class'] = substitute(item[1:], '\.', '', 'g') let current.attr.class = substitute(item[1:], '\.', '', 'g')
endif endif
if item[0] == '[' if item[0] == '['
let kk = split(item[1:-2], '=') let kk = split(item[1:-2], '=')
let current['attr'][kk[0]] = len(kk) > 1 ? join(kk[1:], '=') : '' let current.attr[kk[0]] = len(kk) > 1 ? join(kk[1:], '=') : ''
endif endif
let attr = substitute(strpart(attr, len(item)), '^\s*', '', '') let attr = substitute(strpart(attr, len(item)), '^\s*', '', '')
endwhile endwhile
endif endif
if tag_name =~ '^{.*}$' if tag_name =~ '^{.*}$'
let current['name'] = '' let current.name = ''
let current['value'] = str let current.value = str
else else
let current['value'] = value let current.value = value
endif endif
let current['multiplier'] = multiplier let current.multiplier = multiplier
let current['multiplier'] = multiplier let current.multiplier = multiplier
if !empty(last) if !empty(last)
if operator =~ '>' if operator =~ '>'
unlet! parent unlet! parent
let parent = last let parent = last
let current['parent'] = last let current.parent = last
let current['pos'] = last['pos'] + 1 let current.pos = last.pos + 1
else else
let current['parent'] = parent let current.parent = parent
let current['pos'] = last['pos'] let current.pos = last.pos
endif endif
else else
let current['parent'] = parent let current.parent = parent
let current['pos'] = 1 let current.pos = 1
endif endif
if operator =~ '<' if operator =~ '<'
for c in range(len(operator)) for c in range(len(operator))
let tmp = parent['parent'] let tmp = parent.parent
if empty(tmp) if empty(tmp)
break break
endif endif
@@ -936,31 +934,38 @@ function! s:zen_parseIntoTree(abbr, type)
endfor endfor
endif endif
call add(parent['child'], current) call add(parent.child, current)
let last = current let last = current
if block_start == '(' if block_start =~ '('
if operator =~ '>' for n in range(len(block_start))
let last['pos'] += 1 let pos += [last.pos]
let pos += [last['pos']] endfor
else
let pos += [last['pos']]
endif
endif endif
if block_end =~ ')' if block_end =~ ')'
for n in range(len(block_end)) for n in split(substitute(block_end, ' ', '', 'g'), ')', 1)
for c in range(last['pos'] - pos[-1]) if n == ''
let tmp = parent['parent'] if len(pos) > 0 && last.pos >= pos[-1]
if !has_key(tmp, 'parent') for c in range(last.pos - pos[-1])
break let tmp = parent.parent
if !has_key(tmp, 'parent')
break
endif
let parent = tmp
endfor
call remove(pos, -1)
let last = parent
let last.pos += 1
endif endif
let parent = tmp else
endfor let cl = last.child
call remove(pos, -1) let cls = []
let last = parent for c in range(n[1:])
let last['child'][-1]['multiplier'] = multiplier_block let cls += cl
let last['pos'] += 1 endfor
let last.child = cls
endif
endfor endfor
endif endif
let abbr = abbr[stridx(abbr, match) + len(match):] let abbr = abbr[stridx(abbr, match) + len(match):]
@@ -973,7 +978,6 @@ function! s:zen_parseIntoTree(abbr, type)
echo "value=".value echo "value=".value
echo "multiplier=".multiplier echo "multiplier=".multiplier
echo "block_end=".block_end echo "block_end=".block_end
echo "multiplier_block=".multiplier_block
echo "abbr=".abbr echo "abbr=".abbr
echo "pos=".string(pos) echo "pos=".string(pos)
echo "\n" echo "\n"
@@ -992,52 +996,52 @@ function! s:zen_toString(...)
if len(type) == 0 | let type = 'html' | endif if len(type) == 0 | let type = 'html' | endif
if has_key(s:zen_settings[type], 'indentation') if has_key(s:zen_settings[type], 'indentation')
let indent = s:zen_settings[type]['indentation'] let indent = s:zen_settings[type].indentation
else else
let indent = s:zen_settings['indentation'] let indent = s:zen_settings.indentation
endif endif
let m = 0 let m = 0
let str = '' let str = ''
while m < current['multiplier'] while m < current.multiplier
if len(current['name']) && type == 'html' if len(current.name) && type == 'html'
let str .= '<' . current['name'] let str .= '<' . current.name
for attr in keys(current['attr']) for attr in keys(current.attr)
if current['multiplier'] > 1 && current['attr'][attr] =~ '\$' if current.multiplier > 1 && current.attr[attr] =~ '\$'
let str .= ' ' . attr . '="' . substitute(current['attr'][attr], '\$', m+1, 'g') . '"' let str .= ' ' . attr . '="' . substitute(current.attr[attr], '\$', m+1, 'g') . '"'
else else
let str .= ' ' . attr . '="' . current['attr'][attr] . '"' let str .= ' ' . attr . '="' . current.attr[attr] . '"'
endif endif
endfor endfor
let inner = current['value'][1:-2] let inner = current.value[1:-2]
for child in current['child'] for child in current.child
let inner .= s:zen_toString(child, type) let inner .= s:zen_toString(child, type)
endfor endfor
if len(current['child']) if len(current.child)
let inner = substitute(inner, "\n", "\n" . indent, 'g') let inner = substitute(inner, "\n", "\n" . indent, 'g')
let inner = substitute(inner, indent . "$", "", 'g') let inner = substitute(inner, indent . "$", "", 'g')
let str .= ">\n" . indent . inner . "</" . current['name'] . ">\n" let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
else else
if stridx(','.s:zen_settings[type]['empty_elements'].',', ','.current['name'].',') != -1 if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
let str .= " />\n" let str .= " />\n"
else else
if stridx(','.s:zen_settings[type]['block_elements'].',', ','.current['name'].',') != -1 && len(current['child']) if stridx(','.s:zen_settings[type].block_elements.',', ','.current.name.',') != -1 && len(current.child)
let str .= ">\n" . inner . "|</" . current['name'] . ">\n" let str .= ">\n" . inner . "|</" . current.name . ">\n"
else else
let str .= ">" . inner . "|</" . current['name'] . ">\n" let str .= ">" . inner . "|</" . current.name . ">\n"
endif endif
endif endif
endif endif
else else
let str .= '' . current['snippet'] let str .= '' . current.snippet
if len(str) == 0 if len(str) == 0
let str = current['name'] let str = current.name
if len(current['value']) if len(current.value)
let str .= current['value'][1:-2] let str .= current.value[1:-2]
endif endif
endif endif
let inner = '' let inner = ''
if len(current['child']) if len(current.child)
for n in current['child'] for n in current.child
let inner .= s:zen_toString(n, type) let inner .= s:zen_toString(n, type)
endfor endfor
let inner = substitute(inner, "\n", "\n" . indent, 'g') let inner = substitute(inner, "\n", "\n" . indent, 'g')
@@ -1069,7 +1073,7 @@ function! s:zen_expand(mode) range
let rest = '' let rest = ''
if leader =~ '*' if leader =~ '*'
let query = substitute(leader, '*', '{$line$}*' . (a:lastline - a:firstline + 1), '') let query = substitute(leader, '*', '{$line$}*' . (a:lastline - a:firstline + 1), '')
let items = s:zen_parseIntoTree(query, type)['child'] let items = s:zen_parseIntoTree(query, type).child
for item in items for item in items
let expand .= s:zen_toString(item, type) let expand .= s:zen_toString(item, type)
endfor endfor
@@ -1088,10 +1092,10 @@ function! s:zen_expand(mode) range
for n in range(a:firstline, a:lastline) for n in range(a:firstline, a:lastline)
let str .= getline(n) . "\n" let str .= getline(n) . "\n"
endfor endfor
let items = s:zen_parseIntoTree(leader . "{\n" . str . "}", type)['child'] let items = s:zen_parseIntoTree(leader . "{\n" . str . "}", type).child
else else
let str .= getline(a:firstline) let str .= getline(a:firstline)
let items = s:zen_parseIntoTree(leader . "{" . str . "}", type)['child'] let items = s:zen_parseIntoTree(leader . "{" . str . "}", type).child
endif endif
for item in items for item in items
let expand .= s:zen_toString(item, type) let expand .= s:zen_toString(item, type)
@@ -1106,7 +1110,7 @@ function! s:zen_expand(mode) range
let part = matchstr(line, '\(\S.*\)$') let part = matchstr(line, '\(\S.*\)$')
endif endif
let rest = getline('.')[col('.'):] let rest = getline('.')[col('.'):]
let items = s:zen_parseIntoTree(part, type)['child'] let items = s:zen_parseIntoTree(part, type).child
for item in items for item in items
let expand .= s:zen_toString(item, type) let expand .= s:zen_toString(item, type)
endfor endfor
@@ -1118,10 +1122,10 @@ function! s:zen_expand(mode) range
if expand !~ '|' if expand !~ '|'
let expand .= '|' let expand .= '|'
endif endif
let expand = substitute(expand, '${lang}', s:zen_settings['lang'], 'g') let expand = substitute(expand, '${lang}', s:zen_settings.lang, 'g')
if line[:-len(part)-1] =~ '^\s\+$' if line[:-len(part)-1] =~ '^\s\+$'
let size = len(line) - len(part) let size = len(line) - len(part)
let indent = repeat(s:zen_settings['indentation'], size) let indent = repeat(s:zen_settings.indentation, size)
else else
let indent = '' let indent = ''
endif endif
@@ -1139,7 +1143,7 @@ function! s:zen_expand(mode) range
endfunction endfunction
function! ZenExpand(abbr, type) function! ZenExpand(abbr, type)
let items = s:zen_parseIntoTree(a:abbr, a:type)['child'] let items = s:zen_parseIntoTree(a:abbr, a:type).child
let expand = '' let expand = ''
for item in items for item in items
let expand .= s:zen_toString(item, a:type) let expand .= s:zen_toString(item, a:type)
@@ -1185,13 +1189,13 @@ function! ZenCompleteTag(findstart, base)
return res return res
endif endif
if len(type) == 0 | let type = 'html' | endif if len(type) == 0 | let type = 'html' | endif
for item in keys(s:zen_settings[type]['snippets']) for item in keys(s:zen_settings[type].snippets)
if stridx(item, a:base) != -1 if stridx(item, a:base) != -1
call add(res, item) call add(res, item)
endif endif
endfor endfor
if has_key(s:zen_settings[type], 'aliases') if has_key(s:zen_settings[type], 'aliases')
for item in values(s:zen_settings[type]['aliases']) for item in values(s:zen_settings[type].aliases)
if stridx(item, a:base) != -1 if stridx(item, a:base) != -1
call add(res, item) call add(res, item)
endif endif
@@ -1242,7 +1246,8 @@ endif
"echo ZenExpand('a>b>c<<div', '') "echo ZenExpand('a>b>c<<div', '')
"echo ZenExpand('(#header>h1)+#content+#footer', '') "echo ZenExpand('(#header>h1)+#content+#footer', '')
"echo ZenExpand('(#header>h1)+(#content>(#main>h2+div#entry$.section*5>(h3>a)+div>p*3+ul+)+(#utilities))+(#footer>address)', '') "echo ZenExpand('(#header>h1)+(#content>(#main>h2+div#entry$.section*5>(h3>a)+div>p*3+ul+)+(#utilities))+(#footer>address)', '')
"echo ZenExpand('(div>(ul))+(#utilities)', '') "echo ZenExpand('(div>(ul*2))+(#utilities)', '')
"echo ZenExpand('table>(tr>td*3)*4', '') "echo ZenExpand('table>(tr>td*3)*4', '')
"echo ZenExpand('(((a#foo+a#bar)*2)*3)', '')
" vim:set et: " vim:set et:

View File

@@ -2,7 +2,7 @@ script_name: ZenCoding.vim
script_id: '2981' script_id: '2981'
script_type: utility script_type: utility
script_package: zencoding.vim script_package: zencoding.vim
script_version: '0.25' script_version: '0.26'
required_vim_version: '7.0' required_vim_version: '7.0'
summary: vim plugins for HTML and CSS hi-speed coding. summary: vim plugins for HTML and CSS hi-speed coding.
@@ -22,7 +22,8 @@ detailed_description: |
+------------------------------------- +-------------------------------------
| html:5_ | html:5_
+------------------------------------- +-------------------------------------
"_" is a cursor position. and type "<c-z>," "_" is a cursor position. and type "<c-z>," (Ctrl + z and Comma)
NOTE: Don't worry about key map. you can change it easily.
+------------------------------------- +-------------------------------------
| <!DOCTYPE HTML> | <!DOCTYPE HTML>
| <html lang="en"> | <html lang="en">
@@ -78,6 +79,8 @@ install_details: |
copy zencoding.vim to your plugin directory. copy zencoding.vim to your plugin directory.
versions: versions:
- '0.26': |
This is an upgrade for ZenCoding.vim: The count of '(((a#foo + a#bar)*2)*3)' should be 12.
- '0.25': | - '0.25': |
This is an upgrade for ZenCoding.vim: store undo before working. good luck about 'table>(tr>td*3)*4'. This is an upgrade for ZenCoding.vim: store undo before working. good luck about 'table>(tr>td*3)*4'.
- '0.24': | - '0.24': |