From cd808a5fe5b2cc3bcf4b92d0b6455cab6bbf7448 Mon Sep 17 00:00:00 2001 From: mattn Date: Tue, 11 Mar 2014 16:39:35 +0900 Subject: [PATCH] New emmet feature: update tag --- autoload/emmet.vim | 28 ++++++++++++++++++++++++++++ plugin/emmet.vim | 2 ++ 2 files changed, 30 insertions(+) diff --git a/autoload/emmet.vim b/autoload/emmet.vim index 7c646be..72c4c01 100644 --- a/autoload/emmet.vim +++ b/autoload/emmet.vim @@ -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' diff --git a/plugin/emmet.vim b/plugin/emmet.vim index cd6c385..e1e7f76 100644 --- a/plugin/emmet.vim +++ b/plugin/emmet.vim @@ -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,"")'}, \ {'mode': 'i', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'emmet-expand-word', 'func': '=emmet#util#closePopup()=emmet#expandAbbr(1,"")'}, \ {'mode': 'n', 'var': 'user_emmet_expandword_key', 'key': ';', 'plug': 'emmet-expand-word', 'func': ':call emmet#expandAbbr(1,"")'}, + \ {'mode': 'i', 'var': 'user_emmet_update_tag', 'key': 'u', 'plug': 'emmmet-update-tag', 'func': '=emmet#util#closePopup()=emmet#updateTag()'}, + \ {'mode': 'n', 'var': 'user_emmet_update_tag', 'key': 'u', 'plug': 'emmmet-update-tag', 'func': ':call emmet#updateTag()'}, \ {'mode': 'i', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': ':call emmet#balanceTag(1)'}, \ {'mode': 'n', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': ':call emmet#balanceTag(1)'}, \ {'mode': 'v', 'var': 'user_emmet_balancetaginward_key', 'key': 'd', 'plug': 'emmet-balance-tag-inward', 'func': ':call emmet#balanceTag(2)'},