From 8d43e93dc5b6945cae8b203c83c717736f04bd03 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 23 Feb 2010 19:48:30 +0900 Subject: [PATCH] expand 'ul+' to 'ul>li'. fix undo ring. support visual selection. when type trigger key on visual select, it request you leader like 'ul>li'. if you give 'ul>li*' as leader, you'll get each separate 'ul>li' tags. and when you give 'blockquote' as leader, you'll get blocked text. --- zencoding.vim | 111 +++++++++++++++++++++++++++++--------------- zencoding.vim.vimup | 4 +- 2 files changed, 77 insertions(+), 38 deletions(-) diff --git a/zencoding.vim b/zencoding.vim index a469f9c..83781c7 100644 --- a/zencoding.vim +++ b/zencoding.vim @@ -2,7 +2,7 @@ " File: zencoding.vim " Author: Yasuhiro Matsumoto " Last Change: 23-Feb-2010. -" Version: 0.21 +" Version: 0.22 " 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/ @@ -65,10 +65,33 @@ " GetLatestVimScripts: 2981 1 :AutoInstall: zencoding.vim " script type: plugin -if &cp || (exists('g:loaded_zencoding_vim') && g:loaded_zencoding_vim) +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 +vnoremap ZenCodingExpandVisual :call zen_expand(2) + +if !exists('g:user_zen_expandword_key') + let g:user_zen_expandword_key = '.' +endif +if !hasmapto(g:user_zen_expandword_key, 'i') + exe "imap " . 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 " . g:user_zen_expandabbr_key . " ZenCodingExpandAbbr" +endif +if !hasmapto(g:user_zen_expandabbr_key, 'v') + exe "vmap " . g:user_zen_expandabbr_key . " ZenCodingExpandVisual" +endif + +if exists('s:zen_settings') finish endif -let g:loaded_zencoding_vim = 1 unlet! s:zen_settings let s:zen_settings = { @@ -798,7 +821,7 @@ function! s:zen_parseIntoTree(abbr, type) return { 'child': [] } endif - let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)\+$', '\=s:zen_expandos(submatch(1), type)', 'i') + let abbr = substitute(abbr, '\([a-z][a-z0-9]*\)\++\{-}$', '\=s:zen_expandos(submatch(1), type)', 'i') let mx = '\([\+>#]\|<\+\)\{-}\s*\(@\{-}[a-z][a-z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#[0-9A-Za-z_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|\%(\.[0-9A-Za-z_\-\$]\+\)\)*\)\%(\({[^}]\+}\)\)\{0,1}\%(\*\([0-9]\+\)\)\{0,1}' let last = {} let parent = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'brother': 0 } @@ -888,7 +911,7 @@ function! s:zen_parseIntoTree(abbr, type) let last['brother'] = 1 endif if operator =~ '<' - for c in split(operator, '\zs') + for c in range(len(operator)) let tmp = parent['parent'] if empty(tmp) break @@ -989,20 +1012,53 @@ function! s:zen_get_filetype() return type endfunction -function! s:zen_expand(word) +function! s:zen_expand(mode) range let type = s:zen_get_filetype() - let line = getline('.')[:col('.')-1] - if a:word || type != 'html' - let part = matchstr(line, '\([0-9A-Za-z_\@:]\+\)$') - else - let part = matchstr(line, '\(\S.*\)$') - endif - let rest = getline('.')[col('.'):] - let items = s:zen_parseIntoTree(part, type)['child'] let expand = '' - for item in items - let expand .= s:zen_toString(item, type) - endfor + if a:mode == 2 + let leader = input('Tag: ', '') + if len(leader) == 0 + return + endif + let line = '' + let part = '' + let rest = '' + if leader =~ '\*$' + for n in range(a:firstline, a:lastline) + let items = s:zen_parseIntoTree(leader[:-2] . '{' . getline(n) . '}', type)['child'] + for item in items + let expand .= s:zen_toString(item, type) + endfor + endfor + else + let str = '' + if a:firstline != a:lastline + for n in range(a:firstline, a:lastline) + let str .= getline(n) . "\n" + endfor + 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'] + endif + for item in items + let expand .= s:zen_toString(item, type) + endfor + endif + silent! exe "normal! gvc" + else + let line = getline('.')[:col('.')-1] + if a:mode == 1 || type != 'html' + let part = matchstr(line, '\([0-9A-Za-z_\@:]\+\)$') + else + let part = matchstr(line, '\(\S.*\)$') + endif + let rest = getline('.')[col('.'):] + let items = s:zen_parseIntoTree(part, type)['child'] + for item in items + let expand .= s:zen_toString(item, type) + endfor + endif if len(expand) let expand = substitute(expand, '|', '$cursor$', '') let expand = substitute(expand, '|', '', 'g') @@ -1097,26 +1153,6 @@ if exists('g:user_zen_settings') call s:zen_mergeConfig(s:zen_settings, g:user_zen_settings) endif -if exists('g:use_zen_complete_tag') && g:use_zen_complete_tag - setlocal completefunc=ZenCompleteTag -endif - -inoremap ZenCodingExpandWord u:call zen_expand(1)a -inoremap ZenCodingExpandAbbr u:call zen_expand(0)a - -if !exists('g:user_zen_expandword_key') - let g:user_zen_expandword_key = '.' -endif -if !hasmapto(g:user_zen_expandword_key, 'i') - exe "imap " . 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 " . g:user_zen_expandabbr_key . " ZenCodingExpandAbbr" -endif - " test "echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '') "echo ZenExpand('ol>li*2', '') @@ -1145,5 +1181,6 @@ endif "echo ZenExpand('@i', 'css') "echo ZenExpand('fs:n', 'css') "echo ZenExpand('link:css', '') +"echo ZenExpand('ul+', '') " vim:set et: diff --git a/zencoding.vim.vimup b/zencoding.vim.vimup index ab083a3..bbdb833 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.21' +script_version: '0.22' required_vim_version: '7.0' summary: vim plugins for HTML and CSS hi-speed coding. @@ -71,6 +71,8 @@ install_details: | copy zencoding.vim to your plugin directory. versions: +- '0.22': | + This is an upgrade for ZenCoding.vim: expand 'ul+' to 'ul>li'. fix undo ring. support visual selection. when type trigger key on visual select, it request you leader like 'ul>li'. if you give 'ul>li*' as leader, you'll get each separate 'ul>li' tags. and when you give 'blockquote' as leader, you'll get blocked text. - '0.21': | This is an upgrade for ZenCoding.vim: treat xhtml as html. - '0.20': |