diff --git a/zencoding.vim b/zencoding.vim index 651c30d..af4a171 100644 --- a/zencoding.vim +++ b/zencoding.vim @@ -1,8 +1,8 @@ "============================================================================= " File: zencoding.vim " Author: Yasuhiro Matsumoto -" Last Change: 25-Feb-2010. -" Version: 0.24 +" Last Change: 27-Feb-2010. +" Version: 0.26 " WebPage: http://github.com/mattn/zencoding-vim " Description: vim plugins for HTML and CSS hi-speed coding. " SeeAlso: http://code.google.com/p/zen-coding/ @@ -61,17 +61,21 @@ " \ } " \} " -" 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 " script type: plugin +if !exists('g:zencoding_debug') + let g:zencoding_debug = 0 +endif + if exists('g:use_zen_complete_tag') && g:use_zen_complete_tag setlocal completefunc=ZenCompleteTag endif -inoremap ZenCodingExpandAbbr :call zen_expand(0)a -inoremap ZenCodingExpandWord :call zen_expand(1)a +inoremap ZenCodingExpandAbbr u:call zen_expand(0)a +inoremap ZenCodingExpandWord u:call zen_expand(1)a vnoremap ZenCodingExpandVisual :call zen_expand(2) if !exists('g:user_zen_expandword_key') @@ -90,7 +94,7 @@ if !hasmapto(g:user_zen_expandabbr_key, 'v') exe "vmap " . g:user_zen_expandabbr_key . " ZenCodingExpandVisual" endif -if exists('s:zen_settings') && !exists('g:zencoding_debug') +if exists('s:zen_settings') && g:zencoding_debug == 0 finish endif @@ -814,8 +818,8 @@ let s:zen_settings = { function! s:zen_expandos(key, type) if has_key(s:zen_settings[a:type], 'expandos') - if has_key(s:zen_settings[a:type]['expandos'], a:key) - return 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] endif endif return a:key @@ -830,7 +834,7 @@ function! s:zen_parseIntoTree(abbr, type) endif 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}' + 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 parent = root let last = root @@ -852,31 +856,29 @@ function! s:zen_parseIntoTree(abbr, type) let attributes = tag_name . attributes let tag_name = 'div' endif - if multiplier <= 0 - let multiplier = 1 - endif + if multiplier <= 0 | let multiplier = 1 | endif if has_key(s:zen_settings[type], 'aliases') - if has_key(s:zen_settings[type]['aliases'], tag_name) - let tag_name = 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] endif endif let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 } - if has_key(s:zen_settings[type]['snippets'], tag_name) - let current['snippet'] = 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] else - let current['name'] = substitute(tag_name, ':.*$', '', '') + let current.name = substitute(tag_name, ':.*$', '', '') 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 type(default_attributes[tag_name]) == 4 let a = default_attributes[tag_name] for k in keys(a) - let current['attr'][k] = a[k] + let current.attr[k] = len(a[k]) ? a[k] : '|' endfor else for a in default_attributes[tag_name] for k in keys(a) - let current['attr'][k] = a[k] + let current.attr[k] = len(a[k]) ? a[k] : '|' endfor endfor endif @@ -891,43 +893,43 @@ function! s:zen_parseIntoTree(abbr, type) break endif if item[0] == '#' - let current['attr']['id'] = item[1:] + let current.attr.id = item[1:] endif if item[0] == '.' - let current['attr']['class'] = substitute(item[1:], '\.', '', 'g') + let current.attr.class = substitute(item[1:], '\.', '', 'g') endif if item[0] == '[' 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 let attr = substitute(strpart(attr, len(item)), '^\s*', '', '') endwhile endif if tag_name =~ '^{.*}$' - let current['name'] = '' - let current['value'] = str + let current.name = '' + let current.value = str else - let current['value'] = value + let current.value = value endif - let current['multiplier'] = multiplier + let current.multiplier = multiplier if !empty(last) if operator =~ '>' unlet! parent let parent = last - let current['parent'] = last - let current['pos'] = last['pos'] + 1 + let current.parent = last + let current.pos = last.pos + 1 else - let current['parent'] = parent - let current['pos'] = last['pos'] + let current.parent = parent + let current.pos = last.pos endif else - let current['parent'] = parent - let current['pos'] = 1 + let current.parent = parent + let current.pos = 1 endif if operator =~ '<' for c in range(len(operator)) - let tmp = parent['parent'] + let tmp = parent.parent if empty(tmp) break endif @@ -935,34 +937,45 @@ function! s:zen_parseIntoTree(abbr, type) endfor endif - call add(parent['child'], current) + call add(parent.child, current) let last = current - if block_start == '(' + if block_start =~ '(' if operator =~ '>' - let last['pos'] += 1 - let pos += [last['pos']] - else - let pos += [last['pos']] + let last.pos += 1 endif + for n in range(len(block_start)) + let pos += [last.pos] + endfor endif if block_end =~ ')' - for n in range(len(block_end)) - for c in range(last['pos'] - pos[-1]) - let tmp = parent['parent'] - if !has_key(tmp, 'parent') - break + for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',') + if n == ')' + if len(pos) > 0 && last.pos >= pos[-1] + for c in range(last.pos - pos[-1]) + 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 - let parent = tmp - endfor - call remove(pos, -1) - let last = parent - let last['pos'] += 1 + elseif len(n) + let cl = last.child + let cls = [] + for c in range(n[1:]) + let cls += cl + endfor + let last.child = cls + endif endfor endif let abbr = abbr[stridx(abbr, match) + len(match):] - if 0 + if g:zencoding_debug > 1 echo "str=".str echo "block_start=".block_start echo "tag_name=".tag_name @@ -989,52 +1002,52 @@ function! s:zen_toString(...) if len(type) == 0 | let type = 'html' | endif if has_key(s:zen_settings[type], 'indentation') - let indent = s:zen_settings[type]['indentation'] + let indent = s:zen_settings[type].indentation else - let indent = s:zen_settings['indentation'] + let indent = s:zen_settings.indentation endif let m = 0 let str = '' - while m < current['multiplier'] - if len(current['name']) && type == 'html' - let str .= '<' . current['name'] - for attr in keys(current['attr']) - if current['multiplier'] > 1 && current['attr'][attr] =~ '\$' - let str .= ' ' . attr . '="' . substitute(current['attr'][attr], '\$', m+1, 'g') . '"' + while m < current.multiplier + if len(current.name) && type == 'html' + let str .= '<' . current.name + for attr in keys(current.attr) + if current.multiplier > 1 && current.attr[attr] =~ '\$' + let str .= ' ' . attr . '="' . substitute(current.attr[attr], '\$', m+1, 'g') . '"' else - let str .= ' ' . attr . '="' . current['attr'][attr] . '"' + let str .= ' ' . attr . '="' . current.attr[attr] . '"' endif endfor - let inner = current['value'][1:-2] - for child in current['child'] + let inner = current.value[1:-2] + for child in current.child let inner .= s:zen_toString(child, type) endfor - if len(current['child']) + if len(current.child) let inner = substitute(inner, "\n", "\n" . indent, 'g') let inner = substitute(inner, indent . "$", "", 'g') - let str .= ">\n" . indent . inner . "\n" + let str .= ">\n" . indent . inner . "\n" 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" else - if stridx(','.s:zen_settings[type]['block_elements'].',', ','.current['name'].',') != -1 && len(current['child']) - let str .= ">\n" . inner . "|\n" + if stridx(','.s:zen_settings[type].block_elements.',', ','.current.name.',') != -1 && len(current.child) + let str .= ">\n" . inner . "|\n" else - let str .= ">" . inner . "|\n" + let str .= ">" . inner . "|\n" endif endif endif else - let str .= '' . current['snippet'] + let str .= '' . current.snippet if len(str) == 0 - let str = current['name'] - if len(current['value']) - let str .= current['value'][1:-2] + let str = current.name + if len(current.value) + let str .= current.value[1:-2] endif endif let inner = '' - if len(current['child']) - for n in current['child'] + if len(current.child) + for n in current.child let inner .= s:zen_toString(n, type) endfor let inner = substitute(inner, "\n", "\n" . indent, 'g') @@ -1066,7 +1079,7 @@ function! s:zen_expand(mode) range let rest = '' if leader =~ '*' 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 let expand .= s:zen_toString(item, type) endfor @@ -1085,10 +1098,10 @@ function! s:zen_expand(mode) range for n in range(a:firstline, a:lastline) let str .= getline(n) . "\n" endfor - let items = s:zen_parseIntoTree(leader . "{\n" . str . "}", type)['child'] + let items = s:zen_parseIntoTree(leader . "{\n" . str . "}", type).child else let str .= getline(a:firstline) - let items = s:zen_parseIntoTree(leader . "{" . str . "}", type)['child'] + let items = s:zen_parseIntoTree(leader . "{" . str . "}", type).child endif for item in items let expand .= s:zen_toString(item, type) @@ -1103,7 +1116,7 @@ function! s:zen_expand(mode) range let part = matchstr(line, '\(\S.*\)$') endif let rest = getline('.')[col('.'):] - let items = s:zen_parseIntoTree(part, type)['child'] + let items = s:zen_parseIntoTree(part, type).child for item in items let expand .= s:zen_toString(item, type) endfor @@ -1115,10 +1128,10 @@ function! s:zen_expand(mode) range if expand !~ '|' let expand .= '|' 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\+$' let size = len(line) - len(part) - let indent = repeat(s:zen_settings['indentation'], size) + let indent = repeat(s:zen_settings.indentation, size) else let indent = '' endif @@ -1136,7 +1149,7 @@ function! s:zen_expand(mode) range endfunction 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 = '' for item in items let expand .= s:zen_toString(item, a:type) @@ -1182,13 +1195,13 @@ function! ZenCompleteTag(findstart, base) return res 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 call add(res, item) endif endfor 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 call add(res, item) endif @@ -1202,7 +1215,10 @@ if exists('g:user_zen_settings') call s:zen_mergeConfig(s:zen_settings, g:user_zen_settings) endif -" test +if g:zencoding_debug == 0 + finish +endif + "echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '') "echo ZenExpand('ol>li*2', '') "echo ZenExpand('a', '') @@ -1236,8 +1252,8 @@ endif "echo ZenExpand('a>b>c<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('(div>(ul))+(#utilities)', '') -"echo ZenExpand('(a>b)+(c+d)', '') -"echo zenexpand('(a>b)+(c>d)', '') +"echo ZenExpand('(div>(ul*2)*2)+(#utilities)', '') +"echo ZenExpand('table>(tr>td*3)*4', '') +"echo ZenExpand('(((a#foo+a#bar)*2)*3)', '') " vim:set et: diff --git a/zencoding.vim.vimup b/zencoding.vim.vimup index e1f8c88..d47b27e 100644 --- a/zencoding.vim.vimup +++ b/zencoding.vim.vimup @@ -2,7 +2,7 @@ script_name: ZenCoding.vim script_id: '2981' script_type: utility script_package: zencoding.vim -script_version: '0.24' +script_version: '0.26' required_vim_version: '7.0' summary: vim plugins for HTML and CSS hi-speed coding. @@ -22,7 +22,8 @@ detailed_description: | +------------------------------------- | html:5_ +------------------------------------- - "_" is a cursor position. and type "," + "_" is a cursor position. and type "," (Ctrl + z and Comma) + NOTE: Don't worry about key map. you can change it easily. +------------------------------------- | | @@ -78,6 +79,10 @@ install_details: | copy zencoding.vim to your plugin directory. versions: +- '0.26': | + This is an upgrade for ZenCoding.vim: The count of '(((a#foo + a#bar)*2)*3)' should be 12. +- '0.25': | + This is an upgrade for ZenCoding.vim: store undo before working. good luck about 'table>(tr>td*3)*4'. - '0.24': | This is an upgrade for ZenCoding.vim: fixed behavior of parsing area of visual selection. - '0.23': |