forked from VimPlug/emmet-vim
New emmet feature: update tag
This commit is contained in:
@@ -660,6 +660,34 @@ function! emmet#expandAbbr(mode, abbr) range
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! emmet#updateTag()
|
||||
let type = emmet#getFileType()
|
||||
let region = emmet#util#searchRegion('<\S', '>')
|
||||
if !emmet#util#regionIsValid(region) || !emmet#util#cursorInRegion(region)
|
||||
return ''
|
||||
endif
|
||||
let content = emmet#util#getContent(region)
|
||||
if content !~ '^<[^><]\+>$'
|
||||
echo string(content)
|
||||
return ''
|
||||
endif
|
||||
let current = emmet#lang#html#parseTag(content)
|
||||
if empty(current)
|
||||
return ''
|
||||
endif
|
||||
|
||||
let str = substitute(input('Enter Abbreviation: ', ''), '^\s*\(.*\)\s*$', '\1', 'g')
|
||||
let item = emmet#parseIntoTree(str, type).child[0]
|
||||
for k in keys(item.attr)
|
||||
let current.attr[k] = item.attr[k]
|
||||
endfor
|
||||
let html = substitute(emmet#toString(current, 'html', 1), '\n', '', '')
|
||||
let html = substitute(html, '\${cursor}', '', '')
|
||||
let html = matchstr(html, '^<[^><]\+>')
|
||||
call emmet#util#setContent(region, html)
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
function! emmet#moveNextPrevItem(flag)
|
||||
let type = emmet#getFileType()
|
||||
let rtype = emmet#lang#exists(type) ? type : 'html'
|
||||
|
||||
@@ -106,6 +106,8 @@ function! s:install_plugin(mode, buffer)
|
||||
\ {'mode': 'v', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmmet-expand-abbr', 'func': ':call emmet#expandAbbr(2,"")<cr>'},
|
||||
\ {'mode': 'i', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'emmet-expand-word', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#expandAbbr(1,"")<cr><right>'},
|
||||
\ {'mode': 'n', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'emmet-expand-word', 'func': ':call emmet#expandAbbr(1,"")<cr>'},
|
||||
\ {'mode': 'i', 'var': 'user_emmet_update_tag', 'key': 'u', 'plug': 'emmmet-update-tag', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#updateTag()<cr>'},
|
||||
\ {'mode': 'n', 'var': 'user_emmet_update_tag', 'key': 'u', 'plug': 'emmmet-update-tag', 'func': ':call emmet#updateTag()<cr>'},
|
||||
\ {'mode': 'i', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': '<esc>:call emmet#balanceTag(1)<cr>'},
|
||||
\ {'mode': 'n', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': ':call emmet#balanceTag(1)<cr>'},
|
||||
\ {'mode': 'v', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': ':call emmet#balanceTag(2)<cr>'},
|
||||
|
||||
Reference in New Issue
Block a user