diff --git a/TUTORIAL b/TUTORIAL
index 6d78284..d69e925 100644
--- a/TUTORIAL
+++ b/TUTORIAL
@@ -65,10 +65,7 @@ Tutorial of zencoding.vim
7. Update
Size
- (1) :!start explorer
- (2) right click the file. and click 'Property'.
- (3) check the image size.
- (4) add the size of img tag.
+ type 'i' on img tag
8. Merge Lines
@@ -99,5 +96,5 @@ Tutorial of zencoding.vim
11. Toggle Comment
- under construction
+ type '/' in insert mode.
diff --git a/unittest.vim b/unittest.vim
index 47ecfac..6124bda 100644
--- a/unittest.vim
+++ b/unittest.vim
@@ -1,4 +1,7 @@
-unlet! g:user_zen_settings
+if exists('g:user_zen_settings')
+ let s:old_user_zen_settings = g:user_zen_settings
+ unlet! g:user_zen_settings
+endif
so zencoding.vim
unlet! testgroups
@@ -25,6 +28,10 @@ for testgroup in testgroups
endfor
echo "past:".reltimestr(reltime(start))."\n"
endfor
+
+if exists('g:user_zen_settings')
+ let g:user_zen_settings = s:old_user_zen_settings
+endif
finish
[
diff --git a/zencoding.vim b/zencoding.vim
index cf7e241..cc59552 100644
--- a/zencoding.vim
+++ b/zencoding.vim
@@ -80,39 +80,28 @@ vnoremap ZenCodingExpandVisual :call zen_expandAbbr(2)
inoremap ZenCodingNext :call zen_moveNextPrev(0)
inoremap ZenCodingPrev :call zen_moveNextPrev(1)
inoremap ZenCodingImageSize :call zen_imageSize()a
+inoremap ZenCodingToggleComment :call zen_toggleComment()a
+inoremap ZenCodingSplitJoinTag :call zen_splitJoinTag()a
let s:target = expand(':h') =~ '[\\/]plugin$' ? '' : ''
-if !exists('g:user_zen_expandword_key')
- let g:user_zen_expandword_key = '.'
-endif
-if !hasmapto(g:user_zen_expandword_key, 'i')
- exe "imap " . s:target . " " . g:user_zen_expandword_key . " ZenCodingExpandWord"
-endif
-
-if !exists('g:user_zen_expandabbr_key')
- let g:user_zen_expandabbr_key = ','
-endif
-if !hasmapto(g:user_zen_expandabbr_key, 'i')
- exe "imap " . s:target . " " . g:user_zen_expandabbr_key . " ZenCodingExpandAbbr"
-endif
-if !hasmapto(g:user_zen_expandabbr_key, 'v')
- exe "vmap " . s:target . " " . g:user_zen_expandabbr_key . " ZenCodingExpandVisual"
-endif
-
-if !exists('g:user_zen_next_key')
- let g:user_zen_next_key = 'n'
-endif
-if !hasmapto(g:user_zen_next_key, 'i')
- exe "imap " . s:target . " " . g:user_zen_next_key . " ZenCodingNext"
-endif
-if !exists('g:user_zen_prev_key')
- let g:user_zen_prev_key = 'N'
-endif
-if !hasmapto(g:user_zen_prev_key, 'i')
- exe "imap " . s:target . " " . g:user_zen_prev_key . " ZenCodingPrev"
-endif
-exe "imap " . s:target . " i ZenCodingImageSize"
+for item in [
+\ {'mode': 'i', 'var': 'user_zen_expandword_key', 'key': '.', 'plug': 'ZenCodingExpandWord'},
+\ {'mode': 'i', 'var': 'user_zen_expandabbr_key', 'key': ',', 'plug': 'ZenCodingExpandAbbr'},
+\ {'mode': 'v', 'var': 'user_zen_expandabbr_key', 'key': ',', 'plug': 'ZenCodingExpandVisual'},
+\ {'mode': 'i', 'var': 'user_zen_next_key', 'key': 'n', 'plug': 'ZenCodingNext'},
+\ {'mode': 'i', 'var': 'user_zen_prev_key', 'key': 'N', 'plug': 'ZenCodingPrev'},
+\ {'mode': 'i', 'var': 'user_zen_imagesize_key', 'key': 'i', 'plug': 'ZenCodingImageSize'},
+\ {'mode': 'i', 'var': 'user_zen_togglecomment_key', 'key': '/', 'plug': 'ZenCodingToggleComment'},
+\ {'mode': 'i', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTag'},
+\]
+ if !exists('g:' . item.var)
+ exe "let g:" . item.var . " = '" . item.key . "'"
+ endif
+ if !hasmapto(eval("g:" . item.var), item.mode)
+ exe "imap " . s:target . " " . item.key . " " . item.plug
+ endif
+endfor
if exists('s:zen_settings') && g:zencoding_debug == 0
finish
@@ -1076,7 +1065,11 @@ function! s:zen_toString(...)
endif
endif
else
- let str .= ">" . inner . "|" . current.name . ">"
+ if stridx(','.s:zen_settings[type].empty_elements.',', ','.current.name.',') != -1
+ let str .= " />"
+ else
+ let str .= ">" . inner . "|" . current.name . ">"
+ endif
endif
endif
else
@@ -1199,6 +1192,23 @@ function! s:zen_moveNextPrev(flag)
endif
endfunction
+function! s:zen_parseTag(tag)
+ let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0 }
+ let mx = '<\([a-z][a-z0-9]*\)\(\%(\s[a-z0-9]\+=\%([^"'' \t]\+\|["''][^"'']\+["'']\)\)*\)\(/\{0,1}\)>'
+ let match = matchstr(a:tag, mx)
+ let current.name = substitute(match, mx, '\1', 'i')
+ let attrs = substitute(match, mx, '\2', 'i')
+ let mx = '\([a-z0-9]\+\)=["'']\{0,1}\([^"'' \t]\+\|[^"'']\+\)["'']\{0,1}'
+ while len(attrs) > 0
+ let match = matchstr(attrs, mx)
+ let name = substitute(match, mx, '\1', 'i')
+ let value = substitute(match, mx, '\2', 'i')
+ let current.attr[name] = value
+ let attrs = attrs[stridx(attrs, match) + len(match):]
+ endwhile
+ return current
+endfunction
+
function! s:zen_imageSize()
let line = getline('.')
let mx = '
]\+>'
@@ -1220,28 +1230,72 @@ function! s:zen_imageSize()
if pos == -1 || len(line) == 0
return
endif
- let mx = '^.*\ssrc=["'']\([^"'']\+\)["''].*$'
- let fn = matchstr(match, mx)
- if len(fn) == 0
- return
- endif
- let fn = substitute(fn, mx, '\1', '')
+ let current = s:zen_parseTag(match)
+ let fn = current.attr['src']
let [w, h] = [-1, -1]
- perl <{width}, $ii->{height}));
+ require Image::Info;
+ my $fn = ''.VIM::Eval('l:fn');
+ my $ii;
+ if ($fn =~ /^http\:\/\//) {
+ require File::Temp;
+ require LWP::Simple;
+ my $tmp = File::Temp::tempfile(CLEANUP => 1);
+ my $path = "$tmp";
+ $path =~ s/\\/\//g if $^O eq 'MSWin32';
+ my $res = LWP::Simple::mirror($fn, $path);
+ $ii = Image::Info::image_info($path);
+ } else {
+ $ii = Image::Info::image_info($fn);
+ }
+ VIM::DoCommand(sprintf('let [w, h] = [%d,%d]', $ii->{width} || -1, $ii->{height} || -1));
undef $ii;
-}
+};
+VIM::Msg($@, "ErrorMsg") if $@;
EOF
+ endif
+
if w == -1 && h == -1
return
endif
- " TODO: replace text
- echo '
'
+ let current.attr['width'] = w
+ let current.attr['height'] = h
+ let html = s:zen_toString(current, 'html', 1)
+ let line = getline('.')
+ let line = line[:c-1] . html . line[c + len(match):]
+ call setline(line('.'), line)
+endfunction
+
+function! s:zen_toggleComment()
+ let pos = getpos('.')
+ call search('<', 'bW')
+ if searchpair('', 'bcW')
+ exe "normal! d5l"
+ call search('\([^>]\+>\|<[^/>]\+/>\) -->', 'ceW')
+ exe "normal! d4h"
+ let pos[2] -= 5
+ elseif searchpair('<[a-z]', '', '\([^>]\+>\|<[^/>]\+/>\)', 'bcW')
+ exe "normal! i