Add mergeLines()

This commit is contained in:
Yasuhiro Matsumoto
2019-06-20 00:02:06 +09:00
parent 6ee9d6d417
commit 9f854c868e
9 changed files with 92 additions and 10 deletions

View File

@@ -368,3 +368,7 @@ endfunction
function! emmet#lang#css#removeTag() abort
" nothing to do
endfunction
function! emmet#lang#css#mergeLines() abort
" nothing to do
endfunction

View File

@@ -208,7 +208,34 @@ function! emmet#lang#elm#toString(settings, current, type, inline, filters, item
endif
let str .= "\n"
return str
endfunction
function! emmet#lang#elm#imageEncode() abort
endfunction
function! emmet#lang#elm#parseTag(tag) abort
return {}
endfunction
function! emmet#lang#elm#toggleComment() abort
endfunction
function! emmet#lang#elm#balanceTag(flag) range abort
endfunction
function! emmet#lang#elm#moveNextPrevItem(flag) abort
return emmet#lang#elm#moveNextPrev(a:flag)
endfunction
function! emmet#lang#elm#moveNextPrev(flag) abort
endfunction
function! emmet#lang#elm#splitJoinTag() abort
endfunction
function! emmet#lang#elm#removeTag() abort
endfunction
function! emmet#lang#elm#mergeLines() abort
endfunction

View File

@@ -332,3 +332,6 @@ function! emmet#lang#haml#removeTag() abort
exe sn ',' (n-1) 'delete'
endif
endfunction
function! emmet#lang#haml#mergeLines() abort
endfunction

View File

@@ -955,10 +955,8 @@ function! emmet#lang#html#removeTag() abort
call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^/>]*>', '', '</' . tag_name[1:] . '>', 'W')
else
echomsg string(tag_name)
let pos2 = searchpairpos('<'. tag_name . '[^/>]*>', '', '</' . tag_name . '>', 'W')
endif
echomsg string(pos2)
if pos2 == [0, 0]
return
endif
@@ -968,12 +966,44 @@ function! emmet#lang#html#removeTag() abort
call emmet#util#setContent(block, '')
call setpos('.', [0, block[0][0], block[0][1], 0])
return
endif
if block[0][0] > 0
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
else
if block[0][0] > 0
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
else
call setpos('.', curpos)
return
endif
call setpos('.', curpos)
endif
endfunction
function! emmet#lang#html#mergeLines() abort
let curpos = emmet#util#getcurpos()
let mx = '<\(/\{0,1}[a-zA-Z][-a-zA-Z0-9:_\-]*\)\%(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\s*\%(/\{0,1}\)>'
let pos1 = searchpos(mx, 'bcnW')
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\).*$', '\1', '')
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
if content[-2:] ==# '/>' && emmet#util#cursorInRegion(block)
call setpos('.', [0, block[0][0], block[0][1], 0])
return
endif
if tag_name[0] ==# '/'
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^/>]*>', '', '</' . tag_name[1:] . '>', 'W')
else
let pos2 = searchpairpos('<'. tag_name . '[^/>]*>', '', '</' . tag_name . '>', 'W')
endif
if pos2 == [0, 0]
return
endif
let pos2 = searchpos('>', 'neW')
let block = [pos1, pos2]
let content = emmet#util#getContent(block)
let content = join(map(split(content, mx . '\zs\s*'), 'trim(v:val)'), '')
call emmet#util#setContent(block, content)
if block[0][0] > 0
call setpos('.', [0, block[0][0], block[0][1], 0])
else
call setpos('.', curpos)
endif
endfunction

View File

@@ -329,3 +329,7 @@ function! emmet#lang#jade#removeTag() abort
exe sn ',' (n-1) 'delete'
endif
endfunction
function! emmet#lang#jade#mergeLines() abort
" nothing to do
endfunction

View File

@@ -45,3 +45,7 @@ endfunction
function! emmet#lang#less#removeTag() abort
call emmet#lang#css#removeTag()
endfunction
function! emmet#lang#less#mergeLines() abort
call emmet#lang#css#mergeLines()
endfunction

View File

@@ -158,3 +158,6 @@ endfunction
function! emmet#lang#sass#removeTag() abort
endfunction
function! emmet#lang#sass#mergeLines() abort
endfunction

View File

@@ -123,3 +123,7 @@ endfunction
function! emmet#lang#scss#removeTag() abort
call emmet#lang#css#removeTag()
endfunction
function! emmet#lang#scss#mergeLines() abort
call emmet#lang#css#mergeLines()
endfunction

View File

@@ -279,3 +279,6 @@ function! emmet#lang#slim#removeTag() abort
exe sn ',' (n-1) 'delete'
endif
endfunction
function! emmet#lang#slim#mergeLines() abort
endfunction