11 Commits

Author SHA1 Message Date
Yasuhiro Matsumoto
cc8b1a9f22 Fix basevalue access before empty string check in parseIntoTree
l:basevalue[1] was accessed before checking if l:basevalue is empty.
Moved the empty check first so l:basedirect is only computed when
l:basevalue is non-empty.
2026-03-07 16:46:10 +09:00
Yasuhiro Matsumoto
fbb61e7ef2 Use shellescape() for external commands to prevent command injection
File paths passed to system() via xxd and identify were using manual
double-quote wrapping instead of shellescape(), which could allow
command injection with specially crafted filenames.
2026-03-07 16:45:56 +09:00
Yasuhiro Matsumoto
8623326f4c Fix mergeConfig() list merge bug
When merging two lists, l:rhi is a value from iteration (not an index),
so l:rhs[l:rhi] was incorrectly using values as indices. Changed to use
l:rhi directly. Also removed the redundant l:lhs += l:rhs before the
clear-and-rebuild loop.
2026-03-07 16:44:58 +09:00
Yasuhiro Matsumoto
edb1941955 Fix duplicate mergeLines() definition
The second definition without 'range' was overwriting the first one,
causing the visual selection merge to not work properly. Removed the
duplicate and kept the lang-delegating version.
2026-03-07 16:44:38 +09:00
Yasuhiro Matsumoto
7c44caa0e6 Refactoring 2026-03-07 11:08:24 +09:00
mattn
e983971449 Merge pull request #566 from mmppppss/master
fix bug in len() invalid
2025-07-15 11:44:13 +09:00
Pedro Pozo
56199c129a fix bugemmet.vim
in files with double extension type: "hola.txt.md" it generated an error
it is because you were passing a null to len() that detects if the file does not have an extension len(type)==0
2025-07-14 21:12:24 -04:00
mattn
6c511a8d7d Merge pull request #558 from kola-web/master
support treesitter
2024-08-10 11:07:49 +09:00
kola
033476412e Change treesitter judgment method 2024-08-10 09:32:53 +08:00
kola
8f1581550d my_utils.lua -> emmet_utils.lua 2024-08-10 09:29:20 +08:00
kola
c5c5188a0b support treesitter 2024-08-09 18:06:47 +08:00
15 changed files with 2480 additions and 2458 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -10,19 +10,19 @@ function! emmet#lang#exists(type) abort
endfunction endfunction
function! emmet#lang#type(type) abort function! emmet#lang#type(type) abort
let type = a:type let l:type = a:type
let base = type let l:base = l:type
let settings = emmet#getSettings() let l:settings = emmet#getSettings()
while base != '' while l:base != ''
for b in split(base, '\.') for l:b in split(l:base, '\.')
if emmet#lang#exists(b) if emmet#lang#exists(l:b)
return b return l:b
endif endif
if has_key(settings, b) && has_key(settings[b], 'extends') if has_key(l:settings, l:b) && has_key(l:settings[l:b], 'extends')
let base = settings[b].extends let l:base = l:settings[l:b].extends
break break
else else
let base = '' let l:base = ''
endif endif
endfor endfor
endwhile endwhile
@@ -31,22 +31,22 @@ endfunction
" get all extends for a type recursively " get all extends for a type recursively
function! emmet#lang#getExtends(type) abort function! emmet#lang#getExtends(type) abort
let settings = emmet#getSettings() let l:settings = emmet#getSettings()
if !has_key(settings[a:type], 'extends') if !has_key(l:settings[a:type], 'extends')
return [] return []
endif endif
let extends = settings[a:type].extends let l:extends = l:settings[a:type].extends
if type(extends) ==# 1 if type(l:extends) ==# 1
let tmp = split(extends, '\s*,\s*') let l:tmp = split(l:extends, '\s*,\s*')
unlet! extends unlet! l:extends
let extends = tmp let l:extends = l:tmp
endif endif
for ext in extends for l:ext in l:extends
let extends = extends + emmet#lang#getExtends(ext) let l:extends = l:extends + emmet#lang#getExtends(l:ext)
endfor endfor
return extends return l:extends
endfunction endfunction

View File

@@ -1,6 +1,6 @@
function! emmet#lang#css#findTokens(str) abort function! emmet#lang#css#findTokens(str) abort
let tmp = substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '') let l:tmp = substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '')
if tmp =~ '/' && tmp =~ '^[a-zA-Z0-9/_.]\+$' if l:tmp =~ '/' && l:tmp =~ '^[a-zA-Z0-9/_.]\+$'
" maybe path or something " maybe path or something
return '' return ''
endif endif
@@ -8,281 +8,281 @@ function! emmet#lang#css#findTokens(str) abort
endfunction endfunction
function! emmet#lang#css#parseIntoTree(abbr, type) abort function! emmet#lang#css#parseIntoTree(abbr, type) abort
let abbr = a:abbr let l:abbr = a:abbr
let type = a:type let l:type = a:type
let prefix = 0 let l:prefix = 0
let value = '' let l:value = ''
let indent = emmet#getIndentation(type) let l:indent = emmet#getIndentation(l:type)
let aliases = emmet#getResource(type, 'aliases', {}) let l:aliases = emmet#getResource(l:type, 'aliases', {})
let snippets = emmet#getResource(type, 'snippets', {}) let l:snippets = emmet#getResource(l:type, 'snippets', {})
let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1) 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 " emmet
let tokens = split(abbr, '+\ze[^+)!]') let l:tokens = split(l:abbr, '+\ze[^+)!]')
let block = emmet#util#searchRegion('{', '}') let l:block = emmet#util#searchRegion('{', '}')
if abbr !~# '^@' && emmet#getBaseType(type) ==# 'css' && type !=# 'sass' && type !=# 'styled' && block[0] ==# [0,0] && block[1] ==# [0,0] 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 current = emmet#newNode() let l:current = emmet#newNode()
let current.snippet = substitute(abbr, '\s\+$', '', '') . " {\n" . indent . "${cursor}\n}" let l:current.snippet = substitute(l:abbr, '\s\+$', '', '') . " {\n" . l:indent . "${cursor}\n}"
let current.name = '' let l:current.name = ''
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
else else
for n in range(len(tokens)) for l:n in range(len(l:tokens))
let token = tokens[n] let l:token = l:tokens[l: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\)*\)$') 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(prop) if len(l:prop)
let token = substitute(prop[1], '^(\(.*\))', '\1', '') let l:token = substitute(l:prop[1], '^(\(.*\))', '\1', '')
if token =~# '^-' if l:token =~# '^-'
let prefix = 1 let l:prefix = 1
let token = token[1:] let l:token = l:token[1:]
endif endif
let value = '' let l:value = ''
for vt in split(prop[2], '\a\+\zs') for l:vt in split(l:prop[2], '\a\+\zs')
let ut = matchstr(vt, '[a-z]\+$') let l:ut = matchstr(l:vt, '[a-z]\+$')
if ut == 'auto' if l:ut == 'auto'
let ut = '' let l:ut = ''
endif endif
for v in split(vt, '\d\zs-') for l:v in split(l:vt, '\d\zs-')
if len(value) > 0 if len(l:value) > 0
let value .= ' ' let l:value .= ' '
endif endif
if v !~ '[a-z]\+$' if l:v !~ '[a-z]\+$'
let v .= ut let l:v .= l:ut
endif endif
if token =~# '^[z]' if l:token =~# '^[z]'
" TODO " TODO
let value .= substitute(v, '[^0-9.]*$', '', '') let l:value .= substitute(l:v, '[^0-9.]*$', '', '')
elseif v =~# 'em$' elseif l:v =~# 'em$'
let value .= v let l:value .= l:v
elseif v =~# 'ex$' elseif l:v =~# 'ex$'
let value .= v let l:value .= l:v
elseif v =~# 'vh$' elseif l:v =~# 'vh$'
let value .= v let l:value .= l:v
elseif v =~# 'vw$' elseif l:v =~# 'vw$'
let value .= v let l:value .= l:v
elseif v =~# 'rem$' elseif l:v =~# 'rem$'
let value .= v let l:value .= l:v
elseif v ==# 'auto' elseif l:v ==# 'auto'
let value .= v let l:value .= l:v
elseif v =~# 'p$' elseif l:v =~# 'p$'
let value .= substitute(v, 'p$', '%', '') let l:value .= substitute(l:v, 'p$', '%', '')
elseif v =~# '%$' elseif l:v =~# '%$'
let value .= v let l:value .= l:v
elseif v =~# 'e$' elseif l:v =~# 'e$'
let value .= substitute(v, 'e$', 'em', '') let l:value .= substitute(l:v, 'e$', 'em', '')
elseif v =~# 'x$' elseif l:v =~# 'x$'
let value .= substitute(v, 'x$', 'ex', '') let l:value .= substitute(l:v, 'x$', 'ex', '')
elseif v =~# 're$' elseif l:v =~# 're$'
let value .= substitute(v, 're$', 'rem', '') let l:value .= substitute(l:v, 're$', 'rem', '')
elseif v =~# '\.' elseif l:v =~# '\.'
let value .= v . 'em' let l:value .= l:v . 'em'
elseif v ==# '0' elseif l:v ==# '0'
let value .= '0' let l:value .= '0'
else else
let value .= v . 'px' let l:value .= l:v . 'px'
endif endif
endfor endfor
endfor endfor
endif endif
let tag_name = token let l:tag_name = l:token
if tag_name =~# '.!$' if l:tag_name =~# '.!$'
let tag_name = tag_name[:-2] let l:tag_name = l:tag_name[:-2]
let important = 1 let l:important = 1
else else
let important = 0 let l:important = 0
endif endif
" make default node " make default node
let current = emmet#newNode() let l:current = emmet#newNode()
let current.important = important let l:current.important = l:important
let current.name = tag_name let l:current.name = l:tag_name
" aliases " aliases
if has_key(aliases, tag_name) if has_key(l:aliases, l:tag_name)
let current.name = aliases[tag_name] let l:current.name = l:aliases[l:tag_name]
endif endif
" snippets " snippets
if !empty(snippets) if !empty(l:snippets)
let snippet_name = tag_name let l:snippet_name = l:tag_name
if !has_key(snippets, snippet_name) if !has_key(l:snippets, l:snippet_name)
let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-\)') let l:pat = '^' . join(split(l:tag_name, '\zs'), '\%(\|[^:-]\+-\)')
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
if len(vv) == 0 if len(l:vv) == 0
let vv = filter(sort(keys(snippets)), 'substitute(v:val, ":", "", "g") == snippet_name') let l:vv = filter(sort(keys(l:snippets)), 'substitute(v:val, ":", "", "g") == l:snippet_name')
endif endif
if len(vv) > 0 if len(l:vv) > 0
let snippet_name = vv[0] let l:snippet_name = l:vv[0]
else else
let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-*\)') let l:pat = '^' . join(split(l:tag_name, '\zs'), '\%(\|[^:-]\+-*\)')
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
if len(vv) == 0 if len(l:vv) == 0
let pat = '^' . join(split(tag_name, '\zs'), '[^:]\{-}') let l:pat = '^' . join(split(l:tag_name, '\zs'), '[^:]\{-}')
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
if len(vv) == 0 if len(l:vv) == 0
let pat = '^' . join(split(tag_name, '\zs'), '.\{-}') let l:pat = '^' . join(split(l:tag_name, '\zs'), '.\{-}')
let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat')
endif endif
endif endif
let minl = -1 let l:minl = -1
for vk in vv for l:vk in l:vv
let vvs = snippets[vk] let l:vvs = l:snippets[l:vk]
if minl == -1 || len(vvs) < minl if l:minl == -1 || len(l:vvs) < l:minl
let snippet_name = vk let l:snippet_name = l:vk
let minl = len(vvs) let l:minl = len(l:vvs)
endif endif
endfor endfor
endif endif
endif endif
if has_key(snippets, snippet_name) if has_key(l:snippets, l:snippet_name)
let snippet = snippets[snippet_name] let l:snippet = l:snippets[l:snippet_name]
if use_pipe_for_cursor if l:use_pipe_for_cursor
let snippet = substitute(snippet, '|', '${cursor}', 'g') let l:snippet = substitute(l:snippet, '|', '${cursor}', 'g')
endif endif
let lines = split(snippet, "\n") let l:lines = split(l:snippet, "\n")
call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")') call map(l:lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(l:indent, "\\\\"), "g")')
let current.snippet = join(lines, "\n") let l:current.snippet = join(l:lines, "\n")
let current.name = '' let l:current.name = ''
let current.snippet = substitute(current.snippet, ';', value . ';', '') let l:current.snippet = substitute(l:current.snippet, ';', l:value . ';', '')
if use_pipe_for_cursor && len(value) > 0 if l:use_pipe_for_cursor && len(l:value) > 0
let current.snippet = substitute(current.snippet, '\${cursor}', '', 'g') let l:current.snippet = substitute(l:current.snippet, '\${cursor}', '', 'g')
endif endif
if n < len(tokens) - 1 if l:n < len(l:tokens) - 1
let current.snippet .= "\n" let l:current.snippet .= "\n"
endif endif
endif endif
endif endif
let current.pos = 0 let l:current.pos = 0
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$') let l:lg = matchlist(l:token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$')
if len(lg) == 0 if len(l:lg) == 0
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*)$') let l:lg = matchlist(l:token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*)$')
if len(lg) if len(l:lg)
let [lg[1], lg[2], lg[3]] = ['linear', lg[1], lg[2]] let [l:lg[1], l:lg[2], l:lg[3]] = ['linear', l:lg[1], l:lg[2]]
endif endif
endif endif
if len(lg) if len(l:lg)
let current.name = '' let l: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]) 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(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", lg[2], lg[3]) let l:current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", lg[2], lg[3]) let l:current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", lg[2], lg[3]) let l:current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = printf("background-image:linear-gradient(%s, %s);\n", lg[2], lg[3]) let l:current.snippet = printf("background-image:linear-gradient(%s, %s);\n", l:lg[2], l:lg[3])
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
elseif prefix elseif l:prefix
let snippet = current.snippet let l:snippet = l:current.snippet
let current.snippet = '-webkit-' . snippet . "\n" let l:current.snippet = '-webkit-' . l:snippet . "\n"
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = '-moz-' . snippet . "\n" let l:current.snippet = '-moz-' . l:snippet . "\n"
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = '-o-' . snippet . "\n" let l:current.snippet = '-o-' . l:snippet . "\n"
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = '-ms-' . snippet . "\n" let l:current.snippet = '-ms-' . l:snippet . "\n"
call add(root.child, deepcopy(current)) call add(l:root.child, deepcopy(l:current))
let current.snippet = snippet let l:current.snippet = l:snippet
call add(root.child, current) call add(l:root.child, l:current)
elseif token =~# '^c#\([0-9a-fA-F]\{3}\|[0-9a-fA-F]\{6}\)\(\.[0-9]\+\)\?' elseif l:token =~# '^c#\([0-9a-fA-F]\{3}\|[0-9a-fA-F]\{6}\)\(\.[0-9]\+\)\?'
let cs = split(token, '\.') let l:cs = split(l:token, '\.')
let current.name = '' let l:current.name = ''
let [r,g,b] = [0,0,0] let [l:r,l:g,l:b] = [0,0,0]
if len(cs[0]) == 5 if len(l:cs[0]) == 5
let rgb = matchlist(cs[0], 'c#\(.\)\(.\)\(.\)') let l:rgb = matchlist(l:cs[0], 'c#\(.\)\(.\)\(.\)')
let r = eval('0x'.rgb[1].rgb[1]) let l:r = eval('0x'.l:rgb[1].l:rgb[1])
let g = eval('0x'.rgb[2].rgb[2]) let l:g = eval('0x'.l:rgb[2].l:rgb[2])
let b = eval('0x'.rgb[3].rgb[3]) let l:b = eval('0x'.l:rgb[3].l:rgb[3])
elseif len(cs[0]) == 8 elseif len(l:cs[0]) == 8
let rgb = matchlist(cs[0], 'c#\(..\)\(..\)\(..\)') let l:rgb = matchlist(l:cs[0], 'c#\(..\)\(..\)\(..\)')
let r = eval('0x'.rgb[1]) let l:r = eval('0x'.l:rgb[1])
let g = eval('0x'.rgb[2]) let l:g = eval('0x'.l:rgb[2])
let b = eval('0x'.rgb[3]) let l:b = eval('0x'.l:rgb[3])
endif endif
if len(cs) == 1 if len(l:cs) == 1
let current.snippet = printf('color:rgb(%d, %d, %d);', r, g, b) let l:current.snippet = printf('color:rgb(%d, %d, %d);', l:r, l:g, l:b)
else 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 endif
call add(root.child, current) call add(l:root.child, l:current)
elseif token =~# '^c#' elseif l:token =~# '^c#'
let current.name = '' let l:current.name = ''
let current.snippet = 'color:\${cursor};' let l:current.snippet = 'color:\${cursor};'
call add(root.child, current) call add(l:root.child, l:current)
else else
call add(root.child, current) call add(l:root.child, l:current)
endif endif
endfor endfor
endif endif
return root return l:root
endfunction endfunction
function! emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) abort function! emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) abort
let current = a:current let l:current = a:current
let value = current.value[1:-2] let l:value = l:current.value[1:-2]
let tmp = substitute(value, '\${cursor}', '', 'g') let l:tmp = substitute(l:value, '\${cursor}', '', 'g')
if tmp !~ '.*{[ \t\r\n]*}$' if l:tmp !~ '.*{[ \t\r\n]*}$'
if emmet#useFilter(a:filters, 'fc') if emmet#useFilter(a:filters, 'fc')
let value = substitute(value, '\([^:]\+\):\([^;]*\)', '\1: \2', 'g') let l:value = substitute(l:value, '\([^:]\+\):\([^;]*\)', '\1: \2', 'g')
else else
let value = substitute(value, '\([^:]\+\):\([^;]*\)', '\1:\2', 'g') let l:value = substitute(l:value, '\([^:]\+\):\([^;]*\)', '\1:\2', 'g')
endif endif
if current.important if l:current.important
let value = substitute(value, ';', ' !important;', '') let l:value = substitute(l:value, ';', ' !important;', '')
endif endif
endif endif
return value return l:value
endfunction endfunction
function! emmet#lang#css#imageSize() abort function! emmet#lang#css#imageSize() abort
let img_region = emmet#util#searchRegion('{', '}') let l:img_region = emmet#util#searchRegion('{', '}')
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region) if !emmet#util#regionIsValid(l:img_region) || !emmet#util#cursorInRegion(l:img_region)
return return
endif endif
let content = emmet#util#getContent(img_region) let l:content = emmet#util#getContent(l:img_region)
let fn = matchstr(content, '\<url(\zs[^)]\+\ze)') let l:fn = matchstr(l:content, '\<url(\zs[^)]\+\ze)')
let fn = substitute(fn, '[''" \t]', '', 'g') let l:fn = substitute(l:fn, '[''" \t]', '', 'g')
if fn =~# '^\s*$' if l:fn =~# '^\s*$'
return return
elseif fn !~# '^\(/\|http\)' elseif l:fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let l:fn = simplify(expand('%:h') . '/' . l:fn)
endif endif
let [width, height] = emmet#util#getImageSize(fn) let [l:width, l:height] = emmet#util#getImageSize(l:fn)
if width == -1 && height == -1 if l:width == -1 && l:height == -1
return return
endif endif
let indent = emmet#getIndentation('css') let l:indent = emmet#getIndentation('css')
if content =~# '.*\<width\s*:[^;]*;.*' if l:content =~# '.*\<width\s*:[^;]*;.*'
let content = substitute(content, '\<width\s*:[^;]*;', 'width: ' . width . 'px;', '') let l:content = substitute(l:content, '\<width\s*:[^;]*;', 'width: ' . l:width . 'px;', '')
else else
let content = substitute(content, '}', indent . 'width: ' . width . "px;\n}", '') let l:content = substitute(l:content, '}', l:indent . 'width: ' . l:width . "px;\n}", '')
endif endif
if content =~# '.*\<height\s*:[^;]*;.*' if l:content =~# '.*\<height\s*:[^;]*;.*'
let content = substitute(content, '\<height\s*:[^;]*;', 'height: ' . height . 'px;', '') let l:content = substitute(l:content, '\<height\s*:[^;]*;', 'height: ' . l:height . 'px;', '')
else else
let content = substitute(content, '}', indent . 'height: ' . height . "px;\n}", '') let l:content = substitute(l:content, '}', l:indent . 'height: ' . l:height . "px;\n}", '')
endif endif
call emmet#util#setContent(img_region, content) call emmet#util#setContent(l:img_region, l:content)
endfunction endfunction
function! emmet#lang#css#imageEncode() abort function! emmet#lang#css#imageEncode() abort
let img_region = emmet#util#searchRegion('url(', ')') let l:img_region = emmet#util#searchRegion('url(', ')')
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region) if !emmet#util#regionIsValid(l:img_region) || !emmet#util#cursorInRegion(l:img_region)
return return
endif endif
let content = emmet#util#getContent(img_region) let l:content = emmet#util#getContent(l:img_region)
let fn = matchstr(content, '\<url(\zs[^)]\+\ze)') let l:fn = matchstr(l:content, '\<url(\zs[^)]\+\ze)')
let fn = substitute(fn, '[''" \t]', '', 'g') let l:fn = substitute(l:fn, '[''" \t]', '', 'g')
if fn =~# '^\s*$' if l:fn =~# '^\s*$'
return return
elseif fn !~# '^\(/\|http\)' elseif l:fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let l:fn = simplify(expand('%:h') . '/' . l:fn)
endif endif
let encoded = emmet#util#imageEncodeDecode(fn, 0) let l:encoded = emmet#util#imageEncodeDecode(l:fn, 0)
call emmet#util#setContent(img_region, 'url(' . encoded . ')') call emmet#util#setContent(l:img_region, 'url(' . l:encoded . ')')
endfunction endfunction
function! emmet#lang#css#parseTag(tag) abort function! emmet#lang#css#parseTag(tag) abort
@@ -290,67 +290,67 @@ function! emmet#lang#css#parseTag(tag) abort
endfunction endfunction
function! emmet#lang#css#toggleComment() abort function! emmet#lang#css#toggleComment() abort
let line = getline('.') let l:line = getline('.')
let mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$' let l:mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$'
if line =~# '{\s*$' if l:line =~# '{\s*$'
let block = emmet#util#searchRegion('/\*', '\*/\zs') let l:block = emmet#util#searchRegion('/\*', '\*/\zs')
if emmet#util#regionIsValid(block) if emmet#util#regionIsValid(l:block)
let content = emmet#util#getContent(block) let l:content = emmet#util#getContent(l:block)
let content = substitute(content, '/\*\s\(.*\)\s\*/', '\1', '') let l:content = substitute(l:content, '/\*\s\(.*\)\s\*/', '\1', '')
call emmet#util#setContent(block, content) call emmet#util#setContent(l:block, l:content)
else else
let node = expand('<cword>') let l:node = expand('<cword>')
if len(node) if len(l:node)
exe "normal ciw\<c-r>='/* '.node.' */'\<cr>" exe "normal ciw\<c-r>='/* '.l:node.' */'\<cr>"
endif endif
endif endif
else else
if line =~# mx if l:line =~# l:mx
let space = substitute(matchstr(line, mx), mx, '\1', '') let l:space = substitute(matchstr(l:line, l:mx), l:mx, '\1', '')
let line = substitute(matchstr(line, mx), mx, '\2', '') let l:line = substitute(matchstr(l:line, l:mx), l:mx, '\2', '')
let line = space . substitute(line, '^\s*\|\s*$', '\1', 'g') let l:line = l:space . substitute(l:line, '^\s*\|\s*$', '\1', 'g')
else else
let mx = '^\(\s*\)\(''[^'']*''\|[^'']*\|;\)\s*$' let l:mx = '^\(\s*\)\(''[^'']*''\|[^'']*\|;\)\s*$'
" TODO multi-property " TODO multi-property
"let mx = '^\(\s*\)\(\%(''[^'']*''\|[^'';]\+\)*;\{0,1}\)' "let l:mx = '^\(\s*\)\(\%(''[^'']*''\|[^'';]\+\)*;\{0,1}\)'
let line = substitute(line, mx, '\1/* \2 */', '') let l:line = substitute(l:line, l:mx, '\1/* \2 */', '')
endif endif
call setline('.', line) call setline('.', l:line)
endif endif
endfunction endfunction
function! emmet#lang#css#balanceTag(flag) range abort function! emmet#lang#css#balanceTag(flag) range abort
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let l:curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = emmet#util#getcurpos() let l:curpos = emmet#util#getcurpos()
endif endif
let block = emmet#util#getVisualBlock() let l:block = emmet#util#getVisualBlock()
if !emmet#util#regionIsValid(block) if !emmet#util#regionIsValid(l:block)
if a:flag > 0 if a:flag > 0
let block = emmet#util#searchRegion('^', ';') let l:block = emmet#util#searchRegion('^', ';')
if emmet#util#regionIsValid(block) if emmet#util#regionIsValid(l:block)
call emmet#util#selectRegion(block) call emmet#util#selectRegion(l:block)
return return
endif endif
endif endif
else else
if a:flag > 0 if a:flag > 0
let content = emmet#util#getContent(block) let l:content = emmet#util#getContent(l:block)
if content !~# '^{.*}$' if l:content !~# '^{.*}$'
let block = emmet#util#searchRegion('{', '}') let l:block = emmet#util#searchRegion('{', '}')
if emmet#util#regionIsValid(block) if emmet#util#regionIsValid(l:block)
call emmet#util#selectRegion(block) call emmet#util#selectRegion(l:block)
return return
endif endif
endif endif
else else
let pos = searchpos('.*;', 'nW') let l:pos = searchpos('.*;', 'nW')
if pos[0] != 0 if l:pos[0] != 0
call setpos('.', [0, pos[0], pos[1], 0]) call setpos('.', [0, l:pos[0], l:pos[1], 0])
let block = emmet#util#searchRegion('^', ';') let l:block = emmet#util#searchRegion('^', ';')
if emmet#util#regionIsValid(block) if emmet#util#regionIsValid(l:block)
call emmet#util#selectRegion(block) call emmet#util#selectRegion(l:block)
return return
endif endif
endif endif
@@ -359,7 +359,7 @@ function! emmet#lang#css#balanceTag(flag) range abort
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
silent! exe 'normal! gv' silent! exe 'normal! gv'
else else
call setpos('.', curpos) call setpos('.', l:curpos)
endif endif
endfunction endfunction

View File

@@ -3,24 +3,24 @@ function! emmet#lang#elm#findTokens(str) abort
endfunction endfunction
function! emmet#lang#elm#parseIntoTree(abbr, type) abort function! emmet#lang#elm#parseIntoTree(abbr, type) abort
let tree = emmet#lang#html#parseIntoTree(a:abbr, a:type) let l:tree = emmet#lang#html#parseIntoTree(a:abbr, a:type)
if len(tree.child) < 2 | return tree | endif if len(l:tree.child) < 2 | return l:tree | endif
" Add ',' nodes between root elements. " Add ',' nodes between root elements.
let new_children = [] let l:new_children = []
for child in tree.child[0:-2] for l:child in l:tree.child[0:-2]
let comma = emmet#newNode() let l:comma = emmet#newNode()
let comma.name = ',' let l:comma.name = ','
call add(new_children, child) call add(l:new_children, l:child)
call add(new_children, comma) call add(l:new_children, l:comma)
endfor endfor
call add(new_children, tree.child[-1]) call add(l:new_children, l:tree.child[-1])
let tree.child = new_children let l:tree.child = l:new_children
return tree return l:tree
endfunction endfunction
function! emmet#lang#elm#renderNode(node) 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' \, 'div', 'p', 'hr', 'pre', 'blockquote'
\, 'span', 'a', 'code', 'em', 'strong', 'i', 'b', 'u', 'sub', 'sup', 'br' \, 'span', 'a', 'code', 'em', 'strong', 'i', 'b', 'u', 'sub', 'sup', 'br'
\, 'ol', 'ul', 'li', 'dl', 'dt', 'dd' \, 'ol', 'ul', 'li', 'dl', 'dt', 'dd'
@@ -37,14 +37,14 @@ function! emmet#lang#elm#renderNode(node)
\, 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'wbr' \, 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'wbr'
\, 'details', 'summary', 'menuitem', 'menu'] \, 'details', 'summary', 'menuitem', 'menu']
if index(elm_nodes, a:node) >= 0 if index(l:elm_nodes, a:node) >= 0
return a:node return a:node
endif endif
return 'node "' . a:node . '"' return 'node "' . a:node . '"'
endfunction endfunction
function! emmet#lang#elm#renderParam(param) function! emmet#lang#elm#renderParam(param)
let elm_events = ["onClick", "onDoubleClick" let l:elm_events = ["onClick", "onDoubleClick"
\, "onMouseDown", "onMouseUp" \, "onMouseDown", "onMouseUp"
\, "onMouseEnter", "onMouseLeave" \, "onMouseEnter", "onMouseLeave"
\, "onMouseOver", "onMouseOut" \, "onMouseOver", "onMouseOut"
@@ -52,10 +52,10 @@ function! emmet#lang#elm#renderParam(param)
\, "onBlur", "onFocus" \, "onBlur", "onFocus"
\, "on", "onWithOptions", "Options", "defaultOptions" \, "on", "onWithOptions", "Options", "defaultOptions"
\, "targetValue", "targetChecked", "keyCode"] \, "targetValue", "targetChecked", "keyCode"]
if index(elm_events, a:param) >= 0 if index(l:elm_events, a:param) >= 0
return a:param return a:param
endif 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" \, "type", "type_", "value", "defaultValue", "checked", "placeholder", "selected"
\, "accept", "acceptCharset", "action", "autocomplete", "autofocus" \, "accept", "acceptCharset", "action", "autocomplete", "autofocus"
\, "disabled", "enctype", "formaction", "list", "maxlength", "minlength", "method", "multiple" \, "disabled", "enctype", "formaction", "list", "maxlength", "minlength", "method", "multiple"
@@ -75,7 +75,7 @@ function! emmet#lang#elm#renderParam(param)
\, "challenge", "keytype" \, "challenge", "keytype"
\, "cite", "datetime", "pubdate", "manifest"] \, "cite", "datetime", "pubdate", "manifest"]
if index(elm_attributes, a:param) >= 0 if index(l:elm_attributes, a:param) >= 0
if a:param == 'type' if a:param == 'type'
return 'type_' return 'type_'
endif endif
@@ -85,130 +85,130 @@ function! emmet#lang#elm#renderParam(param)
endfunction endfunction
function! emmet#lang#elm#toString(settings, current, type, inline, filters, itemno, indent) abort function! emmet#lang#elm#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let l:settings = a:settings
let current = a:current let l:current = a:current
let type = a:type let l:type = a:type
let inline = a:inline let l:inline = a:inline
let filters = a:filters let l:filters = a:filters
let itemno = a:itemno let l:itemno = a:itemno
let indent = emmet#getIndentation(type) let l:indent = emmet#getIndentation(l:type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
let str = '' let l:str = ''
" comma between items with *, eg. li*3 " comma between items with *, eg. li*3
if itemno > 0 if l:itemno > 0
let str = ", " let l:str = ", "
endif endif
let current_name = current.name let l:current_name = l:current.name
if dollar_expr if l:dollar_expr
let current_name = substitute(current.name, '\$$', itemno+1, '') let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
endif endif
if len(current.name) > 0 if len(l:current.name) > 0
" inserted root comma nodes " inserted root comma nodes
if current_name == ',' if l:current_name == ','
return "\n, " return "\n, "
endif endif
let str .= emmet#lang#elm#renderNode(current_name) let l:str .= emmet#lang#elm#renderNode(l:current_name)
let tmp = '' let l:tmp = ''
for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
if !has_key(current.attr, attr) if !has_key(l:current.attr, l:attr)
continue continue
endif 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') if type(l:Val) == 2 && l:Val == function('emmet#types#true')
let tmp .= ', ' . attr . ' True' let l:tmp .= ', ' . l:attr . ' True'
else else
if dollar_expr if l:dollar_expr
while Val =~# '\$\([^#{]\|$\)' while l:Val =~# '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
endif endif
let valtmp = substitute(Val, '\${cursor}', '', '') let l:valtmp = substitute(l:Val, '\${cursor}', '', '')
if attr ==# 'id' && len(valtmp) > 0 if l:attr ==# 'id' && len(l:valtmp) > 0
let tmp .=', id "' . Val . '"' let l:tmp .=', id "' . l:Val . '"'
elseif attr ==# 'class' && len(valtmp) > 0 elseif l:attr ==# 'class' && len(l:valtmp) > 0
let tmp .= ', class "' . substitute(Val, '\.', ' ', 'g') . '"' let l:tmp .= ', class "' . substitute(l:Val, '\.', ' ', 'g') . '"'
else else
let tmp .= ', ' . attr . ' "' . Val . '"' let l:tmp .= ', ' . l:attr . ' "' . l:Val . '"'
endif endif
endif endif
endfor endfor
if ! len(tmp) if ! len(l:tmp)
let str .= ' []' let l:str .= ' []'
else else
let tmp = strpart(tmp, 2) let l:tmp = strpart(l:tmp, 2)
let str .= ' [ ' . tmp . ' ]' let l:str .= ' [ ' . l:tmp . ' ]'
endif endif
" No children quit early " 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 "Place cursor in node with no value or children
let str .= ' [${cursor}]' let l:str .= ' [${cursor}]'
return str return l:str
endif endif
let inner = '' let l:inner = ''
" Parent contex text " Parent contex text
if len(current.value) > 0 if len(l:current.value) > 0
let text = current.value[1:-2] let l:text = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
" let str = substitute(str, '\$#', text, 'g') " let l:str = substitute(l:str, '\$#', l:text, 'g')
let inner .= ', text "' . text . '"' let l:inner .= ', text "' . l:text . '"'
endif endif
endif endif
" Has children " Has children
for child in current.child for l:child in l:current.child
if len(child.name) == 0 && len(child.value) > 0 if len(l:child.name) == 0 && len(l:child.value) > 0
" Text node " Text node
let text = child.value[1:-2] let l:text = l:child.value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
endif endif
let inner .= ', text "' . text . '"' let l:inner .= ', text "' . l:text . '"'
else else
" Other nodes " 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 endif
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
let inner = strpart(inner, 2) let l:inner = strpart(l:inner, 2)
let inner = substitute(inner, ' ', '', 'g') let l:inner = substitute(l:inner, ' ', '', 'g')
if ! len(inner) if ! len(l:inner)
let str .= ' []' let l:str .= ' []'
else else
let str .= ' [ ' . inner . ' ]' let l:str .= ' [ ' . l:inner . ' ]'
endif endif
else else
let str = current.value[1:-2] let l:str = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let str = substitute(str, '\${nr}', "\n", 'g') let l:str = substitute(l:str, '\${nr}', "\n", 'g')
let str = substitute(str, '\\\$', '$', 'g') let l:str = substitute(l:str, '\\\$', '$', 'g')
endif endif
endif endif
let str .= "\n" let l:str .= "\n"
return str return l:str
endfunction endfunction
function! emmet#lang#elm#imageEncode() abort function! emmet#lang#elm#imageEncode() abort

View File

@@ -7,251 +7,251 @@ function! emmet#lang#haml#parseIntoTree(abbr, type) abort
endfunction endfunction
function! emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) abort function! emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let l:settings = a:settings
let current = a:current let l:current = a:current
let type = a:type let l:type = a:type
let inline = a:inline let l:inline = a:inline
let filters = a:filters let l:filters = a:filters
let itemno = a:itemno let l:itemno = a:itemno
let indent = emmet#getIndentation(type) let l:indent = emmet#getIndentation(l:type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
let attribute_style = emmet#getResource('haml', 'attribute_style', 'hash') let l:attribute_style = emmet#getResource('haml', 'attribute_style', 'hash')
let str = '' let l:str = ''
let current_name = current.name let l:current_name = l:current.name
if dollar_expr if l:dollar_expr
let current_name = substitute(current.name, '\$$', itemno+1, '') let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
endif endif
if len(current.name) > 0 if len(l:current.name) > 0
let str .= '%' . current_name let l:str .= '%' . l:current_name
let tmp = '' let l:tmp = ''
for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
if !has_key(current.attr, attr) if !has_key(l:current.attr, l:attr)
continue continue
endif endif
let Val = current.attr[attr] let l:Val = l:current.attr[l:attr]
if type(Val) == 2 && Val == function('emmet#types#true') if type(l:Val) == 2 && l:Val == function('emmet#types#true')
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let tmp .= ' :' . attr . ' => true' let l:tmp .= ' :' . l:attr . ' => true'
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let tmp .= attr . '=true' let l:tmp .= l:attr . '=true'
end end
else else
if dollar_expr if l:dollar_expr
while Val =~# '\$\([^#{]\|$\)' while l:Val =~# '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
endif endif
let valtmp = substitute(Val, '\${cursor}', '', '') let l:valtmp = substitute(l:Val, '\${cursor}', '', '')
if attr ==# 'id' && len(valtmp) > 0 if l:attr ==# 'id' && len(l:valtmp) > 0
let str .= '#' . Val let l:str .= '#' . l:Val
elseif attr ==# 'class' && len(valtmp) > 0 elseif l:attr ==# 'class' && len(l:valtmp) > 0
let str .= '.' . substitute(Val, ' ', '.', 'g') let l:str .= '.' . substitute(l:Val, ' ', '.', 'g')
else else
if len(tmp) > 0 if len(l:tmp) > 0
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let tmp .= ',' let l:tmp .= ','
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let tmp .= ' ' let l:tmp .= ' '
endif endif
endif endif
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let tmp .= ' :' . attr . ' => "' . Val . '"' let l:tmp .= ' :' . l:attr . ' => "' . l:Val . '"'
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let tmp .= attr . '="' . Val . '"' let l:tmp .= l:attr . '="' . l:Val . '"'
end end
endif endif
endif endif
endfor endfor
if len(tmp) if len(l:tmp)
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let str .= '{' . tmp . ' }' let l:str .= '{' . l:tmp . ' }'
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let str .= '(' . tmp . ')' let l:str .= '(' . l:tmp . ')'
end end
endif endif
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0 if stridx(','.l:settings.html.empty_elements.',', ','.l:current_name.',') != -1 && len(l:current.value) == 0
let str .= '/' let l:str .= '/'
endif endif
let inner = '' let l:inner = ''
if len(current.value) > 0 if len(l:current.value) > 0
let text = current.value[1:-2] let l:text = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
let str = substitute(str, '\$#', text, 'g') let l:str = substitute(l:str, '\$#', l:text, 'g')
endif endif
let lines = split(text, "\n") let l:lines = split(l:text, "\n")
if len(lines) == 1 if len(l:lines) == 1
let str .= ' ' . text let l:str .= ' ' . l:text
else else
for line in lines for l:line in l:lines
let str .= "\n" . indent . line . ' |' let l:str .= "\n" . l:indent . l:line . ' |'
endfor endfor
endif endif
elseif len(current.child) == 0 elseif len(l:current.child) == 0
let str .= '${cursor}' let l:str .= '${cursor}'
endif endif
if len(current.child) == 1 && len(current.child[0].name) == 0 if len(l:current.child) == 1 && len(l:current.child[0].name) == 0
let text = current.child[0].value[1:-2] let l:text = l:current.child[0].value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
endif endif
let lines = split(text, "\n") let l:lines = split(l:text, "\n")
if len(lines) == 1 if len(l:lines) == 1
let str .= ' ' . text let l:str .= ' ' . l:text
else else
for line in lines for l:line in l:lines
let str .= "\n" . indent . line . ' |' let l:str .= "\n" . l:indent . l:line . ' |'
endfor endfor
endif endif
elseif len(current.child) > 0 elseif len(l:current.child) > 0
for child in current.child for l:child in l:current.child
let inner .= emmet#toString(child, type, inline, filters, itemno, indent) let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
let str .= "\n" . indent . inner let l:str .= "\n" . l:indent . l:inner
endif endif
else else
let str = current.value[1:-2] let l:str = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let str = substitute(str, '\${nr}', "\n", 'g') let l:str = substitute(l:str, '\${nr}', "\n", 'g')
let str = substitute(str, '\\\$', '$', 'g') let l:str = substitute(l:str, '\\\$', '$', 'g')
endif endif
endif endif
let str .= "\n" let l:str .= "\n"
return str return l:str
endfunction endfunction
function! emmet#lang#haml#imageSize() abort function! emmet#lang#haml#imageSize() abort
let line = getline('.') let l:line = getline('.')
let current = emmet#lang#haml#parseTag(line) let l:current = emmet#lang#haml#parseTag(l:line)
if empty(current) || !has_key(current.attr, 'src') if empty(l:current) || !has_key(l:current.attr, 'src')
return return
endif endif
let fn = current.attr.src let l:fn = l:current.attr.src
if fn =~# '^\s*$' if l:fn =~# '^\s*$'
return return
elseif fn !~# '^\(/\|http\)' elseif l:fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let l:fn = simplify(expand('%:h') . '/' . l:fn)
endif endif
let [width, height] = emmet#util#getImageSize(fn) let [l:width, l:height] = emmet#util#getImageSize(l:fn)
if width == -1 && height == -1 if l:width == -1 && l:height == -1
return return
endif endif
let current.attr.width = width let l:current.attr.width = l:width
let current.attr.height = height let l:current.attr.height = l:height
let current.attrs_order += ['width', 'height'] let l:current.attrs_order += ['width', 'height']
let haml = emmet#toString(current, 'haml', 1) let l:haml = emmet#toString(l:current, 'haml', 1)
let haml = substitute(haml, '\${cursor}', '', '') let l:haml = substitute(l:haml, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", '', 'g')) call setline('.', substitute(matchstr(l:line, '^\s*') . l:haml, "\n", '', 'g'))
endfunction endfunction
function! emmet#lang#haml#imageEncode() abort function! emmet#lang#haml#imageEncode() abort
endfunction endfunction
function! emmet#lang#haml#parseTag(tag) abort function! emmet#lang#haml#parseTag(tag) abort
let current = emmet#newNode() let l:current = emmet#newNode()
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)' let l:mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
let match = matchstr(a:tag, mx) let l:match = matchstr(a:tag, l:mx)
let current.name = substitute(match, mx, '\1', '') let l:current.name = substitute(l:match, l:mx, '\1', '')
let attrs = substitute(match, mx, '\2', '') let l:attrs = substitute(l:match, l:mx, '\2', '')
let mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' let l:mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
while len(attrs) > 0 while len(l:attrs) > 0
let match = matchstr(attrs, mx) let l:match = matchstr(l:attrs, l:mx)
if len(match) ==# 0 if len(l:match) ==# 0
break break
endif endif
let attr_match = matchlist(match, mx) let l:attr_match = matchlist(l:match, l:mx)
let name = attr_match[1] let l:name = l:attr_match[1]
let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3]
let current.attr[name] = value let l:current.attr[l:name] = l:value
let current.attrs_order += [name] let l:current.attrs_order += [l:name]
let attrs = attrs[stridx(attrs, match) + len(match):] let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):]
endwhile endwhile
return current return l:current
endfunction endfunction
function! emmet#lang#haml#toggleComment() abort function! emmet#lang#haml#toggleComment() abort
let line = getline('.') let l:line = getline('.')
let space = matchstr(line, '^\s*') let l:space = matchstr(l:line, '^\s*')
if line =~# '^\s*-#' if l:line =~# '^\s*-#'
call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*')) call setline('.', l:space . matchstr(l:line[len(l:space)+2:], '^\s*\zs.*'))
elseif line =~# '^\s*%[a-z]' elseif l:line =~# '^\s*%[a-z]'
call setline('.', space . '-# ' . line[len(space):]) call setline('.', l:space . '-# ' . l:line[len(l:space):])
endif endif
endfunction endfunction
function! emmet#lang#haml#balanceTag(flag) range abort 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 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let l:curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = emmet#util#getcurpos() let l:curpos = emmet#util#getcurpos()
endif endif
let n = curpos[1] let l:n = l:curpos[1]
let ml = len(matchstr(getline(n), '^\s*')) let l:ml = len(matchstr(getline(l:n), '^\s*'))
if a:flag > 0 if a:flag > 0
if a:flag == 1 || !emmet#util#regionIsValid(block) if a:flag == 1 || !emmet#util#regionIsValid(l:block)
let n = line('.') let l:n = line('.')
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze%[a-z]'))
if l > 0 && l < ml if l:l > 0 && l:l < l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
endif endif
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
if l > 0 && l > ml if l:l > 0 && l:l > l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
endif endif
endfunction endfunction
@@ -260,76 +260,76 @@ function! emmet#lang#haml#moveNextPrevItem(flag) abort
endfunction endfunction
function! emmet#lang#haml#moveNextPrev(flag) abort function! emmet#lang#haml#moveNextPrev(flag) abort
let pos = search('""', a:flag ? 'Wb' : 'W') let l:pos = search('""', a:flag ? 'Wb' : 'W')
if pos != 0 if l:pos != 0
silent! normal! l silent! normal! l
startinsert startinsert
endif endif
endfunction endfunction
function! emmet#lang#haml#splitJoinTag() abort function! emmet#lang#haml#splitJoinTag() abort
let n = line('.') let l:n = line('.')
let sml = len(matchstr(getline(n), '^\s*%[a-z]')) let l:sml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
while n > 0 while l:n > 0
if getline(n) =~# '^\s*\ze%[a-z]' if getline(l:n) =~# '^\s*\ze%[a-z]'
if len(matchstr(getline(n), '^\s*%[a-z]')) < sml if len(matchstr(getline(l:n), '^\s*%[a-z]')) < l:sml
break break
endif endif
let line = getline(n) let l:line = getline(l:n)
call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) call setline(l:n, substitute(l:line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', ''))
let sn = n let l:sn = l:n
let n += 1 let l:n += 1
let ml = len(matchstr(getline(n), '^\s*%[a-z]')) let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if len(matchstr(getline(n), '^\s*')) > ml if len(matchstr(getline(l:n), '^\s*')) > l:ml
while n <= line('$') while l:n <= line('$')
let l = len(matchstr(getline(n), '^\s*')) let l:l = len(matchstr(getline(l:n), '^\s*'))
if l <= ml if l:l <= l:ml
break break
endif endif
exe n 'delete' exe l:n 'delete'
endwhile endwhile
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
else else
let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)') let l:tag = matchstr(getline(l:sn), '^\s*%\zs\(\w\+\)')
let spaces = matchstr(getline(sn), '^\s*') let l:spaces = matchstr(getline(l:sn), '^\s*')
let settings = emmet#getSettings() let l:settings = emmet#getSettings()
if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1 if stridx(','.l:settings.html.inline_elements.',', ','.l:tag.',') == -1
call append(sn, spaces . ' ') call append(l:sn, l:spaces . ' ')
call setpos('.', [0, sn+1, 1, 0]) call setpos('.', [0, l:sn+1, 1, 0])
else else
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
endif endif
startinsert! startinsert!
endif endif
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
endfunction endfunction
function! emmet#lang#haml#removeTag() abort function! emmet#lang#haml#removeTag() abort
let n = line('.') let l:n = line('.')
let ml = 0 let l:ml = 0
while n > 0 while l:n > 0
if getline(n) =~# '^\s*\ze[a-z]' if getline(l:n) =~# '^\s*\ze[a-z]'
let ml = len(matchstr(getline(n), '^\s*%[a-z]')) let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
let sn = n let l:sn = l:n
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
if sn == n if l:sn == l:n
exe 'delete' exe 'delete'
else else
exe sn ',' (n-1) 'delete' exe l:sn ',' (l:n-1) 'delete'
endif endif
endfunction endfunction

File diff suppressed because it is too large Load Diff

View File

@@ -7,248 +7,248 @@ function! emmet#lang#jade#parseIntoTree(abbr, type) abort
endfunction endfunction
function! emmet#lang#jade#toString(settings, current, type, inline, filters, itemno, indent) abort function! emmet#lang#jade#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let l:settings = a:settings
let current = a:current let l:current = a:current
let type = a:type let l:type = a:type
let inline = a:inline let l:inline = a:inline
let filters = a:filters let l:filters = a:filters
let itemno = a:itemno let l:itemno = a:itemno
let indent = emmet#getIndentation(type) let l:indent = emmet#getIndentation(l:type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
let attribute_style = emmet#getResource('jade', 'attribute_style', 'hash') let l:attribute_style = emmet#getResource('jade', 'attribute_style', 'hash')
let str = '' let l:str = ''
let current_name = current.name let l:current_name = l:current.name
if dollar_expr if l:dollar_expr
let current_name = substitute(current.name, '\$$', itemno+1, '') let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
endif endif
if len(current.name) > 0 if len(l:current.name) > 0
let str .= '' . current_name let l:str .= '' . l:current_name
let tmp = '' let l:tmp = ''
for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
if !has_key(current.attr, attr) if !has_key(l:current.attr, l:attr)
continue continue
endif endif
let Val = current.attr[attr] let l:Val = l:current.attr[l:attr]
if type(Val) == 2 && Val == function('emmet#types#true') if type(l:Val) == 2 && l:Val == function('emmet#types#true')
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let tmp .= ' ' . attr . ' = true' let l:tmp .= ' ' . l:attr . ' = true'
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let tmp .= attr . '=true' let l:tmp .= l:attr . '=true'
end end
else else
if dollar_expr if l:dollar_expr
while Val =~# '\$\([^#{]\|$\)' while l:Val =~# '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
endif endif
let valtmp = substitute(Val, '\${cursor}', '', '') let l:valtmp = substitute(l:Val, '\${cursor}', '', '')
if attr ==# 'id' && len(valtmp) > 0 if l:attr ==# 'id' && len(l:valtmp) > 0
let str .= '#' . Val let l:str .= '#' . l:Val
elseif attr ==# 'class' && len(valtmp) > 0 elseif l:attr ==# 'class' && len(l:valtmp) > 0
let str .= '.' . substitute(Val, ' ', '.', 'g') let l:str .= '.' . substitute(l:Val, ' ', '.', 'g')
else else
if len(tmp) > 0 if len(l:tmp) > 0
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let tmp .= ', ' let l:tmp .= ', '
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let tmp .= ' ' let l:tmp .= ' '
endif endif
endif endif
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let tmp .= '' . attr . '="' . Val . '"' let l:tmp .= '' . l:attr . '="' . l:Val . '"'
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let tmp .= attr . '="' . Val . '"' let l:tmp .= l:attr . '="' . l:Val . '"'
end end
endif endif
endif endif
endfor endfor
if len(tmp) if len(l:tmp)
if attribute_style ==# 'hash' if l:attribute_style ==# 'hash'
let str .= '(' . tmp . ')' let l:str .= '(' . l:tmp . ')'
elseif attribute_style ==# 'html' elseif l:attribute_style ==# 'html'
let str .= '(' . tmp . ')' let l:str .= '(' . l:tmp . ')'
end end
endif endif
let inner = '' let l:inner = ''
if len(current.value) > 0 if len(l:current.value) > 0
let text = current.value[1:-2] let l:text = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
let str = substitute(str, '\$#', text, 'g') let l:str = substitute(l:str, '\$#', l:text, 'g')
endif endif
let lines = split(text, "\n") let l:lines = split(l:text, "\n")
if len(lines) == 1 if len(l:lines) == 1
let str .= ' ' . text let l:str .= ' ' . l:text
else else
for line in lines for l:line in l:lines
let str .= "\n" . indent . line . ' |' let l:str .= "\n" . l:indent . l:line . ' |'
endfor endfor
endif endif
elseif len(current.child) == 0 elseif len(l:current.child) == 0
let str .= '${cursor}' let l:str .= '${cursor}'
endif endif
if len(current.child) == 1 && len(current.child[0].name) == 0 if len(l:current.child) == 1 && len(l:current.child[0].name) == 0
let text = current.child[0].value[1:-2] let l:text = l:current.child[0].value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
endif endif
let lines = split(text, "\n") let l:lines = split(l:text, "\n")
if len(lines) == 1 if len(l:lines) == 1
let str .= ' ' . text let l:str .= ' ' . l:text
else else
for line in lines for l:line in l:lines
let str .= "\n" . indent . line . ' |' let l:str .= "\n" . l:indent . l:line . ' |'
endfor endfor
endif endif
elseif len(current.child) > 0 elseif len(l:current.child) > 0
for child in current.child for l:child in l:current.child
let inner .= emmet#toString(child, type, inline, filters, itemno, indent) let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
let str .= "\n" . indent . inner let l:str .= "\n" . l:indent . l:inner
endif endif
else else
let str = current.value[1:-2] let l:str = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let str = substitute(str, '\${nr}', "\n", 'g') let l:str = substitute(l:str, '\${nr}', "\n", 'g')
let str = substitute(str, '\\\$', '$', 'g') let l:str = substitute(l:str, '\\\$', '$', 'g')
endif endif
endif endif
let str .= "\n" let l:str .= "\n"
return str return l:str
endfunction endfunction
function! emmet#lang#jade#imageSize() abort function! emmet#lang#jade#imageSize() abort
let line = getline('.') let l:line = getline('.')
let current = emmet#lang#jade#parseTag(line) let l:current = emmet#lang#jade#parseTag(l:line)
if empty(current) || !has_key(current.attr, 'src') if empty(l:current) || !has_key(l:current.attr, 'src')
return return
endif endif
let fn = current.attr.src let l:fn = l:current.attr.src
if fn =~# '^\s*$' if l:fn =~# '^\s*$'
return return
elseif fn !~# '^\(/\|http\)' elseif l:fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let l:fn = simplify(expand('%:h') . '/' . l:fn)
endif endif
let [width, height] = emmet#util#getImageSize(fn) let [l:width, l:height] = emmet#util#getImageSize(l:fn)
if width == -1 && height == -1 if l:width == -1 && l:height == -1
return return
endif endif
let current.attr.width = width let l:current.attr.width = l:width
let current.attr.height = height let l:current.attr.height = l:height
let current.attrs_order += ['width', 'height'] let l:current.attrs_order += ['width', 'height']
let jade = emmet#toString(current, 'jade', 1) let l:jade = emmet#toString(l:current, 'jade', 1)
let jade = substitute(jade, '\${cursor}', '', '') let l:jade = substitute(l:jade, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . jade, "\n", '', 'g')) call setline('.', substitute(matchstr(l:line, '^\s*') . l:jade, "\n", '', 'g'))
endfunction endfunction
function! emmet#lang#jade#imageEncode() abort function! emmet#lang#jade#imageEncode() abort
endfunction endfunction
function! emmet#lang#jade#parseTag(tag) abort function! emmet#lang#jade#parseTag(tag) abort
let current = emmet#newNode() let l:current = emmet#newNode()
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)' let l:mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
let match = matchstr(a:tag, mx) let l:match = matchstr(a:tag, l:mx)
let current.name = substitute(match, mx, '\1', '') let l:current.name = substitute(l:match, l:mx, '\1', '')
let attrs = substitute(match, mx, '\2', '') let l:attrs = substitute(l:match, l:mx, '\2', '')
let mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' let l:mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
while len(attrs) > 0 while len(l:attrs) > 0
let match = matchstr(attrs, mx) let l:match = matchstr(l:attrs, l:mx)
if len(match) ==# 0 if len(l:match) ==# 0
break break
endif endif
let attr_match = matchlist(match, mx) let l:attr_match = matchlist(l:match, l:mx)
let name = attr_match[1] let l:name = l:attr_match[1]
let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3]
let current.attr[name] = value let l:current.attr[l:name] = l:value
let current.attrs_order += [name] let l:current.attrs_order += [l:name]
let attrs = attrs[stridx(attrs, match) + len(match):] let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):]
endwhile endwhile
return current return l:current
endfunction endfunction
function! emmet#lang#jade#toggleComment() abort function! emmet#lang#jade#toggleComment() abort
let line = getline('.') let l:line = getline('.')
let space = matchstr(line, '^\s*') let l:space = matchstr(l:line, '^\s*')
if line =~# '^\s*-#' if l:line =~# '^\s*-#'
call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*')) call setline('.', l:space . matchstr(l:line[len(l:space)+2:], '^\s*\zs.*'))
elseif line =~# '^\s*%[a-z]' elseif l:line =~# '^\s*%[a-z]'
call setline('.', space . '-# ' . line[len(space):]) call setline('.', l:space . '-# ' . l:line[len(l:space):])
endif endif
endfunction endfunction
function! emmet#lang#jade#balanceTag(flag) range abort 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 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let l:curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = emmet#util#getcurpos() let l:curpos = emmet#util#getcurpos()
endif endif
let n = curpos[1] let l:n = l:curpos[1]
let ml = len(matchstr(getline(n), '^\s*')) let l:ml = len(matchstr(getline(l:n), '^\s*'))
if a:flag > 0 if a:flag > 0
if a:flag == 1 || !emmet#util#regionIsValid(block) if a:flag == 1 || !emmet#util#regionIsValid(l:block)
let n = line('.') let l:n = line('.')
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze%[a-z]'))
if l > 0 && l < ml if l:l > 0 && l:l < l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
endif endif
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
if l > 0 && l > ml if l:l > 0 && l:l > l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
endif endif
endfunction endfunction
@@ -257,76 +257,76 @@ function! emmet#lang#jade#moveNextPrevItem(flag) abort
endfunction endfunction
function! emmet#lang#jade#moveNextPrev(flag) abort function! emmet#lang#jade#moveNextPrev(flag) abort
let pos = search('""', a:flag ? 'Wb' : 'W') let l:pos = search('""', a:flag ? 'Wb' : 'W')
if pos != 0 if l:pos != 0
silent! normal! l silent! normal! l
startinsert startinsert
endif endif
endfunction endfunction
function! emmet#lang#jade#splitJoinTag() abort function! emmet#lang#jade#splitJoinTag() abort
let n = line('.') let l:n = line('.')
let sml = len(matchstr(getline(n), '^\s*%[a-z]')) let l:sml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
while n > 0 while l:n > 0
if getline(n) =~# '^\s*\ze%[a-z]' if getline(l:n) =~# '^\s*\ze%[a-z]'
if len(matchstr(getline(n), '^\s*%[a-z]')) < sml if len(matchstr(getline(l:n), '^\s*%[a-z]')) < l:sml
break break
endif endif
let line = getline(n) let l:line = getline(l:n)
call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) call setline(l:n, substitute(l:line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', ''))
let sn = n let l:sn = l:n
let n += 1 let l:n += 1
let ml = len(matchstr(getline(n), '^\s*%[a-z]')) let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if len(matchstr(getline(n), '^\s*')) > ml if len(matchstr(getline(l:n), '^\s*')) > l:ml
while n <= line('$') while l:n <= line('$')
let l = len(matchstr(getline(n), '^\s*')) let l:l = len(matchstr(getline(l:n), '^\s*'))
if l <= ml if l:l <= l:ml
break break
endif endif
exe n 'delete' exe l:n 'delete'
endwhile endwhile
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
else else
let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)') let l:tag = matchstr(getline(l:sn), '^\s*%\zs\(\w\+\)')
let spaces = matchstr(getline(sn), '^\s*') let l:spaces = matchstr(getline(l:sn), '^\s*')
let settings = emmet#getSettings() let l:settings = emmet#getSettings()
if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1 if stridx(','.l:settings.html.inline_elements.',', ','.l:tag.',') == -1
call append(sn, spaces . ' ') call append(l:sn, l:spaces . ' ')
call setpos('.', [0, sn+1, 1, 0]) call setpos('.', [0, l:sn+1, 1, 0])
else else
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
endif endif
startinsert! startinsert!
endif endif
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
endfunction endfunction
function! emmet#lang#jade#removeTag() abort function! emmet#lang#jade#removeTag() abort
let n = line('.') let l:n = line('.')
let ml = 0 let l:ml = 0
while n > 0 while l:n > 0
if getline(n) =~# '^\s*\ze[a-z]' if getline(l:n) =~# '^\s*\ze[a-z]'
let ml = len(matchstr(getline(n), '^\s*%[a-z]')) let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]'))
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
let sn = n let l:sn = l:n
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*%[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
if sn == n if l:sn == l:n
exe 'delete' exe 'delete'
else else
exe sn ',' (n-1) 'delete' exe l:sn ',' (l:n-1) 'delete'
endif endif
endfunction endfunction

View File

@@ -7,59 +7,59 @@ function! emmet#lang#sass#parseIntoTree(abbr, type) abort
endfunction endfunction
function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) abort function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let l:settings = a:settings
let current = a:current let l:current = a:current
let type = a:type let l:type = a:type
let inline = a:inline let l:inline = a:inline
let filters = a:filters let l:filters = a:filters
let itemno = a:itemno let l:itemno = a:itemno
let indent = a:indent let l:indent = a:indent
let str = '' let l:str = ''
let current_name = current.name let l:current_name = l:current.name
let current_name = substitute(current.name, '\$$', itemno+1, '') let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
if len(current.name) > 0 if len(l:current.name) > 0
let str .= current_name let l:str .= l:current_name
let tmp = '' let l:tmp = ''
for attr in keys(current.attr) for l:attr in keys(l:current.attr)
let val = current.attr[attr] let l:val = l:current.attr[l:attr]
while val =~# '\$\([^#{]\|$\)' while l:val =~# '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:val = substitute(l:val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
if attr ==# 'id' if l:attr ==# 'id'
let str .= '#' . val let l:str .= '#' . l:val
elseif attr ==# 'class' elseif l:attr ==# 'class'
let str .= '.' . val let l:str .= '.' . l:val
else else
let tmp .= attr . ': ' . val let l:tmp .= l:attr . ': ' . l:val
endif endif
endfor endfor
if len(tmp) > 0 if len(l:tmp) > 0
let str .= "\n" let l:str .= "\n"
for line in split(tmp, "\n") for l:line in split(l:tmp, "\n")
let str .= indent . line . "\n" let l:str .= l:indent . l:line . "\n"
endfor endfor
else else
let str .= "\n" let l:str .= "\n"
endif endif
let inner = '' let l:inner = ''
for child in current.child for l:child in l:current.child
let tmp = emmet#toString(child, type, inline, filters, itemno, indent) let l:tmp = emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
let tmp = substitute(tmp, "\n", "\n" . escape(indent, '\'), 'g') let l:tmp = substitute(l:tmp, "\n", "\n" . escape(l:indent, '\'), 'g')
let tmp = substitute(tmp, "\n" . escape(indent, '\') . '$', '${cursor}\n', 'g') let l:tmp = substitute(l:tmp, "\n" . escape(l:indent, '\') . '$', '${cursor}\n', 'g')
let inner .= tmp let l:inner .= l:tmp
endfor endfor
if len(inner) > 0 if len(l:inner) > 0
let str .= indent . inner let l:str .= l:indent . l:inner
endif endif
else else
let text = emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) let l:text = emmet#lang#css#toString(l:settings, l:current, l:type, l:inline, l:filters, l:itemno, l:indent)
let text = substitute(text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g') let l:text = substitute(l:text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g')
return text return l:text
endif endif
return str return l:str
endfunction endfunction
function! emmet#lang#sass#imageSize() abort function! emmet#lang#sass#imageSize() abort
@@ -75,67 +75,67 @@ function! emmet#lang#sass#toggleComment() abort
endfunction endfunction
function! emmet#lang#sass#balanceTag(flag) range abort 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 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let l:curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = emmet#util#getcurpos() let l:curpos = emmet#util#getcurpos()
endif endif
let n = curpos[1] let l:n = l:curpos[1]
let ml = len(matchstr(getline(n), '^\s*')) let l:ml = len(matchstr(getline(l:n), '^\s*'))
if a:flag > 0 if a:flag > 0
if a:flag == 1 || !emmet#util#regionIsValid(block) if a:flag == 1 || !emmet#util#regionIsValid(l:block)
let n = line('.') let l:n = line('.')
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
if l > 0 && l < ml if l:l > 0 && l:l < l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
endif endif
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
if l > 0 && l > ml if l:l > 0 && l:l > l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
endif endif
endfunction endfunction
@@ -144,10 +144,10 @@ function! emmet#lang#sass#moveNextPrevItem(flag) abort
endfunction endfunction
function! emmet#lang#sass#moveNextPrev(flag) abort function! emmet#lang#sass#moveNextPrev(flag) abort
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') let l:pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
if pos == 2 if l:pos == 2
startinsert! startinsert!
elseif pos != 0 elseif l:pos != 0
silent! normal! l silent! normal! l
startinsert startinsert
endif endif

View File

@@ -11,53 +11,53 @@ function! emmet#lang#scss#parseIntoTree(abbr, type) abort
endfunction endfunction
function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) abort function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let l:settings = a:settings
let current = a:current let l:current = a:current
let type = a:type let l:type = a:type
let inline = a:inline let l:inline = a:inline
let filters = a:filters let l:filters = a:filters
let itemno = a:itemno let l:itemno = a:itemno
let indent = a:indent let l:indent = a:indent
let str = '' let l:str = ''
let current_name = substitute(current.name, '\$$', itemno+1, '') let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
if len(current.name) > 0 if len(l:current.name) > 0
let str .= current_name let l:str .= l:current_name
let tmp = '' let l:tmp = ''
for attr in keys(current.attr) for l:attr in keys(l:current.attr)
let val = current.attr[attr] let l:val = l:current.attr[l:attr]
while val =~# '\$\([^#{]\|$\)' while l:val =~# '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:val = substitute(l:val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
if attr ==# 'id' if l:attr ==# 'id'
let str .= '#' . val let l:str .= '#' . l:val
elseif attr ==# 'class' elseif l:attr ==# 'class'
let str .= '.' . val let l:str .= '.' . l:val
else else
let tmp .= attr . ': ' . val . ';' let l:tmp .= l:attr . ': ' . l:val . ';'
endif endif
endfor endfor
if len(tmp) > 0 if len(l:tmp) > 0
let str .= " {\n" let l:str .= " {\n"
for line in split(tmp, "\n") for l:line in split(l:tmp, "\n")
let str .= indent . line . "\n" let l:str .= l:indent . l:line . "\n"
endfor endfor
else else
let str .= " {\n" let l:str .= " {\n"
endif endif
let inner = '' let l:inner = ''
for child in current.child for l:child in l:current.child
let inner .= emmet#toString(child, type, inline, filters, itemno) let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno)
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
let str .= indent . inner . "${cursor}\n}\n" let l:str .= l:indent . l:inner . "${cursor}\n}\n"
else 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 endif
return str return l:str
endfunction endfunction
function! emmet#lang#scss#imageSize() abort function! emmet#lang#scss#imageSize() abort
@@ -78,33 +78,33 @@ endfunction
function! emmet#lang#scss#balanceTag(flag) range abort function! emmet#lang#scss#balanceTag(flag) range abort
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let l:curpos = [0, line("'<"), col("'<"), 0]
call setpos('.', curpos) call setpos('.', l:curpos)
else else
let curpos = emmet#util#getcurpos() let l:curpos = emmet#util#getcurpos()
endif endif
if a:flag < 0 if a:flag < 0
let ret = searchpair('}', '', '.\zs{') let l:ret = searchpair('}', '', '.\zs{')
else else
let ret = searchpair('{', '', '}', 'bW') let l:ret = searchpair('{', '', '}', 'bW')
endif endif
if ret > 0 if l:ret > 0
let pos1 = emmet#util#getcurpos()[1:2] let l:pos1 = emmet#util#getcurpos()[1:2]
if a:flag < 0 if a:flag < 0
let pos2 = searchpairpos('{', '', '}') let l:pos2 = searchpairpos('{', '', '}')
else else
let pos2 = searchpairpos('{', '', '}') let l:pos2 = searchpairpos('{', '', '}')
endif endif
let block = [pos1, pos2] let l:block = [l:pos1, l:pos2]
if emmet#util#regionIsValid(block) if emmet#util#regionIsValid(l:block)
call emmet#util#selectRegion(block) call emmet#util#selectRegion(l:block)
return return
endif endif
endif endif
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
silent! exe 'normal! gv' silent! exe 'normal! gv'
else else
call setpos('.', curpos) call setpos('.', l:curpos)
endif endif
endfunction endfunction

View File

@@ -7,210 +7,210 @@ function! emmet#lang#slim#parseIntoTree(abbr, type) abort
endfunction endfunction
function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) abort function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) abort
let current = a:current let l:current = a:current
let type = a:type let l:type = a:type
let inline = a:inline let l:inline = a:inline
let filters = a:filters let l:filters = a:filters
let itemno = a:itemno let l:itemno = a:itemno
let indent = emmet#getIndentation(type) let l:indent = emmet#getIndentation(l:type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1)
let str = '' let l:str = ''
let current_name = current.name let l:current_name = l:current.name
if dollar_expr if l:dollar_expr
let current_name = substitute(current.name, '\$$', itemno+1, '') let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '')
endif endif
if len(current.name) > 0 if len(l:current.name) > 0
let str .= current_name let l:str .= l:current_name
for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr))
if !has_key(current.attr, attr) if !has_key(l:current.attr, l:attr)
continue continue
endif endif
let Val = current.attr[attr] let l:Val = l:current.attr[l:attr]
if type(Val) == 2 && Val == function('emmet#types#true') if type(l:Val) == 2 && l:Val == function('emmet#types#true')
let str .= ' ' . attr . '=true' let l:str .= ' ' . l:attr . '=true'
else else
if dollar_expr if l:dollar_expr
while Val =~# '\$\([^#{]\|$\)' while l:Val =~# '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
endwhile endwhile
endif endif
let attr = substitute(attr, '\$$', itemno+1, '') let l:attr = substitute(l:attr, '\$$', l:itemno+1, '')
let str .= ' ' . attr . '="' . Val . '"' let l:str .= ' ' . l:attr . '="' . l:Val . '"'
endif endif
endfor endfor
let inner = '' let l:inner = ''
if len(current.value) > 0 if len(l:current.value) > 0
let str .= "\n" let l:str .= "\n"
let text = current.value[1:-2] let l:text = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
let str = substitute(str, '\$#', text, 'g') let l:str = substitute(l:str, '\$#', l:text, 'g')
endif endif
for line in split(text, "\n") for l:line in split(l:text, "\n")
let str .= indent . '| ' . line . "\n" let l:str .= l:indent . '| ' . l:line . "\n"
endfor endfor
elseif len(current.child) == 0 elseif len(l:current.child) == 0
let str .= '${cursor}' let l:str .= '${cursor}'
endif endif
if len(current.child) == 1 && len(current.child[0].name) == 0 if len(l:current.child) == 1 && len(l:current.child[0].name) == 0
let str .= "\n" let l:str .= "\n"
let text = current.child[0].value[1:-2] let l:text = l:current.child[0].value[1:-2]
if dollar_expr if l:dollar_expr
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:text = substitute(l:text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let text = substitute(text, '\${nr}', "\n", 'g') let l:text = substitute(l:text, '\${nr}', "\n", 'g')
let text = substitute(text, '\\\$', '$', 'g') let l:text = substitute(l:text, '\\\$', '$', 'g')
endif endif
for line in split(text, "\n") for l:line in split(l:text, "\n")
let str .= indent . '| ' . line . "\n" let l:str .= l:indent . '| ' . l:line . "\n"
endfor endfor
elseif len(current.child) > 0 elseif len(l:current.child) > 0
for child in current.child for l:child in l:current.child
let inner .= emmet#toString(child, type, inline, filters, itemno, indent) let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent)
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g')
let str .= "\n" . indent . inner let l:str .= "\n" . l:indent . l:inner
endif endif
else else
let str = current.value[1:-2] let l:str = l:current.value[1:-2]
if dollar_expr if l:dollar_expr
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let l:str = substitute(l:str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g')
let str = substitute(str, '\${nr}', "\n", 'g') let l:str = substitute(l:str, '\${nr}', "\n", 'g')
let str = substitute(str, '\\\$', '$', 'g') let l:str = substitute(l:str, '\\\$', '$', 'g')
endif endif
endif endif
if str !~# "\n$" if l:str !~# "\n$"
let str .= "\n" let l:str .= "\n"
endif endif
return str return l:str
endfunction endfunction
function! emmet#lang#slim#imageSize() abort function! emmet#lang#slim#imageSize() abort
let line = getline('.') let l:line = getline('.')
let current = emmet#lang#slim#parseTag(line) let l:current = emmet#lang#slim#parseTag(l:line)
if empty(current) || !has_key(current.attr, 'src') if empty(l:current) || !has_key(l:current.attr, 'src')
return return
endif endif
let fn = current.attr.src let l:fn = l:current.attr.src
if fn =~# '^\s*$' if l:fn =~# '^\s*$'
return return
elseif fn !~# '^\(/\|http\)' elseif l:fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let l:fn = simplify(expand('%:h') . '/' . l:fn)
endif endif
let [width, height] = emmet#util#getImageSize(fn) let [l:width, l:height] = emmet#util#getImageSize(l:fn)
if width == -1 && height == -1 if l:width == -1 && l:height == -1
return return
endif endif
let current.attr.width = width let l:current.attr.width = l:width
let current.attr.height = height let l:current.attr.height = l:height
let current.attrs_order += ['width', 'height'] let l:current.attrs_order += ['width', 'height']
let slim = emmet#toString(current, 'slim', 1) let l:slim = emmet#toString(l:current, 'slim', 1)
let slim = substitute(slim, '\${cursor}', '', '') let l:slim = substitute(l:slim, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . slim, "\n", '', 'g')) call setline('.', substitute(matchstr(l:line, '^\s*') . l:slim, "\n", '', 'g'))
endfunction endfunction
function! emmet#lang#slim#imageEncode() abort function! emmet#lang#slim#imageEncode() abort
endfunction endfunction
function! emmet#lang#slim#parseTag(tag) abort function! emmet#lang#slim#parseTag(tag) abort
let current = emmet#newNode() let l:current = emmet#newNode()
let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)' let l:mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)'
let match = matchstr(a:tag, mx) let l:match = matchstr(a:tag, l:mx)
let current.name = substitute(match, mx, '\1', '') let l:current.name = substitute(l:match, l:mx, '\1', '')
let attrs = substitute(match, mx, '\2', '') let l:attrs = substitute(l:match, l:mx, '\2', '')
let mx = '\([a-zA-Z0-9]\+\)=\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' let l:mx = '\([a-zA-Z0-9]\+\)=\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
while len(attrs) > 0 while len(l:attrs) > 0
let match = matchstr(attrs, mx) let l:match = matchstr(l:attrs, l:mx)
if len(match) == 0 if len(l:match) == 0
break break
endif endif
let attr_match = matchlist(match, mx) let l:attr_match = matchlist(l:match, l:mx)
let name = attr_match[1] let l:name = l:attr_match[1]
let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3]
let current.attr[name] = value let l:current.attr[l:name] = l:value
let current.attrs_order += [name] let l:current.attrs_order += [l:name]
let attrs = attrs[stridx(attrs, match) + len(match):] let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):]
endwhile endwhile
return current return l:current
endfunction endfunction
function! emmet#lang#slim#toggleComment() abort function! emmet#lang#slim#toggleComment() abort
let line = getline('.') let l:line = getline('.')
let space = matchstr(line, '^\s*') let l:space = matchstr(l:line, '^\s*')
if line =~# '^\s*/' if l:line =~# '^\s*/'
call setline('.', space . line[len(space)+1:]) call setline('.', l:space . l:line[len(l:space)+1:])
elseif line =~# '^\s*[a-z]' elseif l:line =~# '^\s*[a-z]'
call setline('.', space . '/' . line[len(space):]) call setline('.', l:space . '/' . l:line[len(l:space):])
endif endif
endfunction endfunction
function! emmet#lang#slim#balanceTag(flag) range abort 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 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let l:curpos = [0, line("'<"), col("'<"), 0]
else else
let curpos = emmet#util#getcurpos() let l:curpos = emmet#util#getcurpos()
endif endif
let n = curpos[1] let l:n = l:curpos[1]
let ml = len(matchstr(getline(n), '^\s*')) let l:ml = len(matchstr(getline(l:n), '^\s*'))
if a:flag > 0 if a:flag > 0
if a:flag == 1 || !emmet#util#regionIsValid(block) if a:flag == 1 || !emmet#util#regionIsValid(l:block)
let n = line('.') let l:n = line('.')
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
if l > 0 && l < ml if l:l > 0 && l:l < l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
endif endif
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
else else
while n > 0 while l:n > 0
let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]'))
if l > 0 && l > ml if l:l > 0 && l:l > l:ml
let ml = l let l:ml = l:l
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
let sn = n let l:sn = l:n
if n == 0 if l:n == 0
let ml = 0 let l:ml = 0
endif endif
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
call setpos('.', [0, n, 1, 0]) call setpos('.', [0, l:n, 1, 0])
normal! V normal! V
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
endif endif
endfunction endfunction
@@ -219,64 +219,64 @@ function! emmet#lang#slim#moveNextPrevItem(flag) abort
endfunction endfunction
function! emmet#lang#slim#moveNextPrev(flag) abort function! emmet#lang#slim#moveNextPrev(flag) abort
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') let l:pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
if pos == 2 if l:pos == 2
startinsert! startinsert!
elseif pos != 0 elseif l:pos != 0
silent! normal! l silent! normal! l
startinsert startinsert
endif endif
endfunction endfunction
function! emmet#lang#slim#splitJoinTag() abort function! emmet#lang#slim#splitJoinTag() abort
let n = line('.') let l:n = line('.')
while n > 0 while l:n > 0
if getline(n) =~# '^\s*\ze[a-z]' if getline(l:n) =~# '^\s*\ze[a-z]'
let sn = n let l:sn = l:n
let n += 1 let l:n += 1
if getline(n) =~# '^\s*|' if getline(l:n) =~# '^\s*|'
while n <= line('$') while l:n <= line('$')
if getline(n) !~# '^\s*|' if getline(l:n) !~# '^\s*|'
break break
endif endif
exe n 'delete' exe l:n 'delete'
endwhile endwhile
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, l:sn, 1, 0])
else else
let spaces = matchstr(getline(sn), '^\s*') let l:spaces = matchstr(getline(l:sn), '^\s*')
call append(sn, spaces . ' | ') call append(l:sn, l:spaces . ' | ')
call setpos('.', [0, sn+1, 1, 0]) call setpos('.', [0, l:sn+1, 1, 0])
startinsert! startinsert!
endif endif
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
endfunction endfunction
function! emmet#lang#slim#removeTag() abort function! emmet#lang#slim#removeTag() abort
let n = line('.') let l:n = line('.')
let ml = 0 let l:ml = 0
while n > 0 while l:n > 0
if getline(n) =~# '^\s*\ze[a-z]' if getline(l:n) =~# '^\s*\ze[a-z]'
let ml = len(matchstr(getline(n), '^\s*[a-z]')) let l:ml = len(matchstr(getline(l:n), '^\s*[a-z]'))
break break
endif endif
let n -= 1 let l:n -= 1
endwhile endwhile
let sn = n let l:sn = l:n
while n < line('$') while l:n < line('$')
let l = len(matchstr(getline(n), '^\s*[a-z]')) let l:l = len(matchstr(getline(l:n), '^\s*[a-z]'))
if l > 0 && l <= ml if l:l > 0 && l:l <= l:ml
let n -= 1 let l:n -= 1
break break
endif endif
let n += 1 let l:n += 1
endwhile endwhile
if sn == n if l:sn == l:n
exe 'delete' exe 'delete'
else else
exe sn ',' (n-1) 'delete' exe l:sn ',' (l:n-1) 'delete'
endif endif
endfunction endfunction

View File

@@ -1,9 +1,9 @@
function! emmet#lorem#en#expand(command) abort function! emmet#lorem#en#expand(command) abort
let wcount = matchstr(a:command, '\(\d*\)$') let l:wcount = matchstr(a:command, '\(\d*\)$')
let wcount = wcount > 0 ? wcount : 30 let l:wcount = l:wcount > 0 ? l:wcount : 30
let common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit'] let l:common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit']
let words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet', let l:words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
\ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi', \ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
\ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi', \ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
\ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos', \ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
@@ -32,34 +32,34 @@ function! emmet#lorem#en#expand(command) abort
\ 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique', \ 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique',
\ 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere', \ 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere',
\ 'maxime', 'corrupti'] \ 'maxime', 'corrupti']
let ret = [] let l:ret = []
let sentence = 0 let l:sentence = 0
for i in range(wcount) for l:i in range(l:wcount)
let arr = common let l:arr = l:common
if sentence > 0 if l:sentence > 0
let arr += words let l:arr += l:words
endif endif
let r = emmet#util#rand() let l:r = emmet#util#rand()
let word = arr[r % len(arr)] let l:word = l:arr[l:r % len(l:arr)]
if sentence == 0 if l:sentence == 0
let word = substitute(word, '^.', '\U&', '') let l:word = substitute(l:word, '^.', '\U&', '')
endif endif
let sentence += 1 let l:sentence += 1
call add(ret, word) call add(l:ret, l:word)
if (sentence > 5 && emmet#util#rand() < 10000) || i == wcount - 1 if (l:sentence > 5 && emmet#util#rand() < 10000) || l:i == l:wcount - 1
if i == wcount - 1 if l:i == l:wcount - 1
let endc = '?!...'[emmet#util#rand() % 5] let l:endc = '?!...'[emmet#util#rand() % 5]
call add(ret, endc) call add(l:ret, l:endc)
else else
let endc = '?!,...'[emmet#util#rand() % 6] let l:endc = '?!,...'[emmet#util#rand() % 6]
call add(ret, endc . ' ') call add(l:ret, l:endc . ' ')
endif endif
if endc !=# ',' if l:endc !=# ','
let sentence = 0 let l:sentence = 0
endif endif
else else
call add(ret, ' ') call add(l:ret, ' ')
endif endif
endfor endfor
return join(ret, '') return join(l:ret, '')
endfunction endfunction

View File

@@ -1,27 +1,27 @@
scriptencoding utf-8 scriptencoding utf-8
function! emmet#lorem#ja#expand(command) abort function! emmet#lorem#ja#expand(command) abort
let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '') let l:wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '')
let wcount = wcount > 0 ? wcount : 30 let l:wcount = l:wcount > 0 ? l:wcount : 30
let url = "http://www.aozora.gr.jp/cards/000081/files/470_15407.html" let l:url = "http://www.aozora.gr.jp/cards/000081/files/470_15407.html"
let content = emmet#util#cache(url) let l:content = emmet#util#cache(l:url)
if len(content) == 0 if len(l:content) == 0
let content = emmet#util#getContentFromURL(url) let l:content = emmet#util#getContentFromURL(l:url)
let content = matchstr(content, '<div[^>]*>\zs.\{-}</div>') let l:content = matchstr(l:content, '<div[^>]*>\zs.\{-}</div>')
let content = substitute(content, '[ \r]', '', 'g') let l:content = substitute(l:content, '[ \r]', '', 'g')
let content = substitute(content, '<br[^>]*>', "\n", 'g') let l:content = substitute(l:content, '<br[^>]*>', "\n", 'g')
let content = substitute(content, '<[^>]\+>', '', 'g') let l:content = substitute(l:content, '<[^>]\+>', '', 'g')
let content = join(filter(split(content, "\n"), 'len(v:val)>0'), "\n") let l:content = join(filter(split(l:content, "\n"), 'len(v:val)>0'), "\n")
call emmet#util#cache(url, content) call emmet#util#cache(l:url, l:content)
endif endif
let content = substitute(content, "、\n", "、", "g") let l:content = substitute(l:content, "、\n", "、", "g")
let clines = split(content, '\n') let l:clines = split(l:content, '\n')
let lines = filter(clines, 'len(substitute(v:val,".",".","g"))<=wcount') let l:lines = filter(l:clines, 'len(substitute(v:val,".",".","g"))<=l:wcount')
if len(lines) == 0 if len(l:lines) == 0
let lines = clines let l:lines = l:clines
endif endif
let r = emmet#util#rand() let l:r = emmet#util#rand()
return lines[r % len(lines)] return l:lines[l:r % len(l:lines)]
endfunction endfunction

View File

@@ -12,10 +12,10 @@
" begin::end " begin::end
" -------------------- " --------------------
function! emmet#util#deleteContent(region) abort function! emmet#util#deleteContent(region) abort
let lines = getline(a:region[0][0], a:region[1][0]) let l:lines = getline(a:region[0][0], a:region[1][0])
call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
silent! exe 'delete '.(a:region[1][0] - a:region[0][0]) silent! exe 'delete '.(a:region[1][0] - a:region[0][0])
call setline(line('.'), lines[0][:a:region[0][1]-2] . lines[-1][a:region[1][1]]) call setline(line('.'), l:lines[0][:a:region[0][1]-2] . l:lines[-1][a:region[1][1]])
endfunction endfunction
" change_content : change content in region " change_content : change content in region
@@ -37,36 +37,36 @@ endfunction
" baz:end " baz:end
" -------------------- " --------------------
function! emmet#util#setContent(region, content) abort function! emmet#util#setContent(region, content) abort
let newlines = split(a:content, '\n', 1) let l:newlines = split(a:content, '\n', 1)
let oldlines = getline(a:region[0][0], a:region[1][0]) let l:oldlines = getline(a:region[0][0], a:region[1][0])
call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
silent! exe 'delete '.(a:region[1][0] - a:region[0][0]) silent! exe 'delete '.(a:region[1][0] - a:region[0][0])
if len(newlines) == 0 if len(l:newlines) == 0
let tmp = '' let l:tmp = ''
if a:region[0][1] > 1 if a:region[0][1] > 1
let tmp = oldlines[0][:a:region[0][1]-2] let l:tmp = l:oldlines[0][:a:region[0][1]-2]
endif endif
if a:region[1][1] >= 1 if a:region[1][1] >= 1
let tmp .= oldlines[-1][a:region[1][1]:] let l:tmp .= l:oldlines[-1][a:region[1][1]:]
endif endif
call setline(line('.'), tmp) call setline(line('.'), l:tmp)
elseif len(newlines) == 1 elseif len(l:newlines) == 1
if a:region[0][1] > 1 if a:region[0][1] > 1
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0] let l:newlines[0] = l:oldlines[0][:a:region[0][1]-2] . l:newlines[0]
endif endif
if a:region[1][1] >= 1 if a:region[1][1] >= 1
let newlines[0] .= oldlines[-1][a:region[1][1]:] let l:newlines[0] .= l:oldlines[-1][a:region[1][1]:]
endif endif
call setline(line('.'), newlines[0]) call setline(line('.'), l:newlines[0])
else else
if a:region[0][1] > 1 if a:region[0][1] > 1
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0] let l:newlines[0] = l:oldlines[0][:a:region[0][1]-2] . l:newlines[0]
endif endif
if a:region[1][1] >= 1 if a:region[1][1] >= 1
let newlines[-1] .= oldlines[-1][a:region[1][1]:] let l:newlines[-1] .= l:oldlines[-1][a:region[1][1]:]
endif endif
call setline(line('.'), newlines[0]) call setline(line('.'), l:newlines[0])
call append(line('.'), newlines[1:]) call append(line('.'), l:newlines[1:])
endif endif
endfunction endfunction
@@ -93,8 +93,8 @@ endfunction
" this function return 0 or 1 " this function return 0 or 1
function! emmet#util#cursorInRegion(region) abort function! emmet#util#cursorInRegion(region) abort
if !emmet#util#regionIsValid(a:region) | return 0 | endif if !emmet#util#regionIsValid(a:region) | return 0 | endif
let cur = emmet#util#getcurpos()[1:2] let l:cur = emmet#util#getcurpos()[1:2]
return emmet#util#pointInRegion(cur, a:region) return emmet#util#pointInRegion(l:cur, a:region)
endfunction endfunction
" region_is_valid : check region is valid " region_is_valid : check region is valid
@@ -107,11 +107,11 @@ endfunction
" search_region : make region from pattern which is composing start/end " search_region : make region from pattern which is composing start/end
" this function return array of position " this function return array of position
function! emmet#util#searchRegion(start, end) abort function! emmet#util#searchRegion(start, end) abort
let b = searchpairpos(a:start, '', a:end, 'bcnW') let l:b = searchpairpos(a:start, '', a:end, 'bcnW')
if b == [0, 0] if l:b == [0, 0]
return [searchpairpos(a:start, '', a:end, 'bnW'), searchpairpos(a:start, '\%#', a:end, 'nW')] return [searchpairpos(a:start, '', a:end, 'bnW'), searchpairpos(a:start, '\%#', a:end, 'nW')]
else else
return [b, searchpairpos(a:start, '', a:end. '', 'nW')] return [l:b, searchpairpos(a:start, '', a:end. '', 'nW')]
endif endif
endfunction endfunction
@@ -121,14 +121,14 @@ function! emmet#util#getContent(region) abort
if !emmet#util#regionIsValid(a:region) if !emmet#util#regionIsValid(a:region)
return '' return ''
endif endif
let lines = getline(a:region[0][0], a:region[1][0]) let l:lines = getline(a:region[0][0], a:region[1][0])
if a:region[0][0] == a:region[1][0] if a:region[0][0] == a:region[1][0]
let lines[0] = lines[0][a:region[0][1]-1:a:region[1][1]-1] let l:lines[0] = l:lines[0][a:region[0][1]-1:a:region[1][1]-1]
else else
let lines[0] = lines[0][a:region[0][1]-1:] let l:lines[0] = l:lines[0][a:region[0][1]-1:]
let lines[-1] = lines[-1][:a:region[1][1]-1] let l:lines[-1] = l:lines[-1][:a:region[1][1]-1]
endif endif
return join(lines, "\n") return join(l:lines, "\n")
endfunction endfunction
" region_in_region : check region is in the region " region_in_region : check region is in the region
@@ -150,145 +150,145 @@ endfunction
" html utils " html utils
"============================================================================== "==============================================================================
function! emmet#util#getContentFromURL(url) abort function! emmet#util#getContentFromURL(url) abort
let res = system(printf('%s -i %s', g:emmet_curl_command, shellescape(substitute(a:url, '#.*', '', '')))) let l:res = system(printf('%s -i %s', g:emmet_curl_command, shellescape(substitute(a:url, '#.*', '', ''))))
while res =~# '^HTTP/1.\d 3' || res =~# '^HTTP/1\.\d 200 Connection established' || res =~# '^HTTP/1\.\d 100 Continue' while l:res =~# '^HTTP/1.\d 3' || l:res =~# '^HTTP/1\.\d 200 Connection established' || l:res =~# '^HTTP/1\.\d 100 Continue'
let pos = stridx(res, "\r\n\r\n") let l:pos = stridx(l:res, "\r\n\r\n")
if pos != -1 if l:pos != -1
let res = strpart(res, pos+4) let l:res = strpart(l:res, l:pos+4)
else else
let pos = stridx(res, "\n\n") let l:pos = stridx(l:res, "\n\n")
let res = strpart(res, pos+2) let l:res = strpart(l:res, l:pos+2)
endif endif
endwhile endwhile
let pos = stridx(res, "\r\n\r\n") let l:pos = stridx(l:res, "\r\n\r\n")
if pos != -1 if l:pos != -1
let content = strpart(res, pos+4) let l:content = strpart(l:res, l:pos+4)
else else
let pos = stridx(res, "\n\n") let l:pos = stridx(l:res, "\n\n")
let content = strpart(res, pos+2) let l:content = strpart(l:res, l:pos+2)
endif endif
let header = res[:pos-1] let l:header = l:res[:l:pos-1]
let charset = matchstr(content, '<meta[^>]\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>') let l:charset = matchstr(l:content, '<meta[^>]\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>')
if len(charset) == 0 if len(l:charset) == 0
let charset = matchstr(content, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]*>') let l:charset = matchstr(l:content, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]*>')
endif endif
if len(charset) == 0 if len(l:charset) == 0
let charset = matchstr(header, '\nContent-Type:.* charset=[''"]\?\zs[^''";\n]\+\ze') let l:charset = matchstr(l:header, '\nContent-Type:.* charset=[''"]\?\zs[^''";\n]\+\ze')
endif endif
if len(charset) == 0 if len(l:charset) == 0
let s1 = len(split(content, '?')) let l:s1 = len(split(l:content, '?'))
let utf8 = iconv(content, 'utf-8', &encoding) let l:utf8 = iconv(l:content, 'utf-8', &encoding)
let s2 = len(split(utf8, '?')) let l:s2 = len(split(l:utf8, '?'))
return (s2 == s1 || s2 >= s1 * 2) ? utf8 : content return (l:s2 == l:s1 || l:s2 >= l:s1 * 2) ? l:utf8 : l:content
endif endif
return iconv(content, charset, &encoding) return iconv(l:content, l:charset, &encoding)
endfunction endfunction
function! emmet#util#getTextFromHTML(buf) abort function! emmet#util#getTextFromHTML(buf) abort
let threshold_len = 100 let l:threshold_len = 100
let threshold_per = 0.1 let l:threshold_per = 0.1
let buf = a:buf let l:buf = a:buf
let buf = strpart(buf, stridx(buf, '</head>')) let l:buf = strpart(l:buf, stridx(l:buf, '</head>'))
let buf = substitute(buf, '<style[^>]*>.\{-}</style>', '', 'g') let l:buf = substitute(l:buf, '<style[^>]*>.\{-}</style>', '', 'g')
let buf = substitute(buf, '<script[^>]*>.\{-}</script>', '', 'g') let l:buf = substitute(l:buf, '<script[^>]*>.\{-}</script>', '', 'g')
let res = '' let l:res = ''
let max = 0 let l:max = 0
let mx = '\(<td[^>]\{-}>\)\|\(<\/td>\)\|\(<div[^>]\{-}>\)\|\(<\/div>\)' let l:mx = '\(<td[^>]\{-}>\)\|\(<\/td>\)\|\(<div[^>]\{-}>\)\|\(<\/div>\)'
let m = split(buf, mx) let l:m = split(l:buf, l:mx)
for str in m for l:str in l:m
let c = split(str, '<[^>]*?>') let l:c = split(l:str, '<[^>]*?>')
let str = substitute(str, '<[^>]\{-}>', ' ', 'g') let l:str = substitute(l:str, '<[^>]\{-}>', ' ', 'g')
let str = substitute(str, '&gt;', '>', 'g') let l:str = substitute(l:str, '&gt;', '>', 'g')
let str = substitute(str, '&lt;', '<', 'g') let l:str = substitute(l:str, '&lt;', '<', 'g')
let str = substitute(str, '&quot;', '"', 'g') let l:str = substitute(l:str, '&quot;', '"', 'g')
let str = substitute(str, '&apos;', '''', 'g') let l:str = substitute(l:str, '&apos;', '''', 'g')
let str = substitute(str, '&nbsp;', ' ', 'g') let l:str = substitute(l:str, '&nbsp;', ' ', 'g')
let str = substitute(str, '&yen;', '\&#65509;', 'g') let l:str = substitute(l:str, '&yen;', '\&#65509;', 'g')
let str = substitute(str, '&amp;', '\&', 'g') let l:str = substitute(l:str, '&amp;', '\&', 'g')
let str = substitute(str, '^\s*\(.*\)\s*$', '\1', '') let l:str = substitute(l:str, '^\s*\(.*\)\s*$', '\1', '')
let str = substitute(str, '\s\+', ' ', 'g') let l:str = substitute(l:str, '\s\+', ' ', 'g')
let l = len(str) let l:l = len(l:str)
if l > threshold_len if l:l > l:threshold_len
let per = (l+0.0) / len(c) let l:per = (l:l+0.0) / len(l:c)
if max < l && per > threshold_per if l:max < l:l && l:per > l:threshold_per
let max = l let l:max = l:l
let res = str let l:res = l:str
endif endif
endif endif
endfor endfor
let res = substitute(res, '^\s*\(.*\)\s*$', '\1', 'g') let l:res = substitute(l:res, '^\s*\(.*\)\s*$', '\1', 'g')
return res return l:res
endfunction endfunction
function! emmet#util#getImageSize(fn) abort function! emmet#util#getImageSize(fn) abort
let fn = a:fn let l:fn = a:fn
if emmet#util#isImageMagickInstalled() if emmet#util#isImageMagickInstalled()
return emmet#util#imageSizeWithImageMagick(fn) return emmet#util#imageSizeWithImageMagick(l:fn)
endif endif
if filereadable(fn) if filereadable(l:fn)
let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') let l:hex = substitute(system('xxd -p '.shellescape(l:fn)), '\n', '', 'g')
else else
if fn !~# '^\w\+://' if l:fn !~# '^\w\+://'
let path = fnamemodify(expand('%'), ':p:gs?\\?/?') let l:path = fnamemodify(expand('%'), ':p:gs?\\?/?')
if has('win32') || has('win64') | if has('win32') || has('win64') |
let path = tolower(path) let l:path = tolower(l:path)
endif endif
for k in keys(g:emmet_docroot) for l:k in keys(g:emmet_docroot)
let root = fnamemodify(k, ':p:gs?\\?/?') let l:root = fnamemodify(l:k, ':p:gs?\\?/?')
if has('win32') || has('win64') | if has('win32') || has('win64') |
let root = tolower(root) let l:root = tolower(l:root)
endif endif
if stridx(path, root) == 0 if stridx(l:path, l:root) == 0
let v = g:emmet_docroot[k] let l:v = g:emmet_docroot[l:k]
let fn = (len(v) == 0 ? k : v) . fn let l:fn = (len(l:v) == 0 ? l:k : l:v) . l:fn
break break
endif endif
endfor endfor
endif endif
let hex = substitute(system(g:emmet_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g') let l:hex = substitute(system(g:emmet_curl_command.' '.shellescape(l:fn).' | xxd -p'), '\n', '', 'g')
endif endif
let [width, height] = [-1, -1] let [l:width, l:height] = [-1, -1]
if hex =~# '^89504e470d0a1a0a' if l:hex =~# '^89504e470d0a1a0a'
let width = eval('0x'.hex[32:39]) let l:width = eval('0x'.l:hex[32:39])
let height = eval('0x'.hex[40:47]) let l:height = eval('0x'.l:hex[40:47])
endif endif
if hex =~# '^ffd8' if l:hex =~# '^ffd8'
let pos = 4 let l:pos = 4
while pos < len(hex) while l:pos < len(l:hex)
let bs = hex[pos+0:pos+3] let l:bs = l:hex[l:pos+0:l:pos+3]
let pos += 4 let l:pos += 4
if bs ==# 'ffc0' || bs ==# 'ffc2' if l:bs ==# 'ffc0' || l:bs ==# 'ffc2'
let pos += 6 let l:pos += 6
let height = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) let l:height = eval('0x'.l:hex[l:pos+0:l:pos+1])*256 + eval('0x'.l:hex[l:pos+2:l:pos+3])
let pos += 4 let l:pos += 4
let width = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) let l:width = eval('0x'.l:hex[l:pos+0:l:pos+1])*256 + eval('0x'.l:hex[l:pos+2:l:pos+3])
break break
elseif bs =~# 'ffd[9a]' elseif l:bs =~# 'ffd[9a]'
break break
elseif bs =~# 'ff\(e[0-9a-e]\|fe\|db\|dd\|c4\)' elseif l:bs =~# 'ff\(e[0-9a-e]\|fe\|db\|dd\|c4\)'
let pos += (eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])) * 2 let l:pos += (eval('0x'.l:hex[l:pos+0:l:pos+1])*256 + eval('0x'.l:hex[l:pos+2:l:pos+3])) * 2
endif endif
endwhile endwhile
endif endif
if hex =~# '^47494638' if l:hex =~# '^47494638'
let width = eval('0x'.hex[14:15].hex[12:13]) let l:width = eval('0x'.l:hex[14:15].l:hex[12:13])
let height = eval('0x'.hex[18:19].hex[16:17]) let l:height = eval('0x'.l:hex[18:19].l:hex[16:17])
endif endif
return [width, height] return [l:width, l:height]
endfunction endfunction
function! emmet#util#imageSizeWithImageMagick(fn) abort function! emmet#util#imageSizeWithImageMagick(fn) abort
let img_info = system('identify -format "%wx%h" "'.a:fn.'"') let l:img_info = system('identify -format "%wx%h" '.shellescape(a:fn))
let img_size = split(substitute(img_info, '\n', '', ''), 'x') let l:img_size = split(substitute(l:img_info, '\n', '', ''), 'x')
if len(img_size) != 2 if len(l:img_size) != 2
return [-1, -1] return [-1, -1]
endif endif
return img_size return l:img_size
endfunction endfunction
function! emmet#util#isImageMagickInstalled() abort function! emmet#util#isImageMagickInstalled() abort
@@ -299,78 +299,78 @@ function! emmet#util#isImageMagickInstalled() abort
endfunction endfunction
function! s:b64encode(bytes, table, pad) function! s:b64encode(bytes, table, pad)
let b64 = [] let l:b64 = []
for i in range(0, len(a:bytes) - 1, 3) for l:i in range(0, len(a:bytes) - 1, 3)
let n = a:bytes[i] * 0x10000 let l:n = a:bytes[l:i] * 0x10000
\ + get(a:bytes, i + 1, 0) * 0x100 \ + get(a:bytes, l:i + 1, 0) * 0x100
\ + get(a:bytes, i + 2, 0) \ + get(a:bytes, l:i + 2, 0)
call add(b64, a:table[n / 0x40000]) call add(l:b64, a:table[l:n / 0x40000])
call add(b64, a:table[n / 0x1000 % 0x40]) call add(l:b64, a:table[l:n / 0x1000 % 0x40])
call add(b64, a:table[n / 0x40 % 0x40]) call add(l:b64, a:table[l:n / 0x40 % 0x40])
call add(b64, a:table[n % 0x40]) call add(l:b64, a:table[l:n % 0x40])
endfor endfor
if len(a:bytes) % 3 == 2 if len(a:bytes) % 3 == 2
let b64[-1] = a:pad let l:b64[-1] = a:pad
elseif len(a:bytes) % 3 == 1 elseif len(a:bytes) % 3 == 1
let b64[-1] = a:pad let l:b64[-1] = a:pad
let b64[-2] = a:pad let l:b64[-2] = a:pad
endif endif
return b64 return l:b64
endfunction endfunction
function! emmet#util#imageEncodeDecode(fn, flag) abort function! emmet#util#imageEncodeDecode(fn, flag) abort
let fn = a:fn let l:fn = a:fn
if filereadable(fn) if filereadable(l:fn)
let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') let l:hex = substitute(system('xxd -p '.shellescape(l:fn)), '\n', '', 'g')
else else
if fn !~# '^\w\+://' if l:fn !~# '^\w\+://'
let path = fnamemodify(expand('%'), ':p:gs?\\?/?') let l:path = fnamemodify(expand('%'), ':p:gs?\\?/?')
if has('win32') || has('win64') | if has('win32') || has('win64') |
let path = tolower(path) let l:path = tolower(l:path)
endif endif
for k in keys(g:emmet_docroot) for l:k in keys(g:emmet_docroot)
let root = fnamemodify(k, ':p:gs?\\?/?') let l:root = fnamemodify(l:k, ':p:gs?\\?/?')
if has('win32') || has('win64') | if has('win32') || has('win64') |
let root = tolower(root) let l:root = tolower(l:root)
endif endif
if stridx(path, root) == 0 if stridx(l:path, l:root) == 0
let v = g:emmet_docroot[k] let l:v = g:emmet_docroot[l:k]
let fn = (len(v) == 0 ? k : v) . fn let l:fn = (len(l:v) == 0 ? l:k : l:v) . l:fn
break break
endif endif
endfor endfor
endif endif
let hex = substitute(system(g:emmet_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g') let l:hex = substitute(system(g:emmet_curl_command.' '.shellescape(l:fn).' | xxd -p'), '\n', '', 'g')
endif endif
let bin = map(split(hex, '..\zs'), 'eval("0x" . v:val)') let l:bin = map(split(l:hex, '..\zs'), 'eval("0x" . v:val)')
let table = split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', '\zs') let l:table = split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', '\zs')
let ret = 'data:image/' let l:ret = 'data:image/'
if hex =~# '^89504e470d0a1a0a' if l:hex =~# '^89504e470d0a1a0a'
let ret .= 'png' let l:ret .= 'png'
elseif hex =~# '^ffd8' elseif l:hex =~# '^ffd8'
let ret .= 'jpeg' let l:ret .= 'jpeg'
elseif hex =~# '^47494638' elseif l:hex =~# '^47494638'
let ret .= 'gif' let l:ret .= 'gif'
elseif hex =~# '^00000020667479706176696600000000' elseif l:hex =~# '^00000020667479706176696600000000'
let ret .= 'avif' let l:ret .= 'avif'
else else
let ret .= 'unknown' let l:ret .= 'unknown'
endif endif
return ret . ';base64,' . join(s:b64encode(bin, table, '='), '') return l:ret . ';base64,' . join(s:b64encode(l:bin, l:table, '='), '')
endfunction endfunction
function! emmet#util#unique(arr) abort function! emmet#util#unique(arr) abort
let m = {} let l:m = {}
let r = [] let l:r = []
for i in a:arr for l:i in a:arr
if !has_key(m, i) if !has_key(l:m, l:i)
let m[i] = 1 let l:m[l:i] = 1
call add(r, i) call add(l:r, l:i)
endif endif
endfor endfor
return r return l:r
endfunction endfunction
let s:seed = localtime() let s:seed = localtime()
@@ -384,27 +384,27 @@ function! emmet#util#rand() abort
endfunction endfunction
function! emmet#util#cache(name, ...) abort function! emmet#util#cache(name, ...) abort
let content = get(a:000, 0, '') let l:content = get(a:000, 0, '')
let dir = expand('~/.emmet/cache') let l:dir = expand('~/.emmet/cache')
if !isdirectory(dir) if !isdirectory(l:dir)
call mkdir(dir, 'p', 0700) call mkdir(l:dir, 'p', 0700)
endif endif
let file = dir . '/' . substitute(a:name, '\W', '_', 'g') let l:file = l:dir . '/' . substitute(a:name, '\W', '_', 'g')
if len(content) == 0 if len(l:content) == 0
if !filereadable(file) if !filereadable(l:file)
return '' return ''
endif endif
return join(readfile(file), "\n") return join(readfile(l:file), "\n")
endif endif
call writefile(split(content, "\n"), file) call writefile(split(l:content, "\n"), l:file)
endfunction endfunction
function! emmet#util#getcurpos() abort function! emmet#util#getcurpos() abort
let pos = getpos('.') let l:pos = getpos('.')
if mode(0) ==# 'i' && pos[2] > 0 if mode(0) ==# 'i' && l:pos[2] > 0
let pos[2] -=1 let l:pos[2] -=1
endif endif
return pos return l:pos
endfunction endfunction
function! emmet#util#closePopup() abort function! emmet#util#closePopup() abort

25
lua/emmet_utils.lua Normal file
View File

@@ -0,0 +1,25 @@
local M = {}
M.get_node_at_cursor = function()
local ts_utils = require("nvim-treesitter.ts_utils")
local node = ts_utils.get_node_at_cursor()
if not node then
return nil
end
while node do
local node_type = node:type()
if node_type == "element" then
return "html"
elseif node_type == "stylesheet" then
return "css"
end
node = node:parent()
end
return ""
end
return M

View File

@@ -96,8 +96,8 @@ if !exists('g:user_emmet_leader_key')
endif endif
function! s:install_plugin(mode, buffer) function! s:install_plugin(mode, buffer)
let buffer = a:buffer ? '<buffer>' : '' let l:buffer = a:buffer ? '<buffer>' : ''
let items = [ let l:items = [
\ {'mode': 'i', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#expandAbbr(0,"")<cr>'}, \ {'mode': 'i', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': '<c-r>=emmet#util#closePopup()<cr><c-r>=emmet#expandAbbr(0,"")<cr>'},
\ {'mode': 'n', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(3,"")<cr>'}, \ {'mode': 'n', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(3,"")<cr>'},
\ {'mode': 'v', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(2,"")<cr>'}, \ {'mode': 'v', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(2,"")<cr>'},
@@ -138,20 +138,20 @@ function! s:install_plugin(mode, buffer)
\ {'mode': 'v', 'var': 'user_emmet_codepretty_key', 'key': 'c', 'plug': 'emmet-code-pretty', 'func': ':call emmet#codePretty()<cr>'}, \ {'mode': 'v', 'var': 'user_emmet_codepretty_key', 'key': 'c', 'plug': 'emmet-code-pretty', 'func': ':call emmet#codePretty()<cr>'},
\] \]
let only_plug = get(g:, 'emmet_install_only_plug', 0) let l:only_plug = get(g:, 'emmet_install_only_plug', 0)
for item in items for l:item in l:items
if a:mode !=# 'a' && stridx(a:mode, item.mode) == -1 if a:mode !=# 'a' && stridx(a:mode, l:item.mode) == -1
continue continue
endif endif
exe item.mode . 'noremap '. buffer .' <plug>(' . item.plug . ') ' . item.func exe l:item.mode . 'noremap '. l:buffer .' <plug>(' . l:item.plug . ') ' . l:item.func
if item.var != '' && !only_plug if l:item.var != '' && !l:only_plug
if exists('g:' . item.var) if exists('g:' . l:item.var)
let key = eval('g:' . item.var) let l:key = eval('g:' . l:item.var)
else else
let key = g:user_emmet_leader_key . item.key let l:key = g:user_emmet_leader_key . l:item.key
endif endif
if !hasmapto('<plug>(' . item.plug . ')', item.mode) && !len(maparg(key, item.mode)) if !hasmapto('<plug>(' . l:item.plug . ')', l:item.mode) && !len(maparg(l:key, l:item.mode))
exe item.mode . 'map ' . buffer . ' <unique> <silent>' . key . ' <plug>(' . item.plug . ')' exe l:item.mode . 'map ' . l:buffer . ' <unique> <silent>' . l:key . ' <plug>(' . l:item.plug . ')'
endif endif
endif endif
endfor endfor