mirror of
https://github.com/mattn/emmet-vim.git
synced 2026-08-12 19:11:33 +08:00
Refactoring
This commit is contained in:
+240
-240
@@ -1,6 +1,6 @@
|
||||
function! emmet#lang#css#findTokens(str) abort
|
||||
let tmp = substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '')
|
||||
if tmp =~ '/' && tmp =~ '^[a-zA-Z0-9/_.]\+$'
|
||||
let l:tmp = substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '')
|
||||
if l:tmp =~ '/' && l:tmp =~ '^[a-zA-Z0-9/_.]\+$'
|
||||
" maybe path or something
|
||||
return ''
|
||||
endif
|
||||
@@ -8,281 +8,281 @@ function! emmet#lang#css#findTokens(str) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#css#parseIntoTree(abbr, type) abort
|
||||
let abbr = a:abbr
|
||||
let type = a:type
|
||||
let prefix = 0
|
||||
let value = ''
|
||||
let l:abbr = a:abbr
|
||||
let l:type = a:type
|
||||
let l:prefix = 0
|
||||
let l:value = ''
|
||||
|
||||
let indent = emmet#getIndentation(type)
|
||||
let aliases = emmet#getResource(type, 'aliases', {})
|
||||
let snippets = emmet#getResource(type, 'snippets', {})
|
||||
let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1)
|
||||
let l:indent = emmet#getIndentation(l:type)
|
||||
let l:aliases = emmet#getResource(l:type, 'aliases', {})
|
||||
let l:snippets = emmet#getResource(l:type, 'snippets', {})
|
||||
let l:use_pipe_for_cursor = emmet#getResource(l:type, 'use_pipe_for_cursor', 1)
|
||||
|
||||
let root = emmet#newNode()
|
||||
let l:root = emmet#newNode()
|
||||
|
||||
" emmet
|
||||
let tokens = split(abbr, '+\ze[^+)!]')
|
||||
let block = emmet#util#searchRegion('{', '}')
|
||||
if abbr !~# '^@' && emmet#getBaseType(type) ==# 'css' && type !=# 'sass' && type !=# 'styled' && block[0] ==# [0,0] && block[1] ==# [0,0]
|
||||
let current = emmet#newNode()
|
||||
let current.snippet = substitute(abbr, '\s\+$', '', '') . " {\n" . indent . "${cursor}\n}"
|
||||
let current.name = ''
|
||||
call add(root.child, deepcopy(current))
|
||||
let l:tokens = split(l:abbr, '+\ze[^+)!]')
|
||||
let l:block = emmet#util#searchRegion('{', '}')
|
||||
if l:abbr !~# '^@' && emmet#getBaseType(l:type) ==# 'css' && l:type !=# 'sass' && l:type !=# 'styled' && l:block[0] ==# [0,0] && l:block[1] ==# [0,0]
|
||||
let l:current = emmet#newNode()
|
||||
let l:current.snippet = substitute(l:abbr, '\s\+$', '', '') . " {\n" . l:indent . "${cursor}\n}"
|
||||
let l:current.name = ''
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
else
|
||||
for n in range(len(tokens))
|
||||
let token = tokens[n]
|
||||
let prop = matchlist(token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+\%(p\|e\|em\|x\|vh\|vw\|re\|rem\|%\)\{0,}-\{0,1}\|-auto\)*\)$')
|
||||
if len(prop)
|
||||
let token = substitute(prop[1], '^(\(.*\))', '\1', '')
|
||||
if token =~# '^-'
|
||||
let prefix = 1
|
||||
let token = token[1:]
|
||||
for l:n in range(len(l:tokens))
|
||||
let l:token = l:tokens[l:n]
|
||||
let l:prop = matchlist(l:token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+\%(p\|e\|em\|x\|vh\|vw\|re\|rem\|%\)\{0,}-\{0,1}\|-auto\)*\)$')
|
||||
if len(l:prop)
|
||||
let l:token = substitute(l:prop[1], '^(\(.*\))', '\1', '')
|
||||
if l:token =~# '^-'
|
||||
let l:prefix = 1
|
||||
let l:token = l:token[1:]
|
||||
endif
|
||||
let value = ''
|
||||
for vt in split(prop[2], '\a\+\zs')
|
||||
let ut = matchstr(vt, '[a-z]\+$')
|
||||
if ut == 'auto'
|
||||
let ut = ''
|
||||
let l:value = ''
|
||||
for l:vt in split(l:prop[2], '\a\+\zs')
|
||||
let l:ut = matchstr(l:vt, '[a-z]\+$')
|
||||
if l:ut == 'auto'
|
||||
let l:ut = ''
|
||||
endif
|
||||
for v in split(vt, '\d\zs-')
|
||||
if len(value) > 0
|
||||
let value .= ' '
|
||||
for l:v in split(l:vt, '\d\zs-')
|
||||
if len(l:value) > 0
|
||||
let l:value .= ' '
|
||||
endif
|
||||
if v !~ '[a-z]\+$'
|
||||
let v .= ut
|
||||
if l:v !~ '[a-z]\+$'
|
||||
let l:v .= l:ut
|
||||
endif
|
||||
if token =~# '^[z]'
|
||||
if l:token =~# '^[z]'
|
||||
" TODO
|
||||
let value .= substitute(v, '[^0-9.]*$', '', '')
|
||||
elseif v =~# 'em$'
|
||||
let value .= v
|
||||
elseif v =~# 'ex$'
|
||||
let value .= v
|
||||
elseif v =~# 'vh$'
|
||||
let value .= v
|
||||
elseif v =~# 'vw$'
|
||||
let value .= v
|
||||
elseif v =~# 'rem$'
|
||||
let value .= v
|
||||
elseif v ==# 'auto'
|
||||
let value .= v
|
||||
elseif v =~# 'p$'
|
||||
let value .= substitute(v, 'p$', '%', '')
|
||||
elseif v =~# '%$'
|
||||
let value .= v
|
||||
elseif v =~# 'e$'
|
||||
let value .= substitute(v, 'e$', 'em', '')
|
||||
elseif v =~# 'x$'
|
||||
let value .= substitute(v, 'x$', 'ex', '')
|
||||
elseif v =~# 're$'
|
||||
let value .= substitute(v, 're$', 'rem', '')
|
||||
elseif v =~# '\.'
|
||||
let value .= v . 'em'
|
||||
elseif v ==# '0'
|
||||
let value .= '0'
|
||||
let l:value .= substitute(l:v, '[^0-9.]*$', '', '')
|
||||
elseif l:v =~# 'em$'
|
||||
let l:value .= l:v
|
||||
elseif l:v =~# 'ex$'
|
||||
let l:value .= l:v
|
||||
elseif l:v =~# 'vh$'
|
||||
let l:value .= l:v
|
||||
elseif l:v =~# 'vw$'
|
||||
let l:value .= l:v
|
||||
elseif l:v =~# 'rem$'
|
||||
let l:value .= l:v
|
||||
elseif l:v ==# 'auto'
|
||||
let l:value .= l:v
|
||||
elseif l:v =~# 'p$'
|
||||
let l:value .= substitute(l:v, 'p$', '%', '')
|
||||
elseif l:v =~# '%$'
|
||||
let l:value .= l:v
|
||||
elseif l:v =~# 'e$'
|
||||
let l:value .= substitute(l:v, 'e$', 'em', '')
|
||||
elseif l:v =~# 'x$'
|
||||
let l:value .= substitute(l:v, 'x$', 'ex', '')
|
||||
elseif l:v =~# 're$'
|
||||
let l:value .= substitute(l:v, 're$', 'rem', '')
|
||||
elseif l:v =~# '\.'
|
||||
let l:value .= l:v . 'em'
|
||||
elseif l:v ==# '0'
|
||||
let l:value .= '0'
|
||||
else
|
||||
let value .= v . 'px'
|
||||
let l:value .= l:v . 'px'
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endif
|
||||
|
||||
let tag_name = token
|
||||
if tag_name =~# '.!$'
|
||||
let tag_name = tag_name[:-2]
|
||||
let important = 1
|
||||
let l:tag_name = l:token
|
||||
if l:tag_name =~# '.!$'
|
||||
let l:tag_name = l:tag_name[:-2]
|
||||
let l:important = 1
|
||||
else
|
||||
let important = 0
|
||||
let l:important = 0
|
||||
endif
|
||||
" make default node
|
||||
let current = emmet#newNode()
|
||||
let current.important = important
|
||||
let current.name = tag_name
|
||||
let l:current = emmet#newNode()
|
||||
let l:current.important = l:important
|
||||
let l:current.name = l:tag_name
|
||||
|
||||
" aliases
|
||||
if has_key(aliases, tag_name)
|
||||
let current.name = aliases[tag_name]
|
||||
if has_key(l:aliases, l:tag_name)
|
||||
let l:current.name = l:aliases[l:tag_name]
|
||||
endif
|
||||
|
||||
" snippets
|
||||
if !empty(snippets)
|
||||
let snippet_name = tag_name
|
||||
if !has_key(snippets, snippet_name)
|
||||
let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-\)')
|
||||
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat')
|
||||
if len(vv) == 0
|
||||
let vv = filter(sort(keys(snippets)), 'substitute(v:val, ":", "", "g") == snippet_name')
|
||||
if !empty(l:snippets)
|
||||
let l:snippet_name = l:tag_name
|
||||
if !has_key(l:snippets, l:snippet_name)
|
||||
let l:pat = '^' . join(split(l:tag_name, '\zs'), '\%(\|[^:-]\+-\)')
|
||||
let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
|
||||
if len(l:vv) == 0
|
||||
let l:vv = filter(sort(keys(l:snippets)), 'substitute(v:val, ":", "", "g") == l:snippet_name')
|
||||
endif
|
||||
if len(vv) > 0
|
||||
let snippet_name = vv[0]
|
||||
if len(l:vv) > 0
|
||||
let l:snippet_name = l:vv[0]
|
||||
else
|
||||
let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-*\)')
|
||||
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat')
|
||||
if len(vv) == 0
|
||||
let pat = '^' . join(split(tag_name, '\zs'), '[^:]\{-}')
|
||||
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat')
|
||||
if len(vv) == 0
|
||||
let pat = '^' . join(split(tag_name, '\zs'), '.\{-}')
|
||||
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat')
|
||||
let l:pat = '^' . join(split(l:tag_name, '\zs'), '\%(\|[^:-]\+-*\)')
|
||||
let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
|
||||
if len(l:vv) == 0
|
||||
let l:pat = '^' . join(split(l:tag_name, '\zs'), '[^:]\{-}')
|
||||
let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
|
||||
if len(l:vv) == 0
|
||||
let l:pat = '^' . join(split(l:tag_name, '\zs'), '.\{-}')
|
||||
let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
|
||||
endif
|
||||
endif
|
||||
let minl = -1
|
||||
for vk in vv
|
||||
let vvs = snippets[vk]
|
||||
if minl == -1 || len(vvs) < minl
|
||||
let snippet_name = vk
|
||||
let minl = len(vvs)
|
||||
let l:minl = -1
|
||||
for l:vk in l:vv
|
||||
let l:vvs = l:snippets[l:vk]
|
||||
if l:minl == -1 || len(l:vvs) < l:minl
|
||||
let l:snippet_name = l:vk
|
||||
let l:minl = len(l:vvs)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endif
|
||||
if has_key(snippets, snippet_name)
|
||||
let snippet = snippets[snippet_name]
|
||||
if use_pipe_for_cursor
|
||||
let snippet = substitute(snippet, '|', '${cursor}', 'g')
|
||||
if has_key(l:snippets, l:snippet_name)
|
||||
let l:snippet = l:snippets[l:snippet_name]
|
||||
if l:use_pipe_for_cursor
|
||||
let l:snippet = substitute(l:snippet, '|', '${cursor}', 'g')
|
||||
endif
|
||||
let lines = split(snippet, "\n")
|
||||
call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")')
|
||||
let current.snippet = join(lines, "\n")
|
||||
let current.name = ''
|
||||
let current.snippet = substitute(current.snippet, ';', value . ';', '')
|
||||
if use_pipe_for_cursor && len(value) > 0
|
||||
let current.snippet = substitute(current.snippet, '\${cursor}', '', 'g')
|
||||
let l:lines = split(l:snippet, "\n")
|
||||
call map(l:lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(l:indent, "\\\\"), "g")')
|
||||
let l:current.snippet = join(l:lines, "\n")
|
||||
let l:current.name = ''
|
||||
let l:current.snippet = substitute(l:current.snippet, ';', l:value . ';', '')
|
||||
if l:use_pipe_for_cursor && len(l:value) > 0
|
||||
let l:current.snippet = substitute(l:current.snippet, '\${cursor}', '', 'g')
|
||||
endif
|
||||
if n < len(tokens) - 1
|
||||
let current.snippet .= "\n"
|
||||
if l:n < len(l:tokens) - 1
|
||||
let l:current.snippet .= "\n"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
let current.pos = 0
|
||||
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$')
|
||||
if len(lg) == 0
|
||||
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*)$')
|
||||
if len(lg)
|
||||
let [lg[1], lg[2], lg[3]] = ['linear', lg[1], lg[2]]
|
||||
let l:current.pos = 0
|
||||
let l:lg = matchlist(l:token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$')
|
||||
if len(l:lg) == 0
|
||||
let l:lg = matchlist(l:token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*)$')
|
||||
if len(l:lg)
|
||||
let [l:lg[1], l:lg[2], l:lg[3]] = ['linear', l:lg[1], l:lg[2]]
|
||||
endif
|
||||
endif
|
||||
if len(lg)
|
||||
let current.name = ''
|
||||
let current.snippet = printf("background-image:-webkit-gradient(%s, 0 0, 0 100%, from(%s), to(%s));\n", lg[1], lg[2], lg[3])
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", lg[2], lg[3])
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", lg[2], lg[3])
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", lg[2], lg[3])
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = printf("background-image:linear-gradient(%s, %s);\n", lg[2], lg[3])
|
||||
call add(root.child, deepcopy(current))
|
||||
elseif prefix
|
||||
let snippet = current.snippet
|
||||
let current.snippet = '-webkit-' . snippet . "\n"
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = '-moz-' . snippet . "\n"
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = '-o-' . snippet . "\n"
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = '-ms-' . snippet . "\n"
|
||||
call add(root.child, deepcopy(current))
|
||||
let current.snippet = snippet
|
||||
call add(root.child, current)
|
||||
elseif token =~# '^c#\([0-9a-fA-F]\{3}\|[0-9a-fA-F]\{6}\)\(\.[0-9]\+\)\?'
|
||||
let cs = split(token, '\.')
|
||||
let current.name = ''
|
||||
let [r,g,b] = [0,0,0]
|
||||
if len(cs[0]) == 5
|
||||
let rgb = matchlist(cs[0], 'c#\(.\)\(.\)\(.\)')
|
||||
let r = eval('0x'.rgb[1].rgb[1])
|
||||
let g = eval('0x'.rgb[2].rgb[2])
|
||||
let b = eval('0x'.rgb[3].rgb[3])
|
||||
elseif len(cs[0]) == 8
|
||||
let rgb = matchlist(cs[0], 'c#\(..\)\(..\)\(..\)')
|
||||
let r = eval('0x'.rgb[1])
|
||||
let g = eval('0x'.rgb[2])
|
||||
let b = eval('0x'.rgb[3])
|
||||
if len(l:lg)
|
||||
let l:current.name = ''
|
||||
let l:current.snippet = printf("background-image:-webkit-gradient(%s, 0 0, 0 100%%, from(%s), to(%s));\n", l:lg[1], l:lg[2], l:lg[3])
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = printf("background-image:linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
elseif l:prefix
|
||||
let l:snippet = l:current.snippet
|
||||
let l:current.snippet = '-webkit-' . l:snippet . "\n"
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = '-moz-' . l:snippet . "\n"
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = '-o-' . l:snippet . "\n"
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = '-ms-' . l:snippet . "\n"
|
||||
call add(l:root.child, deepcopy(l:current))
|
||||
let l:current.snippet = l:snippet
|
||||
call add(l:root.child, l:current)
|
||||
elseif l:token =~# '^c#\([0-9a-fA-F]\{3}\|[0-9a-fA-F]\{6}\)\(\.[0-9]\+\)\?'
|
||||
let l:cs = split(l:token, '\.')
|
||||
let l:current.name = ''
|
||||
let [l:r,l:g,l:b] = [0,0,0]
|
||||
if len(l:cs[0]) == 5
|
||||
let l:rgb = matchlist(l:cs[0], 'c#\(.\)\(.\)\(.\)')
|
||||
let l:r = eval('0x'.l:rgb[1].l:rgb[1])
|
||||
let l:g = eval('0x'.l:rgb[2].l:rgb[2])
|
||||
let l:b = eval('0x'.l:rgb[3].l:rgb[3])
|
||||
elseif len(l:cs[0]) == 8
|
||||
let l:rgb = matchlist(l:cs[0], 'c#\(..\)\(..\)\(..\)')
|
||||
let l:r = eval('0x'.l:rgb[1])
|
||||
let l:g = eval('0x'.l:rgb[2])
|
||||
let l:b = eval('0x'.l:rgb[3])
|
||||
endif
|
||||
if len(cs) == 1
|
||||
let current.snippet = printf('color:rgb(%d, %d, %d);', r, g, b)
|
||||
if len(l:cs) == 1
|
||||
let l:current.snippet = printf('color:rgb(%d, %d, %d);', l:r, l:g, l:b)
|
||||
else
|
||||
let current.snippet = printf('color:rgb(%d, %d, %d, %s);', r, g, b, string(str2float('0.'.cs[1])))
|
||||
let l:current.snippet = printf('color:rgb(%d, %d, %d, %s);', l:r, l:g, l:b, string(str2float('0.'.l:cs[1])))
|
||||
endif
|
||||
call add(root.child, current)
|
||||
elseif token =~# '^c#'
|
||||
let current.name = ''
|
||||
let current.snippet = 'color:\${cursor};'
|
||||
call add(root.child, current)
|
||||
call add(l:root.child, l:current)
|
||||
elseif l:token =~# '^c#'
|
||||
let l:current.name = ''
|
||||
let l:current.snippet = 'color:\${cursor};'
|
||||
call add(l:root.child, l:current)
|
||||
else
|
||||
call add(root.child, current)
|
||||
call add(l:root.child, l:current)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return root
|
||||
return l:root
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let current = a:current
|
||||
let value = current.value[1:-2]
|
||||
let tmp = substitute(value, '\${cursor}', '', 'g')
|
||||
if tmp !~ '.*{[ \t\r\n]*}$'
|
||||
let l:current = a:current
|
||||
let l:value = l:current.value[1:-2]
|
||||
let l:tmp = substitute(l:value, '\${cursor}', '', 'g')
|
||||
if l:tmp !~ '.*{[ \t\r\n]*}$'
|
||||
if emmet#useFilter(a:filters, 'fc')
|
||||
let value = substitute(value, '\([^:]\+\):\([^;]*\)', '\1: \2', 'g')
|
||||
let l:value = substitute(l:value, '\([^:]\+\):\([^;]*\)', '\1: \2', 'g')
|
||||
else
|
||||
let value = substitute(value, '\([^:]\+\):\([^;]*\)', '\1:\2', 'g')
|
||||
let l:value = substitute(l:value, '\([^:]\+\):\([^;]*\)', '\1:\2', 'g')
|
||||
endif
|
||||
if current.important
|
||||
let value = substitute(value, ';', ' !important;', '')
|
||||
if l:current.important
|
||||
let l:value = substitute(l:value, ';', ' !important;', '')
|
||||
endif
|
||||
endif
|
||||
return value
|
||||
return l:value
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#css#imageSize() abort
|
||||
let img_region = emmet#util#searchRegion('{', '}')
|
||||
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region)
|
||||
let l:img_region = emmet#util#searchRegion('{', '}')
|
||||
if !emmet#util#regionIsValid(l:img_region) || !emmet#util#cursorInRegion(l:img_region)
|
||||
return
|
||||
endif
|
||||
let content = emmet#util#getContent(img_region)
|
||||
let fn = matchstr(content, '\<url(\zs[^)]\+\ze)')
|
||||
let fn = substitute(fn, '[''" \t]', '', 'g')
|
||||
if fn =~# '^\s*$'
|
||||
let l:content = emmet#util#getContent(l:img_region)
|
||||
let l:fn = matchstr(l:content, '\<url(\zs[^)]\+\ze)')
|
||||
let l:fn = substitute(l:fn, '[''" \t]', '', 'g')
|
||||
if l:fn =~# '^\s*$'
|
||||
return
|
||||
elseif fn !~# '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
elseif l:fn !~# '^\(/\|http\)'
|
||||
let l:fn = simplify(expand('%:h') . '/' . l:fn)
|
||||
endif
|
||||
let [width, height] = emmet#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
let [l:width, l:height] = emmet#util#getImageSize(l:fn)
|
||||
if l:width == -1 && l:height == -1
|
||||
return
|
||||
endif
|
||||
let indent = emmet#getIndentation('css')
|
||||
if content =~# '.*\<width\s*:[^;]*;.*'
|
||||
let content = substitute(content, '\<width\s*:[^;]*;', 'width: ' . width . 'px;', '')
|
||||
let l:indent = emmet#getIndentation('css')
|
||||
if l:content =~# '.*\<width\s*:[^;]*;.*'
|
||||
let l:content = substitute(l:content, '\<width\s*:[^;]*;', 'width: ' . l:width . 'px;', '')
|
||||
else
|
||||
let content = substitute(content, '}', indent . 'width: ' . width . "px;\n}", '')
|
||||
let l:content = substitute(l:content, '}', l:indent . 'width: ' . l:width . "px;\n}", '')
|
||||
endif
|
||||
if content =~# '.*\<height\s*:[^;]*;.*'
|
||||
let content = substitute(content, '\<height\s*:[^;]*;', 'height: ' . height . 'px;', '')
|
||||
if l:content =~# '.*\<height\s*:[^;]*;.*'
|
||||
let l:content = substitute(l:content, '\<height\s*:[^;]*;', 'height: ' . l:height . 'px;', '')
|
||||
else
|
||||
let content = substitute(content, '}', indent . 'height: ' . height . "px;\n}", '')
|
||||
let l:content = substitute(l:content, '}', l:indent . 'height: ' . l:height . "px;\n}", '')
|
||||
endif
|
||||
call emmet#util#setContent(img_region, content)
|
||||
call emmet#util#setContent(l:img_region, l:content)
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#css#imageEncode() abort
|
||||
let img_region = emmet#util#searchRegion('url(', ')')
|
||||
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region)
|
||||
let l:img_region = emmet#util#searchRegion('url(', ')')
|
||||
if !emmet#util#regionIsValid(l:img_region) || !emmet#util#cursorInRegion(l:img_region)
|
||||
return
|
||||
endif
|
||||
let content = emmet#util#getContent(img_region)
|
||||
let fn = matchstr(content, '\<url(\zs[^)]\+\ze)')
|
||||
let fn = substitute(fn, '[''" \t]', '', 'g')
|
||||
if fn =~# '^\s*$'
|
||||
let l:content = emmet#util#getContent(l:img_region)
|
||||
let l:fn = matchstr(l:content, '\<url(\zs[^)]\+\ze)')
|
||||
let l:fn = substitute(l:fn, '[''" \t]', '', 'g')
|
||||
if l:fn =~# '^\s*$'
|
||||
return
|
||||
elseif fn !~# '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
elseif l:fn !~# '^\(/\|http\)'
|
||||
let l:fn = simplify(expand('%:h') . '/' . l:fn)
|
||||
endif
|
||||
let encoded = emmet#util#imageEncodeDecode(fn, 0)
|
||||
call emmet#util#setContent(img_region, 'url(' . encoded . ')')
|
||||
let l:encoded = emmet#util#imageEncodeDecode(l:fn, 0)
|
||||
call emmet#util#setContent(l:img_region, 'url(' . l:encoded . ')')
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#css#parseTag(tag) abort
|
||||
@@ -290,67 +290,67 @@ function! emmet#lang#css#parseTag(tag) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#css#toggleComment() abort
|
||||
let line = getline('.')
|
||||
let mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$'
|
||||
if line =~# '{\s*$'
|
||||
let block = emmet#util#searchRegion('/\*', '\*/\zs')
|
||||
if emmet#util#regionIsValid(block)
|
||||
let content = emmet#util#getContent(block)
|
||||
let content = substitute(content, '/\*\s\(.*\)\s\*/', '\1', '')
|
||||
call emmet#util#setContent(block, content)
|
||||
let l:line = getline('.')
|
||||
let l:mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$'
|
||||
if l:line =~# '{\s*$'
|
||||
let l:block = emmet#util#searchRegion('/\*', '\*/\zs')
|
||||
if emmet#util#regionIsValid(l:block)
|
||||
let l:content = emmet#util#getContent(l:block)
|
||||
let l:content = substitute(l:content, '/\*\s\(.*\)\s\*/', '\1', '')
|
||||
call emmet#util#setContent(l:block, l:content)
|
||||
else
|
||||
let node = expand('<cword>')
|
||||
if len(node)
|
||||
exe "normal ciw\<c-r>='/* '.node.' */'\<cr>"
|
||||
let l:node = expand('<cword>')
|
||||
if len(l:node)
|
||||
exe "normal ciw\<c-r>='/* '.l:node.' */'\<cr>"
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if line =~# mx
|
||||
let space = substitute(matchstr(line, mx), mx, '\1', '')
|
||||
let line = substitute(matchstr(line, mx), mx, '\2', '')
|
||||
let line = space . substitute(line, '^\s*\|\s*$', '\1', 'g')
|
||||
if l:line =~# l:mx
|
||||
let l:space = substitute(matchstr(l:line, l:mx), l:mx, '\1', '')
|
||||
let l:line = substitute(matchstr(l:line, l:mx), l:mx, '\2', '')
|
||||
let l:line = l:space . substitute(l:line, '^\s*\|\s*$', '\1', 'g')
|
||||
else
|
||||
let mx = '^\(\s*\)\(''[^'']*''\|[^'']*\|;\)\s*$'
|
||||
let l:mx = '^\(\s*\)\(''[^'']*''\|[^'']*\|;\)\s*$'
|
||||
" TODO multi-property
|
||||
"let mx = '^\(\s*\)\(\%(''[^'']*''\|[^'';]\+\)*;\{0,1}\)'
|
||||
let line = substitute(line, mx, '\1/* \2 */', '')
|
||||
"let l:mx = '^\(\s*\)\(\%(''[^'']*''\|[^'';]\+\)*;\{0,1}\)'
|
||||
let l:line = substitute(l:line, l:mx, '\1/* \2 */', '')
|
||||
endif
|
||||
call setline('.', line)
|
||||
call setline('.', l:line)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#css#balanceTag(flag) range abort
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
let l:curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = emmet#util#getcurpos()
|
||||
let l:curpos = emmet#util#getcurpos()
|
||||
endif
|
||||
let block = emmet#util#getVisualBlock()
|
||||
if !emmet#util#regionIsValid(block)
|
||||
let l:block = emmet#util#getVisualBlock()
|
||||
if !emmet#util#regionIsValid(l:block)
|
||||
if a:flag > 0
|
||||
let block = emmet#util#searchRegion('^', ';')
|
||||
if emmet#util#regionIsValid(block)
|
||||
call emmet#util#selectRegion(block)
|
||||
let l:block = emmet#util#searchRegion('^', ';')
|
||||
if emmet#util#regionIsValid(l:block)
|
||||
call emmet#util#selectRegion(l:block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if a:flag > 0
|
||||
let content = emmet#util#getContent(block)
|
||||
if content !~# '^{.*}$'
|
||||
let block = emmet#util#searchRegion('{', '}')
|
||||
if emmet#util#regionIsValid(block)
|
||||
call emmet#util#selectRegion(block)
|
||||
let l:content = emmet#util#getContent(l:block)
|
||||
if l:content !~# '^{.*}$'
|
||||
let l:block = emmet#util#searchRegion('{', '}')
|
||||
if emmet#util#regionIsValid(l:block)
|
||||
call emmet#util#selectRegion(l:block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
else
|
||||
let pos = searchpos('.*;', 'nW')
|
||||
if pos[0] != 0
|
||||
call setpos('.', [0, pos[0], pos[1], 0])
|
||||
let block = emmet#util#searchRegion('^', ';')
|
||||
if emmet#util#regionIsValid(block)
|
||||
call emmet#util#selectRegion(block)
|
||||
let l:pos = searchpos('.*;', 'nW')
|
||||
if l:pos[0] != 0
|
||||
call setpos('.', [0, l:pos[0], l:pos[1], 0])
|
||||
let l:block = emmet#util#searchRegion('^', ';')
|
||||
if emmet#util#regionIsValid(l:block)
|
||||
call emmet#util#selectRegion(l:block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
@@ -359,7 +359,7 @@ function! emmet#lang#css#balanceTag(flag) range abort
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe 'normal! gv'
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
call setpos('.', l:curpos)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
+90
-90
@@ -3,24 +3,24 @@ function! emmet#lang#elm#findTokens(str) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#parseIntoTree(abbr, type) abort
|
||||
let tree = emmet#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
if len(tree.child) < 2 | return tree | endif
|
||||
let l:tree = emmet#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
if len(l:tree.child) < 2 | return l:tree | endif
|
||||
|
||||
" Add ',' nodes between root elements.
|
||||
let new_children = []
|
||||
for child in tree.child[0:-2]
|
||||
let comma = emmet#newNode()
|
||||
let comma.name = ','
|
||||
call add(new_children, child)
|
||||
call add(new_children, comma)
|
||||
let l:new_children = []
|
||||
for l:child in l:tree.child[0:-2]
|
||||
let l:comma = emmet#newNode()
|
||||
let l:comma.name = ','
|
||||
call add(l:new_children, l:child)
|
||||
call add(l:new_children, l:comma)
|
||||
endfor
|
||||
call add(new_children, tree.child[-1])
|
||||
let tree.child = new_children
|
||||
return tree
|
||||
call add(l:new_children, l:tree.child[-1])
|
||||
let l:tree.child = l:new_children
|
||||
return l:tree
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#renderNode(node)
|
||||
let elm_nodes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'
|
||||
let l:elm_nodes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'
|
||||
\, 'div', 'p', 'hr', 'pre', 'blockquote'
|
||||
\, 'span', 'a', 'code', 'em', 'strong', 'i', 'b', 'u', 'sub', 'sup', 'br'
|
||||
\, 'ol', 'ul', 'li', 'dl', 'dt', 'dd'
|
||||
@@ -37,14 +37,14 @@ function! emmet#lang#elm#renderNode(node)
|
||||
\, 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'wbr'
|
||||
\, 'details', 'summary', 'menuitem', 'menu']
|
||||
|
||||
if index(elm_nodes, a:node) >= 0
|
||||
if index(l:elm_nodes, a:node) >= 0
|
||||
return a:node
|
||||
endif
|
||||
return 'node "' . a:node . '"'
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#renderParam(param)
|
||||
let elm_events = ["onClick", "onDoubleClick"
|
||||
let l:elm_events = ["onClick", "onDoubleClick"
|
||||
\, "onMouseDown", "onMouseUp"
|
||||
\, "onMouseEnter", "onMouseLeave"
|
||||
\, "onMouseOver", "onMouseOut"
|
||||
@@ -52,10 +52,10 @@ function! emmet#lang#elm#renderParam(param)
|
||||
\, "onBlur", "onFocus"
|
||||
\, "on", "onWithOptions", "Options", "defaultOptions"
|
||||
\, "targetValue", "targetChecked", "keyCode"]
|
||||
if index(elm_events, a:param) >= 0
|
||||
if index(l:elm_events, a:param) >= 0
|
||||
return a:param
|
||||
endif
|
||||
let elm_attributes = ["style", "map" , "class", "id", "title", "hidden"
|
||||
let l:elm_attributes = ["style", "map" , "class", "id", "title", "hidden"
|
||||
\, "type", "type_", "value", "defaultValue", "checked", "placeholder", "selected"
|
||||
\, "accept", "acceptCharset", "action", "autocomplete", "autofocus"
|
||||
\, "disabled", "enctype", "formaction", "list", "maxlength", "minlength", "method", "multiple"
|
||||
@@ -75,7 +75,7 @@ function! emmet#lang#elm#renderParam(param)
|
||||
\, "challenge", "keytype"
|
||||
\, "cite", "datetime", "pubdate", "manifest"]
|
||||
|
||||
if index(elm_attributes, a:param) >= 0
|
||||
if index(l:elm_attributes, a:param) >= 0
|
||||
if a:param == 'type'
|
||||
return 'type_'
|
||||
endif
|
||||
@@ -85,130 +85,130 @@ function! emmet#lang#elm#renderParam(param)
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let settings = a:settings
|
||||
let current = a:current
|
||||
let type = a:type
|
||||
let inline = a:inline
|
||||
let filters = a:filters
|
||||
let itemno = a:itemno
|
||||
let indent = emmet#getIndentation(type)
|
||||
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
|
||||
let str = ''
|
||||
let l:settings = a:settings
|
||||
let l:current = a:current
|
||||
let l:type = a:type
|
||||
let l:inline = a:inline
|
||||
let l:filters = a:filters
|
||||
let l:itemno = a:itemno
|
||||
let l:indent = emmet#getIndentation(l:type)
|
||||
let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
|
||||
let l:str = ''
|
||||
|
||||
" comma between items with *, eg. li*3
|
||||
if itemno > 0
|
||||
let str = ", "
|
||||
if l:itemno > 0
|
||||
let l:str = ", "
|
||||
endif
|
||||
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
let l:current_name = l:current.name
|
||||
if l:dollar_expr
|
||||
let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
|
||||
if len(current.name) > 0
|
||||
if len(l:current.name) > 0
|
||||
" inserted root comma nodes
|
||||
if current_name == ','
|
||||
if l:current_name == ','
|
||||
return "\n, "
|
||||
endif
|
||||
let str .= emmet#lang#elm#renderNode(current_name)
|
||||
let tmp = ''
|
||||
for attr in emmet#util#unique(current.attrs_order + keys(current.attr))
|
||||
if !has_key(current.attr, attr)
|
||||
let l:str .= emmet#lang#elm#renderNode(l:current_name)
|
||||
let l:tmp = ''
|
||||
for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
|
||||
if !has_key(l:current.attr, l:attr)
|
||||
continue
|
||||
endif
|
||||
let Val = current.attr[attr]
|
||||
let l:Val = l:current.attr[l:attr]
|
||||
|
||||
let attr = emmet#lang#elm#renderParam(attr)
|
||||
let l:attr = emmet#lang#elm#renderParam(l:attr)
|
||||
|
||||
if type(Val) == 2 && Val == function('emmet#types#true')
|
||||
let tmp .= ', ' . attr . ' True'
|
||||
if type(l:Val) == 2 && l:Val == function('emmet#types#true')
|
||||
let l:tmp .= ', ' . l:attr . ' True'
|
||||
else
|
||||
if dollar_expr
|
||||
while Val =~# '\$\([^#{]\|$\)'
|
||||
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
if l:dollar_expr
|
||||
while l:Val =~# '\$\([^#{]\|$\)'
|
||||
let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
let valtmp = substitute(Val, '\${cursor}', '', '')
|
||||
if attr ==# 'id' && len(valtmp) > 0
|
||||
let tmp .=', id "' . Val . '"'
|
||||
elseif attr ==# 'class' && len(valtmp) > 0
|
||||
let tmp .= ', class "' . substitute(Val, '\.', ' ', 'g') . '"'
|
||||
let l:valtmp = substitute(l:Val, '\${cursor}', '', '')
|
||||
if l:attr ==# 'id' && len(l:valtmp) > 0
|
||||
let l:tmp .=', id "' . l:Val . '"'
|
||||
elseif l:attr ==# 'class' && len(l:valtmp) > 0
|
||||
let l:tmp .= ', class "' . substitute(l:Val, '\.', ' ', 'g') . '"'
|
||||
else
|
||||
let tmp .= ', ' . attr . ' "' . Val . '"'
|
||||
let l:tmp .= ', ' . l:attr . ' "' . l:Val . '"'
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
if ! len(tmp)
|
||||
let str .= ' []'
|
||||
if ! len(l:tmp)
|
||||
let l:str .= ' []'
|
||||
else
|
||||
let tmp = strpart(tmp, 2)
|
||||
let str .= ' [ ' . tmp . ' ]'
|
||||
let l:tmp = strpart(l:tmp, 2)
|
||||
let l:str .= ' [ ' . l:tmp . ' ]'
|
||||
endif
|
||||
|
||||
" No children quit early
|
||||
if len(current.child) == 0 && len(current.value) == 0
|
||||
if len(l:current.child) == 0 && len(l:current.value) == 0
|
||||
"Place cursor in node with no value or children
|
||||
let str .= ' [${cursor}]'
|
||||
return str
|
||||
let l:str .= ' [${cursor}]'
|
||||
return l:str
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
let l:inner = ''
|
||||
|
||||
" Parent contex text
|
||||
if len(current.value) > 0
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
" let str = substitute(str, '\$#', text, 'g')
|
||||
let inner .= ', text "' . text . '"'
|
||||
if len(l:current.value) > 0
|
||||
let l:text = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
" let l:str = substitute(l:str, '\$#', l:text, 'g')
|
||||
let l:inner .= ', text "' . l:text . '"'
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
" Has children
|
||||
for child in current.child
|
||||
if len(child.name) == 0 && len(child.value) > 0
|
||||
for l:child in l:current.child
|
||||
if len(l:child.name) == 0 && len(l:child.value) > 0
|
||||
" Text node
|
||||
let text = child.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
let l:text = l:child.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
endif
|
||||
let inner .= ', text "' . text . '"'
|
||||
let l:inner .= ', text "' . l:text . '"'
|
||||
else
|
||||
" Other nodes
|
||||
let inner .= ', ' . emmet#toString(child, type, inline, filters, 0, indent)
|
||||
let l:inner .= ', ' . emmet#toString(l:child, l:type, l:inline, l:filters, 0, l:indent)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
|
||||
let inner = strpart(inner, 2)
|
||||
let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
|
||||
let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
|
||||
let l:inner = strpart(l:inner, 2)
|
||||
|
||||
let inner = substitute(inner, ' ', '', 'g')
|
||||
let l:inner = substitute(l:inner, ' ', '', 'g')
|
||||
|
||||
if ! len(inner)
|
||||
let str .= ' []'
|
||||
if ! len(l:inner)
|
||||
let l:str .= ' []'
|
||||
else
|
||||
let str .= ' [ ' . inner . ' ]'
|
||||
let l:str .= ' [ ' . l:inner . ' ]'
|
||||
endif
|
||||
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
let l:str = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:str = substitute(l:str, '\${nr}', "\n", 'g')
|
||||
let l:str = substitute(l:str, '\\\$', '$', 'g')
|
||||
endif
|
||||
endif
|
||||
|
||||
let str .= "\n"
|
||||
return str
|
||||
let l:str .= "\n"
|
||||
return l:str
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#elm#imageEncode() abort
|
||||
|
||||
+202
-202
@@ -7,251 +7,251 @@ function! emmet#lang#haml#parseIntoTree(abbr, type) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let settings = a:settings
|
||||
let current = a:current
|
||||
let type = a:type
|
||||
let inline = a:inline
|
||||
let filters = a:filters
|
||||
let itemno = a:itemno
|
||||
let indent = emmet#getIndentation(type)
|
||||
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
|
||||
let attribute_style = emmet#getResource('haml', 'attribute_style', 'hash')
|
||||
let str = ''
|
||||
let l:settings = a:settings
|
||||
let l:current = a:current
|
||||
let l:type = a:type
|
||||
let l:inline = a:inline
|
||||
let l:filters = a:filters
|
||||
let l:itemno = a:itemno
|
||||
let l:indent = emmet#getIndentation(l:type)
|
||||
let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
|
||||
let l:attribute_style = emmet#getResource('haml', 'attribute_style', 'hash')
|
||||
let l:str = ''
|
||||
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
let l:current_name = l:current.name
|
||||
if l:dollar_expr
|
||||
let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
if len(current.name) > 0
|
||||
let str .= '%' . current_name
|
||||
let tmp = ''
|
||||
for attr in emmet#util#unique(current.attrs_order + keys(current.attr))
|
||||
if !has_key(current.attr, attr)
|
||||
if len(l:current.name) > 0
|
||||
let l:str .= '%' . l:current_name
|
||||
let l:tmp = ''
|
||||
for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
|
||||
if !has_key(l:current.attr, l:attr)
|
||||
continue
|
||||
endif
|
||||
let Val = current.attr[attr]
|
||||
if type(Val) == 2 && Val == function('emmet#types#true')
|
||||
if attribute_style ==# 'hash'
|
||||
let tmp .= ' :' . attr . ' => true'
|
||||
elseif attribute_style ==# 'html'
|
||||
let tmp .= attr . '=true'
|
||||
let l:Val = l:current.attr[l:attr]
|
||||
if type(l:Val) == 2 && l:Val == function('emmet#types#true')
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:tmp .= ' :' . l:attr . ' => true'
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:tmp .= l:attr . '=true'
|
||||
end
|
||||
else
|
||||
if dollar_expr
|
||||
while Val =~# '\$\([^#{]\|$\)'
|
||||
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
if l:dollar_expr
|
||||
while l:Val =~# '\$\([^#{]\|$\)'
|
||||
let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
let valtmp = substitute(Val, '\${cursor}', '', '')
|
||||
if attr ==# 'id' && len(valtmp) > 0
|
||||
let str .= '#' . Val
|
||||
elseif attr ==# 'class' && len(valtmp) > 0
|
||||
let str .= '.' . substitute(Val, ' ', '.', 'g')
|
||||
let l:valtmp = substitute(l:Val, '\${cursor}', '', '')
|
||||
if l:attr ==# 'id' && len(l:valtmp) > 0
|
||||
let l:str .= '#' . l:Val
|
||||
elseif l:attr ==# 'class' && len(l:valtmp) > 0
|
||||
let l:str .= '.' . substitute(l:Val, ' ', '.', 'g')
|
||||
else
|
||||
if len(tmp) > 0
|
||||
if attribute_style ==# 'hash'
|
||||
let tmp .= ','
|
||||
elseif attribute_style ==# 'html'
|
||||
let tmp .= ' '
|
||||
if len(l:tmp) > 0
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:tmp .= ','
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:tmp .= ' '
|
||||
endif
|
||||
endif
|
||||
if attribute_style ==# 'hash'
|
||||
let tmp .= ' :' . attr . ' => "' . Val . '"'
|
||||
elseif attribute_style ==# 'html'
|
||||
let tmp .= attr . '="' . Val . '"'
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:tmp .= ' :' . l:attr . ' => "' . l:Val . '"'
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:tmp .= l:attr . '="' . l:Val . '"'
|
||||
end
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
if len(tmp)
|
||||
if attribute_style ==# 'hash'
|
||||
let str .= '{' . tmp . ' }'
|
||||
elseif attribute_style ==# 'html'
|
||||
let str .= '(' . tmp . ')'
|
||||
if len(l:tmp)
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:str .= '{' . l:tmp . ' }'
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:str .= '(' . l:tmp . ')'
|
||||
end
|
||||
endif
|
||||
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0
|
||||
let str .= '/'
|
||||
if stridx(','.l:settings.html.empty_elements.',', ','.l:current_name.',') != -1 && len(l:current.value) == 0
|
||||
let l:str .= '/'
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
if len(current.value) > 0
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
let str = substitute(str, '\$#', text, 'g')
|
||||
let l:inner = ''
|
||||
if len(l:current.value) > 0
|
||||
let l:text = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
let l:str = substitute(l:str, '\$#', l:text, 'g')
|
||||
endif
|
||||
let lines = split(text, "\n")
|
||||
if len(lines) == 1
|
||||
let str .= ' ' . text
|
||||
let l:lines = split(l:text, "\n")
|
||||
if len(l:lines) == 1
|
||||
let l:str .= ' ' . l:text
|
||||
else
|
||||
for line in lines
|
||||
let str .= "\n" . indent . line . ' |'
|
||||
for l:line in l:lines
|
||||
let l:str .= "\n" . l:indent . l:line . ' |'
|
||||
endfor
|
||||
endif
|
||||
elseif len(current.child) == 0
|
||||
let str .= '${cursor}'
|
||||
elseif len(l:current.child) == 0
|
||||
let l:str .= '${cursor}'
|
||||
endif
|
||||
if len(current.child) == 1 && len(current.child[0].name) == 0
|
||||
let text = current.child[0].value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
if len(l:current.child) == 1 && len(l:current.child[0].name) == 0
|
||||
let l:text = l:current.child[0].value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
endif
|
||||
let lines = split(text, "\n")
|
||||
if len(lines) == 1
|
||||
let str .= ' ' . text
|
||||
let l:lines = split(l:text, "\n")
|
||||
if len(l:lines) == 1
|
||||
let l:str .= ' ' . l:text
|
||||
else
|
||||
for line in lines
|
||||
let str .= "\n" . indent . line . ' |'
|
||||
for l:line in l:lines
|
||||
let l:str .= "\n" . l:indent . l:line . ' |'
|
||||
endfor
|
||||
endif
|
||||
elseif len(current.child) > 0
|
||||
for child in current.child
|
||||
let inner .= emmet#toString(child, type, inline, filters, itemno, indent)
|
||||
elseif len(l:current.child) > 0
|
||||
for l:child in l:current.child
|
||||
let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
|
||||
let str .= "\n" . indent . inner
|
||||
let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
|
||||
let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
|
||||
let l:str .= "\n" . l:indent . l:inner
|
||||
endif
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
let l:str = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:str = substitute(l:str, '\${nr}', "\n", 'g')
|
||||
let l:str = substitute(l:str, '\\\$', '$', 'g')
|
||||
endif
|
||||
endif
|
||||
let str .= "\n"
|
||||
return str
|
||||
let l:str .= "\n"
|
||||
return l:str
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#imageSize() abort
|
||||
let line = getline('.')
|
||||
let current = emmet#lang#haml#parseTag(line)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
let l:line = getline('.')
|
||||
let l:current = emmet#lang#haml#parseTag(l:line)
|
||||
if empty(l:current) || !has_key(l:current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn =~# '^\s*$'
|
||||
let l:fn = l:current.attr.src
|
||||
if l:fn =~# '^\s*$'
|
||||
return
|
||||
elseif fn !~# '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
elseif l:fn !~# '^\(/\|http\)'
|
||||
let l:fn = simplify(expand('%:h') . '/' . l:fn)
|
||||
endif
|
||||
|
||||
let [width, height] = emmet#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
let [l:width, l:height] = emmet#util#getImageSize(l:fn)
|
||||
if l:width == -1 && l:height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let current.attrs_order += ['width', 'height']
|
||||
let haml = emmet#toString(current, 'haml', 1)
|
||||
let haml = substitute(haml, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", '', 'g'))
|
||||
let l:current.attr.width = l:width
|
||||
let l:current.attr.height = l:height
|
||||
let l:current.attrs_order += ['width', 'height']
|
||||
let l:haml = emmet#toString(l:current, 'haml', 1)
|
||||
let l:haml = substitute(l:haml, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(l:line, '^\s*') . l:haml, "\n", '', 'g'))
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#imageEncode() abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#parseTag(tag) abort
|
||||
let current = emmet#newNode()
|
||||
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
|
||||
let match = matchstr(a:tag, mx)
|
||||
let current.name = substitute(match, mx, '\1', '')
|
||||
let attrs = substitute(match, mx, '\2', '')
|
||||
let mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
|
||||
while len(attrs) > 0
|
||||
let match = matchstr(attrs, mx)
|
||||
if len(match) ==# 0
|
||||
let l:current = emmet#newNode()
|
||||
let l:mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
|
||||
let l:match = matchstr(a:tag, l:mx)
|
||||
let l:current.name = substitute(l:match, l:mx, '\1', '')
|
||||
let l:attrs = substitute(l:match, l:mx, '\2', '')
|
||||
let l:mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
|
||||
while len(l:attrs) > 0
|
||||
let l:match = matchstr(l:attrs, l:mx)
|
||||
if len(l:match) ==# 0
|
||||
break
|
||||
endif
|
||||
let attr_match = matchlist(match, mx)
|
||||
let name = attr_match[1]
|
||||
let value = len(attr_match[2]) ? attr_match[2] : attr_match[3]
|
||||
let current.attr[name] = value
|
||||
let current.attrs_order += [name]
|
||||
let attrs = attrs[stridx(attrs, match) + len(match):]
|
||||
let l:attr_match = matchlist(l:match, l:mx)
|
||||
let l:name = l:attr_match[1]
|
||||
let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3]
|
||||
let l:current.attr[l:name] = l:value
|
||||
let l:current.attrs_order += [l:name]
|
||||
let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):]
|
||||
endwhile
|
||||
return current
|
||||
return l:current
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#toggleComment() abort
|
||||
let line = getline('.')
|
||||
let space = matchstr(line, '^\s*')
|
||||
if line =~# '^\s*-#'
|
||||
call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*'))
|
||||
elseif line =~# '^\s*%[a-z]'
|
||||
call setline('.', space . '-# ' . line[len(space):])
|
||||
let l:line = getline('.')
|
||||
let l:space = matchstr(l:line, '^\s*')
|
||||
if l:line =~# '^\s*-#'
|
||||
call setline('.', l:space . matchstr(l:line[len(l:space)+2:], '^\s*\zs.*'))
|
||||
elseif l:line =~# '^\s*%[a-z]'
|
||||
call setline('.', l:space . '-# ' . l:line[len(l:space):])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#balanceTag(flag) range abort
|
||||
let block = emmet#util#getVisualBlock()
|
||||
let l:block = emmet#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
let l:curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = emmet#util#getcurpos()
|
||||
let l:curpos = emmet#util#getcurpos()
|
||||
endif
|
||||
let n = curpos[1]
|
||||
let ml = len(matchstr(getline(n), '^\s*'))
|
||||
let l:n = l:curpos[1]
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*'))
|
||||
|
||||
if a:flag > 0
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(block)
|
||||
let n = line('.')
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(l:block)
|
||||
let l:n = line('.')
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze%[a-z]'))
|
||||
if l > 0 && l < ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze%[a-z]'))
|
||||
if l:l > 0 && l:l < l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
endif
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l > ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
|
||||
if l:l > 0 && l:l > l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -260,76 +260,76 @@ function! emmet#lang#haml#moveNextPrevItem(flag) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#moveNextPrev(flag) abort
|
||||
let pos = search('""', a:flag ? 'Wb' : 'W')
|
||||
if pos != 0
|
||||
let l:pos = search('""', a:flag ? 'Wb' : 'W')
|
||||
if l:pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#splitJoinTag() abort
|
||||
let n = line('.')
|
||||
let sml = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
while n > 0
|
||||
if getline(n) =~# '^\s*\ze%[a-z]'
|
||||
if len(matchstr(getline(n), '^\s*%[a-z]')) < sml
|
||||
let l:n = line('.')
|
||||
let l:sml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
while l:n > 0
|
||||
if getline(l:n) =~# '^\s*\ze%[a-z]'
|
||||
if len(matchstr(getline(l:n), '^\s*%[a-z]')) < l:sml
|
||||
break
|
||||
endif
|
||||
let line = getline(n)
|
||||
call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', ''))
|
||||
let sn = n
|
||||
let n += 1
|
||||
let ml = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if len(matchstr(getline(n), '^\s*')) > ml
|
||||
while n <= line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*'))
|
||||
if l <= ml
|
||||
let l:line = getline(l:n)
|
||||
call setline(l:n, substitute(l:line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', ''))
|
||||
let l:sn = l:n
|
||||
let l:n += 1
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if len(matchstr(getline(l:n), '^\s*')) > l:ml
|
||||
while l:n <= line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*'))
|
||||
if l:l <= l:ml
|
||||
break
|
||||
endif
|
||||
exe n 'delete'
|
||||
exe l:n 'delete'
|
||||
endwhile
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
else
|
||||
let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)')
|
||||
let spaces = matchstr(getline(sn), '^\s*')
|
||||
let settings = emmet#getSettings()
|
||||
if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1
|
||||
call append(sn, spaces . ' ')
|
||||
call setpos('.', [0, sn+1, 1, 0])
|
||||
let l:tag = matchstr(getline(l:sn), '^\s*%\zs\(\w\+\)')
|
||||
let l:spaces = matchstr(getline(l:sn), '^\s*')
|
||||
let l:settings = emmet#getSettings()
|
||||
if stridx(','.l:settings.html.inline_elements.',', ','.l:tag.',') == -1
|
||||
call append(l:sn, l:spaces . ' ')
|
||||
call setpos('.', [0, l:sn+1, 1, 0])
|
||||
else
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
endif
|
||||
startinsert!
|
||||
endif
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#haml#removeTag() abort
|
||||
let n = line('.')
|
||||
let ml = 0
|
||||
while n > 0
|
||||
if getline(n) =~# '^\s*\ze[a-z]'
|
||||
let ml = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
let l:n = line('.')
|
||||
let l:ml = 0
|
||||
while l:n > 0
|
||||
if getline(l:n) =~# '^\s*\ze[a-z]'
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
let sn = n
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
let l:sn = l:n
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
if sn == n
|
||||
if l:sn == l:n
|
||||
exe 'delete'
|
||||
else
|
||||
exe sn ',' (n-1) 'delete'
|
||||
exe l:sn ',' (l:n-1) 'delete'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
+618
-618
File diff suppressed because it is too large
Load Diff
+200
-200
@@ -7,248 +7,248 @@ function! emmet#lang#jade#parseIntoTree(abbr, type) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let settings = a:settings
|
||||
let current = a:current
|
||||
let type = a:type
|
||||
let inline = a:inline
|
||||
let filters = a:filters
|
||||
let itemno = a:itemno
|
||||
let indent = emmet#getIndentation(type)
|
||||
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
|
||||
let attribute_style = emmet#getResource('jade', 'attribute_style', 'hash')
|
||||
let str = ''
|
||||
let l:settings = a:settings
|
||||
let l:current = a:current
|
||||
let l:type = a:type
|
||||
let l:inline = a:inline
|
||||
let l:filters = a:filters
|
||||
let l:itemno = a:itemno
|
||||
let l:indent = emmet#getIndentation(l:type)
|
||||
let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
|
||||
let l:attribute_style = emmet#getResource('jade', 'attribute_style', 'hash')
|
||||
let l:str = ''
|
||||
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
let l:current_name = l:current.name
|
||||
if l:dollar_expr
|
||||
let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
if len(current.name) > 0
|
||||
let str .= '' . current_name
|
||||
let tmp = ''
|
||||
for attr in emmet#util#unique(current.attrs_order + keys(current.attr))
|
||||
if !has_key(current.attr, attr)
|
||||
if len(l:current.name) > 0
|
||||
let l:str .= '' . l:current_name
|
||||
let l:tmp = ''
|
||||
for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
|
||||
if !has_key(l:current.attr, l:attr)
|
||||
continue
|
||||
endif
|
||||
let Val = current.attr[attr]
|
||||
if type(Val) == 2 && Val == function('emmet#types#true')
|
||||
if attribute_style ==# 'hash'
|
||||
let tmp .= ' ' . attr . ' = true'
|
||||
elseif attribute_style ==# 'html'
|
||||
let tmp .= attr . '=true'
|
||||
let l:Val = l:current.attr[l:attr]
|
||||
if type(l:Val) == 2 && l:Val == function('emmet#types#true')
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:tmp .= ' ' . l:attr . ' = true'
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:tmp .= l:attr . '=true'
|
||||
end
|
||||
else
|
||||
if dollar_expr
|
||||
while Val =~# '\$\([^#{]\|$\)'
|
||||
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
if l:dollar_expr
|
||||
while l:Val =~# '\$\([^#{]\|$\)'
|
||||
let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
let valtmp = substitute(Val, '\${cursor}', '', '')
|
||||
if attr ==# 'id' && len(valtmp) > 0
|
||||
let str .= '#' . Val
|
||||
elseif attr ==# 'class' && len(valtmp) > 0
|
||||
let str .= '.' . substitute(Val, ' ', '.', 'g')
|
||||
let l:valtmp = substitute(l:Val, '\${cursor}', '', '')
|
||||
if l:attr ==# 'id' && len(l:valtmp) > 0
|
||||
let l:str .= '#' . l:Val
|
||||
elseif l:attr ==# 'class' && len(l:valtmp) > 0
|
||||
let l:str .= '.' . substitute(l:Val, ' ', '.', 'g')
|
||||
else
|
||||
if len(tmp) > 0
|
||||
if attribute_style ==# 'hash'
|
||||
let tmp .= ', '
|
||||
elseif attribute_style ==# 'html'
|
||||
let tmp .= ' '
|
||||
if len(l:tmp) > 0
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:tmp .= ', '
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:tmp .= ' '
|
||||
endif
|
||||
endif
|
||||
if attribute_style ==# 'hash'
|
||||
let tmp .= '' . attr . '="' . Val . '"'
|
||||
elseif attribute_style ==# 'html'
|
||||
let tmp .= attr . '="' . Val . '"'
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:tmp .= '' . l:attr . '="' . l:Val . '"'
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:tmp .= l:attr . '="' . l:Val . '"'
|
||||
end
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
if len(tmp)
|
||||
if attribute_style ==# 'hash'
|
||||
let str .= '(' . tmp . ')'
|
||||
elseif attribute_style ==# 'html'
|
||||
let str .= '(' . tmp . ')'
|
||||
if len(l:tmp)
|
||||
if l:attribute_style ==# 'hash'
|
||||
let l:str .= '(' . l:tmp . ')'
|
||||
elseif l:attribute_style ==# 'html'
|
||||
let l:str .= '(' . l:tmp . ')'
|
||||
end
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
if len(current.value) > 0
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
let str = substitute(str, '\$#', text, 'g')
|
||||
let l:inner = ''
|
||||
if len(l:current.value) > 0
|
||||
let l:text = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
let l:str = substitute(l:str, '\$#', l:text, 'g')
|
||||
endif
|
||||
let lines = split(text, "\n")
|
||||
if len(lines) == 1
|
||||
let str .= ' ' . text
|
||||
let l:lines = split(l:text, "\n")
|
||||
if len(l:lines) == 1
|
||||
let l:str .= ' ' . l:text
|
||||
else
|
||||
for line in lines
|
||||
let str .= "\n" . indent . line . ' |'
|
||||
for l:line in l:lines
|
||||
let l:str .= "\n" . l:indent . l:line . ' |'
|
||||
endfor
|
||||
endif
|
||||
elseif len(current.child) == 0
|
||||
let str .= '${cursor}'
|
||||
elseif len(l:current.child) == 0
|
||||
let l:str .= '${cursor}'
|
||||
endif
|
||||
if len(current.child) == 1 && len(current.child[0].name) == 0
|
||||
let text = current.child[0].value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
if len(l:current.child) == 1 && len(l:current.child[0].name) == 0
|
||||
let l:text = l:current.child[0].value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
endif
|
||||
let lines = split(text, "\n")
|
||||
if len(lines) == 1
|
||||
let str .= ' ' . text
|
||||
let l:lines = split(l:text, "\n")
|
||||
if len(l:lines) == 1
|
||||
let l:str .= ' ' . l:text
|
||||
else
|
||||
for line in lines
|
||||
let str .= "\n" . indent . line . ' |'
|
||||
for l:line in l:lines
|
||||
let l:str .= "\n" . l:indent . l:line . ' |'
|
||||
endfor
|
||||
endif
|
||||
elseif len(current.child) > 0
|
||||
for child in current.child
|
||||
let inner .= emmet#toString(child, type, inline, filters, itemno, indent)
|
||||
elseif len(l:current.child) > 0
|
||||
for l:child in l:current.child
|
||||
let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
|
||||
let str .= "\n" . indent . inner
|
||||
let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
|
||||
let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
|
||||
let l:str .= "\n" . l:indent . l:inner
|
||||
endif
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
let l:str = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:str = substitute(l:str, '\${nr}', "\n", 'g')
|
||||
let l:str = substitute(l:str, '\\\$', '$', 'g')
|
||||
endif
|
||||
endif
|
||||
let str .= "\n"
|
||||
return str
|
||||
let l:str .= "\n"
|
||||
return l:str
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#imageSize() abort
|
||||
let line = getline('.')
|
||||
let current = emmet#lang#jade#parseTag(line)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
let l:line = getline('.')
|
||||
let l:current = emmet#lang#jade#parseTag(l:line)
|
||||
if empty(l:current) || !has_key(l:current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn =~# '^\s*$'
|
||||
let l:fn = l:current.attr.src
|
||||
if l:fn =~# '^\s*$'
|
||||
return
|
||||
elseif fn !~# '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
elseif l:fn !~# '^\(/\|http\)'
|
||||
let l:fn = simplify(expand('%:h') . '/' . l:fn)
|
||||
endif
|
||||
|
||||
let [width, height] = emmet#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
let [l:width, l:height] = emmet#util#getImageSize(l:fn)
|
||||
if l:width == -1 && l:height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let current.attrs_order += ['width', 'height']
|
||||
let jade = emmet#toString(current, 'jade', 1)
|
||||
let jade = substitute(jade, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(line, '^\s*') . jade, "\n", '', 'g'))
|
||||
let l:current.attr.width = l:width
|
||||
let l:current.attr.height = l:height
|
||||
let l:current.attrs_order += ['width', 'height']
|
||||
let l:jade = emmet#toString(l:current, 'jade', 1)
|
||||
let l:jade = substitute(l:jade, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(l:line, '^\s*') . l:jade, "\n", '', 'g'))
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#imageEncode() abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#parseTag(tag) abort
|
||||
let current = emmet#newNode()
|
||||
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
|
||||
let match = matchstr(a:tag, mx)
|
||||
let current.name = substitute(match, mx, '\1', '')
|
||||
let attrs = substitute(match, mx, '\2', '')
|
||||
let mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
|
||||
while len(attrs) > 0
|
||||
let match = matchstr(attrs, mx)
|
||||
if len(match) ==# 0
|
||||
let l:current = emmet#newNode()
|
||||
let l:mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
|
||||
let l:match = matchstr(a:tag, l:mx)
|
||||
let l:current.name = substitute(l:match, l:mx, '\1', '')
|
||||
let l:attrs = substitute(l:match, l:mx, '\2', '')
|
||||
let l:mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
|
||||
while len(l:attrs) > 0
|
||||
let l:match = matchstr(l:attrs, l:mx)
|
||||
if len(l:match) ==# 0
|
||||
break
|
||||
endif
|
||||
let attr_match = matchlist(match, mx)
|
||||
let name = attr_match[1]
|
||||
let value = len(attr_match[2]) ? attr_match[2] : attr_match[3]
|
||||
let current.attr[name] = value
|
||||
let current.attrs_order += [name]
|
||||
let attrs = attrs[stridx(attrs, match) + len(match):]
|
||||
let l:attr_match = matchlist(l:match, l:mx)
|
||||
let l:name = l:attr_match[1]
|
||||
let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3]
|
||||
let l:current.attr[l:name] = l:value
|
||||
let l:current.attrs_order += [l:name]
|
||||
let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):]
|
||||
endwhile
|
||||
return current
|
||||
return l:current
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#toggleComment() abort
|
||||
let line = getline('.')
|
||||
let space = matchstr(line, '^\s*')
|
||||
if line =~# '^\s*-#'
|
||||
call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*'))
|
||||
elseif line =~# '^\s*%[a-z]'
|
||||
call setline('.', space . '-# ' . line[len(space):])
|
||||
let l:line = getline('.')
|
||||
let l:space = matchstr(l:line, '^\s*')
|
||||
if l:line =~# '^\s*-#'
|
||||
call setline('.', l:space . matchstr(l:line[len(l:space)+2:], '^\s*\zs.*'))
|
||||
elseif l:line =~# '^\s*%[a-z]'
|
||||
call setline('.', l:space . '-# ' . l:line[len(l:space):])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#balanceTag(flag) range abort
|
||||
let block = emmet#util#getVisualBlock()
|
||||
let l:block = emmet#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
let l:curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = emmet#util#getcurpos()
|
||||
let l:curpos = emmet#util#getcurpos()
|
||||
endif
|
||||
let n = curpos[1]
|
||||
let ml = len(matchstr(getline(n), '^\s*'))
|
||||
let l:n = l:curpos[1]
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*'))
|
||||
|
||||
if a:flag > 0
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(block)
|
||||
let n = line('.')
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(l:block)
|
||||
let l:n = line('.')
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze%[a-z]'))
|
||||
if l > 0 && l < ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze%[a-z]'))
|
||||
if l:l > 0 && l:l < l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
endif
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l > ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
|
||||
if l:l > 0 && l:l > l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -257,76 +257,76 @@ function! emmet#lang#jade#moveNextPrevItem(flag) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#moveNextPrev(flag) abort
|
||||
let pos = search('""', a:flag ? 'Wb' : 'W')
|
||||
if pos != 0
|
||||
let l:pos = search('""', a:flag ? 'Wb' : 'W')
|
||||
if l:pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#splitJoinTag() abort
|
||||
let n = line('.')
|
||||
let sml = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
while n > 0
|
||||
if getline(n) =~# '^\s*\ze%[a-z]'
|
||||
if len(matchstr(getline(n), '^\s*%[a-z]')) < sml
|
||||
let l:n = line('.')
|
||||
let l:sml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
while l:n > 0
|
||||
if getline(l:n) =~# '^\s*\ze%[a-z]'
|
||||
if len(matchstr(getline(l:n), '^\s*%[a-z]')) < l:sml
|
||||
break
|
||||
endif
|
||||
let line = getline(n)
|
||||
call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', ''))
|
||||
let sn = n
|
||||
let n += 1
|
||||
let ml = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if len(matchstr(getline(n), '^\s*')) > ml
|
||||
while n <= line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*'))
|
||||
if l <= ml
|
||||
let l:line = getline(l:n)
|
||||
call setline(l:n, substitute(l:line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', ''))
|
||||
let l:sn = l:n
|
||||
let l:n += 1
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if len(matchstr(getline(l:n), '^\s*')) > l:ml
|
||||
while l:n <= line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*'))
|
||||
if l:l <= l:ml
|
||||
break
|
||||
endif
|
||||
exe n 'delete'
|
||||
exe l:n 'delete'
|
||||
endwhile
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
else
|
||||
let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)')
|
||||
let spaces = matchstr(getline(sn), '^\s*')
|
||||
let settings = emmet#getSettings()
|
||||
if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1
|
||||
call append(sn, spaces . ' ')
|
||||
call setpos('.', [0, sn+1, 1, 0])
|
||||
let l:tag = matchstr(getline(l:sn), '^\s*%\zs\(\w\+\)')
|
||||
let l:spaces = matchstr(getline(l:sn), '^\s*')
|
||||
let l:settings = emmet#getSettings()
|
||||
if stridx(','.l:settings.html.inline_elements.',', ','.l:tag.',') == -1
|
||||
call append(l:sn, l:spaces . ' ')
|
||||
call setpos('.', [0, l:sn+1, 1, 0])
|
||||
else
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
endif
|
||||
startinsert!
|
||||
endif
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#jade#removeTag() abort
|
||||
let n = line('.')
|
||||
let ml = 0
|
||||
while n > 0
|
||||
if getline(n) =~# '^\s*\ze[a-z]'
|
||||
let ml = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
let l:n = line('.')
|
||||
let l:ml = 0
|
||||
while l:n > 0
|
||||
if getline(l:n) =~# '^\s*\ze[a-z]'
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
let sn = n
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
let l:sn = l:n
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
if sn == n
|
||||
if l:sn == l:n
|
||||
exe 'delete'
|
||||
else
|
||||
exe sn ',' (n-1) 'delete'
|
||||
exe l:sn ',' (l:n-1) 'delete'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
@@ -7,59 +7,59 @@ function! emmet#lang#sass#parseIntoTree(abbr, type) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let settings = a:settings
|
||||
let current = a:current
|
||||
let type = a:type
|
||||
let inline = a:inline
|
||||
let filters = a:filters
|
||||
let itemno = a:itemno
|
||||
let indent = a:indent
|
||||
let str = ''
|
||||
let l:settings = a:settings
|
||||
let l:current = a:current
|
||||
let l:type = a:type
|
||||
let l:inline = a:inline
|
||||
let l:filters = a:filters
|
||||
let l:itemno = a:itemno
|
||||
let l:indent = a:indent
|
||||
let l:str = ''
|
||||
|
||||
let current_name = current.name
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
if len(current.name) > 0
|
||||
let str .= current_name
|
||||
let tmp = ''
|
||||
for attr in keys(current.attr)
|
||||
let val = current.attr[attr]
|
||||
while val =~# '\$\([^#{]\|$\)'
|
||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let l:current_name = l:current.name
|
||||
let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
|
||||
if len(l:current.name) > 0
|
||||
let l:str .= l:current_name
|
||||
let l:tmp = ''
|
||||
for l:attr in keys(l:current.attr)
|
||||
let l:val = l:current.attr[l:attr]
|
||||
while l:val =~# '\$\([^#{]\|$\)'
|
||||
let l:val = substitute(l:val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
if attr ==# 'id'
|
||||
let str .= '#' . val
|
||||
elseif attr ==# 'class'
|
||||
let str .= '.' . val
|
||||
let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
|
||||
if l:attr ==# 'id'
|
||||
let l:str .= '#' . l:val
|
||||
elseif l:attr ==# 'class'
|
||||
let l:str .= '.' . l:val
|
||||
else
|
||||
let tmp .= attr . ': ' . val
|
||||
let l:tmp .= l:attr . ': ' . l:val
|
||||
endif
|
||||
endfor
|
||||
if len(tmp) > 0
|
||||
let str .= "\n"
|
||||
for line in split(tmp, "\n")
|
||||
let str .= indent . line . "\n"
|
||||
if len(l:tmp) > 0
|
||||
let l:str .= "\n"
|
||||
for l:line in split(l:tmp, "\n")
|
||||
let l:str .= l:indent . l:line . "\n"
|
||||
endfor
|
||||
else
|
||||
let str .= "\n"
|
||||
let l:str .= "\n"
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
for child in current.child
|
||||
let tmp = emmet#toString(child, type, inline, filters, itemno, indent)
|
||||
let tmp = substitute(tmp, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let tmp = substitute(tmp, "\n" . escape(indent, '\') . '$', '${cursor}\n', 'g')
|
||||
let inner .= tmp
|
||||
let l:inner = ''
|
||||
for l:child in l:current.child
|
||||
let l:tmp = emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
|
||||
let l:tmp = substitute(l:tmp, "\n", "\n" . escape(l:indent, '\'), 'g')
|
||||
let l:tmp = substitute(l:tmp, "\n" . escape(l:indent, '\') . '$', '${cursor}\n', 'g')
|
||||
let l:inner .= l:tmp
|
||||
endfor
|
||||
if len(inner) > 0
|
||||
let str .= indent . inner
|
||||
if len(l:inner) > 0
|
||||
let l:str .= l:indent . l:inner
|
||||
endif
|
||||
else
|
||||
let text = emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
let text = substitute(text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g')
|
||||
return text
|
||||
let l:text = emmet#lang#css#toString(l:settings, l:current, l:type, l:inline, l:filters, l:itemno, l:indent)
|
||||
let l:text = substitute(l:text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g')
|
||||
return l:text
|
||||
endif
|
||||
return str
|
||||
return l:str
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#sass#imageSize() abort
|
||||
@@ -75,67 +75,67 @@ function! emmet#lang#sass#toggleComment() abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#sass#balanceTag(flag) range abort
|
||||
let block = emmet#util#getVisualBlock()
|
||||
let l:block = emmet#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
let l:curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = emmet#util#getcurpos()
|
||||
let l:curpos = emmet#util#getcurpos()
|
||||
endif
|
||||
let n = curpos[1]
|
||||
let ml = len(matchstr(getline(n), '^\s*'))
|
||||
let l:n = l:curpos[1]
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*'))
|
||||
|
||||
if a:flag > 0
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(block)
|
||||
let n = line('.')
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(l:block)
|
||||
let l:n = line('.')
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l < ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
|
||||
if l:l > 0 && l:l < l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
endif
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l > ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
|
||||
if l:l > 0 && l:l > l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -144,10 +144,10 @@ function! emmet#lang#sass#moveNextPrevItem(flag) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#sass#moveNextPrev(flag) abort
|
||||
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
|
||||
if pos == 2
|
||||
let l:pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
|
||||
if l:pos == 2
|
||||
startinsert!
|
||||
elseif pos != 0
|
||||
elseif l:pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
|
||||
@@ -11,53 +11,53 @@ function! emmet#lang#scss#parseIntoTree(abbr, type) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let settings = a:settings
|
||||
let current = a:current
|
||||
let type = a:type
|
||||
let inline = a:inline
|
||||
let filters = a:filters
|
||||
let itemno = a:itemno
|
||||
let indent = a:indent
|
||||
let str = ''
|
||||
let l:settings = a:settings
|
||||
let l:current = a:current
|
||||
let l:type = a:type
|
||||
let l:inline = a:inline
|
||||
let l:filters = a:filters
|
||||
let l:itemno = a:itemno
|
||||
let l:indent = a:indent
|
||||
let l:str = ''
|
||||
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
if len(current.name) > 0
|
||||
let str .= current_name
|
||||
let tmp = ''
|
||||
for attr in keys(current.attr)
|
||||
let val = current.attr[attr]
|
||||
while val =~# '\$\([^#{]\|$\)'
|
||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
|
||||
if len(l:current.name) > 0
|
||||
let l:str .= l:current_name
|
||||
let l:tmp = ''
|
||||
for l:attr in keys(l:current.attr)
|
||||
let l:val = l:current.attr[l:attr]
|
||||
while l:val =~# '\$\([^#{]\|$\)'
|
||||
let l:val = substitute(l:val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
if attr ==# 'id'
|
||||
let str .= '#' . val
|
||||
elseif attr ==# 'class'
|
||||
let str .= '.' . val
|
||||
let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
|
||||
if l:attr ==# 'id'
|
||||
let l:str .= '#' . l:val
|
||||
elseif l:attr ==# 'class'
|
||||
let l:str .= '.' . l:val
|
||||
else
|
||||
let tmp .= attr . ': ' . val . ';'
|
||||
let l:tmp .= l:attr . ': ' . l:val . ';'
|
||||
endif
|
||||
endfor
|
||||
if len(tmp) > 0
|
||||
let str .= " {\n"
|
||||
for line in split(tmp, "\n")
|
||||
let str .= indent . line . "\n"
|
||||
if len(l:tmp) > 0
|
||||
let l:str .= " {\n"
|
||||
for l:line in split(l:tmp, "\n")
|
||||
let l:str .= l:indent . l:line . "\n"
|
||||
endfor
|
||||
else
|
||||
let str .= " {\n"
|
||||
let l:str .= " {\n"
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
for child in current.child
|
||||
let inner .= emmet#toString(child, type, inline, filters, itemno)
|
||||
let l:inner = ''
|
||||
for l:child in l:current.child
|
||||
let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
|
||||
let str .= indent . inner . "${cursor}\n}\n"
|
||||
let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
|
||||
let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
|
||||
let l:str .= l:indent . l:inner . "${cursor}\n}\n"
|
||||
else
|
||||
return emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
return emmet#lang#css#toString(l:settings, l:current, l:type, l:inline, l:filters, l:itemno, l:indent)
|
||||
endif
|
||||
return str
|
||||
return l:str
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#scss#imageSize() abort
|
||||
@@ -78,33 +78,33 @@ endfunction
|
||||
|
||||
function! emmet#lang#scss#balanceTag(flag) range abort
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
call setpos('.', curpos)
|
||||
let l:curpos = [0, line("'<"), col("'<"), 0]
|
||||
call setpos('.', l:curpos)
|
||||
else
|
||||
let curpos = emmet#util#getcurpos()
|
||||
let l:curpos = emmet#util#getcurpos()
|
||||
endif
|
||||
if a:flag < 0
|
||||
let ret = searchpair('}', '', '.\zs{')
|
||||
let l:ret = searchpair('}', '', '.\zs{')
|
||||
else
|
||||
let ret = searchpair('{', '', '}', 'bW')
|
||||
let l:ret = searchpair('{', '', '}', 'bW')
|
||||
endif
|
||||
if ret > 0
|
||||
let pos1 = emmet#util#getcurpos()[1:2]
|
||||
if l:ret > 0
|
||||
let l:pos1 = emmet#util#getcurpos()[1:2]
|
||||
if a:flag < 0
|
||||
let pos2 = searchpairpos('{', '', '}')
|
||||
let l:pos2 = searchpairpos('{', '', '}')
|
||||
else
|
||||
let pos2 = searchpairpos('{', '', '}')
|
||||
let l:pos2 = searchpairpos('{', '', '}')
|
||||
endif
|
||||
let block = [pos1, pos2]
|
||||
if emmet#util#regionIsValid(block)
|
||||
call emmet#util#selectRegion(block)
|
||||
let l:block = [l:pos1, l:pos2]
|
||||
if emmet#util#regionIsValid(l:block)
|
||||
call emmet#util#selectRegion(l:block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe 'normal! gv'
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
call setpos('.', l:curpos)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
+164
-164
@@ -7,210 +7,210 @@ function! emmet#lang#slim#parseIntoTree(abbr, type) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) abort
|
||||
let current = a:current
|
||||
let type = a:type
|
||||
let inline = a:inline
|
||||
let filters = a:filters
|
||||
let itemno = a:itemno
|
||||
let indent = emmet#getIndentation(type)
|
||||
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
|
||||
let str = ''
|
||||
let l:current = a:current
|
||||
let l:type = a:type
|
||||
let l:inline = a:inline
|
||||
let l:filters = a:filters
|
||||
let l:itemno = a:itemno
|
||||
let l:indent = emmet#getIndentation(l:type)
|
||||
let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
|
||||
let l:str = ''
|
||||
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
let l:current_name = l:current.name
|
||||
if l:dollar_expr
|
||||
let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
|
||||
endif
|
||||
if len(current.name) > 0
|
||||
let str .= current_name
|
||||
for attr in emmet#util#unique(current.attrs_order + keys(current.attr))
|
||||
if !has_key(current.attr, attr)
|
||||
if len(l:current.name) > 0
|
||||
let l:str .= l:current_name
|
||||
for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
|
||||
if !has_key(l:current.attr, l:attr)
|
||||
continue
|
||||
endif
|
||||
let Val = current.attr[attr]
|
||||
if type(Val) == 2 && Val == function('emmet#types#true')
|
||||
let str .= ' ' . attr . '=true'
|
||||
let l:Val = l:current.attr[l:attr]
|
||||
if type(l:Val) == 2 && l:Val == function('emmet#types#true')
|
||||
let l:str .= ' ' . l:attr . '=true'
|
||||
else
|
||||
if dollar_expr
|
||||
while Val =~# '\$\([^#{]\|$\)'
|
||||
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
if l:dollar_expr
|
||||
while l:Val =~# '\$\([^#{]\|$\)'
|
||||
let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
endif
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
let str .= ' ' . attr . '="' . Val . '"'
|
||||
let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
|
||||
let l:str .= ' ' . l:attr . '="' . l:Val . '"'
|
||||
endif
|
||||
endfor
|
||||
|
||||
let inner = ''
|
||||
if len(current.value) > 0
|
||||
let str .= "\n"
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
let str = substitute(str, '\$#', text, 'g')
|
||||
let l:inner = ''
|
||||
if len(l:current.value) > 0
|
||||
let l:str .= "\n"
|
||||
let l:text = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
let l:str = substitute(l:str, '\$#', l:text, 'g')
|
||||
endif
|
||||
for line in split(text, "\n")
|
||||
let str .= indent . '| ' . line . "\n"
|
||||
for l:line in split(l:text, "\n")
|
||||
let l:str .= l:indent . '| ' . l:line . "\n"
|
||||
endfor
|
||||
elseif len(current.child) == 0
|
||||
let str .= '${cursor}'
|
||||
elseif len(l:current.child) == 0
|
||||
let l:str .= '${cursor}'
|
||||
endif
|
||||
if len(current.child) == 1 && len(current.child[0].name) == 0
|
||||
let str .= "\n"
|
||||
let text = current.child[0].value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
if len(l:current.child) == 1 && len(l:current.child[0].name) == 0
|
||||
let l:str .= "\n"
|
||||
let l:text = l:current.child[0].value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:text = substitute(l:text, '\${nr}', "\n", 'g')
|
||||
let l:text = substitute(l:text, '\\\$', '$', 'g')
|
||||
endif
|
||||
for line in split(text, "\n")
|
||||
let str .= indent . '| ' . line . "\n"
|
||||
for l:line in split(l:text, "\n")
|
||||
let l:str .= l:indent . '| ' . l:line . "\n"
|
||||
endfor
|
||||
elseif len(current.child) > 0
|
||||
for child in current.child
|
||||
let inner .= emmet#toString(child, type, inline, filters, itemno, indent)
|
||||
elseif len(l:current.child) > 0
|
||||
for l:child in l:current.child
|
||||
let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
|
||||
let str .= "\n" . indent . inner
|
||||
let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
|
||||
let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
|
||||
let l:str .= "\n" . l:indent . l:inner
|
||||
endif
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
let l:str = l:current.value[1:-2]
|
||||
if l:dollar_expr
|
||||
let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
|
||||
let l:str = substitute(l:str, '\${nr}', "\n", 'g')
|
||||
let l:str = substitute(l:str, '\\\$', '$', 'g')
|
||||
endif
|
||||
endif
|
||||
if str !~# "\n$"
|
||||
let str .= "\n"
|
||||
if l:str !~# "\n$"
|
||||
let l:str .= "\n"
|
||||
endif
|
||||
return str
|
||||
return l:str
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#imageSize() abort
|
||||
let line = getline('.')
|
||||
let current = emmet#lang#slim#parseTag(line)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
let l:line = getline('.')
|
||||
let l:current = emmet#lang#slim#parseTag(l:line)
|
||||
if empty(l:current) || !has_key(l:current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn =~# '^\s*$'
|
||||
let l:fn = l:current.attr.src
|
||||
if l:fn =~# '^\s*$'
|
||||
return
|
||||
elseif fn !~# '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
elseif l:fn !~# '^\(/\|http\)'
|
||||
let l:fn = simplify(expand('%:h') . '/' . l:fn)
|
||||
endif
|
||||
|
||||
let [width, height] = emmet#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
let [l:width, l:height] = emmet#util#getImageSize(l:fn)
|
||||
if l:width == -1 && l:height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let current.attrs_order += ['width', 'height']
|
||||
let slim = emmet#toString(current, 'slim', 1)
|
||||
let slim = substitute(slim, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(line, '^\s*') . slim, "\n", '', 'g'))
|
||||
let l:current.attr.width = l:width
|
||||
let l:current.attr.height = l:height
|
||||
let l:current.attrs_order += ['width', 'height']
|
||||
let l:slim = emmet#toString(l:current, 'slim', 1)
|
||||
let l:slim = substitute(l:slim, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(l:line, '^\s*') . l:slim, "\n", '', 'g'))
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#imageEncode() abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#parseTag(tag) abort
|
||||
let current = emmet#newNode()
|
||||
let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)'
|
||||
let match = matchstr(a:tag, mx)
|
||||
let current.name = substitute(match, mx, '\1', '')
|
||||
let attrs = substitute(match, mx, '\2', '')
|
||||
let mx = '\([a-zA-Z0-9]\+\)=\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
|
||||
while len(attrs) > 0
|
||||
let match = matchstr(attrs, mx)
|
||||
if len(match) == 0
|
||||
let l:current = emmet#newNode()
|
||||
let l:mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)'
|
||||
let l:match = matchstr(a:tag, l:mx)
|
||||
let l:current.name = substitute(l:match, l:mx, '\1', '')
|
||||
let l:attrs = substitute(l:match, l:mx, '\2', '')
|
||||
let l:mx = '\([a-zA-Z0-9]\+\)=\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
|
||||
while len(l:attrs) > 0
|
||||
let l:match = matchstr(l:attrs, l:mx)
|
||||
if len(l:match) == 0
|
||||
break
|
||||
endif
|
||||
let attr_match = matchlist(match, mx)
|
||||
let name = attr_match[1]
|
||||
let value = len(attr_match[2]) ? attr_match[2] : attr_match[3]
|
||||
let current.attr[name] = value
|
||||
let current.attrs_order += [name]
|
||||
let attrs = attrs[stridx(attrs, match) + len(match):]
|
||||
let l:attr_match = matchlist(l:match, l:mx)
|
||||
let l:name = l:attr_match[1]
|
||||
let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3]
|
||||
let l:current.attr[l:name] = l:value
|
||||
let l:current.attrs_order += [l:name]
|
||||
let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):]
|
||||
endwhile
|
||||
return current
|
||||
return l:current
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#toggleComment() abort
|
||||
let line = getline('.')
|
||||
let space = matchstr(line, '^\s*')
|
||||
if line =~# '^\s*/'
|
||||
call setline('.', space . line[len(space)+1:])
|
||||
elseif line =~# '^\s*[a-z]'
|
||||
call setline('.', space . '/' . line[len(space):])
|
||||
let l:line = getline('.')
|
||||
let l:space = matchstr(l:line, '^\s*')
|
||||
if l:line =~# '^\s*/'
|
||||
call setline('.', l:space . l:line[len(l:space)+1:])
|
||||
elseif l:line =~# '^\s*[a-z]'
|
||||
call setline('.', l:space . '/' . l:line[len(l:space):])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#balanceTag(flag) range abort
|
||||
let block = emmet#util#getVisualBlock()
|
||||
let l:block = emmet#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
let l:curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = emmet#util#getcurpos()
|
||||
let l:curpos = emmet#util#getcurpos()
|
||||
endif
|
||||
let n = curpos[1]
|
||||
let ml = len(matchstr(getline(n), '^\s*'))
|
||||
let l:n = l:curpos[1]
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*'))
|
||||
|
||||
if a:flag > 0
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(block)
|
||||
let n = line('.')
|
||||
if a:flag == 1 || !emmet#util#regionIsValid(l:block)
|
||||
let l:n = line('.')
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l < ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
|
||||
if l:l > 0 && l:l < l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
endif
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l > ml
|
||||
let ml = l
|
||||
while l:n > 0
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
|
||||
if l:l > 0 && l:l > l:ml
|
||||
let l:ml = l:l
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
let l:sn = l:n
|
||||
if l:n == 0
|
||||
let l:ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
call setpos('.', [0, l:n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -219,64 +219,64 @@ function! emmet#lang#slim#moveNextPrevItem(flag) abort
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#moveNextPrev(flag) abort
|
||||
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
|
||||
if pos == 2
|
||||
let l:pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
|
||||
if l:pos == 2
|
||||
startinsert!
|
||||
elseif pos != 0
|
||||
elseif l:pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#splitJoinTag() abort
|
||||
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*|'
|
||||
let l:n = line('.')
|
||||
while l:n > 0
|
||||
if getline(l:n) =~# '^\s*\ze[a-z]'
|
||||
let l:sn = l:n
|
||||
let l:n += 1
|
||||
if getline(l:n) =~# '^\s*|'
|
||||
while l:n <= line('$')
|
||||
if getline(l:n) !~# '^\s*|'
|
||||
break
|
||||
endif
|
||||
exe n 'delete'
|
||||
exe l:n 'delete'
|
||||
endwhile
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
call setpos('.', [0, l:sn, 1, 0])
|
||||
else
|
||||
let spaces = matchstr(getline(sn), '^\s*')
|
||||
call append(sn, spaces . ' | ')
|
||||
call setpos('.', [0, sn+1, 1, 0])
|
||||
let l:spaces = matchstr(getline(l:sn), '^\s*')
|
||||
call append(l:sn, l:spaces . ' | ')
|
||||
call setpos('.', [0, l:sn+1, 1, 0])
|
||||
startinsert!
|
||||
endif
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! emmet#lang#slim#removeTag() abort
|
||||
let n = line('.')
|
||||
let ml = 0
|
||||
while n > 0
|
||||
if getline(n) =~# '^\s*\ze[a-z]'
|
||||
let ml = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
let l:n = line('.')
|
||||
let l:ml = 0
|
||||
while l:n > 0
|
||||
if getline(l:n) =~# '^\s*\ze[a-z]'
|
||||
let l:ml = len(matchstr(getline(l:n), '^\s*[a-z]'))
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
let l:n -= 1
|
||||
endwhile
|
||||
let sn = n
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
let l:sn = l:n
|
||||
while l:n < line('$')
|
||||
let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
|
||||
if l:l > 0 && l:l <= l:ml
|
||||
let l:n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
let l:n += 1
|
||||
endwhile
|
||||
if sn == n
|
||||
if l:sn == l:n
|
||||
exe 'delete'
|
||||
else
|
||||
exe sn ',' (n-1) 'delete'
|
||||
exe l:sn ',' (l:n-1) 'delete'
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
Reference in New Issue
Block a user