From 69617e73d3de18bcbe6a291734cb7fca72314417 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 23 Feb 2010 13:46:33 +0900 Subject: [PATCH] add new option 'g:use_zen_complete_tag' for complete abbr. --- zencoding.vim | 64 ++++++++++++++++++++++++++++++++------------- zencoding.vim.vimup | 8 +++++- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/zencoding.vim b/zencoding.vim index d5b8408..07ba721 100644 --- a/zencoding.vim +++ b/zencoding.vim @@ -2,7 +2,7 @@ " File: zencoding.vim " Author: Yasuhiro Matsumoto " Last Change: 23-Feb-2010. -" Version: 0.19 +" Version: 0.20 " 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/ @@ -994,8 +994,6 @@ function! s:zen_expand(word) let rest = getline('.')[col('.'):] let items = s:zen_parseIntoTree(part, type)['child'] let expand = '' - let g:hoge = line - let g:moge = part for item in items let expand .= s:zen_toString(item, type) endfor @@ -1035,21 +1033,6 @@ function! ZenExpand(abbr, type) return expand endfunction -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 - function! s:zen_mergeConfig(lhs, rhs) if type(a:lhs) == 3 && type(a:rhs) == 3 call remove(a:lhs, 0, len(a:lhs)-1) @@ -1073,9 +1056,54 @@ function! s:zen_mergeConfig(lhs, rhs) endif endfunction +function! ZenCompleteTag(findstart, base) + if a:findstart + let line = getline('.') + let start = col('.') - 1 + while start > 0 && line[start - 1] =~ '[a-zA-Z0-9:\@]' + let start -= 1 + endwhile + return start + else + let type = &ft + let res = [] + if !has_key(s:zen_settings, type) + return res + endif + if len(type) == 0 | let type = 'html' | endif + for item in keys(s:zen_settings[type]['snippets']) + if stridx(item, a:base) != -1 + call add(res, item) + endif + endfor + return res + endif +endfunction + 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', '') diff --git a/zencoding.vim.vimup b/zencoding.vim.vimup index a9fb46e..e8d3f19 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.19' +script_version: '0.20' required_vim_version: '7.0' summary: vim plugins for HTML and CSS hi-speed coding. @@ -61,12 +61,18 @@ detailed_description: | \ } \} + let g:user_zen_expandabbr_key = '' + + let g:use_zen_complete_tag = 1 + You can set language attribute in html using zen_settings['lang']. install_details: | copy zencoding.vim to your plugin directory. versions: +- '0.20': | + This is an upgrade for ZenCoding.vim: add option use_zen_complete_tag for complete abbr. - '0.19': | This is an upgrade for ZenCoding.vim: fixed problem that couldn't expand 'link:css' correctly. - '0.18': |