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

This commit is contained in:
mattn
2011-04-09 00:36:51 +09:00
4 changed files with 71 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" zencoding.vim " zencoding.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 22-Nov-2010. " Last Change: 24-Feb-2011.
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
@@ -61,8 +61,12 @@ function! s:zen_parseIntoTree(abbr, type)
let indent = s:zen_settings.indentation let indent = s:zen_settings.indentation
endif endif
let abbr = substitute(abbr, '\([a-zA-Z][a-zA-Z0-9]*\)+\([()]\|$\)', '\="(".s:zen_getExpandos(type, submatch(1)).")".submatch(2)', 'i') if s:zen_isExtends(type, "html")
let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#]\{-}[a-zA-Z\!][a-zA-Z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#{[{}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 abbr = substitute(abbr, '\([a-zA-Z][a-zA-Z0-9]*\)+\([()]\|$\)', '\="(".s:zen_getExpandos(type, submatch(1)).")".submatch(2)', 'i')
let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#.]\{-}[a-zA-Z\!][a-zA-Z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#{[{}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}\)*\)'
else
let mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#.]\{-}[a-zA-Z\!][a-zA-Z0-9:\!\+\-]*\|{[^}]\+}\)\(\%(\%(#{[{}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}\)*\)'
endif
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
@@ -85,6 +89,10 @@ 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 tag_name =~ '^\.'
let attributes = tag_name . attributes
let tag_name = 'div'
endif
if multiplier <= 0 | let multiplier = 1 | endif if multiplier <= 0 | let multiplier = 1 | endif
" make default node " make default node
@@ -327,8 +335,8 @@ function! s:zen_toString_haml(settings, current, type, inline, filters, itemno,
for attr in keys(current.attr) for attr in keys(current.attr)
let val = current.attr[attr] let val = current.attr[attr]
if current.multiplier > 1 if current.multiplier > 1
while val =~ '\$[^{]*' while val =~ '\$\([^{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]*\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile endwhile
endif endif
if attr == 'id' if attr == 'id'
@@ -345,8 +353,6 @@ function! s:zen_toString_haml(settings, current, type, inline, filters, itemno,
endif endif
if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1 && len(current.value) == 0 if stridx(','.settings.html.empty_elements.',', ','.current.name.',') != -1 && len(current.value) == 0
let str .= "/" let str .= "/"
elseif stridx(','.settings.html.block_elements.',', ','.current.name.',') != -1 && (len(current.child) == 0 && len(current.value) == 0)
let str .= '<'
endif endif
let inner = '' let inner = ''
@@ -434,9 +440,13 @@ function! s:zen_toString_html(settings, current, type, inline, filters, itemno,
elseif len(current.child) elseif len(current.child)
if inline == 0 if inline == 0
if stridx(','.settings.html.inline_elements.',', ','.current.name.',') == -1 if stridx(','.settings.html.inline_elements.',', ','.current.name.',') == -1
let inner = substitute(inner, "\n", "\n" . indent, 'g') if inner =~ "\n$"
let inner = substitute(inner, indent . "$", "", 'g') let inner = substitute(inner, "\n", "\n" . indent, 'g')
let str .= ">\n" . indent . inner . "</" . current.name . ">\n" let inner = substitute(inner, indent . "$", "", 'g')
let str .= ">\n" . indent . inner . "</" . current.name . ">\n"
else
let str .= ">\n" . indent . inner . indent . "\n</" . current.name . ">\n"
endif
else else
let str .= ">" . inner . "</" . current.name . ">\n" let str .= ">" . inner . "</" . current.name . ">\n"
endif endif
@@ -585,6 +595,8 @@ endfunction
function! s:zen_getFileType() function! s:zen_getFileType()
let type = &ft let type = &ft
if type == 'xslt' | let type = 'xsl' | endif if type == 'xslt' | let type = 'xsl' | endif
if type == 'htmldjango' | let type = 'html' | endif
if type == 'html.django_template' | let type = 'html' | endif
if synIDattr(synID(line("."), col("."), 1), "name") =~ '^css' if synIDattr(synID(line("."), col("."), 1), "name") =~ '^css'
let type = 'css' let type = 'css'
endif endif
@@ -634,8 +646,12 @@ function! zencoding#expandAbbr(mode) range
for n in range(a:firstline, a:lastline) for n in range(a:firstline, a:lastline)
let lline = getline(n) let lline = getline(n)
let lpart = substitute(lline, '^\s*', '', '') let lpart = substitute(lline, '^\s*', '', '')
let expand = substitute(expand, '\$line\$', lpart, '') let pos = stridx(expand, "$line$")
if pos != -1
let expand = expand[:pos-1] . lpart . expand[pos+6:]
endif
endfor endfor
let expand = substitute(expand, '\$line\$', '', 'g')
else else
let str = '' let str = ''
if a:firstline != a:lastline if a:firstline != a:lastline
@@ -676,9 +692,6 @@ function! zencoding#expandAbbr(mode) range
else else
let part = matchstr(line, '\(\S.*\)$') let part = matchstr(line, '\(\S.*\)$')
endif endif
if part =~ '!'
let part = substitute(part, '.*!', '!', '')
endif
let rest = getline('.')[len(line):] let rest = getline('.')[len(line):]
let str = part let str = part
let mx = '|\(\%(html\|haml\|e\|c\|fc\|xsl\)\s*,\{0,1}\s*\)*$' let mx = '|\(\%(html\|haml\|e\|c\|fc\|xsl\)\s*,\{0,1}\s*\)*$'
@@ -729,6 +742,9 @@ function! zencoding#expandAbbr(mode) range
silent! exe "normal! v7h\"_s" silent! exe "normal! v7h\"_s"
let &selection = oldselection let &selection = oldselection
endif endif
if g:zencoding_debug > 1
call getchar()
endif
endfunction endfunction
function! zencoding#moveNextPrev(flag) function! zencoding#moveNextPrev(flag)
@@ -775,8 +791,8 @@ function! zencoding#imageSize()
endif endif
if hex =~ '^47494638' if hex =~ '^47494638'
let type = 'gif' let type = 'gif'
let width = eval('0x'.hex[18:19].hex[16:17]) let width = eval('0x'.hex[14:15].hex[12:13])
let height = eval('0x'.hex[14:15].hex[12:13]) let height = eval('0x'.hex[18:19].hex[16:17])
endif endif
if width == -1 && height == -1 if width == -1 && height == -1
@@ -1791,7 +1807,8 @@ let s:zen_settings = {
\ 'pgba:r': 'page-break-after:right;', \ 'pgba:r': 'page-break-after:right;',
\ 'orp': 'orphans:|;', \ 'orp': 'orphans:|;',
\ 'wid': 'widows:|;' \ 'wid': 'widows:|;'
\ } \ },
\ 'filters': 'fc'
\ }, \ },
\ 'html': { \ 'html': {
\ 'snippets': { \ 'snippets': {

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: 22-Nov-2010. " Last Change: 14-Jan-2011.
" Version: 0.50 " Version: 0.52
" 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/

View File

@@ -23,6 +23,7 @@ function! s:testExpandAbbr()
else else
echohl WarningMsg | echon "ng\n" | echohl None echohl WarningMsg | echon "ng\n" | echohl None
echohl ErrorMsg | echo "failed test #".(n+1) | echohl None echohl ErrorMsg | echo "failed test #".(n+1) | echohl None
set more
echo " expect:".tests[n].result echo " expect:".tests[n].result
echo " got:".res echo " got:".res
echo "" echo ""
@@ -412,6 +413,12 @@ finish
'type': "html", 'type': "html",
'result': "<div>\n\t<a id=\"foo\" href=\"\">bar</a>\n</div>\n", 'result': "<div>\n\t<a id=\"foo\" href=\"\">bar</a>\n</div>\n",
}, },
{
'name': ".content{Hello!}",
'query': ".content{Hello!}",
'type': "html",
'result': "<div class=\"content\">Hello!</div>\n",
},
], ],
}, },
{ {
@@ -435,6 +442,12 @@ finish
'type': "css", 'type': "css",
'result': "float: left;", 'result': "float: left;",
}, },
{
'name': "bg+",
'query': "bg+",
'type': "css",
'result': "background:#FFF url() 0 0 no-repeat;",
},
], ],
}, },
{ {
@@ -450,7 +463,19 @@ finish
'name': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}|haml", 'name': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}|haml",
'query': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}|haml", 'query': "div>p+ul#foo>li.bar$[foo=bar][bar=baz]*3>{baz}|haml",
'type': "haml", 'type': "haml",
'result': "%div\n %p<\n %ul#foo\n %li.bar1{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar2{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar3{ :foo => \"bar\", :bar => \"baz\" } baz\n", 'result': "%div\n %p\n %ul#foo\n %li.bar1{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar2{ :foo => \"bar\", :bar => \"baz\" } baz\n %li.bar3{ :foo => \"bar\", :bar => \"baz\" } baz\n",
},
{
'name': "a*3|haml",
'query': "a*3|haml",
'type': "haml",
'result': "%a{ :href => \"\" }\n%a{ :href => \"\" }\n%a{ :href => \"\" }\n",
},
{
'name': ".content{Hello!}|haml",
'query': ".content{Hello!}|haml",
'type': "haml",
'result': "%div.content Hello!\n",
}, },
], ],
}, },

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.zip script_package: zencoding-vim.zip
script_version: '0.50' script_version: '0.51'
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.
@@ -98,6 +98,14 @@ install_details: |
# git clone http://github.com/mattn/zencoding-vim.git # git clone http://github.com/mattn/zencoding-vim.git
versions: versions:
- '0.52': |
[fix] broken wrap expanding.
- '0.51': |
This is an upgrade for ZenCoding.vim:
[fix] wrap expanding with '&'.
[fix] expand .content to class="content".
[fix] haml expanding.
[fix] bg+ snippet
- '0.50': | - '0.50': |
This is an upgrade for ZenCoding.vim: This is an upgrade for ZenCoding.vim:
[fix] fixed parsing '#{{foo}}' and '.{{bar}}'. [fix] fixed parsing '#{{foo}}' and '.{{bar}}'.