forked from VimPlug/emmet-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.
This commit is contained in:
111
zencoding.vim
111
zencoding.vim
@@ -2,7 +2,7 @@
|
|||||||
" File: zencoding.vim
|
" File: zencoding.vim
|
||||||
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
|
||||||
" Last Change: 23-Feb-2010.
|
" Last Change: 23-Feb-2010.
|
||||||
" Version: 0.21
|
" Version: 0.22
|
||||||
" 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.
|
||||||
" SeeAlso: http://code.google.com/p/zen-coding/
|
" SeeAlso: http://code.google.com/p/zen-coding/
|
||||||
@@ -65,10 +65,33 @@
|
|||||||
" GetLatestVimScripts: 2981 1 :AutoInstall: zencoding.vim
|
" GetLatestVimScripts: 2981 1 :AutoInstall: zencoding.vim
|
||||||
" script type: plugin
|
" 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 <plug>ZenCodingExpandAbbr <esc>:call <sid>zen_expand(0)<cr>a
|
||||||
|
inoremap <plug>ZenCodingExpandWord <esc>:call <sid>zen_expand(1)<cr>a
|
||||||
|
vnoremap <plug>ZenCodingExpandVisual :call <sid>zen_expand(2)<cr>
|
||||||
|
|
||||||
|
if !exists('g:user_zen_expandword_key')
|
||||||
|
let g:user_zen_expandword_key = '<c-z>.'
|
||||||
|
endif
|
||||||
|
if !hasmapto(g:user_zen_expandword_key, 'i')
|
||||||
|
exe "imap <buffer> " . g:user_zen_expandword_key . " <plug>ZenCodingExpandWord"
|
||||||
|
endif
|
||||||
|
if !exists('g:user_zen_expandabbr_key')
|
||||||
|
let g:user_zen_expandabbr_key = '<c-z>,'
|
||||||
|
endif
|
||||||
|
if !hasmapto(g:user_zen_expandabbr_key, 'i')
|
||||||
|
exe "imap <buffer> " . g:user_zen_expandabbr_key . " <plug>ZenCodingExpandAbbr"
|
||||||
|
endif
|
||||||
|
if !hasmapto(g:user_zen_expandabbr_key, 'v')
|
||||||
|
exe "vmap <buffer> " . g:user_zen_expandabbr_key . " <plug>ZenCodingExpandVisual"
|
||||||
|
endif
|
||||||
|
|
||||||
|
if exists('s:zen_settings')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let g:loaded_zencoding_vim = 1
|
|
||||||
|
|
||||||
unlet! s:zen_settings
|
unlet! s:zen_settings
|
||||||
let s:zen_settings = {
|
let s:zen_settings = {
|
||||||
@@ -798,7 +821,7 @@ function! s:zen_parseIntoTree(abbr, type)
|
|||||||
return { 'child': [] }
|
return { 'child': [] }
|
||||||
endif
|
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 mx = '\([\+>#]\|<\+\)\{-}\s*\(@\{-}[a-z][a-z0-9:\!\-]*\|{[^}]\+}\)\(\%(\%(#[0-9A-Za-z_\-\$]\+\)\|\%(\[[^\]]\+\]\)\|\%(\.[0-9A-Za-z_\-\$]\+\)\)*\)\%(\({[^}]\+}\)\)\{0,1}\%(\*\([0-9]\+\)\)\{0,1}'
|
||||||
let last = {}
|
let last = {}
|
||||||
let parent = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'brother': 0 }
|
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
|
let last['brother'] = 1
|
||||||
endif
|
endif
|
||||||
if operator =~ '<'
|
if operator =~ '<'
|
||||||
for c in split(operator, '\zs')
|
for c in range(len(operator))
|
||||||
let tmp = parent['parent']
|
let tmp = parent['parent']
|
||||||
if empty(tmp)
|
if empty(tmp)
|
||||||
break
|
break
|
||||||
@@ -989,20 +1012,53 @@ function! s:zen_get_filetype()
|
|||||||
return type
|
return type
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:zen_expand(word)
|
function! s:zen_expand(mode) range
|
||||||
let type = s:zen_get_filetype()
|
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 = ''
|
let expand = ''
|
||||||
for item in items
|
if a:mode == 2
|
||||||
let expand .= s:zen_toString(item, type)
|
let leader = input('Tag: ', '')
|
||||||
endfor
|
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)
|
if len(expand)
|
||||||
let expand = substitute(expand, '|', '$cursor$', '')
|
let expand = substitute(expand, '|', '$cursor$', '')
|
||||||
let expand = substitute(expand, '|', '', 'g')
|
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)
|
call s:zen_mergeConfig(s:zen_settings, g:user_zen_settings)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists('g:use_zen_complete_tag') && g:use_zen_complete_tag
|
|
||||||
setlocal completefunc=ZenCompleteTag
|
|
||||||
endif
|
|
||||||
|
|
||||||
inoremap <plug>ZenCodingExpandWord <c-g>u<esc>:call <sid>zen_expand(1)<cr>a
|
|
||||||
inoremap <plug>ZenCodingExpandAbbr <c-g>u<esc>:call <sid>zen_expand(0)<cr>a
|
|
||||||
|
|
||||||
if !exists('g:user_zen_expandword_key')
|
|
||||||
let g:user_zen_expandword_key = '<c-z>.'
|
|
||||||
endif
|
|
||||||
if !hasmapto(g:user_zen_expandword_key, 'i')
|
|
||||||
exe "imap " . g:user_zen_expandword_key . " <plug>ZenCodingExpandWord"
|
|
||||||
endif
|
|
||||||
if !exists('g:user_zen_expandabbr_key')
|
|
||||||
let g:user_zen_expandabbr_key = '<c-z>,'
|
|
||||||
endif
|
|
||||||
if !hasmapto(g:user_zen_expandabbr_key, 'i')
|
|
||||||
exe "imap " . g:user_zen_expandabbr_key . " <plug>ZenCodingExpandAbbr"
|
|
||||||
endif
|
|
||||||
|
|
||||||
" test
|
" test
|
||||||
"echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '')
|
"echo ZenExpand('html:xt>div#header>div#logo+ul#nav>li.item-$*5>a', '')
|
||||||
"echo ZenExpand('ol>li*2', '')
|
"echo ZenExpand('ol>li*2', '')
|
||||||
@@ -1145,5 +1181,6 @@ endif
|
|||||||
"echo ZenExpand('@i', 'css')
|
"echo ZenExpand('@i', 'css')
|
||||||
"echo ZenExpand('fs:n', 'css')
|
"echo ZenExpand('fs:n', 'css')
|
||||||
"echo ZenExpand('link:css', '')
|
"echo ZenExpand('link:css', '')
|
||||||
|
"echo ZenExpand('ul+', '')
|
||||||
|
|
||||||
" vim:set et:
|
" vim:set et:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ script_name: ZenCoding.vim
|
|||||||
script_id: '2981'
|
script_id: '2981'
|
||||||
script_type: utility
|
script_type: utility
|
||||||
script_package: zencoding.vim
|
script_package: zencoding.vim
|
||||||
script_version: '0.21'
|
script_version: '0.22'
|
||||||
required_vim_version: '7.0'
|
required_vim_version: '7.0'
|
||||||
summary: vim plugins for HTML and CSS hi-speed coding.
|
summary: vim plugins for HTML and CSS hi-speed coding.
|
||||||
|
|
||||||
@@ -71,6 +71,8 @@ install_details: |
|
|||||||
copy zencoding.vim to your plugin directory.
|
copy zencoding.vim to your plugin directory.
|
||||||
|
|
||||||
versions:
|
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': |
|
- '0.21': |
|
||||||
This is an upgrade for ZenCoding.vim: treat xhtml as html.
|
This is an upgrade for ZenCoding.vim: treat xhtml as html.
|
||||||
- '0.20': |
|
- '0.20': |
|
||||||
|
|||||||
Reference in New Issue
Block a user