From 0baf7df3f3fb44e46a36dcd6d0cf7f56996c7aa3 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 8 Mar 2010 00:05:57 +0900 Subject: [PATCH] fixed comment block. --- zencoding.vim | 80 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/zencoding.vim b/zencoding.vim index 08f6b3e..b200949 100644 --- a/zencoding.vim +++ b/zencoding.vim @@ -1,7 +1,7 @@ "============================================================================= " File: zencoding.vim " Author: Yasuhiro Matsumoto -" Last Change: 06-Mar-2010. +" Last Change: 07-Mar-2010. " Version: 0.27 " WebPage: http://github.com/mattn/zencoding-vim " Description: vim plugins for HTML and CSS hi-speed coding. @@ -80,13 +80,17 @@ for item in [ \ {'mode': 'i', 'var': 'user_zen_expandword_key', 'key': '.', 'plug': 'ZenCodingExpandWord', 'func': 'u:call zen_expandAbbr(1)a'}, \ {'mode': 'v', 'var': 'user_zen_expandabbr_key', 'key': ',', 'plug': 'ZenCodingExpandVisual', 'func': ':call zen_expandAbbr(2)'}, \ {'mode': 'n', 'var': 'user_zen_expandabbr_key', 'key': ',', 'plug': 'ZenCodingExpandNormal', 'func': ':call zen_expandAbbr(0)'}, +\ {'mode': 'i', 'var': 'user_zen_balancetaginward_key', 'key': 'd', 'plug': 'ZenCodingBalanceTagInward', 'func': ':call zen_balanceTag(0)a'}, +\ {'mode': 'n', 'var': 'user_zen_balancetaginward_key', 'key': 'd', 'plug': 'ZenCodingBalanceTagInward', 'func': ':call zen_balanceTag(0)'}, +\ {'mode': 'i', 'var': 'user_zen_balancetagoutward_key', 'key': 'D', 'plug': 'ZenCodingBalanceTagOutward', 'func': ':call zen_balanceTag(1)a'}, +\ {'mode': 'n', 'var': 'user_zen_balancetagoutward_key', 'key': 'D', 'plug': 'ZenCodingBalanceTagOutward', 'func': ':call zen_balanceTag(1)'}, \ {'mode': 'i', 'var': 'user_zen_next_key', 'key': 'n', 'plug': 'ZenCodingNext', 'func': ':call zen_moveNextPrev(0)'}, \ {'mode': 'i', 'var': 'user_zen_prev_key', 'key': 'N', 'plug': 'ZenCodingPrev', 'func': ':call zen_moveNextPrev(1)'}, \ {'mode': 'i', 'var': 'user_zen_imagesize_key', 'key': 'i', 'plug': 'ZenCodingImageSize', 'func': ':call zen_imageSize()'}, \ {'mode': 'i', 'var': 'user_zen_togglecomment_key', 'key': '/', 'plug': 'ZenCodingToggleComment', 'func': ':call zen_toggleComment()a'}, \ {'mode': 'n', 'var': 'user_zen_togglecomment_key', 'key': '/', 'plug': 'ZenCodingToggleComment', 'func': ':call zen_toggleComment()'}, -\ {'mode': 'i', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTag', 'func': ':call zen_splitJoinTag()a'}, -\ {'mode': 'n', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTag', 'func': ':call zen_splitJoinTag()'}, +\ {'mode': 'i', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTagInsert', 'func': ':call zen_splitJoinTag()a'}, +\ {'mode': 'n', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTagNormal', 'func': ':call zen_splitJoinTag()'}, \ {'mode': 'i', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': ':call zen_removeTag()a'}, \ {'mode': 'n', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': ':call zen_removeTag()'}, \] @@ -1281,7 +1285,9 @@ endfunction function! s:zen_toggleComment() let pos = getpos('.') - let block = s:search_region('<[a-zA-Z][a-zA-Z0-9]*[^\/>]*>', '\(<\/[^>]\+>\)') + "let block = s:search_region('<[a-zA-Z][a-zA-Z0-9]*[^\/>]*>', '\(<\/[^>]\+>\)') + "let block = s:search_region('<[a-zA-Z][a-zA-Z0-9]*[^\/>]*>', '\(<\/[^>]\+>\)') + let pos1 = searchpos('<[a-zA-Z][a-zA-Z0-9]*[^\/>]*>', if !s:cursor_in_region(block) let mx1 = '<[a-zA-Z][a-zA-Z0-9]*[^/>\s]*' let mx2 = '[^/>\s]*/>' @@ -1313,35 +1319,35 @@ function! s:zen_toggleComment() endfunction function! s:zen_splitJoinTag() - let mx1 = '<[a-zA-Z][a-zA-Z0-9]*[^/>]*' - let mx2 = '/>' - let empty = s:search_region(mx1, mx2) - if s:cursor_in_region(empty) - let content = s:get_content(empty) - let tag_name = substitute(content, '^<\([a-zA-Z0-9]*\).*$', '\1', '') - let content = matchstr(content, mx1) . ">\n' - call s:change_content(empty, content) - call setpos('.', [0, empty[0][0], empty[0][1], 0]) - else - let mx1 = '<[a-zA-Z][a-zA-Z0-9]*[^/>]*>' - let mx2 = '<\/[^>]\+>' - let block = s:search_region(mx1, mx2) - if s:cursor_in_region(block) - let content = s:get_content(block) - let content = matchstr(content, mx1)[:-2] . '/>' - call s:change_content(block, content) - call setpos('.', [0, block[0][0], block[0][1], 0]) - endif - endif -endfunction - -function! s:zen_removeTag() let mx1 = '<[a-zA-Z][a-zA-Z0-9]*[^/>]*>' let mx2 = '<\/[^>]\+>' let block = s:search_region(mx1, mx2) if s:cursor_in_region(block) let content = s:get_content(block) - let tag_name = substitute(content, '^<\([a-zA-Z0-9]*\).*$', '\1', '') + let content = matchstr(content, mx1)[:-2] . '/>' + call s:change_content(block, content) + call setpos('.', [0, block[0][0], block[0][1], 0]) + else + let mx1 = '<[a-zA-Z][a-zA-Z0-9]*[^\/>]*' + let mx2 = '/>' + let empty = s:search_region(mx1, mx2) + if s:cursor_in_region(empty) + let content = s:get_content(empty) + let tag_name = substitute(content, '^<\([a-zA-Z0-9]*\).*$', '\1', '') + let content = matchstr(content, mx1) . ">\n' + call s:change_content(empty, content) + call setpos('.', [0, empty[0][0], empty[0][1], 0]) + endif + endif +endfunction + +function! s:zen_removeTag() + let mx = '<\([a-zA-Z][a-zA-Z0-9]*\)[^/>]*>' + let pos1 = searchpos(mx, 'bcnW') + let tag_name = substitute(matchstr(getline(pos1[0]), mx), mx, '\1', '') + let pos2 = searchpos('', 'cnW') + let block = [pos1, pos2] + if s:cursor_in_region(block) if matchstr(content, mx2) =~ ']*>' + let pos1 = searchpos(mx, 'bcnW') + let tag_name = substitute(matchstr(getline(pos1[0]), mx), mx, '\1', '') + let pos2 = searchpos('', 'cnW') + let block = [pos1, pos2] + if s:cursor_in_region(block) + call s:select_region(block) + else + let mx1 = '<[a-zA-Z][a-zA-Z0-9]*[^/>]*' + let mx2 = '/>' + let empty = s:search_region(mx1, mx2) + if s:cursor_in_region(empty) + call s:select_region(empty) + endif + endif +endfunction + function! ZenExpand(abbr, type, orig) let items = s:zen_parseIntoTree(a:abbr, a:type).child let expand = ''