From 671226c00548212cbba685a20501430cd7d365a2 Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 4 Mar 2010 03:19:14 +0900 Subject: [PATCH] refact & add image size (in progress) --- zencoding.vim | 67 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/zencoding.vim b/zencoding.vim index a744218..cf7e241 100644 --- a/zencoding.vim +++ b/zencoding.vim @@ -1,7 +1,7 @@ "============================================================================= " File: zencoding.vim " Author: Yasuhiro Matsumoto -" Last Change: 03-Mar-2010. +" Last Change: 04-Mar-2010. " Version: 0.27 " WebPage: http://github.com/mattn/zencoding-vim " Description: vim plugins for HTML and CSS hi-speed coding. @@ -74,11 +74,12 @@ if exists('g:use_zen_complete_tag') && g:use_zen_complete_tag setlocal completefunc=ZenCompleteTag endif -inoremap ZenCodingExpandAbbr u:call zen_expand(0)a -inoremap ZenCodingExpandWord u:call zen_expand(1)a -vnoremap ZenCodingExpandVisual :call zen_expand(2) -inoremap ZenCodingNext :call zen_nextprev(0) -inoremap ZenCodingPrev :call zen_nextprev(1) +inoremap ZenCodingExpandAbbr u:call zen_expandAbbr(0)a +inoremap ZenCodingExpandWord u:call zen_expandAbbr(1)a +vnoremap ZenCodingExpandVisual :call zen_expandAbbr(2) +inoremap ZenCodingNext :call zen_moveNextPrev(0) +inoremap ZenCodingPrev :call zen_moveNextPrev(1) +inoremap ZenCodingImageSize :call zen_imageSize()a let s:target = expand(':h') =~ '[\\/]plugin$' ? '' : '' @@ -111,6 +112,7 @@ 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" if exists('s:zen_settings') && g:zencoding_debug == 0 finish @@ -1099,15 +1101,15 @@ function! s:zen_toString(...) return str endfunction -function! s:zen_get_filetype() +function! s:zen_getFileType() let type = &ft if len(type) == 0 | let type = 'html' | endif if type == 'xhtml' | let type = 'html' | endif return type endfunction -function! s:zen_expand(mode) range - let type = s:zen_get_filetype() +function! s:zen_expandAbbr(mode) range + let type = s:zen_getFileType() let expand = '' if a:mode == 2 let leader = substitute(input('Tag: ', ''), ' ', '', 'g') @@ -1188,7 +1190,7 @@ function! s:zen_expand(mode) range endif endfunction -function! s:zen_nextprev(flag) +function! s:zen_moveNextPrev(flag) if search('><\/\|\(""\)\|^\s*$', a:flag ? 'Wpb' : 'Wp') == 3 startinsert! else @@ -1197,6 +1199,51 @@ function! s:zen_nextprev(flag) endif endfunction +function! s:zen_imageSize() + let line = getline('.') + let mx = ']\+>' + let c = 0 + let match = '' + while len(line) + let match = matchstr(line, mx) + if len(match) == 0 + let c = -1 + endif + let pos = stridx(line, match) + let c += pos + if c <= col('.') && (col('.') < c + len(match)) + break + endif + let line = line[pos + len(match):] + let c += len(match) + endwhile + 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 [w, h] = [-1, -1] + + perl <{width}, $ii->{height})); + undef $ii; +} +EOF + if w == -1 && h == -1 + return + endif + " TODO: replace text + echo '' +endfunction + function! ZenExpand(abbr, type, orig) let items = s:zen_parseIntoTree(a:abbr, a:type).child let expand = ''