splitJoinTag for haml & slim.

This commit is contained in:
mattn
2012-06-04 22:58:01 +09:00
parent 85b6ed4349
commit 9835978968
4 changed files with 58 additions and 3 deletions

View File

@@ -140,3 +140,7 @@ endfunction
function! zencoding#lang#css#splitJoinTag() function! zencoding#lang#css#splitJoinTag()
" nothing to do " nothing to do
endfunction endfunction
function! zencoding#lang#css#removeTag()
" nothing to do
endfunction

View File

@@ -198,6 +198,34 @@ function! zencoding#lang#haml#moveNextPrev(flag)
endfunction endfunction
function! zencoding#lang#haml#splitJoinTag() function! zencoding#lang#haml#splitJoinTag()
let n = line('.')
while n > 0
if getline(n) =~ '^\s*\ze%[a-z]'
let line = getline(n)
call setline(n, matchstr(line, '^\s*%\w\+\s*{[^}]*}'))
let sn = n
let n += 1
let ml = len(matchstr(getline(n), '^\s*%[a-z]'))
if getline(n) =~ '^\s*|'
while n < line('$')
let l = len(matchstr(getline(n), '^\s*'))
if l <= ml
break
endif
exe n "delete"
let n += 1
endwhile
call setpos('.', [0, sn, 1, 0])
else
let spaces = matchstr(getline(sn), '^\s*')
call append(sn, spaces . ' | ')
call setpos('.', [0, sn+1, 1, 0])
startinsert!
endif
break
endif
let n -= 1
endwhile
endfunction endfunction
function! zencoding#lang#haml#removeTag() function! zencoding#lang#haml#removeTag()

View File

@@ -187,7 +187,30 @@ function! zencoding#lang#slim#moveNextPrev(flag)
endfunction endfunction
function! zencoding#lang#slim#splitJoinTag() function! zencoding#lang#slim#splitJoinTag()
" TODO let n = line('.')
while n > 0
if getline(n) =~ '^\s*\ze[a-z]'
let sn = n
let n += 1
if getline(n) =~ '^\s*|'
while n < line('$')
if getline(n) !~ '^\s*|'
break
endif
exe n "delete"
let n += 1
endwhile
call setpos('.', [0, sn, 1, 0])
else
let spaces = matchstr(getline(sn), '^\s*')
call append(sn, spaces . ' | ')
call setpos('.', [0, sn+1, 1, 0])
startinsert!
endif
break
endif
let n -= 1
endwhile
endfunction endfunction
function! zencoding#lang#slim#removeTag() function! zencoding#lang#slim#removeTag()

View File

@@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" File: zencoding.vim " File: zencoding.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 03-Jun-2012. " Last Change: 04-Jun-2012.
" Version: 0.72 " Version: 0.72
" WebPage: http://github.com/mattn/zencoding-vim " WebPage: http://github.com/mattn/zencoding-vim
" Description: vim plugins for HTML and CSS hi-speed coding. " Description: vim plugins for HTML and CSS hi-speed coding.
@@ -112,7 +112,7 @@ function! s:install_plugin()
\ {'mode': 'i', 'var': 'user_zen_togglecomment_key', 'key': '/', 'plug': 'ZenCodingToggleComment', 'func': '<esc>:call zencoding#toggleComment()<cr>a'}, \ {'mode': 'i', 'var': 'user_zen_togglecomment_key', 'key': '/', 'plug': 'ZenCodingToggleComment', 'func': '<esc>:call zencoding#toggleComment()<cr>a'},
\ {'mode': 'n', 'var': 'user_zen_togglecomment_key', 'key': '/', 'plug': 'ZenCodingToggleComment', 'func': ':call zencoding#toggleComment()<cr>'}, \ {'mode': 'n', 'var': 'user_zen_togglecomment_key', 'key': '/', 'plug': 'ZenCodingToggleComment', 'func': ':call zencoding#toggleComment()<cr>'},
\ {'mode': 'v', 'var': 'user_zen_mergelines_key', 'key': 'm', 'plug': 'ZenCodingMergeLines', 'func': ':call zencoding#mergeLines()<cr>'}, \ {'mode': 'v', 'var': 'user_zen_mergelines_key', 'key': 'm', 'plug': 'ZenCodingMergeLines', 'func': ':call zencoding#mergeLines()<cr>'},
\ {'mode': 'i', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTagInsert', 'func': '<esc>:call zencoding#splitJoinTag()<cr>a'}, \ {'mode': 'i', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTagInsert', 'func': '<esc>:call zencoding#splitJoinTag()<cr>'},
\ {'mode': 'n', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTagNormal', 'func': ':call zencoding#splitJoinTag()<cr>'}, \ {'mode': 'n', 'var': 'user_zen_splitjointag_key', 'key': 'j', 'plug': 'ZenCodingSplitJoinTagNormal', 'func': ':call zencoding#splitJoinTag()<cr>'},
\ {'mode': 'i', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': '<esc>:call zencoding#removeTag()<cr>a'}, \ {'mode': 'i', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': '<esc>:call zencoding#removeTag()<cr>a'},
\ {'mode': 'n', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': ':call zencoding#removeTag()<cr>'}, \ {'mode': 'n', 'var': 'user_zen_removetag_key', 'key': 'k', 'plug': 'ZenCodingRemoveTag', 'func': ':call zencoding#removeTag()<cr>'},