Merge branch 'master' of git@github.com:mattn/zencoding-vim

Conflicts:
	zencoding.vim
This commit is contained in:
mattn
2010-02-27 01:13:26 +09:00
2 changed files with 110 additions and 89 deletions

View File

@@ -1,8 +1,8 @@
"============================================================================= "=============================================================================
" File: zencoding.vim " File: zencoding.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 25-Feb-2010. " Last Change: 27-Feb-2010.
" Version: 0.24 " 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,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 " GetLatestVimScripts: 2981 1 :AutoInstall: zencoding.vim
" script type: plugin " 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 if exists('g:use_zen_complete_tag') && g:use_zen_complete_tag
setlocal completefunc=ZenCompleteTag setlocal completefunc=ZenCompleteTag
endif endif
inoremap <plug>ZenCodingExpandAbbr <esc>:call <sid>zen_expand(0)<cr>a inoremap <plug>ZenCodingExpandAbbr <c-g>u<esc>:call <sid>zen_expand(0)<cr>a
inoremap <plug>ZenCodingExpandWord <esc>:call <sid>zen_expand(1)<cr>a inoremap <plug>ZenCodingExpandWord <c-g>u<esc>:call <sid>zen_expand(1)<cr>a
vnoremap <plug>ZenCodingExpandVisual :call <sid>zen_expand(2)<cr> vnoremap <plug>ZenCodingExpandVisual :call <sid>zen_expand(2)<cr>
if !exists('g:user_zen_expandword_key') if !exists('g:user_zen_expandword_key')
@@ -90,7 +94,7 @@ if !hasmapto(g:user_zen_expandabbr_key, 'v')
exe "vmap <buffer> " . g:user_zen_expandabbr_key . " <plug>ZenCodingExpandVisual" exe "vmap <buffer> " . g:user_zen_expandabbr_key . " <plug>ZenCodingExpandVisual"
endif endif
if exists('s:zen_settings') && !exists('g:zencoding_debug') if exists('s:zen_settings') && g:zencoding_debug == 0
finish finish
endif endif
@@ -814,8 +818,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 +834,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}' 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
@@ -852,31 +856,29 @@ function! s:zen_parseIntoTree(abbr, type)
let attributes = tag_name . attributes let attributes = tag_name . attributes
let tag_name = 'div' let tag_name = 'div'
endif endif
if multiplier <= 0 if multiplier <= 0 | let multiplier = 1 | endif
let multiplier = 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] = 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] = a[k] let current.attr[k] = len(a[k]) ? a[k] : '|'
endfor endfor
endfor endfor
endif endif
@@ -891,43 +893,43 @@ 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
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
@@ -935,34 +937,45 @@ 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 =~ '>' if operator =~ '>'
let last['pos'] += 1 let last.pos += 1
let pos += [last['pos']]
else
let pos += [last['pos']]
endif endif
for n in range(len(block_start))
let pos += [last.pos]
endfor
endif endif
if block_end =~ ')' if block_end =~ ')'
for n in range(len(block_end)) for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',')
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 elseif len(n)
endfor let cl = last.child
call remove(pos, -1) let cls = []
let last = parent for c in range(n[1:])
let last['pos'] += 1 let cls += cl
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):]
if 0 if g:zencoding_debug > 1
echo "str=".str echo "str=".str
echo "block_start=".block_start echo "block_start=".block_start
echo "tag_name=".tag_name echo "tag_name=".tag_name
@@ -989,52 +1002,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')
@@ -1066,7 +1079,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
@@ -1085,10 +1098,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)
@@ -1103,7 +1116,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
@@ -1115,10 +1128,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
@@ -1136,7 +1149,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)
@@ -1182,13 +1195,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
@@ -1202,7 +1215,10 @@ if exists('g:user_zen_settings')
call s:zen_mergeConfig(s:zen_settings, g:user_zen_settings) call s:zen_mergeConfig(s:zen_settings, g:user_zen_settings)
endif 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('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '')
"echo ZenExpand('ol>li*2', '') "echo ZenExpand('ol>li*2', '')
"echo ZenExpand('a', '') "echo ZenExpand('a', '')
@@ -1236,8 +1252,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)*2)+(#utilities)', '')
"echo ZenExpand('(a>b)+(c+d)', '') "echo ZenExpand('table>(tr>td*3)*4', '')
"echo zenexpand('(a>b)+(c>d)', '') "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.24' 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,10 @@ 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': |
This is an upgrade for ZenCoding.vim: store undo before working. good luck about 'table>(tr>td*3)*4'.
- '0.24': | - '0.24': |
This is an upgrade for ZenCoding.vim: fixed behavior of parsing area of visual selection. This is an upgrade for ZenCoding.vim: fixed behavior of parsing area of visual selection.
- '0.23': | - '0.23': |