diff --git a/autoload/emmet.vim b/autoload/emmet.vim index 86766d7..23e331b 100644 --- a/autoload/emmet.vim +++ b/autoload/emmet.vim @@ -9,27 +9,27 @@ set cpoptions&vim let s:filtermx = '|\(\%(bem\|html\|blade\|haml\|slim\|e\|c\|s\|fc\|xsl\|t\|\/[^ ]\+\)\s*,\{0,1}\s*\)*$' function! emmet#getExpandos(type, key) abort - let expandos = emmet#getResource(a:type, 'expandos', {}) - if has_key(expandos, a:key) - return expandos[a:key] + let l:expandos = emmet#getResource(a:type, 'expandos', {}) + if has_key(l:expandos, a:key) + return l:expandos[a:key] endif return a:key endfunction function! emmet#splitFilterArg(filters) abort - for f in a:filters - if f =~# '^/' - return f[1:] + for l:f in a:filters + if l:f =~# '^/' + return l:f[1:] endif endfor return '' endfunction function! emmet#useFilter(filters, filter) abort - for f in a:filters - if a:filter ==# '/' && f =~# '^/' + for l:f in a:filters + if a:filter ==# '/' && l:f =~# '^/' return 1 - elseif f ==# a:filter + elseif l:f ==# a:filter return 1 endif endfor @@ -38,21 +38,21 @@ endfunction function! emmet#getIndentation(...) abort if a:0 > 0 - let type = a:1 + let l:type = a:1 else - let type = emmet#getFileType() + let l:type = emmet#getFileType() endif - if has_key(s:emmet_settings, type) && has_key(s:emmet_settings[type], 'indentation') - let indent = s:emmet_settings[type].indentation + if has_key(s:emmet_settings, l:type) && has_key(s:emmet_settings[l:type], 'indentation') + let l:indent = s:emmet_settings[l:type].indentation elseif has_key(s:emmet_settings, 'indentation') - let indent = s:emmet_settings.indentation + let l:indent = s:emmet_settings.indentation elseif has_key(s:emmet_settings.variables, 'indentation') - let indent = s:emmet_settings.variables.indentation + let l:indent = s:emmet_settings.variables.indentation else - let sw = exists('*shiftwidth') ? shiftwidth() : &l:shiftwidth - let indent = (&l:expandtab || &l:tabstop !=# sw) ? repeat(' ', sw) : "\t" + let l:sw = exists('*shiftwidth') ? shiftwidth() : &l:shiftwidth + let l:indent = (&l:expandtab || &l:tabstop !=# l:sw) ? repeat(' ', l:sw) : "\t" endif - return indent + return l:indent endfunction function! emmet#getBaseType(type) abort @@ -62,15 +62,15 @@ function! emmet#getBaseType(type) abort if !has_key(s:emmet_settings[a:type], 'extends') return a:type endif - let extends = s:emmet_settings[a:type].extends - if type(extends) ==# 1 - let tmp = split(extends, '\s*,\s*') - let ext = tmp[0] + let l:extends = s:emmet_settings[a:type].extends + if type(l:extends) ==# 1 + let l:tmp = split(l:extends, '\s*,\s*') + let l:ext = l:tmp[0] else - let ext = extends[0] + let l:ext = l:extends[0] endif - if a:type !=# ext - return emmet#getBaseType(ext) + if a:type !=# l:ext + return emmet#getBaseType(l:ext) endif return '' endfunction @@ -85,9 +85,9 @@ function! emmet#isExtends(type, extend) abort if !has_key(s:emmet_settings[a:type], 'extends') return 0 endif - let extends = emmet#lang#getExtends(a:type) - for ext in extends - if a:extend ==# ext + let l:extends = emmet#lang#getExtends(a:type) + for l:ext in l:extends + if a:extend ==# l:ext return 1 endif endfor @@ -95,9 +95,9 @@ function! emmet#isExtends(type, extend) abort endfunction function! emmet#parseIntoTree(abbr, type) abort - let abbr = a:abbr - let type = a:type - return emmet#lang#{emmet#lang#type(type)}#parseIntoTree(abbr, type) + let l:abbr = a:abbr + let l:type = a:type + return emmet#lang#{emmet#lang#type(l:type)}#parseIntoTree(l:abbr, l:type) endfunction function! emmet#expandAbbrIntelligent(feedkey) abort @@ -108,62 +108,62 @@ function! emmet#expandAbbrIntelligent(feedkey) abort endfunction function! emmet#isExpandable() abort - let line = getline('.') - if col('.') < len(line) - let line = matchstr(line, '^\(.*\%'.col('.').'c\)') + let l:line = getline('.') + if col('.') < len(l:line) + let l:line = matchstr(l:line, '^\(.*\%'.col('.').'c\)') endif - let part = matchstr(line, '\(\S.*\)$') - let type = emmet#getFileType() - let rtype = emmet#lang#type(type) - let part = emmet#lang#{rtype}#findTokens(part) - return len(part) > 0 + let l:part = matchstr(l:line, '\(\S.*\)$') + let l:type = emmet#getFileType() + let l:rtype = emmet#lang#type(l:type) + let l:part = emmet#lang#{l:rtype}#findTokens(l:part) + return len(l:part) > 0 endfunction function! emmet#mergeConfig(lhs, rhs) abort - let [lhs, rhs] = [a:lhs, a:rhs] - if type(lhs) ==# 3 - if type(rhs) ==# 3 - let lhs += rhs - if len(lhs) - call remove(lhs, 0, len(lhs)-1) + let [l:lhs, l:rhs] = [a:lhs, a:rhs] + if type(l:lhs) ==# 3 + if type(l:rhs) ==# 3 + let l:lhs += l:rhs + if len(l:lhs) + call remove(l:lhs, 0, len(l:lhs)-1) endif - for rhi in rhs - call add(lhs, rhs[rhi]) + for l:rhi in l:rhs + call add(l:lhs, l:rhs[l:rhi]) endfor - elseif type(rhs) ==# 4 - let lhs += map(keys(rhs), '{v:val : rhs[v:val]}') + elseif type(l:rhs) ==# 4 + let l:lhs += map(keys(l:rhs), '{v:val : l:rhs[v:val]}') endif - elseif type(lhs) ==# 4 - if type(rhs) ==# 3 - for V in rhs - if type(V) != 4 + elseif type(l:lhs) ==# 4 + if type(l:rhs) ==# 3 + for l:V in l:rhs + if type(l:V) != 4 continue endif - for k in keys(V) - let lhs[k] = V[k] + for l:k in keys(l:V) + let l:lhs[l:k] = l:V[l:k] endfor endfor - elseif type(rhs) ==# 4 - for key in keys(rhs) - if type(rhs[key]) ==# 3 - if !has_key(lhs, key) - let lhs[key] = [] + elseif type(l:rhs) ==# 4 + for l:key in keys(l:rhs) + if type(l:rhs[l:key]) ==# 3 + if !has_key(l:lhs, l:key) + let l:lhs[l:key] = [] endif - if type(lhs[key]) == 3 - let lhs[key] += rhs[key] - elseif type(lhs[key]) == 4 - for k in keys(rhs[key]) - let lhs[key][k] = rhs[key][k] + if type(l:lhs[l:key]) == 3 + let l:lhs[l:key] += l:rhs[l:key] + elseif type(l:lhs[l:key]) == 4 + for l:k in keys(l:rhs[l:key]) + let l:lhs[l:key][l:k] = l:rhs[l:key][l:k] endfor endif - elseif type(rhs[key]) ==# 4 - if has_key(lhs, key) - call emmet#mergeConfig(lhs[key], rhs[key]) + elseif type(l:rhs[l:key]) ==# 4 + if has_key(l:lhs, l:key) + call emmet#mergeConfig(l:lhs[l:key], l:rhs[l:key]) else - let lhs[key] = rhs[key] + let l:lhs[l:key] = l:rhs[l:key] endif else - let lhs[key] = rhs[key] + let l:lhs[l:key] = l:rhs[l:key] endif endfor endif @@ -175,127 +175,127 @@ function! emmet#newNode() abort endfunction function! s:itemno(itemno, current) abort - let current = a:current - if current.basedirect > 0 - return current.basevalue - 1 + a:itemno + let l:current = a:current + if l:current.basedirect > 0 + return l:current.basevalue - 1 + a:itemno else - return current.multiplier + current.basevalue - 2 - a:itemno + return l:current.multiplier + l:current.basevalue - 2 - a:itemno endif endfunction function! s:localvar(current, key) abort - let val = '' - let cur = a:current - while !empty(cur) - if has_key(cur, 'variables') && has_key(cur.variables, a:key) - return cur.variables[a:key] + let l:val = '' + let l:cur = a:current + while !empty(l:cur) + if has_key(l:cur, 'variables') && has_key(l:cur.variables, a:key) + return l:cur.variables[a:key] endif - let cur = cur.parent + let l:cur = l:cur.parent endwhile return '' endfunction function! emmet#toString(...) abort - let current = a:1 + let l:current = a:1 if a:0 > 1 - let type = a:2 + let l:type = a:2 else - let type = &filetype + let l:type = &filetype endif - if len(type) ==# 0 | let type = 'html' | endif + if len(l:type) ==# 0 | let l:type = 'html' | endif if a:0 > 2 - let inline = a:3 + let l:inline = a:3 else - let inline = 0 + let l:inline = 0 endif if a:0 > 3 if type(a:4) ==# 1 - let filters = split(a:4, '\s*,\s*') + let l:filters = split(a:4, '\s*,\s*') else - let filters = a:4 + let l:filters = a:4 endif else - let filters = ['html'] + let l:filters = ['html'] endif if a:0 > 4 - let group_itemno = a:5 + let l:group_itemno = a:5 else - let group_itemno = 0 + let l:group_itemno = 0 endif if a:0 > 5 - let indent = a:6 + let l:indent = a:6 else - let indent = '' + let l:indent = '' endif - let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) - let itemno = 0 - let str = '' - let rtype = emmet#lang#type(type) - while itemno < current.multiplier - if len(current.name) - if current.multiplier ==# 1 - let inner = emmet#lang#{rtype}#toString(s:emmet_settings, current, type, inline, filters, s:itemno(group_itemno, current), indent) + let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1) + let l:itemno = 0 + let l:str = '' + let l:rtype = emmet#lang#type(l:type) + while l:itemno < l:current.multiplier + if len(l:current.name) + if l:current.multiplier ==# 1 + let l:inner = emmet#lang#{l:rtype}#toString(s:emmet_settings, l:current, l:type, l:inline, l:filters, s:itemno(l:group_itemno, l:current), l:indent) else - let inner = emmet#lang#{rtype}#toString(s:emmet_settings, current, type, inline, filters, s:itemno(itemno, current), indent) + let l:inner = emmet#lang#{l:rtype}#toString(s:emmet_settings, l:current, l:type, l:inline, l:filters, s:itemno(l:itemno, l:current), l:indent) endif - if current.multiplier > 1 - let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g') + if l:current.multiplier > 1 + let l:inner = substitute(l:inner, '\$#', '$line'.(l:itemno+1).'$', 'g') endif - let str .= inner + let l:str .= l:inner else - let snippet = current.snippet - if len(snippet) ==# 0 - let snippets = emmet#getResource(type, 'snippets', {}) - if !empty(snippets) && has_key(snippets, 'emmet_snippet') - let snippet = snippets['emmet_snippet'] + let l:snippet = l:current.snippet + if len(l:snippet) ==# 0 + let l:snippets = emmet#getResource(l:type, 'snippets', {}) + if !empty(l:snippets) && has_key(l:snippets, 'emmet_snippet') + let l:snippet = l:snippets['emmet_snippet'] endif endif - if len(snippet) > 0 - let tmp = snippet - let tmp = substitute(tmp, '\${emmet_name}', current.name, 'g') - let snippet_node = emmet#newNode() - let snippet_node.value = '{'.tmp.'}' - let snippet_node.important = current.important - let snippet_node.multiplier = current.multiplier - let str .= emmet#lang#{rtype}#toString(s:emmet_settings, snippet_node, type, inline, filters, s:itemno(group_itemno, current), indent) - if current.multiplier > 1 - let str .= "\n" + if len(l:snippet) > 0 + let l:tmp = l:snippet + let l:tmp = substitute(l:tmp, '\${emmet_name}', l:current.name, 'g') + let l:snippet_node = emmet#newNode() + let l:snippet_node.value = '{'.l:tmp.'}' + let l:snippet_node.important = l:current.important + let l:snippet_node.multiplier = l:current.multiplier + let l:str .= emmet#lang#{l:rtype}#toString(s:emmet_settings, l:snippet_node, l:type, l:inline, l:filters, s:itemno(l:group_itemno, l:current), l:indent) + if l:current.multiplier > 1 + let l:str .= "\n" endif else - if len(current.name) - let str .= current.name + if len(l:current.name) + let l:str .= l:current.name endif - if len(current.value) - let text = current.value[1:-2] - if dollar_expr + if len(l:current.value) + let l:text = l:current.value[1:-2] + if l:dollar_expr " TODO: regexp engine specified if exists('®expengine') - let text = substitute(text, '\%#=1\%(\\\)\@\ 0 - let key = get(matcharr, 1) - if key !~# '^\d\+:' - let key = substitute(key, '\\{', '{', 'g') - let key = substitute(key, '\\}', '}', 'g') - let value = emmet#getDollarValueByKey(key) - if type(value) ==# type('') - let expr = get(matcharr, 0) - call add(dollar_list, {'expr': expr, 'value': value}) + let l:matcharr = matchlist(l:expand, l:dollar_reg) + if len(l:matcharr) > 0 + let l:key = get(l:matcharr, 1) + if l:key !~# '^\d\+:' + let l:key = substitute(l:key, '\\{', '{', 'g') + let l:key = substitute(l:key, '\\}', '}', 'g') + let l:value = emmet#getDollarValueByKey(l:key) + if type(l:value) ==# type('') + let l:expr = get(l:matcharr, 0) + call add(l:dollar_list, {'expr': l:expr, 'value': l:value}) endif endif else break endif - let expand = substitute(expand, dollar_reg, '', '') + let l:expand = substitute(l:expand, l:dollar_reg, '', '') endwhile - return dollar_list + return l:dollar_list endfunction function! emmet#getDollarValueByKey(key) abort - let ret = 0 - let key = a:key - let ftsetting = get(s:emmet_settings, emmet#getFileType()) - if type(ftsetting) ==# 4 && has_key(ftsetting, key) - let V = get(ftsetting, key) - if type(V) ==# 1 | return V | endif + let l:ret = 0 + let l:key = a:key + let l:ftsetting = get(s:emmet_settings, emmet#getFileType()) + if type(l:ftsetting) ==# 4 && has_key(l:ftsetting, l:key) + let l:V = get(l:ftsetting, l:key) + if type(l:V) ==# 1 | return l:V | endif endif - if type(ret) !=# 1 && has_key(s:emmet_settings.variables, key) - let V = get(s:emmet_settings.variables, key) - if type(V) ==# 1 | return V | endif + if type(l:ret) !=# 1 && has_key(s:emmet_settings.variables, l:key) + let l:V = get(s:emmet_settings.variables, l:key) + if type(l:V) ==# 1 | return l:V | endif endif if has_key(s:emmet_settings, 'custom_expands') && type(s:emmet_settings['custom_expands']) ==# 4 - for k in keys(s:emmet_settings['custom_expands']) - if key =~# k - let V = get(s:emmet_settings['custom_expands'], k) - if type(V) ==# 1 | return V | endif - if type(V) ==# 2 | return V(key) | endif + for l:k in keys(s:emmet_settings['custom_expands']) + if l:key =~# l:k + let l:V = get(s:emmet_settings['custom_expands'], l:k) + if type(l:V) ==# 1 | return l:V | endif + if type(l:V) ==# 2 | return l:V(l:key) | endif endif endfor endif - return ret + return l:ret endfunction function! emmet#reExpandDollarExpr(expand, times) abort - let expand = a:expand - let dollar_exprs = emmet#getDollarExprs(expand) - if len(dollar_exprs) > 0 + let l:expand = a:expand + let l:dollar_exprs = emmet#getDollarExprs(l:expand) + if len(l:dollar_exprs) > 0 if a:times < 9 - for n in range(len(dollar_exprs)) - let pair = get(dollar_exprs, n) - let pat = get(pair, 'expr') - let sub = get(pair, 'value') - let expand = substitute(expand, pat, sub, '') + for l:n in range(len(l:dollar_exprs)) + let l:pair = get(l:dollar_exprs, l:n) + let l:pat = get(l:pair, 'expr') + let l:sub = get(l:pair, 'value') + let l:expand = substitute(l:expand, l:pat, l:sub, '') endfor - return emmet#reExpandDollarExpr(expand, a:times + 1) + return emmet#reExpandDollarExpr(l:expand, a:times + 1) endif endif - return expand + return l:expand endfunction function! emmet#expandDollarExpr(expand) abort @@ -504,20 +504,20 @@ function! emmet#expandDollarExpr(expand) abort endfunction function! emmet#expandCursorExpr(expand, mode) abort - let expand = a:expand - if expand !~# '\${cursor}' + let l:expand = a:expand + if l:expand !~# '\${cursor}' if a:mode ==# 2 - let expand = '${cursor}' . expand + let l:expand = '${cursor}' . l:expand else - let expand .= '${cursor}' + let l:expand .= '${cursor}' endif endif - let expand = substitute(expand, '\${\d\+:\?\([^}]\+\)}', '$select$$cursor$\1$select$', 'g') - let expand = substitute(expand, '\${\d\+}', '$select$$cursor$$select$', 'g') - let expand = substitute(expand, '\${cursor}', '$cursor$', '') - let expand = substitute(expand, '\${cursor}', '', 'g') - let expand = substitute(expand, '\${cursor}', '', 'g') - return expand + let l:expand = substitute(l:expand, '\${\d\+:\?\([^}]\+\)}', '$select$$cursor$\1$select$', 'g') + let l:expand = substitute(l:expand, '\${\d\+}', '$select$$cursor$$select$', 'g') + let l:expand = substitute(l:expand, '\${cursor}', '$cursor$', '') + let l:expand = substitute(l:expand, '\${cursor}', '', 'g') + let l:expand = substitute(l:expand, '\${cursor}', '', 'g') + return l:expand endfunction function! emmet#unescapeDollarExpr(expand) abort @@ -525,216 +525,216 @@ function! emmet#unescapeDollarExpr(expand) abort endfunction function! emmet#expandAbbr(mode, abbr) range abort - let type = emmet#getFileType(1) - let indent = emmet#getIndentation(type) - let expand = '' - let line = '' - let part = '' - let rest = '' + let l:type = emmet#getFileType(1) + let l:indent = emmet#getIndentation(l:type) + let l:expand = '' + let l:line = '' + let l:part = '' + let l:rest = '' - let filters = emmet#getFilters(type) - if len(filters) ==# 0 - let filters = ['html'] + let l:filters = emmet#getFilters(l:type) + if len(l:filters) ==# 0 + let l:filters = ['html'] endif if a:mode ==# 2 - let leader = substitute(input('Tag: ', ''), '^\s*\(.*\)\s*$', '\1', 'g') - if len(leader) ==# 0 + let l:leader = substitute(input('Tag: ', ''), '^\s*\(.*\)\s*$', '\1', 'g') + if len(l:leader) ==# 0 return '' endif - if leader =~# s:filtermx - let filters = map(split(matchstr(leader, s:filtermx)[1:], '\s*[^\\]\zs,\s*'), 'substitute(v:val, "\\\\\\\\zs.\\\\ze", "&", "g")') - let leader = substitute(leader, s:filtermx, '', '') + if l:leader =~# s:filtermx + let l:filters = map(split(matchstr(l:leader, s:filtermx)[1:], '\s*[^\\]\zs,\s*'), 'substitute(v:val, "\\\\\\\\zs.\\\\ze", "&", "g")') + let l:leader = substitute(l:leader, s:filtermx, '', '') endif - if leader =~# '\*' - let query = substitute(leader, '*', '*' . (a:lastline - a:firstline + 1), '') - if query !~# '}\s*$' && query !~# '\$#' - let query .= '>{$#}' + if l:leader =~# '\*' + let l:query = substitute(l:leader, '*', '*' . (a:lastline - a:firstline + 1), '') + if l:query !~# '}\s*$' && l:query !~# '\$#' + let l:query .= '>{$#}' endif - if emmet#useFilter(filters, '/') - let spl = emmet#splitFilterArg(filters) - let fline = getline(a:firstline) - let query = substitute(query, '>\{0,1}{\$#}\s*$', '{\\$column\\$}*' . len(split(fline, spl)), '') + if emmet#useFilter(l:filters, '/') + let l:spl = emmet#splitFilterArg(l:filters) + let l:fline = getline(a:firstline) + let l:query = substitute(l:query, '>\{0,1}{\$#}\s*$', '{\\$column\\$}*' . len(split(l:fline, l:spl)), '') else - let spl = '' + let l:spl = '' endif - let items = emmet#parseIntoTree(query, type).child - let itemno = 0 - for item in items - let inner = emmet#toString(item, type, 0, filters, 0, indent) - let inner = substitute(inner, '\$#', '$line'.(itemno*(a:lastline - a:firstline + 1)/len(items)+1).'$', 'g') - let expand .= inner - let itemno = itemno + 1 + let l:items = emmet#parseIntoTree(l:query, l:type).child + let l:itemno = 0 + for l:item in l:items + let l:inner = emmet#toString(l:item, l:type, 0, l:filters, 0, l:indent) + let l:inner = substitute(l:inner, '\$#', '$line'.(l:itemno*(a:lastline - a:firstline + 1)/len(l:items)+1).'$', 'g') + let l:expand .= l:inner + let l:itemno = l:itemno + 1 endfor - if emmet#useFilter(filters, 'e') - let expand = substitute(expand, '&', '\&', 'g') - let expand = substitute(expand, '<', '\<', 'g') - let expand = substitute(expand, '>', '\>', 'g') + if emmet#useFilter(l:filters, 'e') + let l:expand = substitute(l:expand, '&', '\&', 'g') + let l:expand = substitute(l:expand, '<', '\<', 'g') + let l:expand = substitute(l:expand, '>', '\>', 'g') endif - let line = getline(a:firstline) - let part = substitute(line, '^\s*', '', '') - for n in range(a:firstline, a:lastline) - let lline = getline(n) - let lpart = substitute(lline, '^\s\+', '', '') - if emmet#useFilter(filters, 't') - let lpart = substitute(lpart, '^[0-9.-]\+\s\+', '', '') - let lpart = substitute(lpart, '\s\+$', '', '') + let l:line = getline(a:firstline) + let l:part = substitute(l:line, '^\s*', '', '') + for l:n in range(a:firstline, a:lastline) + let l:lline = getline(l:n) + let l:lpart = substitute(l:lline, '^\s\+', '', '') + if emmet#useFilter(l:filters, 't') + let l:lpart = substitute(l:lpart, '^[0-9.-]\+\s\+', '', '') + let l:lpart = substitute(l:lpart, '\s\+$', '', '') endif - if emmet#useFilter(filters, '/') - for column in split(lpart, spl) - let expand = substitute(expand, '\$column\$', '\=column', '') + if emmet#useFilter(l:filters, '/') + for l:column in split(l:lpart, l:spl) + let l:expand = substitute(l:expand, '\$column\$', '\=l:column', '') endfor else - let expand = substitute(expand, '\$line'.(n-a:firstline+1).'\$', '\=lpart', 'g') + let l:expand = substitute(l:expand, '\$line'.(l:n-a:firstline+1).'\$', '\=l:lpart', 'g') endif endfor - let expand = substitute(expand, '\$line\d*\$', '', 'g') - let expand = substitute(expand, '\$column\$', '', 'g') - let content = join(getline(a:firstline, a:lastline), "\n") - if stridx(expand, '$#') < len(expand)-2 - let expand = substitute(expand, '^\(.*\)\$#\s*$', '\1', '') + let l:expand = substitute(l:expand, '\$line\d*\$', '', 'g') + let l:expand = substitute(l:expand, '\$column\$', '', 'g') + let l:content = join(getline(a:firstline, a:lastline), "\n") + if stridx(l:expand, '$#') < len(l:expand)-2 + let l:expand = substitute(l:expand, '^\(.*\)\$#\s*$', '\1', '') endif - let expand = substitute(expand, '\$#', '\=content', 'g') + let l:expand = substitute(l:expand, '\$#', '\=l:content', 'g') else - let str = '' + let l:str = '' if visualmode() ==# 'V' - let line = getline(a:firstline) - let lspaces = matchstr(line, '^\s*', '', '') - let part = substitute(line, '^\s*', '', '') - for n in range(a:firstline, a:lastline) - if len(leader) > 0 - let line = getline(a:firstline) - let spaces = matchstr(line, '^\s*', '', '') - if len(spaces) >= len(lspaces) - let str .= indent . getline(n)[len(lspaces):] . "\n" + let l:line = getline(a:firstline) + let l:lspaces = matchstr(l:line, '^\s*', '', '') + let l:part = substitute(l:line, '^\s*', '', '') + for l:n in range(a:firstline, a:lastline) + if len(l:leader) > 0 + let l:line = getline(a:firstline) + let l:spaces = matchstr(l:line, '^\s*', '', '') + if len(l:spaces) >= len(l:lspaces) + let l:str .= l:indent . getline(l:n)[len(l:lspaces):] . "\n" else - let str .= getline(n) . "\n" + let l:str .= getline(l:n) . "\n" endif else - let lpart = substitute(getline(n), '^\s*', '', '') - let str .= lpart . "\n" + let l:lpart = substitute(getline(l:n), '^\s*', '', '') + let l:str .= l:lpart . "\n" endif endfor - if stridx(leader, '{$#}') ==# -1 - let leader .= '{$#}' + if stridx(l:leader, '{$#}') ==# -1 + let l:leader .= '{$#}' endif - let items = emmet#parseIntoTree(leader, type).child + let l:items = emmet#parseIntoTree(l:leader, l:type).child else - let save_regcont = @" - let save_regtype = getregtype('"') + let l:save_regcont = @" + let l:save_regtype = getregtype('"') silent! normal! gvygv - let str = @" - call setreg('"', save_regcont, save_regtype) - if stridx(leader, '{$#}') ==# -1 - let leader .= '{$#}' + let l:str = @" + call setreg('"', l:save_regcont, l:save_regtype) + if stridx(l:leader, '{$#}') ==# -1 + let l:leader .= '{$#}' endif - let items = emmet#parseIntoTree(leader, type).child + let l:items = emmet#parseIntoTree(l:leader, l:type).child endif - for item in items - let expand .= emmet#toString(item, type, 0, filters, 0, '') + for l:item in l:items + let l:expand .= emmet#toString(l:item, l:type, 0, l:filters, 0, '') endfor - if emmet#useFilter(filters, 'e') - let expand = substitute(expand, '&', '\&', 'g') - let expand = substitute(expand, '<', '\<', 'g') - let expand = substitute(expand, '>', '\>', 'g') + if emmet#useFilter(l:filters, 'e') + let l:expand = substitute(l:expand, '&', '\&', 'g') + let l:expand = substitute(l:expand, '<', '\<', 'g') + let l:expand = substitute(l:expand, '>', '\>', 'g') endif - if stridx(leader, '{$#}') !=# -1 - let expand = substitute(expand, '\$#', '\="\n" . str', 'g') + if stridx(l:leader, '{$#}') !=# -1 + let l:expand = substitute(l:expand, '\$#', '\="\n" . l:str', 'g') endif endif elseif a:mode ==# 4 - let line = getline('.') - let spaces = matchstr(line, '^\s*') - if line !~# '^\s*$' - put =spaces.a:abbr + let l:line = getline('.') + let l:spaces = matchstr(l:line, '^\s*') + if l:line !~# '^\s*$' + put =l:spaces.a:abbr else - call setline('.', spaces.a:abbr) + call setline('.', l:spaces.a:abbr) endif normal! $ call emmet#expandAbbr(0, '') return '' else - let line = getline('.') - if col('.') < len(line) - let line = matchstr(line, '^\(.*\%'.col('.').'c\)') + let l:line = getline('.') + if col('.') < len(l:line) + let l:line = matchstr(l:line, '^\(.*\%'.col('.').'c\)') endif if a:mode ==# 1 - let part = matchstr(line, '\([a-zA-Z0-9:_\-\@|]\+\)$') + let l:part = matchstr(l:line, '\([a-zA-Z0-9:_\-\@|]\+\)$') else - let part = matchstr(line, '\(\S.*\)$') - let rtype = emmet#lang#type(type) - let part = emmet#lang#{rtype}#findTokens(part) - let line = line[0: strridx(line, part) + len(part) - 1] + let l:part = matchstr(l:line, '\(\S.*\)$') + let l:rtype = emmet#lang#type(l:type) + let l:part = emmet#lang#{l:rtype}#findTokens(l:part) + let l:line = l:line[0: strridx(l:line, l:part) + len(l:part) - 1] endif if col('.') ==# col('$') - let rest = '' + let l:rest = '' else - let rest = getline('.')[len(line):] + let l:rest = getline('.')[len(l:line):] endif - let str = part - if str =~# s:filtermx - let filters = split(matchstr(str, s:filtermx)[1:], '\s*,\s*') - let str = substitute(str, s:filtermx, '', '') + let l:str = l:part + if l:str =~# s:filtermx + let l:filters = split(matchstr(l:str, s:filtermx)[1:], '\s*,\s*') + let l:str = substitute(l:str, s:filtermx, '', '') endif - let items = emmet#parseIntoTree(str, type).child - for item in items - let expand .= emmet#toString(item, type, 0, filters, 0, indent) + let l:items = emmet#parseIntoTree(l:str, l:type).child + for l:item in l:items + let l:expand .= emmet#toString(l:item, l:type, 0, l:filters, 0, l:indent) endfor - if emmet#useFilter(filters, 'e') - let expand = substitute(expand, '&', '\&', 'g') - let expand = substitute(expand, '<', '\<', 'g') - let expand = substitute(expand, '>', '\>', 'g') + if emmet#useFilter(l:filters, 'e') + let l:expand = substitute(l:expand, '&', '\&', 'g') + let l:expand = substitute(l:expand, '<', '\<', 'g') + let l:expand = substitute(l:expand, '>', '\>', 'g') endif - let expand = substitute(expand, '\$line\([0-9]\+\)\$', '\=submatch(1)', 'g') + let l:expand = substitute(l:expand, '\$line\([0-9]\+\)\$', '\=submatch(1)', 'g') endif - let expand = emmet#expandDollarExpr(expand) - let expand = emmet#expandCursorExpr(expand, a:mode) - if len(expand) + let l:expand = emmet#expandDollarExpr(l:expand) + let l:expand = emmet#expandCursorExpr(l:expand, a:mode) + if len(l:expand) if has_key(s:emmet_settings, 'timezone') && len(s:emmet_settings.timezone) - let expand = substitute(expand, '${datetime}', strftime('%Y-%m-%dT%H:%M:%S') . s:emmet_settings.timezone, 'g') + let l:expand = substitute(l:expand, '${datetime}', strftime('%Y-%m-%dT%H:%M:%S') . s:emmet_settings.timezone, 'g') else " TODO: on windows, %z/%Z is 'Tokyo(Standard)' - let expand = substitute(expand, '${datetime}', strftime('%Y-%m-%dT%H:%M:%S %z'), 'g') + let l:expand = substitute(l:expand, '${datetime}', strftime('%Y-%m-%dT%H:%M:%S %z'), 'g') endif - let expand = emmet#unescapeDollarExpr(expand) + let l:expand = emmet#unescapeDollarExpr(l:expand) if a:mode ==# 2 && visualmode() ==# 'v' if a:firstline ==# a:lastline - let expand = substitute(expand, '[\r\n]\s*', '', 'g') + let l:expand = substitute(l:expand, '[\r\n]\s*', '', 'g') else - let expand = substitute(expand, '[\n]$', '', 'g') + let l:expand = substitute(l:expand, '[\n]$', '', 'g') endif silent! normal! gv - let col = col('''<') + let l:col = col('''<') silent! normal! c - let line = getline('.') - let lhs = matchstr(line, '.*\%<'.col.'c.') - let rhs = matchstr(line, '\%>'.(col-1).'c.*') - let expand = lhs.expand.rhs - let lines = split(expand, '\n') - call setline(line('.'), lines[0]) - if len(lines) > 1 - call append(line('.'), lines[1:]) + let l:line = getline('.') + let l:lhs = matchstr(l:line, '.*\%<'.l:col.'c.') + let l:rhs = matchstr(l:line, '\%>'.(l:col-1).'c.*') + let l:expand = l:lhs.l:expand.l:rhs + let l:lines = split(l:expand, '\n') + call setline(line('.'), l:lines[0]) + if len(l:lines) > 1 + call append(line('.'), l:lines[1:]) endif else - if line[:-len(part)-1] =~# '^\s\+$' - let indent = line[:-len(part)-1] + if l:line[:-len(l:part)-1] =~# '^\s\+$' + let l:indent = l:line[:-len(l:part)-1] else - let indent = '' + let l:indent = '' endif - let expand = substitute(expand, '[\r\n]\s*$', '', 'g') - if emmet#useFilter(filters, 's') - let epart = substitute(expand, '[\r\n]\s*', '', 'g') + let l:expand = substitute(l:expand, '[\r\n]\s*$', '', 'g') + if emmet#useFilter(l:filters, 's') + let l:epart = substitute(l:expand, '[\r\n]\s*', '', 'g') else - let epart = substitute(expand, '[\r\n]', "\n" . indent, 'g') + let l:epart = substitute(l:expand, '[\r\n]', "\n" . l:indent, 'g') endif - let expand = line[:-len(part)-1] . epart . rest - let lines = split(expand, '[\r\n]', 1) + let l:expand = l:line[:-len(l:part)-1] . l:epart . l:rest + let l:lines = split(l:expand, '[\r\n]', 1) if a:mode ==# 2 silent! exe 'normal! gvc' endif - call setline('.', lines[0]) - if len(lines) > 1 - call append('.', lines[1:]) + call setline('.', l:lines[0]) + if len(l:lines) > 1 + call append('.', l:lines[1:]) endif endif endif @@ -742,26 +742,26 @@ function! emmet#expandAbbr(mode, abbr) range abort call getchar() endif if search('\ze\$\(cursor\|select\)\$', 'c') - let oldselection = &selection + let l:oldselection = &selection let &selection = 'inclusive' if foldclosed(line('.')) !=# -1 silent! foldopen endif - let pos = emmet#util#getcurpos() - let use_selection = emmet#getResource(type, 'use_selection', 0) + let l:pos = emmet#util#getcurpos() + let l:use_selection = emmet#getResource(l:type, 'use_selection', 0) try let l:gdefault = &gdefault let &gdefault = 0 - if use_selection && getline('.')[col('.')-1:] =~# '^\$select' - let pos[2] += 1 + if l:use_selection && getline('.')[col('.')-1:] =~# '^\$select' + let l:pos[2] += 1 silent! s/\$select\$// - let next = searchpos('.\ze\$select\$', 'nW') + let l:next = searchpos('.\ze\$select\$', 'nW') silent! %s/\$\(cursor\|select\)\$//g - call emmet#util#selectRegion([pos[1:2], next]) + call emmet#util#selectRegion([l:pos[1:2], l:next]) return "\gv" else silent! %s/\$\(cursor\|select\)\$//g - silent! call setpos('.', pos) + silent! call setpos('.', l:pos) if col('.') < col('$') return "\" endif @@ -769,253 +769,253 @@ function! emmet#expandAbbr(mode, abbr) range abort finally let &gdefault = l:gdefault endtry - let &selection = oldselection + let &selection = l:oldselection endif return '' endfunction function! emmet#updateTag() abort - let type = emmet#getFileType() - let region = emmet#util#searchRegion('<\S', '>') - if !emmet#util#regionIsValid(region) || !emmet#util#cursorInRegion(region) + let l:type = emmet#getFileType() + let l:region = emmet#util#searchRegion('<\S', '>') + if !emmet#util#regionIsValid(l:region) || !emmet#util#cursorInRegion(l:region) return '' endif - let content = emmet#util#getContent(region) - let content = matchstr(content, '^<[^><]\+>') - if content !~# '^<[^><]\+>$' + let l:content = emmet#util#getContent(l:region) + let l:content = matchstr(l:content, '^<[^><]\+>') + if l:content !~# '^<[^><]\+>$' return '' endif - let current = emmet#lang#html#parseTag(content) - if empty(current) + let l:current = emmet#lang#html#parseTag(l:content) + if empty(l:current) return '' endif - let old_tag_name = current.name + let l:old_tag_name = l:current.name - let str = substitute(input('Enter Abbreviation: ', ''), '^\s*\(.*\)\s*$', '\1', 'g') - let tag_changed = str =~# '^\s*\w' - let item = emmet#parseIntoTree(str, type).child[0] - for k in keys(item.attr) - let current.attr[k] = item.attr[k] + let l:str = substitute(input('Enter Abbreviation: ', ''), '^\s*\(.*\)\s*$', '\1', 'g') + let l:tag_changed = l:str =~# '^\s*\w' + let l:item = emmet#parseIntoTree(l:str, l:type).child[0] + for l:k in keys(l:item.attr) + let l:current.attr[l:k] = l:item.attr[l:k] endfor - if tag_changed - let current.name = item.name + if l:tag_changed + let l:current.name = l:item.name endif - let html = substitute(emmet#toString(current, 'html', 1), '\n', '', '') - let html = substitute(html, '\${cursor}', '', '') - let html = matchstr(html, '^<[^><]\+>') - if tag_changed - let pos2 = searchpairpos('<' . old_tag_name . '\>[^>]*>', '', '', 'W') - if pos2 != [0, 0] - let html .= emmet#util#getContent([region[1], pos2])[1:-2] - let html .= '' - let region = [region[0], [pos2[0], pos2[1] + len(old_tag_name) + 3]] + let l:html = substitute(emmet#toString(l:current, 'html', 1), '\n', '', '') + let l:html = substitute(l:html, '\${cursor}', '', '') + let l:html = matchstr(l:html, '^<[^><]\+>') + if l:tag_changed + let l:pos2 = searchpairpos('<' . l:old_tag_name . '\>[^>]*>', '', '', 'W') + if l:pos2 != [0, 0] + let l:html .= emmet#util#getContent([l:region[1], l:pos2])[1:-2] + let l:html .= '' + let l:region = [l:region[0], [l:pos2[0], l:pos2[1] + len(l:old_tag_name) + 3]] endif endif - call emmet#util#setContent(region, html) + call emmet#util#setContent(l:region, l:html) return '' endfunction function! emmet#moveNextPrevItem(flag) abort - let type = emmet#getFileType() - return emmet#lang#{emmet#lang#type(type)}#moveNextPrevItem(a:flag) + let l:type = emmet#getFileType() + return emmet#lang#{emmet#lang#type(l:type)}#moveNextPrevItem(a:flag) endfunction function! emmet#moveNextPrev(flag) abort - let type = emmet#getFileType() - return emmet#lang#{emmet#lang#type(type)}#moveNextPrev(a:flag) + let l:type = emmet#getFileType() + return emmet#lang#{emmet#lang#type(l:type)}#moveNextPrev(a:flag) endfunction function! emmet#imageSize() abort - let orgpos = emmet#util#getcurpos() - let type = emmet#getFileType() - call emmet#lang#{emmet#lang#type(type)}#imageSize() - silent! call setpos('.', orgpos) + let l:orgpos = emmet#util#getcurpos() + let l:type = emmet#getFileType() + call emmet#lang#{emmet#lang#type(l:type)}#imageSize() + silent! call setpos('.', l:orgpos) return '' endfunction function! emmet#imageEncode() abort - let type = emmet#getFileType() - return emmet#lang#{emmet#lang#type(type)}#imageEncode() + let l:type = emmet#getFileType() + return emmet#lang#{emmet#lang#type(l:type)}#imageEncode() endfunction function! emmet#toggleComment() abort - let type = emmet#getFileType() - call emmet#lang#{emmet#lang#type(type)}#toggleComment() + let l:type = emmet#getFileType() + call emmet#lang#{emmet#lang#type(l:type)}#toggleComment() return '' endfunction function! emmet#balanceTag(flag) range abort - let type = emmet#getFileType() - return emmet#lang#{emmet#lang#type(type)}#balanceTag(a:flag) + let l:type = emmet#getFileType() + return emmet#lang#{emmet#lang#type(l:type)}#balanceTag(a:flag) endfunction function! emmet#splitJoinTag() abort - let type = emmet#getFileType() - return emmet#lang#{emmet#lang#type(type)}#splitJoinTag() + let l:type = emmet#getFileType() + return emmet#lang#{emmet#lang#type(l:type)}#splitJoinTag() endfunction function! emmet#mergeLines() range abort - let lines = join(map(getline(a:firstline, a:lastline), 'matchstr(v:val, "^\\s*\\zs.*\\ze\\s*$")'), '') - let indent = substitute(getline('.'), '^\(\s*\).*', '\1', '') + let l:lines = join(map(getline(a:firstline, a:lastline), 'matchstr(v:val, "^\\s*\\zs.*\\ze\\s*$")'), '') + let l:indent = substitute(getline('.'), '^\(\s*\).*', '\1', '') silent! exe 'normal! gvc' - call setline('.', indent . lines) + call setline('.', l:indent . l:lines) endfunction function! emmet#removeTag() abort - let type = emmet#getFileType() - call emmet#lang#{emmet#lang#type(type)}#removeTag() + let l:type = emmet#getFileType() + call emmet#lang#{emmet#lang#type(l:type)}#removeTag() return '' endfunction function! emmet#mergeLines() abort - let type = emmet#getFileType() - call emmet#lang#{emmet#lang#type(type)}#mergeLines() + let l:type = emmet#getFileType() + call emmet#lang#{emmet#lang#type(l:type)}#mergeLines() return '' endfunction function! emmet#anchorizeURL(flag) abort - let mx = 'https\=:\/\/[-!#$%&*+,./:;=?@0-9a-zA-Z_~]\+' - let pos1 = searchpos(mx, 'bcnW') - let url = matchstr(getline(pos1[0])[pos1[1]-1:], mx) - let block = [pos1, [pos1[0], pos1[1] + len(url) - 1]] - if !emmet#util#cursorInRegion(block) + let l:mx = 'https\=:\/\/[-!#$%&*+,./:;=?@0-9a-zA-Z_~]\+' + let l:pos1 = searchpos(l:mx, 'bcnW') + let l:url = matchstr(getline(l:pos1[0])[l:pos1[1]-1:], l:mx) + let l:block = [l:pos1, [l:pos1[0], l:pos1[1] + len(l:url) - 1]] + if !emmet#util#cursorInRegion(l:block) return '' endif - let mx = '.*]*>\s*\zs\([^<]\+\)\ze\s*<\/title[^>]*>.*' - let content = emmet#util#getContentFromURL(url) - let content = substitute(content, '\r', '', 'g') - let content = substitute(content, '[ \n]\+', ' ', 'g') - let content = substitute(content, '', '', 'g') - let title = matchstr(content, mx) + let l:mx = '.*]*>\s*\zs\([^<]\+\)\ze\s*<\/title[^>]*>.*' + let l:content = emmet#util#getContentFromURL(l:url) + let l:content = substitute(l:content, '\r', '', 'g') + let l:content = substitute(l:content, '[ \n]\+', ' ', 'g') + let l:content = substitute(l:content, '', '', 'g') + let l:title = matchstr(l:content, l:mx) - let type = emmet#getFileType() - let rtype = emmet#lang#type(type) + let l:type = emmet#getFileType() + let l:rtype = emmet#lang#type(l:type) if &filetype ==# 'markdown' - let expand = printf('[%s](%s)', substitute(title, '[\[\]]', '\\&', 'g'), url) + let l:expand = printf('[%s](%s)', substitute(l:title, '[\[\]]', '\\&', 'g'), l:url) elseif &filetype ==# 'rst' - let expand = printf('`%s <%s>`_', substitute(title, '[\[\]]', '\\&', 'g'), url) + let l:expand = printf('`%s <%s>`_', substitute(l:title, '[\[\]]', '\\&', 'g'), l:url) elseif a:flag ==# 0 - let a = emmet#lang#html#parseTag('') - let a.attr.href = url - let a.value = '{' . title . '}' - let expand = emmet#toString(a, rtype, 0, []) - let expand = substitute(expand, '\${cursor}', '', 'g') + let l:a = emmet#lang#html#parseTag('') + let l:a.attr.href = l:url + let l:a.value = '{' . l:title . '}' + let l:expand = emmet#toString(l:a, l:rtype, 0, []) + let l:expand = substitute(l:expand, '\${cursor}', '', 'g') else - let body = emmet#util#getTextFromHTML(content) - let body = '{' . substitute(body, '^\(.\{0,100}\).*', '\1', '') . '...}' + let l:body = emmet#util#getTextFromHTML(l:content) + let l:body = '{' . substitute(l:body, '^\(.\{0,100}\).*', '\1', '') . '...}' - let blockquote = emmet#lang#html#parseTag('
') - let a = emmet#lang#html#parseTag('') - let a.attr.href = url - let a.value = '{' . title . '}' - call add(blockquote.child, a) - call add(blockquote.child, emmet#lang#html#parseTag('
')) - let p = emmet#lang#html#parseTag('

') - let p.value = body - call add(blockquote.child, p) - let cite = emmet#lang#html#parseTag('') - let cite.value = '{' . url . '}' - call add(blockquote.child, cite) - let expand = emmet#toString(blockquote, rtype, 0, []) - let expand = substitute(expand, '\${cursor}', '', 'g') + let l:blockquote = emmet#lang#html#parseTag('

') + let l:a = emmet#lang#html#parseTag('') + let l:a.attr.href = l:url + let l:a.value = '{' . l:title . '}' + call add(l:blockquote.child, l:a) + call add(l:blockquote.child, emmet#lang#html#parseTag('
')) + let l:p = emmet#lang#html#parseTag('

') + let l:p.value = l:body + call add(l:blockquote.child, l:p) + let l:cite = emmet#lang#html#parseTag('') + let l:cite.value = '{' . l:url . '}' + call add(l:blockquote.child, l:cite) + let l:expand = emmet#toString(l:blockquote, l:rtype, 0, []) + let l:expand = substitute(l:expand, '\${cursor}', '', 'g') endif - let indent = substitute(getline('.'), '^\(\s*\).*', '\1', '') - let expand = substitute(expand, "\n", "\n" . indent, 'g') - call emmet#util#setContent(block, expand) + let l:indent = substitute(getline('.'), '^\(\s*\).*', '\1', '') + let l:expand = substitute(l:expand, "\n", "\n" . l:indent, 'g') + call emmet#util#setContent(l:block, l:expand) return '' endfunction function! emmet#codePretty() range abort - let type = input('FileType: ', &filetype, 'filetype') - if len(type) ==# 0 + let l:type = input('FileType: ', &filetype, 'filetype') + if len(l:type) ==# 0 return endif - let block = emmet#util#getVisualBlock() - let content = emmet#util#getContent(block) + let l:block = emmet#util#getVisualBlock() + let l:content = emmet#util#getContent(l:block) silent! 1new - let &l:filetype = type - call setline(1, split(content, "\n")) - let old_lazyredraw = &lazyredraw + let &l:filetype = l:type + call setline(1, split(l:content, "\n")) + let l:old_lazyredraw = &lazyredraw set lazyredraw silent! TOhtml - let &lazyredraw = old_lazyredraw - let content = join(getline(1, '$'), "\n") + let &lazyredraw = l:old_lazyredraw + let l:content = join(getline(1, '$'), "\n") silent! bw! silent! bw! - let content = matchstr(content, ']*>[\s\n]*\zs.*\ze') - call emmet#util#setContent(block, content) + let l:content = matchstr(l:content, ']*>[\s\n]*\zs.*\ze') + call emmet#util#setContent(l:block, l:content) endfunction function! emmet#expandWord(abbr, type, orig) abort - let str = a:abbr - let type = a:type - let indent = emmet#getIndentation(type) + let l:str = a:abbr + let l:type = a:type + let l:indent = emmet#getIndentation(l:type) - if len(type) ==# 0 | let type = 'html' | endif - if str =~# s:filtermx - let filters = split(matchstr(str, s:filtermx)[1:], '\s*,\s*') - let str = substitute(str, s:filtermx, '', '') + if len(l:type) ==# 0 | let l:type = 'html' | endif + if l:str =~# s:filtermx + let l:filters = split(matchstr(l:str, s:filtermx)[1:], '\s*,\s*') + let l:str = substitute(l:str, s:filtermx, '', '') else - let filters = emmet#getFilters(a:type) - if len(filters) ==# 0 - let filters = ['html'] + let l:filters = emmet#getFilters(a:type) + if len(l:filters) ==# 0 + let l:filters = ['html'] endif endif - let str = substitute(str, '|', '${cursor}', 'g') - let items = emmet#parseIntoTree(str, a:type).child - let expand = '' - for item in items - let expand .= emmet#toString(item, a:type, 0, filters, 0, indent) + let l:str = substitute(l:str, '|', '${cursor}', 'g') + let l:items = emmet#parseIntoTree(l:str, a:type).child + let l:expand = '' + for l:item in l:items + let l:expand .= emmet#toString(l:item, a:type, 0, l:filters, 0, l:indent) endfor - if emmet#useFilter(filters, 'e') - let expand = substitute(expand, '&', '\&', 'g') - let expand = substitute(expand, '<', '\<', 'g') - let expand = substitute(expand, '>', '\>', 'g') + if emmet#useFilter(l:filters, 'e') + let l:expand = substitute(l:expand, '&', '\&', 'g') + let l:expand = substitute(l:expand, '<', '\<', 'g') + let l:expand = substitute(l:expand, '>', '\>', 'g') endif - if emmet#useFilter(filters, 's') - let expand = substitute(expand, "\n\s\*", '', 'g') + if emmet#useFilter(l:filters, 's') + let l:expand = substitute(l:expand, "\n\s\*", '', 'g') endif if a:orig ==# 0 - let expand = emmet#expandDollarExpr(expand) - let expand = substitute(expand, '\${cursor}', '', 'g') + let l:expand = emmet#expandDollarExpr(l:expand) + let l:expand = substitute(l:expand, '\${cursor}', '', 'g') endif - return expand + return l:expand endfunction function! emmet#getSnippets(type) abort - let type = a:type - if len(type) ==# 0 || !has_key(s:emmet_settings, type) - let type = 'html' + let l:type = a:type + if len(l:type) ==# 0 || !has_key(s:emmet_settings, l:type) + let l:type = 'html' endif - return emmet#getResource(type, 'snippets', {}) + return emmet#getResource(l:type, 'snippets', {}) endfunction function! emmet#completeTag(findstart, base) abort if a:findstart - let line = getline('.') - let start = col('.') - 1 - while start > 0 && line[start - 1] =~# '[a-zA-Z0-9:_\@\-]' - let start -= 1 + let l:line = getline('.') + let l:start = col('.') - 1 + while l:start > 0 && l:line[l:start - 1] =~# '[a-zA-Z0-9:_\@\-]' + let l:start -= 1 endwhile - return start + return l:start else - let type = emmet#getFileType() - let res = [] + let l:type = emmet#getFileType() + let l:res = [] - let snippets = emmet#getResource(type, 'snippets', {}) - for item in keys(snippets) - if stridx(item, a:base) !=# -1 - call add(res, substitute(item, '\${cursor}\||', '', 'g')) + let l:snippets = emmet#getResource(l:type, 'snippets', {}) + for l:item in keys(l:snippets) + if stridx(l:item, a:base) !=# -1 + call add(l:res, substitute(l:item, '\${cursor}\||', '', 'g')) endif endfor - let aliases = emmet#getResource(type, 'aliases', {}) - for item in values(aliases) - if stridx(item, a:base) !=# -1 - call add(res, substitute(item, '\${cursor}\||', '', 'g')) + let l:aliases = emmet#getResource(l:type, 'aliases', {}) + for l:item in values(l:aliases) + if stridx(l:item, a:base) !=# -1 + call add(l:res, substitute(l:item, '\${cursor}\||', '', 'g')) endif endfor - return res + return l:res endif endfunction diff --git a/autoload/emmet/lang.vim b/autoload/emmet/lang.vim index 37e426b..e8cfda1 100644 --- a/autoload/emmet/lang.vim +++ b/autoload/emmet/lang.vim @@ -10,19 +10,19 @@ function! emmet#lang#exists(type) abort endfunction function! emmet#lang#type(type) abort - let type = a:type - let base = type - let settings = emmet#getSettings() - while base != '' - for b in split(base, '\.') - if emmet#lang#exists(b) - return b + let l:type = a:type + let l:base = l:type + let l:settings = emmet#getSettings() + while l:base != '' + for l:b in split(l:base, '\.') + if emmet#lang#exists(l:b) + return l:b endif - if has_key(settings, b) && has_key(settings[b], 'extends') - let base = settings[b].extends + if has_key(l:settings, l:b) && has_key(l:settings[l:b], 'extends') + let l:base = l:settings[l:b].extends break else - let base = '' + let l:base = '' endif endfor endwhile @@ -31,22 +31,22 @@ endfunction " get all extends for a type recursively 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 [] endif - let extends = settings[a:type].extends - if type(extends) ==# 1 - let tmp = split(extends, '\s*,\s*') - unlet! extends - let extends = tmp + let l:extends = l:settings[a:type].extends + if type(l:extends) ==# 1 + let l:tmp = split(l:extends, '\s*,\s*') + unlet! l:extends + let l:extends = l:tmp endif - for ext in extends - let extends = extends + emmet#lang#getExtends(ext) + for l:ext in l:extends + let l:extends = l:extends + emmet#lang#getExtends(l:ext) endfor - return extends + return l:extends endfunction diff --git a/autoload/emmet/lang/css.vim b/autoload/emmet/lang/css.vim index d26f942..2f9fc38 100644 --- a/autoload/emmet/lang/css.vim +++ b/autoload/emmet/lang/css.vim @@ -1,6 +1,6 @@ function! emmet#lang#css#findTokens(str) abort - let tmp = substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '') - if tmp =~ '/' && tmp =~ '^[a-zA-Z0-9/_.]\+$' + let l:tmp = substitute(substitute(a:str, '^.*[;{]\s*', '', ''), '}\s*$', '', '') + if l:tmp =~ '/' && l:tmp =~ '^[a-zA-Z0-9/_.]\+$' " maybe path or something return '' endif @@ -8,281 +8,281 @@ function! emmet#lang#css#findTokens(str) abort endfunction function! emmet#lang#css#parseIntoTree(abbr, type) abort - let abbr = a:abbr - let type = a:type - let prefix = 0 - let value = '' + let l:abbr = a:abbr + let l:type = a:type + let l:prefix = 0 + let l:value = '' - let indent = emmet#getIndentation(type) - let aliases = emmet#getResource(type, 'aliases', {}) - let snippets = emmet#getResource(type, 'snippets', {}) - let use_pipe_for_cursor = emmet#getResource(type, 'use_pipe_for_cursor', 1) + let l:indent = emmet#getIndentation(l:type) + let l:aliases = emmet#getResource(l:type, 'aliases', {}) + let l:snippets = emmet#getResource(l:type, 'snippets', {}) + let l:use_pipe_for_cursor = emmet#getResource(l:type, 'use_pipe_for_cursor', 1) - let root = emmet#newNode() + let l:root = emmet#newNode() " emmet - let tokens = split(abbr, '+\ze[^+)!]') - let block = emmet#util#searchRegion('{', '}') - if abbr !~# '^@' && emmet#getBaseType(type) ==# 'css' && type !=# 'sass' && type !=# 'styled' && block[0] ==# [0,0] && block[1] ==# [0,0] - let current = emmet#newNode() - let current.snippet = substitute(abbr, '\s\+$', '', '') . " {\n" . indent . "${cursor}\n}" - let current.name = '' - call add(root.child, deepcopy(current)) + let l:tokens = split(l:abbr, '+\ze[^+)!]') + let l:block = emmet#util#searchRegion('{', '}') + if l:abbr !~# '^@' && emmet#getBaseType(l:type) ==# 'css' && l:type !=# 'sass' && l:type !=# 'styled' && l:block[0] ==# [0,0] && l:block[1] ==# [0,0] + let l:current = emmet#newNode() + let l:current.snippet = substitute(l:abbr, '\s\+$', '', '') . " {\n" . l:indent . "${cursor}\n}" + let l:current.name = '' + call add(l:root.child, deepcopy(l:current)) else - for n in range(len(tokens)) - let token = tokens[n] - let prop = matchlist(token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+\%(p\|e\|em\|x\|vh\|vw\|re\|rem\|%\)\{0,}-\{0,1}\|-auto\)*\)$') - if len(prop) - let token = substitute(prop[1], '^(\(.*\))', '\1', '') - if token =~# '^-' - let prefix = 1 - let token = token[1:] + for l:n in range(len(l:tokens)) + let l:token = l:tokens[l:n] + let l:prop = matchlist(l:token, '^\(-\{0,1}[a-zA-Z]\+\|[a-zA-Z0-9]\++\{0,1}\|([a-zA-Z0-9]\++\{0,1})\)\(\%([0-9.-]\+\%(p\|e\|em\|x\|vh\|vw\|re\|rem\|%\)\{0,}-\{0,1}\|-auto\)*\)$') + if len(l:prop) + let l:token = substitute(l:prop[1], '^(\(.*\))', '\1', '') + if l:token =~# '^-' + let l:prefix = 1 + let l:token = l:token[1:] endif - let value = '' - for vt in split(prop[2], '\a\+\zs') - let ut = matchstr(vt, '[a-z]\+$') - if ut == 'auto' - let ut = '' + let l:value = '' + for l:vt in split(l:prop[2], '\a\+\zs') + let l:ut = matchstr(l:vt, '[a-z]\+$') + if l:ut == 'auto' + let l:ut = '' endif - for v in split(vt, '\d\zs-') - if len(value) > 0 - let value .= ' ' + for l:v in split(l:vt, '\d\zs-') + if len(l:value) > 0 + let l:value .= ' ' endif - if v !~ '[a-z]\+$' - let v .= ut + if l:v !~ '[a-z]\+$' + let l:v .= l:ut endif - if token =~# '^[z]' + if l:token =~# '^[z]' " TODO - let value .= substitute(v, '[^0-9.]*$', '', '') - elseif v =~# 'em$' - let value .= v - elseif v =~# 'ex$' - let value .= v - elseif v =~# 'vh$' - let value .= v - elseif v =~# 'vw$' - let value .= v - elseif v =~# 'rem$' - let value .= v - elseif v ==# 'auto' - let value .= v - elseif v =~# 'p$' - let value .= substitute(v, 'p$', '%', '') - elseif v =~# '%$' - let value .= v - elseif v =~# 'e$' - let value .= substitute(v, 'e$', 'em', '') - elseif v =~# 'x$' - let value .= substitute(v, 'x$', 'ex', '') - elseif v =~# 're$' - let value .= substitute(v, 're$', 'rem', '') - elseif v =~# '\.' - let value .= v . 'em' - elseif v ==# '0' - let value .= '0' + let l:value .= substitute(l:v, '[^0-9.]*$', '', '') + elseif l:v =~# 'em$' + let l:value .= l:v + elseif l:v =~# 'ex$' + let l:value .= l:v + elseif l:v =~# 'vh$' + let l:value .= l:v + elseif l:v =~# 'vw$' + let l:value .= l:v + elseif l:v =~# 'rem$' + let l:value .= l:v + elseif l:v ==# 'auto' + let l:value .= l:v + elseif l:v =~# 'p$' + let l:value .= substitute(l:v, 'p$', '%', '') + elseif l:v =~# '%$' + let l:value .= l:v + elseif l:v =~# 'e$' + let l:value .= substitute(l:v, 'e$', 'em', '') + elseif l:v =~# 'x$' + let l:value .= substitute(l:v, 'x$', 'ex', '') + elseif l:v =~# 're$' + let l:value .= substitute(l:v, 're$', 'rem', '') + elseif l:v =~# '\.' + let l:value .= l:v . 'em' + elseif l:v ==# '0' + let l:value .= '0' else - let value .= v . 'px' + let l:value .= l:v . 'px' endif endfor endfor endif - let tag_name = token - if tag_name =~# '.!$' - let tag_name = tag_name[:-2] - let important = 1 + let l:tag_name = l:token + if l:tag_name =~# '.!$' + let l:tag_name = l:tag_name[:-2] + let l:important = 1 else - let important = 0 + let l:important = 0 endif " make default node - let current = emmet#newNode() - let current.important = important - let current.name = tag_name + let l:current = emmet#newNode() + let l:current.important = l:important + let l:current.name = l:tag_name " aliases - if has_key(aliases, tag_name) - let current.name = aliases[tag_name] + if has_key(l:aliases, l:tag_name) + let l:current.name = l:aliases[l:tag_name] endif " snippets - if !empty(snippets) - let snippet_name = tag_name - if !has_key(snippets, snippet_name) - let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-\)') - let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') - if len(vv) == 0 - let vv = filter(sort(keys(snippets)), 'substitute(v:val, ":", "", "g") == snippet_name') + if !empty(l:snippets) + let l:snippet_name = l:tag_name + if !has_key(l:snippets, l:snippet_name) + let l:pat = '^' . join(split(l:tag_name, '\zs'), '\%(\|[^:-]\+-\)') + let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat') + if len(l:vv) == 0 + let l:vv = filter(sort(keys(l:snippets)), 'substitute(v:val, ":", "", "g") == l:snippet_name') endif - if len(vv) > 0 - let snippet_name = vv[0] + if len(l:vv) > 0 + let l:snippet_name = l:vv[0] else - let pat = '^' . join(split(tag_name, '\zs'), '\%(\|[^:-]\+-*\)') - let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') - if len(vv) == 0 - let pat = '^' . join(split(tag_name, '\zs'), '[^:]\{-}') - let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') - if len(vv) == 0 - let pat = '^' . join(split(tag_name, '\zs'), '.\{-}') - let vv = filter(sort(keys(snippets)), 'snippets[v:val] =~ pat') + let l:pat = '^' . join(split(l:tag_name, '\zs'), '\%(\|[^:-]\+-*\)') + let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat') + if len(l:vv) == 0 + let l:pat = '^' . join(split(l:tag_name, '\zs'), '[^:]\{-}') + let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat') + if len(l:vv) == 0 + let l:pat = '^' . join(split(l:tag_name, '\zs'), '.\{-}') + let l:vv = filter(sort(keys(l:snippets)), 'l:snippets[v:val] =~ l:pat') endif endif - let minl = -1 - for vk in vv - let vvs = snippets[vk] - if minl == -1 || len(vvs) < minl - let snippet_name = vk - let minl = len(vvs) + let l:minl = -1 + for l:vk in l:vv + let l:vvs = l:snippets[l:vk] + if l:minl == -1 || len(l:vvs) < l:minl + let l:snippet_name = l:vk + let l:minl = len(l:vvs) endif endfor endif endif - if has_key(snippets, snippet_name) - let snippet = snippets[snippet_name] - if use_pipe_for_cursor - let snippet = substitute(snippet, '|', '${cursor}', 'g') + if has_key(l:snippets, l:snippet_name) + let l:snippet = l:snippets[l:snippet_name] + if l:use_pipe_for_cursor + let l:snippet = substitute(l:snippet, '|', '${cursor}', 'g') endif - let lines = split(snippet, "\n") - call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")') - let current.snippet = join(lines, "\n") - let current.name = '' - let current.snippet = substitute(current.snippet, ';', value . ';', '') - if use_pipe_for_cursor && len(value) > 0 - let current.snippet = substitute(current.snippet, '\${cursor}', '', 'g') + let l:lines = split(l:snippet, "\n") + call map(l:lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(l:indent, "\\\\"), "g")') + let l:current.snippet = join(l:lines, "\n") + let l:current.name = '' + let l:current.snippet = substitute(l:current.snippet, ';', l:value . ';', '') + if l:use_pipe_for_cursor && len(l:value) > 0 + let l:current.snippet = substitute(l:current.snippet, '\${cursor}', '', 'g') endif - if n < len(tokens) - 1 - let current.snippet .= "\n" + if l:n < len(l:tokens) - 1 + let l:current.snippet .= "\n" endif endif endif - let current.pos = 0 - let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$') - if len(lg) == 0 - let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*)$') - if len(lg) - let [lg[1], lg[2], lg[3]] = ['linear', lg[1], lg[2]] + let l:current.pos = 0 + let l:lg = matchlist(l:token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$') + if len(l:lg) == 0 + let l:lg = matchlist(l:token, '^\%(linear-gradient\|lg\)(\s*\(\S\+\)\s*,\s*\([^,]\+\)\s*)$') + if len(l:lg) + let [l:lg[1], l:lg[2], l:lg[3]] = ['linear', l:lg[1], l:lg[2]] endif endif - if len(lg) - let current.name = '' - let current.snippet = printf("background-image:-webkit-gradient(%s, 0 0, 0 100%, from(%s), to(%s));\n", lg[1], lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - let current.snippet = printf("background-image:linear-gradient(%s, %s);\n", lg[2], lg[3]) - call add(root.child, deepcopy(current)) - elseif prefix - let snippet = current.snippet - let current.snippet = '-webkit-' . snippet . "\n" - call add(root.child, deepcopy(current)) - let current.snippet = '-moz-' . snippet . "\n" - call add(root.child, deepcopy(current)) - let current.snippet = '-o-' . snippet . "\n" - call add(root.child, deepcopy(current)) - let current.snippet = '-ms-' . snippet . "\n" - call add(root.child, deepcopy(current)) - let current.snippet = snippet - call add(root.child, current) - elseif token =~# '^c#\([0-9a-fA-F]\{3}\|[0-9a-fA-F]\{6}\)\(\.[0-9]\+\)\?' - let cs = split(token, '\.') - let current.name = '' - let [r,g,b] = [0,0,0] - if len(cs[0]) == 5 - let rgb = matchlist(cs[0], 'c#\(.\)\(.\)\(.\)') - let r = eval('0x'.rgb[1].rgb[1]) - let g = eval('0x'.rgb[2].rgb[2]) - let b = eval('0x'.rgb[3].rgb[3]) - elseif len(cs[0]) == 8 - let rgb = matchlist(cs[0], 'c#\(..\)\(..\)\(..\)') - let r = eval('0x'.rgb[1]) - let g = eval('0x'.rgb[2]) - let b = eval('0x'.rgb[3]) + if len(l:lg) + let l:current.name = '' + let l:current.snippet = printf("background-image:-webkit-gradient(%s, 0 0, 0 100%%, from(%s), to(%s));\n", l:lg[1], l:lg[2], l:lg[3]) + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = printf("background-image:-webkit-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3]) + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = printf("background-image:-moz-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3]) + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = printf("background-image:-o-linear-gradient(%s, %s);\n", l:lg[2], l:lg[3]) + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = printf("background-image:linear-gradient(%s, %s);\n", l:lg[2], l:lg[3]) + call add(l:root.child, deepcopy(l:current)) + elseif l:prefix + let l:snippet = l:current.snippet + let l:current.snippet = '-webkit-' . l:snippet . "\n" + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = '-moz-' . l:snippet . "\n" + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = '-o-' . l:snippet . "\n" + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = '-ms-' . l:snippet . "\n" + call add(l:root.child, deepcopy(l:current)) + let l:current.snippet = l:snippet + call add(l:root.child, l:current) + elseif l:token =~# '^c#\([0-9a-fA-F]\{3}\|[0-9a-fA-F]\{6}\)\(\.[0-9]\+\)\?' + let l:cs = split(l:token, '\.') + let l:current.name = '' + let [l:r,l:g,l:b] = [0,0,0] + if len(l:cs[0]) == 5 + let l:rgb = matchlist(l:cs[0], 'c#\(.\)\(.\)\(.\)') + let l:r = eval('0x'.l:rgb[1].l:rgb[1]) + let l:g = eval('0x'.l:rgb[2].l:rgb[2]) + let l:b = eval('0x'.l:rgb[3].l:rgb[3]) + elseif len(l:cs[0]) == 8 + let l:rgb = matchlist(l:cs[0], 'c#\(..\)\(..\)\(..\)') + let l:r = eval('0x'.l:rgb[1]) + let l:g = eval('0x'.l:rgb[2]) + let l:b = eval('0x'.l:rgb[3]) endif - if len(cs) == 1 - let current.snippet = printf('color:rgb(%d, %d, %d);', r, g, b) + if len(l:cs) == 1 + let l:current.snippet = printf('color:rgb(%d, %d, %d);', l:r, l:g, l:b) else - let current.snippet = printf('color:rgb(%d, %d, %d, %s);', r, g, b, string(str2float('0.'.cs[1]))) + let l:current.snippet = printf('color:rgb(%d, %d, %d, %s);', l:r, l:g, l:b, string(str2float('0.'.l:cs[1]))) endif - call add(root.child, current) - elseif token =~# '^c#' - let current.name = '' - let current.snippet = 'color:\${cursor};' - call add(root.child, current) + call add(l:root.child, l:current) + elseif l:token =~# '^c#' + let l:current.name = '' + let l:current.snippet = 'color:\${cursor};' + call add(l:root.child, l:current) else - call add(root.child, current) + call add(l:root.child, l:current) endif endfor endif - return root + return l:root endfunction function! emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) abort - let current = a:current - let value = current.value[1:-2] - let tmp = substitute(value, '\${cursor}', '', 'g') - if tmp !~ '.*{[ \t\r\n]*}$' + let l:current = a:current + let l:value = l:current.value[1:-2] + let l:tmp = substitute(l:value, '\${cursor}', '', 'g') + if l:tmp !~ '.*{[ \t\r\n]*}$' if emmet#useFilter(a:filters, 'fc') - let value = substitute(value, '\([^:]\+\):\([^;]*\)', '\1: \2', 'g') + let l:value = substitute(l:value, '\([^:]\+\):\([^;]*\)', '\1: \2', 'g') else - let value = substitute(value, '\([^:]\+\):\([^;]*\)', '\1:\2', 'g') + let l:value = substitute(l:value, '\([^:]\+\):\([^;]*\)', '\1:\2', 'g') endif - if current.important - let value = substitute(value, ';', ' !important;', '') + if l:current.important + let l:value = substitute(l:value, ';', ' !important;', '') endif endif - return value + return l:value endfunction function! emmet#lang#css#imageSize() abort - let img_region = emmet#util#searchRegion('{', '}') - if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region) + let l:img_region = emmet#util#searchRegion('{', '}') + if !emmet#util#regionIsValid(l:img_region) || !emmet#util#cursorInRegion(l:img_region) return endif - let content = emmet#util#getContent(img_region) - let fn = matchstr(content, '\') - if len(node) - exe "normal ciw\='/* '.node.' */'\" + let l:node = expand('') + if len(l:node) + exe "normal ciw\='/* '.l:node.' */'\" endif endif else - if line =~# mx - let space = substitute(matchstr(line, mx), mx, '\1', '') - let line = substitute(matchstr(line, mx), mx, '\2', '') - let line = space . substitute(line, '^\s*\|\s*$', '\1', 'g') + if l:line =~# l:mx + let l:space = substitute(matchstr(l:line, l:mx), l:mx, '\1', '') + let l:line = substitute(matchstr(l:line, l:mx), l:mx, '\2', '') + let l:line = l:space . substitute(l:line, '^\s*\|\s*$', '\1', 'g') else - let mx = '^\(\s*\)\(''[^'']*''\|[^'']*\|;\)\s*$' + let l:mx = '^\(\s*\)\(''[^'']*''\|[^'']*\|;\)\s*$' " TODO multi-property - "let mx = '^\(\s*\)\(\%(''[^'']*''\|[^'';]\+\)*;\{0,1}\)' - let line = substitute(line, mx, '\1/* \2 */', '') + "let l:mx = '^\(\s*\)\(\%(''[^'']*''\|[^'';]\+\)*;\{0,1}\)' + let l:line = substitute(l:line, l:mx, '\1/* \2 */', '') endif - call setline('.', line) + call setline('.', l:line) endif endfunction function! emmet#lang#css#balanceTag(flag) range abort if a:flag == -2 || a:flag == 2 - let curpos = [0, line("'<"), col("'<"), 0] + let l:curpos = [0, line("'<"), col("'<"), 0] else - let curpos = emmet#util#getcurpos() + let l:curpos = emmet#util#getcurpos() endif - let block = emmet#util#getVisualBlock() - if !emmet#util#regionIsValid(block) + let l:block = emmet#util#getVisualBlock() + if !emmet#util#regionIsValid(l:block) if a:flag > 0 - let block = emmet#util#searchRegion('^', ';') - if emmet#util#regionIsValid(block) - call emmet#util#selectRegion(block) + let l:block = emmet#util#searchRegion('^', ';') + if emmet#util#regionIsValid(l:block) + call emmet#util#selectRegion(l:block) return endif endif else if a:flag > 0 - let content = emmet#util#getContent(block) - if content !~# '^{.*}$' - let block = emmet#util#searchRegion('{', '}') - if emmet#util#regionIsValid(block) - call emmet#util#selectRegion(block) + let l:content = emmet#util#getContent(l:block) + if l:content !~# '^{.*}$' + let l:block = emmet#util#searchRegion('{', '}') + if emmet#util#regionIsValid(l:block) + call emmet#util#selectRegion(l:block) return endif endif else - let pos = searchpos('.*;', 'nW') - if pos[0] != 0 - call setpos('.', [0, pos[0], pos[1], 0]) - let block = emmet#util#searchRegion('^', ';') - if emmet#util#regionIsValid(block) - call emmet#util#selectRegion(block) + let l:pos = searchpos('.*;', 'nW') + if l:pos[0] != 0 + call setpos('.', [0, l:pos[0], l:pos[1], 0]) + let l:block = emmet#util#searchRegion('^', ';') + if emmet#util#regionIsValid(l:block) + call emmet#util#selectRegion(l:block) return endif endif @@ -359,7 +359,7 @@ function! emmet#lang#css#balanceTag(flag) range abort if a:flag == -2 || a:flag == 2 silent! exe 'normal! gv' else - call setpos('.', curpos) + call setpos('.', l:curpos) endif endfunction diff --git a/autoload/emmet/lang/elm.vim b/autoload/emmet/lang/elm.vim index ce663bd..bbab6f8 100644 --- a/autoload/emmet/lang/elm.vim +++ b/autoload/emmet/lang/elm.vim @@ -3,24 +3,24 @@ function! emmet#lang#elm#findTokens(str) abort endfunction function! emmet#lang#elm#parseIntoTree(abbr, type) abort - let tree = emmet#lang#html#parseIntoTree(a:abbr, a:type) - if len(tree.child) < 2 | return tree | endif + let l:tree = emmet#lang#html#parseIntoTree(a:abbr, a:type) + if len(l:tree.child) < 2 | return l:tree | endif " Add ',' nodes between root elements. - let new_children = [] - for child in tree.child[0:-2] - let comma = emmet#newNode() - let comma.name = ',' - call add(new_children, child) - call add(new_children, comma) + let l:new_children = [] + for l:child in l:tree.child[0:-2] + let l:comma = emmet#newNode() + let l:comma.name = ',' + call add(l:new_children, l:child) + call add(l:new_children, l:comma) endfor - call add(new_children, tree.child[-1]) - let tree.child = new_children - return tree + call add(l:new_children, l:tree.child[-1]) + let l:tree.child = l:new_children + return l:tree endfunction function! emmet#lang#elm#renderNode(node) - let elm_nodes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6' + let l:elm_nodes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6' \, 'div', 'p', 'hr', 'pre', 'blockquote' \, 'span', 'a', 'code', 'em', 'strong', 'i', 'b', 'u', 'sub', 'sup', 'br' \, 'ol', 'ul', 'li', 'dl', 'dt', 'dd' @@ -37,14 +37,14 @@ function! emmet#lang#elm#renderNode(node) \, 'mark', 'ruby', 'rt', 'rp', 'bdi', 'bdo', 'wbr' \, 'details', 'summary', 'menuitem', 'menu'] - if index(elm_nodes, a:node) >= 0 + if index(l:elm_nodes, a:node) >= 0 return a:node endif return 'node "' . a:node . '"' endfunction function! emmet#lang#elm#renderParam(param) - let elm_events = ["onClick", "onDoubleClick" + let l:elm_events = ["onClick", "onDoubleClick" \, "onMouseDown", "onMouseUp" \, "onMouseEnter", "onMouseLeave" \, "onMouseOver", "onMouseOut" @@ -52,10 +52,10 @@ function! emmet#lang#elm#renderParam(param) \, "onBlur", "onFocus" \, "on", "onWithOptions", "Options", "defaultOptions" \, "targetValue", "targetChecked", "keyCode"] - if index(elm_events, a:param) >= 0 + if index(l:elm_events, a:param) >= 0 return a:param endif - let elm_attributes = ["style", "map" , "class", "id", "title", "hidden" + let l:elm_attributes = ["style", "map" , "class", "id", "title", "hidden" \, "type", "type_", "value", "defaultValue", "checked", "placeholder", "selected" \, "accept", "acceptCharset", "action", "autocomplete", "autofocus" \, "disabled", "enctype", "formaction", "list", "maxlength", "minlength", "method", "multiple" @@ -75,7 +75,7 @@ function! emmet#lang#elm#renderParam(param) \, "challenge", "keytype" \, "cite", "datetime", "pubdate", "manifest"] - if index(elm_attributes, a:param) >= 0 + if index(l:elm_attributes, a:param) >= 0 if a:param == 'type' return 'type_' endif @@ -85,130 +85,130 @@ function! emmet#lang#elm#renderParam(param) endfunction function! emmet#lang#elm#toString(settings, current, type, inline, filters, itemno, indent) abort - let settings = a:settings - let current = a:current - let type = a:type - let inline = a:inline - let filters = a:filters - let itemno = a:itemno - let indent = emmet#getIndentation(type) - let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) - let str = '' + let l:settings = a:settings + let l:current = a:current + let l:type = a:type + let l:inline = a:inline + let l:filters = a:filters + let l:itemno = a:itemno + let l:indent = emmet#getIndentation(l:type) + let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1) + let l:str = '' " comma between items with *, eg. li*3 - if itemno > 0 - let str = ", " + if l:itemno > 0 + let l:str = ", " endif - let current_name = current.name - if dollar_expr - let current_name = substitute(current.name, '\$$', itemno+1, '') + let l:current_name = l:current.name + if l:dollar_expr + let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '') endif - if len(current.name) > 0 + if len(l:current.name) > 0 " inserted root comma nodes - if current_name == ',' + if l:current_name == ',' return "\n, " endif - let str .= emmet#lang#elm#renderNode(current_name) - let tmp = '' - for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) - if !has_key(current.attr, attr) + let l:str .= emmet#lang#elm#renderNode(l:current_name) + let l:tmp = '' + for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr)) + if !has_key(l:current.attr, l:attr) continue endif - let Val = current.attr[attr] + let l:Val = l:current.attr[l:attr] - let attr = emmet#lang#elm#renderParam(attr) + let l:attr = emmet#lang#elm#renderParam(l:attr) - if type(Val) == 2 && Val == function('emmet#types#true') - let tmp .= ', ' . attr . ' True' + if type(l:Val) == 2 && l:Val == function('emmet#types#true') + let l:tmp .= ', ' . l:attr . ' True' else - if dollar_expr - while Val =~# '\$\([^#{]\|$\)' - let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') + if l:dollar_expr + while l:Val =~# '\$\([^#{]\|$\)' + let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g') endwhile - let attr = substitute(attr, '\$$', itemno+1, '') + let l:attr = substitute(l:attr, '\$$', l:itemno+1, '') endif - let valtmp = substitute(Val, '\${cursor}', '', '') - if attr ==# 'id' && len(valtmp) > 0 - let tmp .=', id "' . Val . '"' - elseif attr ==# 'class' && len(valtmp) > 0 - let tmp .= ', class "' . substitute(Val, '\.', ' ', 'g') . '"' + let l:valtmp = substitute(l:Val, '\${cursor}', '', '') + if l:attr ==# 'id' && len(l:valtmp) > 0 + let l:tmp .=', id "' . l:Val . '"' + elseif l:attr ==# 'class' && len(l:valtmp) > 0 + let l:tmp .= ', class "' . substitute(l:Val, '\.', ' ', 'g') . '"' else - let tmp .= ', ' . attr . ' "' . Val . '"' + let l:tmp .= ', ' . l:attr . ' "' . l:Val . '"' endif endif endfor - if ! len(tmp) - let str .= ' []' + if ! len(l:tmp) + let l:str .= ' []' else - let tmp = strpart(tmp, 2) - let str .= ' [ ' . tmp . ' ]' + let l:tmp = strpart(l:tmp, 2) + let l:str .= ' [ ' . l:tmp . ' ]' endif " No children quit early - if len(current.child) == 0 && len(current.value) == 0 + if len(l:current.child) == 0 && len(l:current.value) == 0 "Place cursor in node with no value or children - let str .= ' [${cursor}]' - return str + let l:str .= ' [${cursor}]' + return l:str endif - let inner = '' + let l:inner = '' " Parent contex text - if len(current.value) > 0 - let text = current.value[1:-2] - if dollar_expr - let text = substitute(text, '\%(\\\)\@\ 0 + let l:text = l:current.value[1:-2] + if l:dollar_expr + let l:text = substitute(l:text, '\%(\\\)\@\ 0 + for l:child in l:current.child + if len(l:child.name) == 0 && len(l:child.value) > 0 " Text node - let text = child.value[1:-2] - if dollar_expr - let text = substitute(text, '\%(\\\)\@\ 0 - let str .= '%' . current_name - let tmp = '' - for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) - if !has_key(current.attr, attr) + if len(l:current.name) > 0 + let l:str .= '%' . l:current_name + let l:tmp = '' + for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr)) + if !has_key(l:current.attr, l:attr) continue endif - let Val = current.attr[attr] - if type(Val) == 2 && Val == function('emmet#types#true') - if attribute_style ==# 'hash' - let tmp .= ' :' . attr . ' => true' - elseif attribute_style ==# 'html' - let tmp .= attr . '=true' + let l:Val = l:current.attr[l:attr] + if type(l:Val) == 2 && l:Val == function('emmet#types#true') + if l:attribute_style ==# 'hash' + let l:tmp .= ' :' . l:attr . ' => true' + elseif l:attribute_style ==# 'html' + let l:tmp .= l:attr . '=true' end else - if dollar_expr - while Val =~# '\$\([^#{]\|$\)' - let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') + if l:dollar_expr + while l:Val =~# '\$\([^#{]\|$\)' + let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g') endwhile - let attr = substitute(attr, '\$$', itemno+1, '') + let l:attr = substitute(l:attr, '\$$', l:itemno+1, '') endif - let valtmp = substitute(Val, '\${cursor}', '', '') - if attr ==# 'id' && len(valtmp) > 0 - let str .= '#' . Val - elseif attr ==# 'class' && len(valtmp) > 0 - let str .= '.' . substitute(Val, ' ', '.', 'g') + let l:valtmp = substitute(l:Val, '\${cursor}', '', '') + if l:attr ==# 'id' && len(l:valtmp) > 0 + let l:str .= '#' . l:Val + elseif l:attr ==# 'class' && len(l:valtmp) > 0 + let l:str .= '.' . substitute(l:Val, ' ', '.', 'g') else - if len(tmp) > 0 - if attribute_style ==# 'hash' - let tmp .= ',' - elseif attribute_style ==# 'html' - let tmp .= ' ' + if len(l:tmp) > 0 + if l:attribute_style ==# 'hash' + let l:tmp .= ',' + elseif l:attribute_style ==# 'html' + let l:tmp .= ' ' endif endif - if attribute_style ==# 'hash' - let tmp .= ' :' . attr . ' => "' . Val . '"' - elseif attribute_style ==# 'html' - let tmp .= attr . '="' . Val . '"' + if l:attribute_style ==# 'hash' + let l:tmp .= ' :' . l:attr . ' => "' . l:Val . '"' + elseif l:attribute_style ==# 'html' + let l:tmp .= l:attr . '="' . l:Val . '"' end endif endif endfor - if len(tmp) - if attribute_style ==# 'hash' - let str .= '{' . tmp . ' }' - elseif attribute_style ==# 'html' - let str .= '(' . tmp . ')' + if len(l:tmp) + if l:attribute_style ==# 'hash' + let l:str .= '{' . l:tmp . ' }' + elseif l:attribute_style ==# 'html' + let l:str .= '(' . l:tmp . ')' end endif - if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0 - let str .= '/' + if stridx(','.l:settings.html.empty_elements.',', ','.l:current_name.',') != -1 && len(l:current.value) == 0 + let l:str .= '/' endif - let inner = '' - if len(current.value) > 0 - let text = current.value[1:-2] - if dollar_expr - let text = substitute(text, '\%(\\\)\@\ 0 + let l:text = l:current.value[1:-2] + if l:dollar_expr + let l:text = substitute(l:text, '\%(\\\)\@\ 0 - for child in current.child - let inner .= emmet#toString(child, type, inline, filters, itemno, indent) + elseif len(l:current.child) > 0 + for l:child in l:current.child + let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent) endfor - let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') - let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') - let str .= "\n" . indent . inner + let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g') + let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g') + let l:str .= "\n" . l:indent . l:inner endif else - let str = current.value[1:-2] - if dollar_expr - let str = substitute(str, '\%(\\\)\@\\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' - while len(attrs) > 0 - let match = matchstr(attrs, mx) - if len(match) ==# 0 + let l:current = emmet#newNode() + let l:mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)' + let l:match = matchstr(a:tag, l:mx) + let l:current.name = substitute(l:match, l:mx, '\1', '') + let l:attrs = substitute(l:match, l:mx, '\2', '') + let l:mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' + while len(l:attrs) > 0 + let l:match = matchstr(l:attrs, l:mx) + if len(l:match) ==# 0 break endif - let attr_match = matchlist(match, mx) - let name = attr_match[1] - let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] - let current.attr[name] = value - let current.attrs_order += [name] - let attrs = attrs[stridx(attrs, match) + len(match):] + let l:attr_match = matchlist(l:match, l:mx) + let l:name = l:attr_match[1] + let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3] + let l:current.attr[l:name] = l:value + let l:current.attrs_order += [l:name] + let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):] endwhile - return current + return l:current endfunction function! emmet#lang#haml#toggleComment() abort - let line = getline('.') - let space = matchstr(line, '^\s*') - if line =~# '^\s*-#' - call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*')) - elseif line =~# '^\s*%[a-z]' - call setline('.', space . '-# ' . line[len(space):]) + let l:line = getline('.') + let l:space = matchstr(l:line, '^\s*') + if l:line =~# '^\s*-#' + call setline('.', l:space . matchstr(l:line[len(l:space)+2:], '^\s*\zs.*')) + elseif l:line =~# '^\s*%[a-z]' + call setline('.', l:space . '-# ' . l:line[len(l:space):]) endif endfunction function! emmet#lang#haml#balanceTag(flag) range abort - let block = emmet#util#getVisualBlock() + let l:block = emmet#util#getVisualBlock() if a:flag == -2 || a:flag == 2 - let curpos = [0, line("'<"), col("'<"), 0] + let l:curpos = [0, line("'<"), col("'<"), 0] else - let curpos = emmet#util#getcurpos() + let l:curpos = emmet#util#getcurpos() endif - let n = curpos[1] - let ml = len(matchstr(getline(n), '^\s*')) + let l:n = l:curpos[1] + let l:ml = len(matchstr(getline(l:n), '^\s*')) if a:flag > 0 - if a:flag == 1 || !emmet#util#regionIsValid(block) - let n = line('.') + if a:flag == 1 || !emmet#util#regionIsValid(l:block) + let l:n = line('.') else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze%[a-z]')) - if l > 0 && l < ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze%[a-z]')) + if l:l > 0 && l:l < l:ml + let l:ml = l:l break endif - let n -= 1 + let l:n -= 1 endwhile endif - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*%[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) - if l > 0 && l > ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]')) + if l:l > 0 && l:l > l:ml + let l:ml = l:l break endif - let n += 1 + let l:n += 1 endwhile - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*%[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) endif endfunction @@ -260,76 +260,76 @@ function! emmet#lang#haml#moveNextPrevItem(flag) abort endfunction function! emmet#lang#haml#moveNextPrev(flag) abort - let pos = search('""', a:flag ? 'Wb' : 'W') - if pos != 0 + let l:pos = search('""', a:flag ? 'Wb' : 'W') + if l:pos != 0 silent! normal! l startinsert endif endfunction function! emmet#lang#haml#splitJoinTag() abort - let n = line('.') - let sml = len(matchstr(getline(n), '^\s*%[a-z]')) - while n > 0 - if getline(n) =~# '^\s*\ze%[a-z]' - if len(matchstr(getline(n), '^\s*%[a-z]')) < sml + let l:n = line('.') + let l:sml = len(matchstr(getline(l:n), '^\s*%[a-z]')) + while l:n > 0 + if getline(l:n) =~# '^\s*\ze%[a-z]' + if len(matchstr(getline(l:n), '^\s*%[a-z]')) < l:sml break endif - let line = getline(n) - call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) - let sn = n - let n += 1 - let ml = len(matchstr(getline(n), '^\s*%[a-z]')) - if len(matchstr(getline(n), '^\s*')) > ml - while n <= line('$') - let l = len(matchstr(getline(n), '^\s*')) - if l <= ml + let l:line = getline(l:n) + call setline(l:n, substitute(l:line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) + let l:sn = l:n + let l:n += 1 + let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if len(matchstr(getline(l:n), '^\s*')) > l:ml + while l:n <= line('$') + let l:l = len(matchstr(getline(l:n), '^\s*')) + if l:l <= l:ml break endif - exe n 'delete' + exe l:n 'delete' endwhile - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) else - let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)') - let spaces = matchstr(getline(sn), '^\s*') - let settings = emmet#getSettings() - if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1 - call append(sn, spaces . ' ') - call setpos('.', [0, sn+1, 1, 0]) + let l:tag = matchstr(getline(l:sn), '^\s*%\zs\(\w\+\)') + let l:spaces = matchstr(getline(l:sn), '^\s*') + let l:settings = emmet#getSettings() + if stridx(','.l:settings.html.inline_elements.',', ','.l:tag.',') == -1 + call append(l:sn, l:spaces . ' ') + call setpos('.', [0, l:sn+1, 1, 0]) else - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) endif startinsert! endif break endif - let n -= 1 + let l:n -= 1 endwhile endfunction function! emmet#lang#haml#removeTag() abort - let n = line('.') - let ml = 0 - while n > 0 - if getline(n) =~# '^\s*\ze[a-z]' - let ml = len(matchstr(getline(n), '^\s*%[a-z]')) + let l:n = line('.') + let l:ml = 0 + while l:n > 0 + if getline(l:n) =~# '^\s*\ze[a-z]' + let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]')) break endif - let n -= 1 + let l:n -= 1 endwhile - let sn = n - while n < line('$') - let l = len(matchstr(getline(n), '^\s*%[a-z]')) - if l > 0 && l <= ml - let n -= 1 + let l:sn = l:n + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - if sn == n + if l:sn == l:n exe 'delete' else - exe sn ',' (n-1) 'delete' + exe l:sn ',' (l:n-1) 'delete' endif endfunction diff --git a/autoload/emmet/lang/html.vim b/autoload/emmet/lang/html.vim index 20bbf1c..dfb04b9 100644 --- a/autoload/emmet/lang/html.vim +++ b/autoload/emmet/lang/html.vim @@ -14,54 +14,54 @@ let s:mx = '\([+>]\|[<^]\+\)\{-}' \ .'\(\%()\%(\(@-\{0,1}[0-9]*\)\{0,1}\*[0-9]\+\)\{0,1}\)*\)' function! emmet#lang#html#findTokens(str) abort - let str = a:str - let [pos, last_pos] = [0, 0] + let l:str = a:str + let [l:pos, l:last_pos] = [0, 0] while 1 - let tag = matchstr(str, '<[a-zA-Z].\{-}>', pos) - if len(tag) == 0 + let l:tag = matchstr(l:str, '<[a-zA-Z].\{-}>', l:pos) + if len(l:tag) == 0 break endif - let pos = stridx(str, tag, pos) + len(tag) + let l:pos = stridx(l:str, l:tag, l:pos) + len(l:tag) endwhile while 1 - let tag = matchstr(str, '{%[^%]\{-}%}', pos) - if len(tag) == 0 + let l:tag = matchstr(l:str, '{%[^%]\{-}%}', l:pos) + if len(l:tag) == 0 break endif - let pos = stridx(str, tag, pos) + len(tag) + let l:pos = stridx(l:str, l:tag, l:pos) + len(l:tag) endwhile - let last_pos = pos - while len(str) > 0 - let white = matchstr(str, '^\s\+', pos) - if white != '' - let last_pos = pos + len(white) - let pos = last_pos + let l:last_pos = l:pos + while len(l:str) > 0 + let l:white = matchstr(l:str, '^\s\+', l:pos) + if l:white != '' + let l:last_pos = l:pos + len(l:white) + let l:pos = l:last_pos endif - let token = matchstr(str, s:mx, pos) - if token ==# '' + let l:token = matchstr(l:str, s:mx, l:pos) + if l:token ==# '' break endif - let pos = stridx(str, token, pos) + len(token) + let l:pos = stridx(l:str, l:token, l:pos) + len(l:token) endwhile - let str = a:str[last_pos :-1] - if str =~# '^\w\+="[^"]*$' + let l:str = a:str[l:last_pos :-1] + if l:str =~# '^\w\+="[^"]*$' return '' endif - return str + return l:str endfunction function! emmet#lang#html#parseIntoTree(abbr, type) abort - let abbr = a:abbr - let type = a:type + let l:abbr = a:abbr + let l:type = a:type - let settings = emmet#getSettings() - if !has_key(settings, type) - let type = 'html' + let l:settings = emmet#getSettings() + if !has_key(l:settings, l:type) + let l:type = 'html' endif - if len(type) == 0 | let type = 'html' | endif + if len(l:type) == 0 | let l:type = 'html' | endif - let indent = emmet#getIndentation(type) - let pmap = { + let l:indent = emmet#getIndentation(l:type) + let l:pmap = { \'p': 'span', \'ul': 'li', \'ol': 'li', @@ -79,198 +79,198 @@ function! emmet#lang#html#parseIntoTree(abbr, type) abort \'map': 'area' \} - let inlineLevel = split('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var',',') + let l:inlineLevel = split('a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var',',') - let custom_expands = emmet#getResource(type, 'custom_expands', {}) - if empty(custom_expands) && has_key(settings, 'custom_expands') - let custom_expands = settings['custom_expands'] + let l:custom_expands = emmet#getResource(l:type, 'custom_expands', {}) + if empty(l:custom_expands) && has_key(l:settings, 'custom_expands') + let l:custom_expands = l:settings['custom_expands'] endif " try 'foo' to (foo-x) - let rabbr = emmet#getExpandos(type, abbr) - if rabbr == abbr + let l:rabbr = emmet#getExpandos(l:type, l:abbr) + if l:rabbr == l:abbr " try 'foo+(' to (foo-x) - let rabbr = substitute(abbr, '\%(+\|^\)\([a-zA-Z][a-zA-Z0-9+]\+\)+\([(){}>]\|$\)', '\="(".emmet#getExpandos(type, submatch(1)).")".submatch(2)', 'i') + let l:rabbr = substitute(l:abbr, '\%(+\|^\)\([a-zA-Z][a-zA-Z0-9+]\+\)+\([(){}>]\|$\)', '\="(".emmet#getExpandos(l:type, submatch(1)).")".submatch(2)', 'i') endif - let abbr = rabbr + let l:abbr = l:rabbr - let root = emmet#newNode() - let root['variables'] = {} - let parent = root - let last = root - let pos = [] - while len(abbr) + let l:root = emmet#newNode() + let l:root['variables'] = {} + let l:parent = l:root + let l:last = l:root + let l:pos = [] + while len(l:abbr) " parse line - let match = matchstr(abbr, s:mx) - let str = substitute(match, s:mx, '\0', 'ig') - let operator = substitute(match, s:mx, '\1', 'ig') - let block_start = substitute(match, s:mx, '\2', 'ig') - let tag_name = substitute(match, s:mx, '\3', 'ig') - let attributes = substitute(match, s:mx, '\4', 'ig') - let value = substitute(match, s:mx, '\5', 'ig') - let basevalue = substitute(match, s:mx, '\6', 'ig') - let multiplier = 0 + substitute(match, s:mx, '\7', 'ig') - let block_end = substitute(match, s:mx, '\8', 'ig') - let custom = '' - let important = 0 - if len(str) == 0 + let l:match = matchstr(l:abbr, s:mx) + let l:str = substitute(l:match, s:mx, '\0', 'ig') + let l:operator = substitute(l:match, s:mx, '\1', 'ig') + let l:block_start = substitute(l:match, s:mx, '\2', 'ig') + let l:tag_name = substitute(l:match, s:mx, '\3', 'ig') + let l:attributes = substitute(l:match, s:mx, '\4', 'ig') + let l:value = substitute(l:match, s:mx, '\5', 'ig') + let l:basevalue = substitute(l:match, s:mx, '\6', 'ig') + let l:multiplier = 0 + substitute(l:match, s:mx, '\7', 'ig') + let l:block_end = substitute(l:match, s:mx, '\8', 'ig') + let l:custom = '' + let l:important = 0 + if len(l:str) == 0 break endif - if tag_name =~# '^#' - let attributes = tag_name . attributes - let tag_name = '' + if l:tag_name =~# '^#' + let l:attributes = l:tag_name . l:attributes + let l:tag_name = '' endif - if tag_name =~# '[^!]!$' - let tag_name = tag_name[:-2] - let important = 1 + if l:tag_name =~# '[^!]!$' + let l:tag_name = l:tag_name[:-2] + let l:important = 1 endif - if tag_name =~# '^\.' - let attributes = tag_name . attributes - let tag_name = '' + if l:tag_name =~# '^\.' + let l:attributes = l:tag_name . l:attributes + let l:tag_name = '' endif - if tag_name =~# '^\[.*\]$' - let attributes = tag_name . attributes - let tag_name = '' + if l:tag_name =~# '^\[.*\]$' + let l:attributes = l:tag_name . l:attributes + let l:tag_name = '' endif - for k in keys(custom_expands) - if tag_name =~ k - let custom = tag_name - let tag_name = '' + for l:k in keys(l:custom_expands) + if l:tag_name =~ l:k + let l:custom = l:tag_name + let l:tag_name = '' break endif endfor - if empty(tag_name) - let pname = len(parent.child) > 0 ? parent.child[0].name : '' - if !empty(pname) && has_key(pmap, pname) && custom == '' - let tag_name = pmap[pname] - elseif !empty(pname) && index(inlineLevel, pname) > -1 - let tag_name = 'span' - elseif len(custom) == 0 - let tag_name = 'div' - elseif len(custom) != 0 && multiplier > 1 - let tag_name = 'div' + if empty(l:tag_name) + let l:pname = len(l:parent.child) > 0 ? l:parent.child[0].name : '' + if !empty(l:pname) && has_key(l:pmap, l:pname) && l:custom == '' + let l:tag_name = l:pmap[l:pname] + elseif !empty(l:pname) && index(l:inlineLevel, l:pname) > -1 + let l:tag_name = 'span' + elseif len(l:custom) == 0 + let l:tag_name = 'div' + elseif len(l:custom) != 0 && l:multiplier > 1 + let l:tag_name = 'div' else - let tag_name = custom + let l:tag_name = l:custom endif endif - let basedirect = basevalue[1] ==# '-' ? -1 : 1 - if basevalue != '' - let basevalue = 0 + abs(basevalue[1:]) + let l:basedirect = l:basevalue[1] ==# '-' ? -1 : 1 + if l:basevalue != '' + let l:basevalue = 0 + abs(l:basevalue[1:]) else - let basevalue = 1 + let l:basevalue = 1 endif - if multiplier <= 0 | let multiplier = 1 | endif + if l:multiplier <= 0 | let l:multiplier = 1 | endif " make default node - let current = emmet#newNode() + let l:current = emmet#newNode() - let current.name = tag_name - let current.important = important + let l:current.name = l:tag_name + let l:current.important = l:important " aliases - let aliases = emmet#getResource(type, 'aliases', {}) - if has_key(aliases, tag_name) - let current.name = aliases[tag_name] + let l:aliases = emmet#getResource(l:type, 'aliases', {}) + if has_key(l:aliases, l:tag_name) + let l:current.name = l:aliases[l:tag_name] endif - 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) " snippets - let snippets = emmet#getResource(type, 'snippets', {}) - if !empty(snippets) - let snippet_name = tag_name - if has_key(snippets, snippet_name) - let snippet = snippet_name - while has_key(snippets, snippet) - let snippet = snippets[snippet] + let l:snippets = emmet#getResource(l:type, 'snippets', {}) + if !empty(l:snippets) + let l:snippet_name = l:tag_name + if has_key(l:snippets, l:snippet_name) + let l:snippet = l:snippet_name + while has_key(l:snippets, l:snippet) + let l:snippet = l:snippets[l:snippet] endwhile - if use_pipe_for_cursor - let snippet = substitute(snippet, '|', '${cursor}', 'g') + if l:use_pipe_for_cursor + let l:snippet = substitute(l:snippet, '|', '${cursor}', 'g') endif " just redirect to expanding - if type == 'html' && snippet !~ '^\s*[{\[<]' - return emmet#lang#html#parseIntoTree(snippet, a:type) + if l:type == 'html' && l:snippet !~ '^\s*[{\[<]' + return emmet#lang#html#parseIntoTree(l:snippet, a:type) endif - let lines = split(snippet, "\n", 1) - call map(lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(indent, "\\\\"), "g")') - let current.snippet = join(lines, "\n") - let current.name = '' + let l:lines = split(l:snippet, "\n", 1) + call map(l:lines, 'substitute(v:val, "\\( \\|\\t\\)", escape(l:indent, "\\\\"), "g")') + let l:current.snippet = join(l:lines, "\n") + let l:current.name = '' endif endif - for k in keys(custom_expands) - if tag_name =~# k - let snippet = '${' . (empty(custom) ? tag_name : custom) . '}' - let current.name = '' - let current.snippet = snippet + for l:k in keys(l:custom_expands) + if l:tag_name =~# l:k + let l:snippet = '${' . (empty(l:custom) ? l:tag_name : l:custom) . '}' + let l:current.name = '' + let l:current.snippet = l:snippet break - elseif custom =~# k - let snippet = '${' . custom . '}' - let current.snippet = '${' . custom . '}' - if current.name != '' - let snode = emmet#newNode() - let snode.snippet = snippet - let snode.parent = current - call add(current.child, snode) + elseif l:custom =~# l:k + let l:snippet = '${' . l:custom . '}' + let l:current.snippet = '${' . l:custom . '}' + if l:current.name != '' + let l:snode = emmet#newNode() + let l:snode.snippet = l:snippet + let l:snode.parent = l:current + call add(l:current.child, l:snode) else - let current.snippet = snippet + let l:current.snippet = l:snippet endif break endif endfor " default_attributes - let default_attributes = emmet#getResource(type, 'default_attributes', {}) - if !empty(default_attributes) - for pat in [current.name, tag_name] - if has_key(default_attributes, pat) - if type(default_attributes[pat]) == 4 - let a = default_attributes[pat] - let current.attrs_order += keys(a) - if use_pipe_for_cursor - for k in keys(a) - if type(a[k]) == 7 - call remove(current.attr, k) + let l:default_attributes = emmet#getResource(l:type, 'default_attributes', {}) + if !empty(l:default_attributes) + for l:pat in [l:current.name, l:tag_name] + if has_key(l:default_attributes, l:pat) + if type(l:default_attributes[l:pat]) == 4 + let l:a = l:default_attributes[l:pat] + let l:current.attrs_order += keys(l:a) + if l:use_pipe_for_cursor + for l:k in keys(l:a) + if type(l:a[l:k]) == 7 + call remove(l:current.attr, l:k) continue endif - let current.attr[k] = len(a[k]) ? substitute(a[k], '|', '${cursor}', 'g') : '${cursor}' + let l:current.attr[l:k] = len(l:a[l:k]) ? substitute(l:a[l:k], '|', '${cursor}', 'g') : '${cursor}' endfor else - for k in keys(a) - if type(a[k]) == 7 - call remove(current.attr, k) + for l:k in keys(l:a) + if type(l:a[l:k]) == 7 + call remove(l:current.attr, l:k) continue endif - let current.attr[k] = a[k] + let l:current.attr[l:k] = l:a[l:k] endfor endif else - for a in default_attributes[pat] - let current.attrs_order += keys(a) - if use_pipe_for_cursor - for k in keys(a) - if type(a[k]) == 7 - call remove(current.attr, k) + for l:a in l:default_attributes[l:pat] + let l:current.attrs_order += keys(l:a) + if l:use_pipe_for_cursor + for l:k in keys(l:a) + if type(l:a[l:k]) == 7 + call remove(l:current.attr, l:k) continue endif - let current.attr[k] = len(a[k]) ? substitute(a[k], '|', '${cursor}', 'g') : '${cursor}' + let l:current.attr[l:k] = len(l:a[l:k]) ? substitute(l:a[l:k], '|', '${cursor}', 'g') : '${cursor}' endfor else - for k in keys(a) - if type(a[k]) == 7 - call remove(current.attr, k) + for l:k in keys(l:a) + if type(l:a[l:k]) == 7 + call remove(l:current.attr, l:k) continue endif - let current.attr[k] = a[k] + let l:current.attr[l:k] = l:a[l:k] endfor endif endfor endif - if has_key(settings.html.default_attributes, current.name) - let current.name = substitute(current.name, ':.*$', '', '') + if has_key(l:settings.html.default_attributes, l:current.name) + let l:current.name = substitute(l:current.name, ':.*$', '', '') endif break endif @@ -278,187 +278,187 @@ function! emmet#lang#html#parseIntoTree(abbr, type) abort endif " parse attributes - if len(attributes) - let attr = attributes - while len(attr) - let item = matchstr(attr, '\(\%(\%(#[{}a-zA-Z0-9_\-\$]\+\)\|\%(\[\%(\[[^\]]*\]\|"[^"]*"\|[^"\[\]]*\)\+\]\)\|\%(\.[{}a-zA-Z0-9_\-\$]\+\)*\)\)') + if len(l:attributes) + let l:attr = l:attributes + while len(l:attr) + let l:item = matchstr(l:attr, '\(\%(\%(#[{}a-zA-Z0-9_\-\$]\+\)\|\%(\[\%(\[[^\]]*\]\|"[^"]*"\|[^"\[\]]*\)\+\]\)\|\%(\.[{}a-zA-Z0-9_\-\$]\+\)*\)\)') if g:emmet_debug > 1 - echomsg 'attr=' . item + echomsg 'attr=' . l:item endif - if len(item) == 0 + if len(l:item) == 0 break endif - if item[0] ==# '#' - let current.attr.id = item[1:] - let root['variables']['id'] = current.attr.id + if l:item[0] ==# '#' + let l:current.attr.id = l:item[1:] + let l:root['variables']['id'] = l:current.attr.id endif - if item[0] ==# '.' - let current.attr.class = substitute(item[1:], '\.', ' ', 'g') - let root['variables']['class'] = current.attr.class + if l:item[0] ==# '.' + let l:current.attr.class = substitute(l:item[1:], '\.', ' ', 'g') + let l:root['variables']['class'] = l:current.attr.class endif - if item[0] ==# '[' - let atts = item[1:-2] - if matchstr(atts, '^\s*\zs[0-9a-zA-Z_\-:]\+\(="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\)') ==# '' - let ks = [] - if has_key(default_attributes, current.name) - let dfa = default_attributes[current.name] - let ks = type(dfa) == 3 ? len(dfa) > 0 ? keys(dfa[0]) : [] : keys(dfa) + if l:item[0] ==# '[' + let l:atts = l:item[1:-2] + if matchstr(l:atts, '^\s*\zs[0-9a-zA-Z_\-:]\+\(="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\)') ==# '' + let l:ks = [] + if has_key(l:default_attributes, l:current.name) + let l:dfa = l:default_attributes[l:current.name] + let l:ks = type(l:dfa) == 3 ? len(l:dfa) > 0 ? keys(l:dfa[0]) : [] : keys(l:dfa) endif - if len(ks) == 0 && has_key(default_attributes, current.name . ':src') - let dfa = default_attributes[current.name . ':src'] - let ks = type(dfa) == 3 ? len(dfa) > 0 ? keys(dfa[0]) : [] : keys(dfa) + if len(l:ks) == 0 && has_key(l:default_attributes, l:current.name . ':src') + let l:dfa = l:default_attributes[l:current.name . ':src'] + let l:ks = type(l:dfa) == 3 ? len(l:dfa) > 0 ? keys(l:dfa[0]) : [] : keys(l:dfa) endif - if len(ks) > 0 - let current.attr[ks[0]] = atts - elseif atts =~# '\.$' - let current.attr[atts[:-2]] = function('emmet#types#true') + if len(l:ks) > 0 + let l:current.attr[l:ks[0]] = l:atts + elseif l:atts =~# '\.$' + let l:current.attr[l:atts[:-2]] = function('emmet#types#true') else - let current.attr[atts] = '' + let l:current.attr[l:atts] = '' endif else - while len(atts) - let amat = matchstr(atts, '^\s*\zs\([0-9a-zA-Z-:]\+\%(={{.\{-}}}\|="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\|[^ ''"\]]*\)\{0,1}\)') - if len(amat) == 0 + while len(l:atts) + let l:amat = matchstr(l:atts, '^\s*\zs\([0-9a-zA-Z-:]\+\%(={{.\{-}}}\|="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\|[^ ''"\]]*\)\{0,1}\)') + if len(l:amat) == 0 break endif - let key = split(amat, '=')[0] - let Val = amat[len(key)+1:] - if key =~# '\.$' && Val ==# '' - let key = key[:-2] - unlet Val - let Val = function('emmet#types#true') - elseif Val =~# '^["'']' - let Val = Val[1:-2] + let l:key = split(l:amat, '=')[0] + let l:Val = l:amat[len(l:key)+1:] + if l:key =~# '\.$' && l:Val ==# '' + let l:key = l:key[:-2] + unlet l:Val + let l:Val = function('emmet#types#true') + elseif l:Val =~# '^["'']' + let l:Val = l:Val[1:-2] endif - let current.attr[key] = Val - if index(current.attrs_order, key) == -1 - let current.attrs_order += [key] + let l:current.attr[l:key] = l:Val + if index(l:current.attrs_order, l:key) == -1 + let l:current.attrs_order += [l:key] endif - let atts = atts[stridx(atts, amat) + len(amat):] - unlet Val + let l:atts = l:atts[stridx(l:atts, l:amat) + len(l:amat):] + unlet l:Val endwhile endif endif - let attr = substitute(strpart(attr, len(item)), '^\s*', '', '') + let l:attr = substitute(strpart(l:attr, len(l:item)), '^\s*', '', '') endwhile endif " parse text - if tag_name =~# '^{.*}$' - let current.name = '' - let current.value = tag_name + if l:tag_name =~# '^{.*}$' + let l:current.name = '' + let l:current.value = l:tag_name else - let current.value = value + let l:current.value = l:value endif - let current.basedirect = basedirect - let current.basevalue = basevalue - let current.multiplier = multiplier + let l:current.basedirect = l:basedirect + let l:current.basevalue = l:basevalue + let l:current.multiplier = l:multiplier " parse step inside/outside - if !empty(last) - if operator =~# '>' - unlet! parent - let parent = last - let current.parent = last - let current.pos = last.pos + 1 + if !empty(l:last) + if l:operator =~# '>' + unlet! l:parent + let l:parent = l:last + let l:current.parent = l:last + let l:current.pos = l:last.pos + 1 else - let current.parent = parent - let current.pos = last.pos + let l:current.parent = l:parent + let l:current.pos = l:last.pos endif else - let current.parent = parent - let current.pos = 1 + let l:current.parent = l:parent + let l:current.pos = 1 endif - if operator =~# '[<^]' - for c in range(len(operator)) - let tmp = parent.parent - if empty(tmp) + if l:operator =~# '[<^]' + for l:c in range(len(l:operator)) + let l:tmp = l:parent.parent + if empty(l:tmp) break endif - let parent = tmp - let current.parent = tmp + let l:parent = l:tmp + let l:current.parent = l:tmp endfor endif - call add(parent.child, current) - let last = current + call add(l:parent.child, l:current) + let l:last = l:current " parse block - if block_start =~# '(' - if operator =~# '>' - let last.pos += 1 + if l:block_start =~# '(' + if l:operator =~# '>' + let l:last.pos += 1 endif - let last.block = 1 - for n in range(len(block_start)) - let pos += [last.pos] + let l:last.block = 1 + for l:n in range(len(l:block_start)) + let l:pos += [l:last.pos] endfor endif - if block_end =~# ')' - for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',') - if n ==# ')' - if len(pos) > 0 && last.pos >= pos[-1] - for c in range(last.pos - pos[-1]) - let tmp = parent.parent - if !has_key(tmp, 'parent') + if l:block_end =~# ')' + for l:n in split(substitute(substitute(l:block_end, ' ', '', 'g'), ')', ',),', 'g'), ',') + if l:n ==# ')' + if len(l:pos) > 0 && l:last.pos >= l:pos[-1] + for l:c in range(l:last.pos - l:pos[-1]) + let l:tmp = l:parent.parent + if !has_key(l:tmp, 'parent') break endif - let parent = tmp + let l:parent = l:tmp endfor - if len(pos) > 0 - call remove(pos, -1) + if len(l:pos) > 0 + call remove(l:pos, -1) endif - let last = parent - let last.pos += 1 + let l:last = l:parent + let l:last.pos += 1 endif - elseif len(n) - let st = 0 - for nc in range(len(last.child)) - if last.child[nc].block - let st = nc + elseif len(l:n) + let l:st = 0 + for l:nc in range(len(l:last.child)) + if l:last.child[l:nc].block + let l:st = l:nc break endif endfor - let cl = last.child[st :] - let cls = [] - for c in range(n[1:]) - for cc in cl - if cc.multiplier > 1 - let cc.basedirect = c + 1 + let l:cl = l:last.child[l:st :] + let l:cls = [] + for l:c in range(l:n[1:]) + for l:cc in l:cl + if l:cc.multiplier > 1 + let l:cc.basedirect = l:c + 1 else - let cc.basevalue = c + 1 + let l:cc.basevalue = l:c + 1 endif endfor - let cls += deepcopy(cl) + let l:cls += deepcopy(l:cl) endfor - if st > 0 - let last.child = last.child[:st-1] + cls + if l:st > 0 + let l:last.child = l:last.child[:l:st-1] + l:cls else - let last.child = cls + let l:last.child = l:cls endif endif endfor endif - let abbr = abbr[stridx(abbr, match) + len(match):] - if abbr == '/' - let current.empty = 1 + let l:abbr = l:abbr[stridx(l:abbr, l:match) + len(l:match):] + if l:abbr == '/' + let l:current.empty = 1 endif if g:emmet_debug > 1 - echomsg 'str='.str - echomsg 'block_start='.block_start - echomsg 'tag_name='.tag_name - echomsg 'operator='.operator - echomsg 'attributes='.attributes - echomsg 'value='.value - echomsg 'basevalue='.basevalue - echomsg 'multiplier='.multiplier - echomsg 'block_end='.block_end - echomsg 'abbr='.abbr - echomsg 'pos='.string(pos) + echomsg 'str='.l:str + echomsg 'block_start='.l:block_start + echomsg 'tag_name='.l:tag_name + echomsg 'operator='.l:operator + echomsg 'attributes='.l:attributes + echomsg 'value='.l:value + echomsg 'basevalue='.l:basevalue + echomsg 'multiplier='.l:multiplier + echomsg 'block_end='.l:block_end + echomsg 'abbr='.l:abbr + echomsg 'pos='.string(l:pos) echomsg '---' endif endwhile - return root + return l:root endfunction function! s:dollar_add(base,no) abort @@ -472,438 +472,438 @@ function! s:dollar_add(base,no) abort endfunction function! emmet#lang#html#toString(settings, current, type, inline, filters, itemno, indent) abort - let settings = a:settings - let current = a:current - let type = a:type - let inline = a:inline - let filters = a:filters - let itemno = a:itemno - let indent = a:indent - let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) - let q = emmet#getResource(type, 'quote_char', '"') - let ct = emmet#getResource(type, 'comment_type', 'both') - let an = emmet#getResource(type, 'attribute_name', {}) - let empty_elements = emmet#getResource(type, 'empty_elements', settings.html.empty_elements) - let empty_element_suffix = emmet#getResource(type, 'empty_element_suffix', settings.html.empty_element_suffix) + let l:settings = a:settings + let l:current = a:current + let l:type = a:type + let l:inline = a:inline + let l:filters = a:filters + let l:itemno = a:itemno + let l:indent = a:indent + let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1) + let l:q = emmet#getResource(l:type, 'quote_char', '"') + let l:ct = emmet#getResource(l:type, 'comment_type', 'both') + let l:an = emmet#getResource(l:type, 'attribute_name', {}) + let l:empty_elements = emmet#getResource(l:type, 'empty_elements', l:settings.html.empty_elements) + let l:empty_element_suffix = emmet#getResource(l:type, 'empty_element_suffix', l:settings.html.empty_element_suffix) - if emmet#useFilter(filters, 'haml') - return emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) + if emmet#useFilter(l:filters, 'haml') + return emmet#lang#haml#toString(l:settings, l:current, l:type, l:inline, l:filters, l:itemno, l:indent) endif - if emmet#useFilter(filters, 'slim') - return emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) + if emmet#useFilter(l:filters, 'slim') + return emmet#lang#slim#toString(l:settings, l:current, l:type, l:inline, l:filters, l:itemno, l:indent) endif - let comment = '' - let current_name = current.name - if dollar_expr - let current_name = substitute(current_name, '\$$', itemno+1, '') + let l:comment = '' + let l:current_name = l:current.name + if l:dollar_expr + let l:current_name = substitute(l:current_name, '\$$', l:itemno+1, '') endif - let str = '' - if len(current_name) == 0 - let text = current.value[1:-2] - if dollar_expr + let l:str = '' + if len(l:current_name) == 0 + let l:text = l:current.value[1:-2] + if l:dollar_expr " TODO: regexp engine specified - let nr = itemno + 1 + let l:nr = l:itemno + 1 if exists('®expengine') - let text = substitute(text, '\%#=1\%(\\\)\@\ 0 - let str .= '<' . current_name + if len(l:current_name) > 0 + let l:str .= '<' . l:current_name endif - for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) - if !has_key(current.attr, attr) + for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr)) + if !has_key(l:current.attr, l:attr) continue endif - let Val = current.attr[attr] - if type(Val) == 2 && Val == function('emmet#types#true') - unlet Val - let Val = 'true' + let l:Val = l:current.attr[l:attr] + if type(l:Val) == 2 && l:Val == function('emmet#types#true') + unlet l:Val + let l:Val = 'true' if g:emmet_html5 - let str .= ' ' . attr + let l:str .= ' ' . l:attr else - let str .= ' ' . attr . '=' . q . attr . q + let l:str .= ' ' . l:attr . '=' . l:q . l:attr . l:q endif - if emmet#useFilter(filters, 'c') - if attr ==# 'id' | let comment .= '#' . Val | endif - if attr ==# 'class' | let comment .= '.' . Val | endif + if emmet#useFilter(l:filters, 'c') + if l:attr ==# 'id' | let l:comment .= '#' . l:Val | endif + if l:attr ==# 'class' | let l:comment .= '.' . l:Val | endif endif else - if dollar_expr - while Val =~# '\$\([^#{]\|$\)' + if l:dollar_expr + while l:Val =~# '\$\([^#{]\|$\)' " TODO: regexp engine specified if exists('®expengine') - let Val = substitute(Val, '\%#=1\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') + let l:Val = substitute(l:Val, '\%#=1\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g') else - 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') endif endwhile - let attr = substitute(attr, '\$$', itemno+1, '') + let l:attr = substitute(l:attr, '\$$', l:itemno+1, '') endif - if attr ==# 'class' && emmet#useFilter(filters, 'bem') - let vals = split(Val, '\s\+') - let Val = '' - let lead = '' - for _val in vals - if len(Val) > 0 - let Val .= ' ' + if l:attr ==# 'class' && emmet#useFilter(l:filters, 'bem') + let l:vals = split(l:Val, '\s\+') + let l:Val = '' + let l:lead = '' + for l:_val in l:vals + if len(l:Val) > 0 + let l:Val .= ' ' endif - if _val =~# '^_' - if has_key(current.parent.attr, 'class') - let lead = current.parent.attr["class"] - if _val =~# '^__' - let Val .= lead . _val + if l:_val =~# '^_' + if has_key(l:current.parent.attr, 'class') + let l:lead = l:current.parent.attr["class"] + if l:_val =~# '^__' + let l:Val .= l:lead . l:_val else - let Val .= lead . ' ' . lead . _val + let l:Val .= l:lead . ' ' . l:lead . l:_val endif else - let lead = split(vals[0], '_')[0] - let Val .= lead . _val + let l:lead = split(l:vals[0], '_')[0] + let l:Val .= l:lead . l:_val endif - elseif _val =~# '^-' - for l in split(_val, '_') - if len(Val) > 0 - let Val .= ' ' + elseif l:_val =~# '^-' + for l:l in split(l:_val, '_') + if len(l:Val) > 0 + let l:Val .= ' ' endif - let l = substitute(l, '^-', '__', '') - if len(lead) == 0 - let pattr = current.parent.attr - if has_key(pattr, 'class') - let lead = split(pattr['class'], '\s\+')[0] + let l:l = substitute(l:l, '^-', '__', '') + if len(l:lead) == 0 + let l:pattr = l:current.parent.attr + if has_key(l:pattr, 'class') + let l:lead = split(l:pattr['class'], '\s\+')[0] endif endif - let Val .= lead . l - let lead .= l . '_' + let l:Val .= l:lead . l:l + let l:lead .= l:l . '_' endfor else - let Val .= _val + let l:Val .= l:_val endif endfor endif - if has_key(an, attr) - let attr = an[attr] + if has_key(l:an, l:attr) + let l:attr = l:an[l:attr] endif - if emmet#isExtends(type, 'jsx') && Val =~ '^{.*}$' - let str .= ' ' . attr . '=' . Val + if emmet#isExtends(l:type, 'jsx') && l:Val =~ '^{.*}$' + let l:str .= ' ' . l:attr . '=' . l:Val else - let str .= ' ' . attr . '=' . q . Val . q + let l:str .= ' ' . l:attr . '=' . l:q . l:Val . l:q endif - if emmet#useFilter(filters, 'c') - if attr ==# 'id' | let comment .= '#' . Val | endif - if attr ==# 'class' | let comment .= '.' . Val | endif + if emmet#useFilter(l:filters, 'c') + if l:attr ==# 'id' | let l:comment .= '#' . l:Val | endif + if l:attr ==# 'class' | let l:comment .= '.' . l:Val | endif endif endif - unlet Val + unlet l:Val endfor - if len(comment) > 0 && ct ==# 'both' - let str = '\n" . str + if len(l:comment) > 0 && l:ct ==# 'both' + let l:str = '\n" . l:str endif - if current.empty - let str .= ' />' - elseif stridx(','.empty_elements.',', ','.current_name.',') != -1 - let str .= empty_element_suffix + if l:current.empty + let l:str .= ' />' + elseif stridx(','.l:empty_elements.',', ','.l:current_name.',') != -1 + let l:str .= l:empty_element_suffix else - let str .= '>' - let text = current.value[1:-2] - if dollar_expr + let l:str .= '>' + let l:text = l:current.value[1:-2] + if l:dollar_expr " TODO: regexp engine specified - let nr = itemno + 1 + let l:nr = l:itemno + 1 if exists('®expengine') - let text = substitute(text, '\%#=1\%(\\\)\@\ 0 - for n in range(nc) - let child = current.child[n] - if child.multiplier > 1 || (child.multiplier == 1 && len(child.child) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1) || settings.html.block_all_childless - let str .= "\n" . indent - let dr = 1 - elseif len(current_name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 - if nc > 1 || (len(child.name) > 0 && stridx(','.settings.html.inline_elements.',', ','.child.name.',') == -1) - let str .= "\n" . indent - let dr = 1 - elseif current.multiplier == 1 && nc == 1 && len(child.name) == 0 - let str .= "\n" . indent - let dr = 1 + let l:str .= l:text + let l:nc = len(l:current.child) + let l:dr = 0 + if l:nc > 0 + for l:n in range(l:nc) + let l:child = l:current.child[l:n] + if l:child.multiplier > 1 || (l:child.multiplier == 1 && len(l:child.child) > 0 && stridx(','.l:settings.html.inline_elements.',', ','.l:current_name.',') == -1) || l:settings.html.block_all_childless + let l:str .= "\n" . l:indent + let l:dr = 1 + elseif len(l:current_name) > 0 && stridx(','.l:settings.html.inline_elements.',', ','.l:current_name.',') == -1 + if l:nc > 1 || (len(l:child.name) > 0 && stridx(','.l:settings.html.inline_elements.',', ','.l:child.name.',') == -1) + let l:str .= "\n" . l:indent + let l:dr = 1 + elseif l:current.multiplier == 1 && l:nc == 1 && len(l:child.name) == 0 + let l:str .= "\n" . l:indent + let l:dr = 1 endif endif - let inner = emmet#toString(child, type, 0, filters, itemno, indent) - let inner = substitute(inner, "^\n", '', 'g') - let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') - let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') - let str .= inner + let l:inner = emmet#toString(l:child, l:type, 0, l:filters, l:itemno, l:indent) + let l:inner = substitute(l:inner, "^\n", '', 'g') + let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g') + let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g') + let l:str .= l:inner endfor else - if settings.html.indent_blockelement && len(current_name) > 0 && stridx(','.settings.html.inline_elements.',', ','.current_name.',') == -1 || settings.html.block_all_childless - let str .= "\n" . indent . '${cursor}' . "\n" + if l:settings.html.indent_blockelement && len(l:current_name) > 0 && stridx(','.l:settings.html.inline_elements.',', ','.l:current_name.',') == -1 || l:settings.html.block_all_childless + let l:str .= "\n" . l:indent . '${cursor}' . "\n" else - let str .= '${cursor}' + let l:str .= '${cursor}' endif endif - if dr - let str .= "\n" + if l:dr + let l:str .= "\n" endif - let str .= '' + let l:str .= '' endif - if len(comment) > 0 - if ct ==# 'lastonly' - let str .= '' + if len(l:comment) > 0 + if l:ct ==# 'lastonly' + let l:str .= '' else - let str .= "\n' + let l:str .= "\n' endif endif - if len(current_name) > 0 && current.multiplier > 0 || stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1 - let str .= "\n" + if len(l:current_name) > 0 && l:current.multiplier > 0 || stridx(','.l:settings.html.block_elements.',', ','.l:current_name.',') != -1 + let l:str .= "\n" endif - return str + return l:str endfunction function! emmet#lang#html#imageSize() abort - let img_region = emmet#util#searchRegion('') - if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region) + let l:img_region = emmet#util#searchRegion('') + if !emmet#util#regionIsValid(l:img_region) || !emmet#util#cursorInRegion(l:img_region) return endif - let content = emmet#util#getContent(img_region) - if content !~# '^<]\+>$' + let l:content = emmet#util#getContent(l:img_region) + if l:content !~# '^<]\+>$' return endif - let current = emmet#lang#html#parseTag(content) - if empty(current) || !has_key(current.attr, 'src') + let l:current = emmet#lang#html#parseTag(l:content) + if empty(l:current) || !has_key(l:current.attr, 'src') return endif - let fn = current.attr.src - if fn =~# '^\s*$' + let l:fn = l:current.attr.src + if l:fn =~# '^\s*$' return - elseif fn !~# '^\(/\|http\)' - let fn = simplify(expand('%:h') . '/' . fn) + elseif l:fn !~# '^\(/\|http\)' + let l:fn = simplify(expand('%:h') . '/' . l:fn) endif - let [width, height] = emmet#util#getImageSize(fn) - if width == -1 && height == -1 + let [l:width, l:height] = emmet#util#getImageSize(l:fn) + if l:width == -1 && l:height == -1 return endif - let current.attr.width = width - let current.attr.height = height - let current.attrs_order += ['width', 'height'] - let html = substitute(emmet#toString(current, 'html', 1), '\n', '', '') - let html = substitute(html, '\${cursor}', '', '') - call emmet#util#setContent(img_region, html) + let l:current.attr.width = l:width + let l:current.attr.height = l:height + let l:current.attrs_order += ['width', 'height'] + let l:html = substitute(emmet#toString(l:current, 'html', 1), '\n', '', '') + let l:html = substitute(l:html, '\${cursor}', '', '') + call emmet#util#setContent(l:img_region, l:html) endfunction function! emmet#lang#html#imageEncode() abort - let img_region = emmet#util#searchRegion('') - if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region) + let l:img_region = emmet#util#searchRegion('') + if !emmet#util#regionIsValid(l:img_region) || !emmet#util#cursorInRegion(l:img_region) return endif - let content = emmet#util#getContent(img_region) - if content !~# '^<]\+>$' + let l:content = emmet#util#getContent(l:img_region) + if l:content !~# '^<]\+>$' return endif - let current = emmet#lang#html#parseTag(content) - if empty(current) || !has_key(current.attr, 'src') + let l:current = emmet#lang#html#parseTag(l:content) + if empty(l:current) || !has_key(l:current.attr, 'src') return endif - let fn = current.attr.src - if fn =~# '^\s*$' + let l:fn = l:current.attr.src + if l:fn =~# '^\s*$' return - elseif fn !~# '^\(/\|http\)' - let fn = simplify(expand('%:h') . '/' . fn) + elseif l:fn !~# '^\(/\|http\)' + let l:fn = simplify(expand('%:h') . '/' . l:fn) endif - let encoded = emmet#util#imageEncodeDecode(fn, 0) - let current.attr.src = encoded - let content = substitute(emmet#toString(current, 'html', 1), '\n', '', '') - let content = substitute(content, '\${cursor}', '', '') - call emmet#util#setContent(img_region, content) + let l:encoded = emmet#util#imageEncodeDecode(l:fn, 0) + let l:current.attr.src = l:encoded + let l:content = substitute(emmet#toString(l:current, 'html', 1), '\n', '', '') + let l:content = substitute(l:content, '\${cursor}', '', '') + call emmet#util#setContent(l:img_region, l:content) endfunction function! emmet#lang#html#parseTag(tag) abort - let current = emmet#newNode() - let mx = '<\([a-zA-Z][a-zA-Z0-9-]*\)\(\%(\s[a-zA-Z][a-zA-Z0-9-]\+=\?\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\(/\{0,1}\)>' - let match = matchstr(a:tag, mx) - let current.name = substitute(match, mx, '\1', 'i') - let attrs = substitute(match, mx, '\2', 'i') - let mx = '\([a-zA-Z0-9-]\+\)\(\(=[^"'' \t]\+\)\|="\([^"]\{-}\)"\|=''\([^'']\{-}\)''\)\?' - while len(attrs) > 0 - let match = matchstr(attrs, mx) - if len(match) == 0 + let l:current = emmet#newNode() + let l:mx = '<\([a-zA-Z][a-zA-Z0-9-]*\)\(\%(\s[a-zA-Z][a-zA-Z0-9-]\+=\?\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\(/\{0,1}\)>' + let l:match = matchstr(a:tag, l:mx) + let l:current.name = substitute(l:match, l:mx, '\1', 'i') + let l:attrs = substitute(l:match, l:mx, '\2', 'i') + let l:mx = '\([a-zA-Z0-9-]\+\)\(\(=[^"'' \t]\+\)\|="\([^"]\{-}\)"\|=''\([^'']\{-}\)''\)\?' + while len(l:attrs) > 0 + let l:match = matchstr(l:attrs, l:mx) + if len(l:match) == 0 break endif - let attr_match = matchlist(match, mx) - let name = attr_match[1] - if len(attr_match[2]) - let Val = len(attr_match[3]) ? attr_match[3] : attr_match[4] + let l:attr_match = matchlist(l:match, l:mx) + let l:name = l:attr_match[1] + if len(l:attr_match[2]) + let l:Val = len(l:attr_match[3]) ? l:attr_match[3] : l:attr_match[4] else - let Val = function('emmet#types#true') + let l:Val = function('emmet#types#true') endif - let current.attr[name] = Val - let current.attrs_order += [name] - let attrs = attrs[stridx(attrs, match) + len(match):] + let l:current.attr[l:name] = l:Val + let l:current.attrs_order += [l:name] + let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):] endwhile - return current + return l:current endfunction function! emmet#lang#html#toggleComment() abort - let orgpos = getpos('.') - let curpos = getpos('.') - let mx = '<\%#[^>]*>' + let l:orgpos = getpos('.') + let l:curpos = getpos('.') + let l:mx = '<\%#[^>]*>' while 1 - let block = emmet#util#searchRegion('') - if emmet#util#regionIsValid(block) - let block[1][1] += 2 - let content = emmet#util#getContent(block) - let content = substitute(content, '^$', '\1', '') - call emmet#util#setContent(block, content) - silent! call setpos('.', orgpos) + let l:block = emmet#util#searchRegion('') + if emmet#util#regionIsValid(l:block) + let l:block[1][1] += 2 + let l:content = emmet#util#getContent(l:block) + let l:content = substitute(l:content, '^$', '\1', '') + call emmet#util#setContent(l:block, l:content) + silent! call setpos('.', l:orgpos) return endif - let block = emmet#util#searchRegion('<[^>]', '>') - if !emmet#util#regionIsValid(block) - let pos1 = searchpos('<', 'bcW') - if pos1[0] == 0 && pos1[1] == 0 + let l:block = emmet#util#searchRegion('<[^>]', '>') + if !emmet#util#regionIsValid(l:block) + let l:pos1 = searchpos('<', 'bcW') + if l:pos1[0] == 0 && l:pos1[1] == 0 return endif - let curpos = getpos('.') + let l:curpos = getpos('.') continue endif - let pos1 = block[0] - let pos2 = block[1] - let content = emmet#util#getContent(block) - let tag_name = matchstr(content, '^<\zs/\{0,1}[^ \r\n>]\+') - if tag_name[0] ==# '/' - call setpos('.', [0, pos1[0], pos1[1], 0]) - let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^/>]*>', '', '', 'bnW') - let pos1 = searchpos('>', 'cneW') - let block = [pos2, pos1] - elseif tag_name =~# '/$' - if !emmet#util#pointInRegion(orgpos[1:2], block) + let l:pos1 = l:block[0] + let l:pos2 = l:block[1] + let l:content = emmet#util#getContent(l:block) + let l:tag_name = matchstr(l:content, '^<\zs/\{0,1}[^ \r\n>]\+') + if l:tag_name[0] ==# '/' + call setpos('.', [0, l:pos1[0], l:pos1[1], 0]) + let l:pos2 = searchpairpos('<'. l:tag_name[1:] . '\>[^/>]*>', '', '', 'bnW') + let l:pos1 = searchpos('>', 'cneW') + let l:block = [l:pos2, l:pos1] + elseif l:tag_name =~# '/$' + if !emmet#util#pointInRegion(l:orgpos[1:2], l:block) " it's broken tree - call setpos('.', orgpos) - let block = emmet#util#searchRegion('>', '<') - let content = '><' - call emmet#util#setContent(block, content) - silent! call setpos('.', orgpos) + call setpos('.', l:orgpos) + let l:block = emmet#util#searchRegion('>', '<') + let l:content = '><' + call emmet#util#setContent(l:block, l:content) + silent! call setpos('.', l:orgpos) return endif else - call setpos('.', [0, pos2[0], pos2[1], 0]) - let pos3 = searchpairpos('<'. tag_name . '\>[^/>]*>', '', '', 'nW') - if pos3 == [0, 0] - let block = [pos1, pos2] + call setpos('.', [0, l:pos2[0], l:pos2[1], 0]) + let l:pos3 = searchpairpos('<'. l:tag_name . '\>[^/>]*>', '', '', 'nW') + if l:pos3 == [0, 0] + let l:block = [l:pos1, l:pos2] else - call setpos('.', [0, pos3[0], pos3[1], 0]) - let pos2 = searchpos('>', 'neW') - let block = [pos1, pos2] + call setpos('.', [0, l:pos3[0], l:pos3[1], 0]) + let l:pos2 = searchpos('>', 'neW') + let l:block = [l:pos1, l:pos2] endif endif - if !emmet#util#regionIsValid(block) - silent! call setpos('.', orgpos) + if !emmet#util#regionIsValid(l:block) + silent! call setpos('.', l:orgpos) return endif - if emmet#util#pointInRegion(curpos[1:2], block) - let content = '' - call emmet#util#setContent(block, content) - silent! call setpos('.', orgpos) + if emmet#util#pointInRegion(l:curpos[1:2], l:block) + let l:content = '' + call emmet#util#setContent(l:block, l:content) + silent! call setpos('.', l:orgpos) return endif endwhile endfunction function! emmet#lang#html#balanceTag(flag) range abort - let vblock = emmet#util#getVisualBlock() - let curpos = emmet#util#getcurpos() - let settings = emmet#getSettings() + let l:vblock = emmet#util#getVisualBlock() + let l:curpos = emmet#util#getcurpos() + let l:settings = emmet#getSettings() if a:flag > 0 - let mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*' - let last = curpos[1:2] + let l:mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*' + let l:last = l:curpos[1:2] while 1 - let pos1 = searchpos(mx, 'bW') - let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) - let tag_name = matchstr(content, '^<\zs[a-zA-Z0-9:_\-]*\ze') - if stridx(','.settings.html.empty_elements.',', ','.tag_name.',') != -1 - let pos2 = searchpos('>', 'nW') + let l:pos1 = searchpos(l:mx, 'bW') + let l:content = matchstr(getline(l:pos1[0])[l:pos1[1]-1:], l:mx) + let l:tag_name = matchstr(l:content, '^<\zs[a-zA-Z0-9:_\-]*\ze') + if stridx(','.l:settings.html.empty_elements.',', ','.l:tag_name.',') != -1 + let l:pos2 = searchpos('>', 'nW') else - let pos2 = searchpairpos('<' . tag_name . '[^>]*>', '', '', 'nW') + let l:pos2 = searchpairpos('<' . l:tag_name . '[^>]*>', '', '', 'nW') endif - let block = [pos1, pos2] - if pos1 == [0, 0] + let l:block = [l:pos1, l:pos2] + if l:pos1 == [0, 0] break endif - if emmet#util#pointInRegion(last, block) && emmet#util#regionIsValid(block) - call emmet#util#selectRegion(block) + if emmet#util#pointInRegion(l:last, l:block) && emmet#util#regionIsValid(l:block) + call emmet#util#selectRegion(l:block) return endif - if pos1 == last + if l:pos1 == l:last break endif - let last = pos1 + let l:last = l:pos1 endwhile else - let mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>' + let l:mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>' while 1 - let pos1 = searchpos(mx, 'W') - if pos1 == [0, 0] || pos1 == curpos[1:2] - let pos1 = searchpos('>\zs', 'W') - let pos2 = searchpos('.\ze<', 'W') - let block = [pos1, pos2] - if emmet#util#regionIsValid(block) - call emmet#util#selectRegion(block) + let l:pos1 = searchpos(l:mx, 'W') + if l:pos1 == [0, 0] || l:pos1 == l:curpos[1:2] + let l:pos1 = searchpos('>\zs', 'W') + let l:pos2 = searchpos('.\ze<', 'W') + let l:block = [l:pos1, l:pos2] + if emmet#util#regionIsValid(l:block) + call emmet#util#selectRegion(l:block) return endif endif - let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) - let tag_name = matchstr(content, '^<\zs[a-zA-Z0-9:_\-]*\ze') - if stridx(','.settings.html.empty_elements.',', ','.tag_name.',') != -1 - let pos2 = searchpos('>', 'nW') + let l:content = matchstr(getline(l:pos1[0])[l:pos1[1]-1:], l:mx) + let l:tag_name = matchstr(l:content, '^<\zs[a-zA-Z0-9:_\-]*\ze') + if stridx(','.l:settings.html.empty_elements.',', ','.l:tag_name.',') != -1 + let l:pos2 = searchpos('>', 'nW') else - let pos2 = searchpairpos('<' . tag_name . '[^>]*>', '', '', 'nW') + let l:pos2 = searchpairpos('<' . l:tag_name . '[^>]*>', '', '', 'nW') endif - let block = [pos1, pos2] - if pos1 == [0, 0] + let l:block = [l:pos1, l:pos2] + if l:pos1 == [0, 0] break endif - if emmet#util#regionIsValid(block) - call emmet#util#selectRegion(block) + if emmet#util#regionIsValid(l:block) + call emmet#util#selectRegion(l:block) return endif endwhile endif - call setpos('.', curpos) + call setpos('.', l:curpos) endfunction function! emmet#lang#html#moveNextPrevItem(flag) abort silent! exe "normal \" - let mx = '\%([0-9a-zA-Z-:]\+\%(="[^"]*"\|=''[^'']*''\|[^ ''">\]]*\)\{0,1}\)' - let pos = searchpos('\s'.mx.'\zs', '') - if pos != [0,0] - call feedkeys('v?\s\zs'.mx."\", '') + let l:mx = '\%([0-9a-zA-Z-:]\+\%(="[^"]*"\|=''[^'']*''\|[^ ''">\]]*\)\{0,1}\)' + let l:pos = searchpos('\s'.l:mx.'\zs', '') + if l:pos != [0,0] + call feedkeys('v?\s\zs'.l:mx."\", '') endif return '' endfunction function! emmet#lang#html#moveNextPrev(flag) abort - let pos = search('\%(<\/\|\(""\)\|^\(\s*\)$', a:flag ? 'Wpb' : 'Wp') - if pos == 3 + let l:pos = search('\%(<\/\|\(""\)\|^\(\s*\)$', a:flag ? 'Wpb' : 'Wp') + if l:pos == 3 startinsert! - elseif pos != 0 + elseif l:pos != 0 silent! normal! l startinsert endif @@ -911,126 +911,126 @@ function! emmet#lang#html#moveNextPrev(flag) abort endfunction function! emmet#lang#html#splitJoinTag() abort - let curpos = emmet#util#getcurpos() - let mx = '<\(/\{0,1}[a-zA-Z][-a-zA-Z0-9:_\-]*\)\%(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\s*\%(/\{0,1}\)>' + let l:curpos = emmet#util#getcurpos() + let l:mx = '<\(/\{0,1}[a-zA-Z][-a-zA-Z0-9:_\-]*\)\%(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\s*\%(/\{0,1}\)>' while 1 - let old = getpos('.')[1:2] - let pos1 = searchpos(mx, 'bcnW') - let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) - let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\).*$', '\1', '') - let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]] - if content[-2:] ==# '/>' && emmet#util#cursorInRegion(block) - let content = substitute(content[:-3], '\s*$', '', '') . '>' - call emmet#util#setContent(block, content) - call setpos('.', [0, block[0][0], block[0][1], 0]) + let l:old = getpos('.')[1:2] + let l:pos1 = searchpos(l:mx, 'bcnW') + let l:content = matchstr(getline(l:pos1[0])[l:pos1[1]-1:], l:mx) + let l:tag_name = substitute(l:content, '^<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\).*$', '\1', '') + let l:block = [l:pos1, [l:pos1[0], l:pos1[1] + len(l:content) - 1]] + if l:content[-2:] ==# '/>' && emmet#util#cursorInRegion(l:block) + let l:content = substitute(l:content[:-3], '\s*$', '', '') . '>' + call emmet#util#setContent(l:block, l:content) + call setpos('.', [0, l:block[0][0], l:block[0][1], 0]) return endif - if tag_name[0] ==# '/' - let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW') - call setpos('.', [0, pos1[0], pos1[1], 0]) - let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^/>]*>', '', '', 'W') + if l:tag_name[0] ==# '/' + let l:pos1 = searchpos('<' . l:tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW') + call setpos('.', [0, l:pos1[0], l:pos1[1], 0]) + let l:pos2 = searchpairpos('<'. l:tag_name[1:] . '\>[^/>]*>', '', '', 'W') else - let pos2 = searchpairpos('<'. tag_name . '[^/>]*>', '', '', 'W') + let l:pos2 = searchpairpos('<'. l:tag_name . '[^/>]*>', '', '', 'W') endif - if pos2 == [0, 0] + if l:pos2 == [0, 0] return endif - let pos2 = searchpos('>', 'neW') - let block = [pos1, pos2] - if emmet#util#pointInRegion(curpos[1:2], block) - let content = matchstr(content, mx)[:-2] . ' />' - call emmet#util#setContent(block, content) - call setpos('.', [0, block[0][0], block[0][1], 0]) + let l:pos2 = searchpos('>', 'neW') + let l:block = [l:pos1, l:pos2] + if emmet#util#pointInRegion(l:curpos[1:2], l:block) + let l:content = matchstr(l:content, l:mx)[:-2] . ' />' + call emmet#util#setContent(l:block, l:content) + call setpos('.', [0, l:block[0][0], l:block[0][1], 0]) return endif - if block[0][0] > 0 - call setpos('.', [0, block[0][0]-1, block[0][1], 0]) + if l:block[0][0] > 0 + call setpos('.', [0, l:block[0][0]-1, l:block[0][1], 0]) else - call setpos('.', curpos) + call setpos('.', l:curpos) return endif - if pos1 == old - call setpos('.', curpos) + if l:pos1 == l:old + call setpos('.', l:curpos) return endif endwhile endfunction function! emmet#lang#html#removeTag() abort - let curpos = emmet#util#getcurpos() - let mx = '<\(/\{0,1}[a-zA-Z][-a-zA-Z0-9:_\-]*\)\%(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\s*\%(/\{0,1}\)>' + let l:curpos = emmet#util#getcurpos() + let l:mx = '<\(/\{0,1}[a-zA-Z][-a-zA-Z0-9:_\-]*\)\%(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\s*\%(/\{0,1}\)>' - let pos1 = searchpos(mx, 'bcnW') - let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) - let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\).*$', '\1', '') - let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]] - if content[-2:] ==# '/>' && emmet#util#cursorInRegion(block) - call emmet#util#setContent(block, '') - call setpos('.', [0, block[0][0], block[0][1], 0]) + let l:pos1 = searchpos(l:mx, 'bcnW') + let l:content = matchstr(getline(l:pos1[0])[l:pos1[1]-1:], l:mx) + let l:tag_name = substitute(l:content, '^<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\).*$', '\1', '') + let l:block = [l:pos1, [l:pos1[0], l:pos1[1] + len(l:content) - 1]] + if l:content[-2:] ==# '/>' && emmet#util#cursorInRegion(l:block) + call emmet#util#setContent(l:block, '') + call setpos('.', [0, l:block[0][0], l:block[0][1], 0]) return endif - if tag_name[0] ==# '/' - let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW') - call setpos('.', [0, pos1[0], pos1[1], 0]) - let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^/>]*>', '', '', 'W') + if l:tag_name[0] ==# '/' + let l:pos1 = searchpos('<' . l:tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW') + call setpos('.', [0, l:pos1[0], l:pos1[1], 0]) + let l:pos2 = searchpairpos('<'. l:tag_name[1:] . '\>[^/>]*>', '', '', 'W') else - let pos2 = searchpairpos('<'. tag_name . '[^/>]*>', '', '', 'W') + let l:pos2 = searchpairpos('<'. l:tag_name . '[^/>]*>', '', '', 'W') endif - if pos2 == [0, 0] + if l:pos2 == [0, 0] return endif - let pos2 = searchpos('>', 'neW') - let block = [pos1, pos2] - if emmet#util#pointInRegion(curpos[1:2], block) - call emmet#util#setContent(block, '') - call setpos('.', [0, block[0][0], block[0][1], 0]) + let l:pos2 = searchpos('>', 'neW') + let l:block = [l:pos1, l:pos2] + if emmet#util#pointInRegion(l:curpos[1:2], l:block) + call emmet#util#setContent(l:block, '') + call setpos('.', [0, l:block[0][0], l:block[0][1], 0]) return endif - if block[0][0] > 0 - call setpos('.', [0, block[0][0]-1, block[0][1], 0]) + if l:block[0][0] > 0 + call setpos('.', [0, l:block[0][0]-1, l:block[0][1], 0]) else - call setpos('.', curpos) + call setpos('.', l:curpos) endif endfunction function! emmet#lang#html#mergeLines() abort - let curpos = emmet#util#getcurpos() - let settings = emmet#getSettings() + let l:curpos = emmet#util#getcurpos() + let l:settings = emmet#getSettings() - let mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>' - let last = curpos[1:2] + let l:mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>' + let l:last = l:curpos[1:2] while 1 - let pos1 = searchpos(mx, 'bcW') - let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) - echomsg string(content) - let tag_name = matchstr(content, '^<\zs[a-zA-Z0-9:_\-]*\ze') - if stridx(','.settings.html.empty_elements.',', ','.tag_name.',') != -1 - let pos2 = searchpos('>', 'nW') + let l:pos1 = searchpos(l:mx, 'bcW') + let l:content = matchstr(getline(l:pos1[0])[l:pos1[1]-1:], l:mx) + echomsg string(l:content) + let l:tag_name = matchstr(l:content, '^<\zs[a-zA-Z0-9:_\-]*\ze') + if stridx(','.l:settings.html.empty_elements.',', ','.l:tag_name.',') != -1 + let l:pos2 = searchpos('>', 'nW') else - let pos2 = searchpairpos('<' . tag_name . '[^>]*>', '', '', 'nW') + let l:pos2 = searchpairpos('<' . l:tag_name . '[^>]*>', '', '', 'nW') endif - if pos1 == [0, 0] || pos2 == [0, 0] - call setpos('.', curpos) + if l:pos1 == [0, 0] || l:pos2 == [0, 0] + call setpos('.', l:curpos) return endif - let block = [pos1, pos2] - if emmet#util#pointInRegion(last, block) && emmet#util#regionIsValid(block) + let l:block = [l:pos1, l:pos2] + if emmet#util#pointInRegion(l:last, l:block) && emmet#util#regionIsValid(l:block) break endif - if pos1 == last - call setpos('.', curpos) + if l:pos1 == l:last + call setpos('.', l:curpos) return endif - let last = pos1 + let l:last = l:pos1 endwhile - let content = emmet#util#getContent(block) - let mx = '<\(/\{0,1}[a-zA-Z][-a-zA-Z0-9:_\-]*\)\%(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\s*\%(/\{0,1}\)>' - let content = join(map(split(content, mx . '\zs\s*'), 'trim(v:val)'), '') - call emmet#util#setContent(block, content) - if block[0][0] > 0 - call setpos('.', [0, block[0][0], block[0][1], 0]) + let l:content = emmet#util#getContent(l:block) + let l:mx = '<\(/\{0,1}[a-zA-Z][-a-zA-Z0-9:_\-]*\)\%(\%(\s[a-zA-Z][a-zA-Z0-9]\+=\%([^"'' \t]\+\|"[^"]\{-}"\|''[^'']\{-}''\)\s*\)*\)\s*\%(/\{0,1}\)>' + let l:content = join(map(split(l:content, l:mx . '\zs\s*'), 'trim(v:val)'), '') + call emmet#util#setContent(l:block, l:content) + if l:block[0][0] > 0 + call setpos('.', [0, l:block[0][0], l:block[0][1], 0]) else - call setpos('.', curpos) + call setpos('.', l:curpos) endif endfunction diff --git a/autoload/emmet/lang/jade.vim b/autoload/emmet/lang/jade.vim index f59f22d..a052d53 100644 --- a/autoload/emmet/lang/jade.vim +++ b/autoload/emmet/lang/jade.vim @@ -7,248 +7,248 @@ function! emmet#lang#jade#parseIntoTree(abbr, type) abort endfunction function! emmet#lang#jade#toString(settings, current, type, inline, filters, itemno, indent) abort - let settings = a:settings - let current = a:current - let type = a:type - let inline = a:inline - let filters = a:filters - let itemno = a:itemno - let indent = emmet#getIndentation(type) - let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) - let attribute_style = emmet#getResource('jade', 'attribute_style', 'hash') - let str = '' + let l:settings = a:settings + let l:current = a:current + let l:type = a:type + let l:inline = a:inline + let l:filters = a:filters + let l:itemno = a:itemno + let l:indent = emmet#getIndentation(l:type) + let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1) + let l:attribute_style = emmet#getResource('jade', 'attribute_style', 'hash') + let l:str = '' - let current_name = current.name - if dollar_expr - let current_name = substitute(current.name, '\$$', itemno+1, '') + let l:current_name = l:current.name + if l:dollar_expr + let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '') endif - if len(current.name) > 0 - let str .= '' . current_name - let tmp = '' - for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) - if !has_key(current.attr, attr) + if len(l:current.name) > 0 + let l:str .= '' . l:current_name + let l:tmp = '' + for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr)) + if !has_key(l:current.attr, l:attr) continue endif - let Val = current.attr[attr] - if type(Val) == 2 && Val == function('emmet#types#true') - if attribute_style ==# 'hash' - let tmp .= ' ' . attr . ' = true' - elseif attribute_style ==# 'html' - let tmp .= attr . '=true' + let l:Val = l:current.attr[l:attr] + if type(l:Val) == 2 && l:Val == function('emmet#types#true') + if l:attribute_style ==# 'hash' + let l:tmp .= ' ' . l:attr . ' = true' + elseif l:attribute_style ==# 'html' + let l:tmp .= l:attr . '=true' end else - if dollar_expr - while Val =~# '\$\([^#{]\|$\)' - let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') + if l:dollar_expr + while l:Val =~# '\$\([^#{]\|$\)' + let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g') endwhile - let attr = substitute(attr, '\$$', itemno+1, '') + let l:attr = substitute(l:attr, '\$$', l:itemno+1, '') endif - let valtmp = substitute(Val, '\${cursor}', '', '') - if attr ==# 'id' && len(valtmp) > 0 - let str .= '#' . Val - elseif attr ==# 'class' && len(valtmp) > 0 - let str .= '.' . substitute(Val, ' ', '.', 'g') + let l:valtmp = substitute(l:Val, '\${cursor}', '', '') + if l:attr ==# 'id' && len(l:valtmp) > 0 + let l:str .= '#' . l:Val + elseif l:attr ==# 'class' && len(l:valtmp) > 0 + let l:str .= '.' . substitute(l:Val, ' ', '.', 'g') else - if len(tmp) > 0 - if attribute_style ==# 'hash' - let tmp .= ', ' - elseif attribute_style ==# 'html' - let tmp .= ' ' + if len(l:tmp) > 0 + if l:attribute_style ==# 'hash' + let l:tmp .= ', ' + elseif l:attribute_style ==# 'html' + let l:tmp .= ' ' endif endif - if attribute_style ==# 'hash' - let tmp .= '' . attr . '="' . Val . '"' - elseif attribute_style ==# 'html' - let tmp .= attr . '="' . Val . '"' + if l:attribute_style ==# 'hash' + let l:tmp .= '' . l:attr . '="' . l:Val . '"' + elseif l:attribute_style ==# 'html' + let l:tmp .= l:attr . '="' . l:Val . '"' end endif endif endfor - if len(tmp) - if attribute_style ==# 'hash' - let str .= '(' . tmp . ')' - elseif attribute_style ==# 'html' - let str .= '(' . tmp . ')' + if len(l:tmp) + if l:attribute_style ==# 'hash' + let l:str .= '(' . l:tmp . ')' + elseif l:attribute_style ==# 'html' + let l:str .= '(' . l:tmp . ')' end endif - let inner = '' - if len(current.value) > 0 - let text = current.value[1:-2] - if dollar_expr - let text = substitute(text, '\%(\\\)\@\ 0 + let l:text = l:current.value[1:-2] + if l:dollar_expr + let l:text = substitute(l:text, '\%(\\\)\@\ 0 - for child in current.child - let inner .= emmet#toString(child, type, inline, filters, itemno, indent) + elseif len(l:current.child) > 0 + for l:child in l:current.child + let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent) endfor - let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') - let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') - let str .= "\n" . indent . inner + let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g') + let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g') + let l:str .= "\n" . l:indent . l:inner endif else - let str = current.value[1:-2] - if dollar_expr - let str = substitute(str, '\%(\\\)\@\\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' - while len(attrs) > 0 - let match = matchstr(attrs, mx) - if len(match) ==# 0 + let l:current = emmet#newNode() + let l:mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)' + let l:match = matchstr(a:tag, l:mx) + let l:current.name = substitute(l:match, l:mx, '\1', '') + let l:attrs = substitute(l:match, l:mx, '\2', '') + let l:mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' + while len(l:attrs) > 0 + let l:match = matchstr(l:attrs, l:mx) + if len(l:match) ==# 0 break endif - let attr_match = matchlist(match, mx) - let name = attr_match[1] - let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] - let current.attr[name] = value - let current.attrs_order += [name] - let attrs = attrs[stridx(attrs, match) + len(match):] + let l:attr_match = matchlist(l:match, l:mx) + let l:name = l:attr_match[1] + let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3] + let l:current.attr[l:name] = l:value + let l:current.attrs_order += [l:name] + let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):] endwhile - return current + return l:current endfunction function! emmet#lang#jade#toggleComment() abort - let line = getline('.') - let space = matchstr(line, '^\s*') - if line =~# '^\s*-#' - call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*')) - elseif line =~# '^\s*%[a-z]' - call setline('.', space . '-# ' . line[len(space):]) + let l:line = getline('.') + let l:space = matchstr(l:line, '^\s*') + if l:line =~# '^\s*-#' + call setline('.', l:space . matchstr(l:line[len(l:space)+2:], '^\s*\zs.*')) + elseif l:line =~# '^\s*%[a-z]' + call setline('.', l:space . '-# ' . l:line[len(l:space):]) endif endfunction function! emmet#lang#jade#balanceTag(flag) range abort - let block = emmet#util#getVisualBlock() + let l:block = emmet#util#getVisualBlock() if a:flag == -2 || a:flag == 2 - let curpos = [0, line("'<"), col("'<"), 0] + let l:curpos = [0, line("'<"), col("'<"), 0] else - let curpos = emmet#util#getcurpos() + let l:curpos = emmet#util#getcurpos() endif - let n = curpos[1] - let ml = len(matchstr(getline(n), '^\s*')) + let l:n = l:curpos[1] + let l:ml = len(matchstr(getline(l:n), '^\s*')) if a:flag > 0 - if a:flag == 1 || !emmet#util#regionIsValid(block) - let n = line('.') + if a:flag == 1 || !emmet#util#regionIsValid(l:block) + let l:n = line('.') else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze%[a-z]')) - if l > 0 && l < ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze%[a-z]')) + if l:l > 0 && l:l < l:ml + let l:ml = l:l break endif - let n -= 1 + let l:n -= 1 endwhile endif - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*%[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) - if l > 0 && l > ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]')) + if l:l > 0 && l:l > l:ml + let l:ml = l:l break endif - let n += 1 + let l:n += 1 endwhile - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*%[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) endif endfunction @@ -257,76 +257,76 @@ function! emmet#lang#jade#moveNextPrevItem(flag) abort endfunction function! emmet#lang#jade#moveNextPrev(flag) abort - let pos = search('""', a:flag ? 'Wb' : 'W') - if pos != 0 + let l:pos = search('""', a:flag ? 'Wb' : 'W') + if l:pos != 0 silent! normal! l startinsert endif endfunction function! emmet#lang#jade#splitJoinTag() abort - let n = line('.') - let sml = len(matchstr(getline(n), '^\s*%[a-z]')) - while n > 0 - if getline(n) =~# '^\s*\ze%[a-z]' - if len(matchstr(getline(n), '^\s*%[a-z]')) < sml + let l:n = line('.') + let l:sml = len(matchstr(getline(l:n), '^\s*%[a-z]')) + while l:n > 0 + if getline(l:n) =~# '^\s*\ze%[a-z]' + if len(matchstr(getline(l:n), '^\s*%[a-z]')) < l:sml break endif - let line = getline(n) - call setline(n, substitute(line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) - let sn = n - let n += 1 - let ml = len(matchstr(getline(n), '^\s*%[a-z]')) - if len(matchstr(getline(n), '^\s*')) > ml - while n <= line('$') - let l = len(matchstr(getline(n), '^\s*')) - if l <= ml + let l:line = getline(l:n) + call setline(l:n, substitute(l:line, '^\s*%\w\+\%(\s*{[^}]*}\|\s\)\zs.*', '', '')) + let l:sn = l:n + let l:n += 1 + let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if len(matchstr(getline(l:n), '^\s*')) > l:ml + while l:n <= line('$') + let l:l = len(matchstr(getline(l:n), '^\s*')) + if l:l <= l:ml break endif - exe n 'delete' + exe l:n 'delete' endwhile - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) else - let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)') - let spaces = matchstr(getline(sn), '^\s*') - let settings = emmet#getSettings() - if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1 - call append(sn, spaces . ' ') - call setpos('.', [0, sn+1, 1, 0]) + let l:tag = matchstr(getline(l:sn), '^\s*%\zs\(\w\+\)') + let l:spaces = matchstr(getline(l:sn), '^\s*') + let l:settings = emmet#getSettings() + if stridx(','.l:settings.html.inline_elements.',', ','.l:tag.',') == -1 + call append(l:sn, l:spaces . ' ') + call setpos('.', [0, l:sn+1, 1, 0]) else - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) endif startinsert! endif break endif - let n -= 1 + let l:n -= 1 endwhile endfunction function! emmet#lang#jade#removeTag() abort - let n = line('.') - let ml = 0 - while n > 0 - if getline(n) =~# '^\s*\ze[a-z]' - let ml = len(matchstr(getline(n), '^\s*%[a-z]')) + let l:n = line('.') + let l:ml = 0 + while l:n > 0 + if getline(l:n) =~# '^\s*\ze[a-z]' + let l:ml = len(matchstr(getline(l:n), '^\s*%[a-z]')) break endif - let n -= 1 + let l:n -= 1 endwhile - let sn = n - while n < line('$') - let l = len(matchstr(getline(n), '^\s*%[a-z]')) - if l > 0 && l <= ml - let n -= 1 + let l:sn = l:n + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*%[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - if sn == n + if l:sn == l:n exe 'delete' else - exe sn ',' (n-1) 'delete' + exe l:sn ',' (l:n-1) 'delete' endif endfunction diff --git a/autoload/emmet/lang/sass.vim b/autoload/emmet/lang/sass.vim index 3d3fd58..368eda1 100644 --- a/autoload/emmet/lang/sass.vim +++ b/autoload/emmet/lang/sass.vim @@ -7,59 +7,59 @@ function! emmet#lang#sass#parseIntoTree(abbr, type) abort endfunction function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) abort - let settings = a:settings - let current = a:current - let type = a:type - let inline = a:inline - let filters = a:filters - let itemno = a:itemno - let indent = a:indent - let str = '' + let l:settings = a:settings + let l:current = a:current + let l:type = a:type + let l:inline = a:inline + let l:filters = a:filters + let l:itemno = a:itemno + let l:indent = a:indent + let l:str = '' - let current_name = current.name - let current_name = substitute(current.name, '\$$', itemno+1, '') - if len(current.name) > 0 - let str .= current_name - let tmp = '' - for attr in keys(current.attr) - let val = current.attr[attr] - while val =~# '\$\([^#{]\|$\)' - let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') + let l:current_name = l:current.name + let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '') + if len(l:current.name) > 0 + let l:str .= l:current_name + let l:tmp = '' + for l:attr in keys(l:current.attr) + let l:val = l:current.attr[l:attr] + while l:val =~# '\$\([^#{]\|$\)' + let l:val = substitute(l:val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g') endwhile - let attr = substitute(attr, '\$$', itemno+1, '') - if attr ==# 'id' - let str .= '#' . val - elseif attr ==# 'class' - let str .= '.' . val + let l:attr = substitute(l:attr, '\$$', l:itemno+1, '') + if l:attr ==# 'id' + let l:str .= '#' . l:val + elseif l:attr ==# 'class' + let l:str .= '.' . l:val else - let tmp .= attr . ': ' . val + let l:tmp .= l:attr . ': ' . l:val endif endfor - if len(tmp) > 0 - let str .= "\n" - for line in split(tmp, "\n") - let str .= indent . line . "\n" + if len(l:tmp) > 0 + let l:str .= "\n" + for l:line in split(l:tmp, "\n") + let l:str .= l:indent . l:line . "\n" endfor else - let str .= "\n" + let l:str .= "\n" endif - let inner = '' - for child in current.child - let tmp = emmet#toString(child, type, inline, filters, itemno, indent) - let tmp = substitute(tmp, "\n", "\n" . escape(indent, '\'), 'g') - let tmp = substitute(tmp, "\n" . escape(indent, '\') . '$', '${cursor}\n', 'g') - let inner .= tmp + let l:inner = '' + for l:child in l:current.child + let l:tmp = emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent) + let l:tmp = substitute(l:tmp, "\n", "\n" . escape(l:indent, '\'), 'g') + let l:tmp = substitute(l:tmp, "\n" . escape(l:indent, '\') . '$', '${cursor}\n', 'g') + let l:inner .= l:tmp endfor - if len(inner) > 0 - let str .= indent . inner + if len(l:inner) > 0 + let l:str .= l:indent . l:inner endif else - let text = emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) - let text = substitute(text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g') - return text + let l:text = emmet#lang#css#toString(l:settings, l:current, l:type, l:inline, l:filters, l:itemno, l:indent) + let l:text = substitute(l:text, '\s*;\ze\(\${[^}]\+}\)\?\(\n\|$\)', '', 'g') + return l:text endif - return str + return l:str endfunction function! emmet#lang#sass#imageSize() abort @@ -75,67 +75,67 @@ function! emmet#lang#sass#toggleComment() abort endfunction function! emmet#lang#sass#balanceTag(flag) range abort - let block = emmet#util#getVisualBlock() + let l:block = emmet#util#getVisualBlock() if a:flag == -2 || a:flag == 2 - let curpos = [0, line("'<"), col("'<"), 0] + let l:curpos = [0, line("'<"), col("'<"), 0] else - let curpos = emmet#util#getcurpos() + let l:curpos = emmet#util#getcurpos() endif - let n = curpos[1] - let ml = len(matchstr(getline(n), '^\s*')) + let l:n = l:curpos[1] + let l:ml = len(matchstr(getline(l:n), '^\s*')) if a:flag > 0 - if a:flag == 1 || !emmet#util#regionIsValid(block) - let n = line('.') + if a:flag == 1 || !emmet#util#regionIsValid(l:block) + let l:n = line('.') else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) - if l > 0 && l < ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]')) + if l:l > 0 && l:l < l:ml + let l:ml = l:l break endif - let n -= 1 + let l:n -= 1 endwhile endif - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) - if l > 0 && l > ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]')) + if l:l > 0 && l:l > l:ml + let l:ml = l:l break endif - let n += 1 + let l:n += 1 endwhile - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) endif endfunction @@ -144,10 +144,10 @@ function! emmet#lang#sass#moveNextPrevItem(flag) abort endfunction function! emmet#lang#sass#moveNextPrev(flag) abort - let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') - if pos == 2 + let l:pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') + if l:pos == 2 startinsert! - elseif pos != 0 + elseif l:pos != 0 silent! normal! l startinsert endif diff --git a/autoload/emmet/lang/scss.vim b/autoload/emmet/lang/scss.vim index ae35469..cb82d4d 100644 --- a/autoload/emmet/lang/scss.vim +++ b/autoload/emmet/lang/scss.vim @@ -11,53 +11,53 @@ function! emmet#lang#scss#parseIntoTree(abbr, type) abort endfunction function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) abort - let settings = a:settings - let current = a:current - let type = a:type - let inline = a:inline - let filters = a:filters - let itemno = a:itemno - let indent = a:indent - let str = '' + let l:settings = a:settings + let l:current = a:current + let l:type = a:type + let l:inline = a:inline + let l:filters = a:filters + let l:itemno = a:itemno + let l:indent = a:indent + let l:str = '' - let current_name = substitute(current.name, '\$$', itemno+1, '') - if len(current.name) > 0 - let str .= current_name - let tmp = '' - for attr in keys(current.attr) - let val = current.attr[attr] - while val =~# '\$\([^#{]\|$\)' - let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') + let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '') + if len(l:current.name) > 0 + let l:str .= l:current_name + let l:tmp = '' + for l:attr in keys(l:current.attr) + let l:val = l:current.attr[l:attr] + while l:val =~# '\$\([^#{]\|$\)' + let l:val = substitute(l:val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g') endwhile - let attr = substitute(attr, '\$$', itemno+1, '') - if attr ==# 'id' - let str .= '#' . val - elseif attr ==# 'class' - let str .= '.' . val + let l:attr = substitute(l:attr, '\$$', l:itemno+1, '') + if l:attr ==# 'id' + let l:str .= '#' . l:val + elseif l:attr ==# 'class' + let l:str .= '.' . l:val else - let tmp .= attr . ': ' . val . ';' + let l:tmp .= l:attr . ': ' . l:val . ';' endif endfor - if len(tmp) > 0 - let str .= " {\n" - for line in split(tmp, "\n") - let str .= indent . line . "\n" + if len(l:tmp) > 0 + let l:str .= " {\n" + for l:line in split(l:tmp, "\n") + let l:str .= l:indent . l:line . "\n" endfor else - let str .= " {\n" + let l:str .= " {\n" endif - let inner = '' - for child in current.child - let inner .= emmet#toString(child, type, inline, filters, itemno) + let l:inner = '' + for l:child in l:current.child + let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno) endfor - let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') - let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') - let str .= indent . inner . "${cursor}\n}\n" + let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g') + let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g') + let l:str .= l:indent . l:inner . "${cursor}\n}\n" else - return emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) + return emmet#lang#css#toString(l:settings, l:current, l:type, l:inline, l:filters, l:itemno, l:indent) endif - return str + return l:str endfunction function! emmet#lang#scss#imageSize() abort @@ -78,33 +78,33 @@ endfunction function! emmet#lang#scss#balanceTag(flag) range abort if a:flag == -2 || a:flag == 2 - let curpos = [0, line("'<"), col("'<"), 0] - call setpos('.', curpos) + let l:curpos = [0, line("'<"), col("'<"), 0] + call setpos('.', l:curpos) else - let curpos = emmet#util#getcurpos() + let l:curpos = emmet#util#getcurpos() endif if a:flag < 0 - let ret = searchpair('}', '', '.\zs{') + let l:ret = searchpair('}', '', '.\zs{') else - let ret = searchpair('{', '', '}', 'bW') + let l:ret = searchpair('{', '', '}', 'bW') endif - if ret > 0 - let pos1 = emmet#util#getcurpos()[1:2] + if l:ret > 0 + let l:pos1 = emmet#util#getcurpos()[1:2] if a:flag < 0 - let pos2 = searchpairpos('{', '', '}') + let l:pos2 = searchpairpos('{', '', '}') else - let pos2 = searchpairpos('{', '', '}') + let l:pos2 = searchpairpos('{', '', '}') endif - let block = [pos1, pos2] - if emmet#util#regionIsValid(block) - call emmet#util#selectRegion(block) + let l:block = [l:pos1, l:pos2] + if emmet#util#regionIsValid(l:block) + call emmet#util#selectRegion(l:block) return endif endif if a:flag == -2 || a:flag == 2 silent! exe 'normal! gv' else - call setpos('.', curpos) + call setpos('.', l:curpos) endif endfunction diff --git a/autoload/emmet/lang/slim.vim b/autoload/emmet/lang/slim.vim index c583c1c..c64a0fe 100644 --- a/autoload/emmet/lang/slim.vim +++ b/autoload/emmet/lang/slim.vim @@ -7,210 +7,210 @@ function! emmet#lang#slim#parseIntoTree(abbr, type) abort endfunction function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) abort - let current = a:current - let type = a:type - let inline = a:inline - let filters = a:filters - let itemno = a:itemno - let indent = emmet#getIndentation(type) - let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) - let str = '' + let l:current = a:current + let l:type = a:type + let l:inline = a:inline + let l:filters = a:filters + let l:itemno = a:itemno + let l:indent = emmet#getIndentation(l:type) + let l:dollar_expr = emmet#getResource(l:type, 'dollar_expr', 1) + let l:str = '' - let current_name = current.name - if dollar_expr - let current_name = substitute(current.name, '\$$', itemno+1, '') + let l:current_name = l:current.name + if l:dollar_expr + let l:current_name = substitute(l:current.name, '\$$', l:itemno+1, '') endif - if len(current.name) > 0 - let str .= current_name - for attr in emmet#util#unique(current.attrs_order + keys(current.attr)) - if !has_key(current.attr, attr) + if len(l:current.name) > 0 + let l:str .= l:current_name + for l:attr in emmet#util#unique(l:current.attrs_order + keys(l:current.attr)) + if !has_key(l:current.attr, l:attr) continue endif - let Val = current.attr[attr] - if type(Val) == 2 && Val == function('emmet#types#true') - let str .= ' ' . attr . '=true' + let l:Val = l:current.attr[l:attr] + if type(l:Val) == 2 && l:Val == function('emmet#types#true') + let l:str .= ' ' . l:attr . '=true' else - if dollar_expr - while Val =~# '\$\([^#{]\|$\)' - let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') + if l:dollar_expr + while l:Val =~# '\$\([^#{]\|$\)' + let l:Val = substitute(l:Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", l:itemno+1).submatch(2)', 'g') endwhile endif - let attr = substitute(attr, '\$$', itemno+1, '') - let str .= ' ' . attr . '="' . Val . '"' + let l:attr = substitute(l:attr, '\$$', l:itemno+1, '') + let l:str .= ' ' . l:attr . '="' . l:Val . '"' endif endfor - let inner = '' - if len(current.value) > 0 - let str .= "\n" - let text = current.value[1:-2] - if dollar_expr - let text = substitute(text, '\%(\\\)\@\ 0 + let l:str .= "\n" + let l:text = l:current.value[1:-2] + if l:dollar_expr + let l:text = substitute(l:text, '\%(\\\)\@\ 0 - for child in current.child - let inner .= emmet#toString(child, type, inline, filters, itemno, indent) + elseif len(l:current.child) > 0 + for l:child in l:current.child + let l:inner .= emmet#toString(l:child, l:type, l:inline, l:filters, l:itemno, l:indent) endfor - let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') - let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') - let str .= "\n" . indent . inner + let l:inner = substitute(l:inner, "\n", "\n" . escape(l:indent, '\'), 'g') + let l:inner = substitute(l:inner, "\n" . escape(l:indent, '\') . '$', '', 'g') + let l:str .= "\n" . l:indent . l:inner endif else - let str = current.value[1:-2] - if dollar_expr - let str = substitute(str, '\%(\\\)\@\ 0 - let match = matchstr(attrs, mx) - if len(match) == 0 + let l:current = emmet#newNode() + let l:mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)' + let l:match = matchstr(a:tag, l:mx) + let l:current.name = substitute(l:match, l:mx, '\1', '') + let l:attrs = substitute(l:match, l:mx, '\2', '') + let l:mx = '\([a-zA-Z0-9]\+\)=\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' + while len(l:attrs) > 0 + let l:match = matchstr(l:attrs, l:mx) + if len(l:match) == 0 break endif - let attr_match = matchlist(match, mx) - let name = attr_match[1] - let value = len(attr_match[2]) ? attr_match[2] : attr_match[3] - let current.attr[name] = value - let current.attrs_order += [name] - let attrs = attrs[stridx(attrs, match) + len(match):] + let l:attr_match = matchlist(l:match, l:mx) + let l:name = l:attr_match[1] + let l:value = len(l:attr_match[2]) ? l:attr_match[2] : l:attr_match[3] + let l:current.attr[l:name] = l:value + let l:current.attrs_order += [l:name] + let l:attrs = l:attrs[stridx(l:attrs, l:match) + len(l:match):] endwhile - return current + return l:current endfunction function! emmet#lang#slim#toggleComment() abort - let line = getline('.') - let space = matchstr(line, '^\s*') - if line =~# '^\s*/' - call setline('.', space . line[len(space)+1:]) - elseif line =~# '^\s*[a-z]' - call setline('.', space . '/' . line[len(space):]) + let l:line = getline('.') + let l:space = matchstr(l:line, '^\s*') + if l:line =~# '^\s*/' + call setline('.', l:space . l:line[len(l:space)+1:]) + elseif l:line =~# '^\s*[a-z]' + call setline('.', l:space . '/' . l:line[len(l:space):]) endif endfunction function! emmet#lang#slim#balanceTag(flag) range abort - let block = emmet#util#getVisualBlock() + let l:block = emmet#util#getVisualBlock() if a:flag == -2 || a:flag == 2 - let curpos = [0, line("'<"), col("'<"), 0] + let l:curpos = [0, line("'<"), col("'<"), 0] else - let curpos = emmet#util#getcurpos() + let l:curpos = emmet#util#getcurpos() endif - let n = curpos[1] - let ml = len(matchstr(getline(n), '^\s*')) + let l:n = l:curpos[1] + let l:ml = len(matchstr(getline(l:n), '^\s*')) if a:flag > 0 - if a:flag == 1 || !emmet#util#regionIsValid(block) - let n = line('.') + if a:flag == 1 || !emmet#util#regionIsValid(l:block) + let l:n = line('.') else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) - if l > 0 && l < ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]')) + if l:l > 0 && l:l < l:ml + let l:ml = l:l break endif - let n -= 1 + let l:n -= 1 endwhile endif - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) else - while n > 0 - let l = len(matchstr(getline(n), '^\s*\ze[a-z]')) - if l > 0 && l > ml - let ml = l + while l:n > 0 + let l:l = len(matchstr(getline(l:n), '^\s*\ze[a-z]')) + if l:l > 0 && l:l > l:ml + let l:ml = l:l break endif - let n += 1 + let l:n += 1 endwhile - let sn = n - if n == 0 - let ml = 0 + let l:sn = l:n + if l:n == 0 + let l:ml = 0 endif - while n < line('$') - let l = len(matchstr(getline(n), '^\s*[a-z]')) - if l > 0 && l <= ml - let n -= 1 + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - call setpos('.', [0, n, 1, 0]) + call setpos('.', [0, l:n, 1, 0]) normal! V - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) endif endfunction @@ -219,64 +219,64 @@ function! emmet#lang#slim#moveNextPrevItem(flag) abort endfunction function! emmet#lang#slim#moveNextPrev(flag) abort - let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') - if pos == 2 + let l:pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') + if l:pos == 2 startinsert! - elseif pos != 0 + elseif l:pos != 0 silent! normal! l startinsert endif endfunction function! emmet#lang#slim#splitJoinTag() abort - let n = line('.') - while n > 0 - if getline(n) =~# '^\s*\ze[a-z]' - let sn = n - let n += 1 - if getline(n) =~# '^\s*|' - while n <= line('$') - if getline(n) !~# '^\s*|' + let l:n = line('.') + while l:n > 0 + if getline(l:n) =~# '^\s*\ze[a-z]' + let l:sn = l:n + let l:n += 1 + if getline(l:n) =~# '^\s*|' + while l:n <= line('$') + if getline(l:n) !~# '^\s*|' break endif - exe n 'delete' + exe l:n 'delete' endwhile - call setpos('.', [0, sn, 1, 0]) + call setpos('.', [0, l:sn, 1, 0]) else - let spaces = matchstr(getline(sn), '^\s*') - call append(sn, spaces . ' | ') - call setpos('.', [0, sn+1, 1, 0]) + let l:spaces = matchstr(getline(l:sn), '^\s*') + call append(l:sn, l:spaces . ' | ') + call setpos('.', [0, l:sn+1, 1, 0]) startinsert! endif break endif - let n -= 1 + let l:n -= 1 endwhile endfunction function! emmet#lang#slim#removeTag() abort - let n = line('.') - let ml = 0 - while n > 0 - if getline(n) =~# '^\s*\ze[a-z]' - let ml = len(matchstr(getline(n), '^\s*[a-z]')) + let l:n = line('.') + let l:ml = 0 + while l:n > 0 + if getline(l:n) =~# '^\s*\ze[a-z]' + let l:ml = len(matchstr(getline(l:n), '^\s*[a-z]')) break endif - let n -= 1 + let l:n -= 1 endwhile - let sn = n - while n < line('$') - let l = len(matchstr(getline(n), '^\s*[a-z]')) - if l > 0 && l <= ml - let n -= 1 + let l:sn = l:n + while l:n < line('$') + let l:l = len(matchstr(getline(l:n), '^\s*[a-z]')) + if l:l > 0 && l:l <= l:ml + let l:n -= 1 break endif - let n += 1 + let l:n += 1 endwhile - if sn == n + if l:sn == l:n exe 'delete' else - exe sn ',' (n-1) 'delete' + exe l:sn ',' (l:n-1) 'delete' endif endfunction diff --git a/autoload/emmet/lorem/en.vim b/autoload/emmet/lorem/en.vim index 30713e4..459fba1 100644 --- a/autoload/emmet/lorem/en.vim +++ b/autoload/emmet/lorem/en.vim @@ -1,9 +1,9 @@ function! emmet#lorem#en#expand(command) abort - let wcount = matchstr(a:command, '\(\d*\)$') - let wcount = wcount > 0 ? wcount : 30 - - let common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit'] - let words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet', + let l:wcount = matchstr(a:command, '\(\d*\)$') + let l:wcount = l:wcount > 0 ? l:wcount : 30 + + let l:common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit'] + let l:words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet', \ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi', \ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi', \ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos', @@ -32,34 +32,34 @@ function! emmet#lorem#en#expand(command) abort \ 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique', \ 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere', \ 'maxime', 'corrupti'] - let ret = [] - let sentence = 0 - for i in range(wcount) - let arr = common - if sentence > 0 - let arr += words + let l:ret = [] + let l:sentence = 0 + for l:i in range(l:wcount) + let l:arr = l:common + if l:sentence > 0 + let l:arr += l:words endif - let r = emmet#util#rand() - let word = arr[r % len(arr)] - if sentence == 0 - let word = substitute(word, '^.', '\U&', '') + let l:r = emmet#util#rand() + let l:word = l:arr[l:r % len(l:arr)] + if l:sentence == 0 + let l:word = substitute(l:word, '^.', '\U&', '') endif - let sentence += 1 - call add(ret, word) - if (sentence > 5 && emmet#util#rand() < 10000) || i == wcount - 1 - if i == wcount - 1 - let endc = '?!...'[emmet#util#rand() % 5] - call add(ret, endc) + let l:sentence += 1 + call add(l:ret, l:word) + if (l:sentence > 5 && emmet#util#rand() < 10000) || l:i == l:wcount - 1 + if l:i == l:wcount - 1 + let l:endc = '?!...'[emmet#util#rand() % 5] + call add(l:ret, l:endc) else - let endc = '?!,...'[emmet#util#rand() % 6] - call add(ret, endc . ' ') + let l:endc = '?!,...'[emmet#util#rand() % 6] + call add(l:ret, l:endc . ' ') endif - if endc !=# ',' - let sentence = 0 + if l:endc !=# ',' + let l:sentence = 0 endif else - call add(ret, ' ') + call add(l:ret, ' ') endif endfor - return join(ret, '') + return join(l:ret, '') endfunction diff --git a/autoload/emmet/lorem/ja.vim b/autoload/emmet/lorem/ja.vim index f99d8fa..2b430dc 100644 --- a/autoload/emmet/lorem/ja.vim +++ b/autoload/emmet/lorem/ja.vim @@ -1,27 +1,27 @@ scriptencoding utf-8 function! emmet#lorem#ja#expand(command) abort - let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '') - let wcount = wcount > 0 ? wcount : 30 + let l:wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '') + let l:wcount = l:wcount > 0 ? l:wcount : 30 - let url = "http://www.aozora.gr.jp/cards/000081/files/470_15407.html" - let content = emmet#util#cache(url) - if len(content) == 0 - let content = emmet#util#getContentFromURL(url) - let content = matchstr(content, ']*>\zs.\{-}') - let content = substitute(content, '[ \r]', '', 'g') - let content = substitute(content, ']*>', "\n", 'g') - let content = substitute(content, '<[^>]\+>', '', 'g') - let content = join(filter(split(content, "\n"), 'len(v:val)>0'), "\n") - call emmet#util#cache(url, content) + let l:url = "http://www.aozora.gr.jp/cards/000081/files/470_15407.html" + let l:content = emmet#util#cache(l:url) + if len(l:content) == 0 + let l:content = emmet#util#getContentFromURL(l:url) + let l:content = matchstr(l:content, ']*>\zs.\{-}') + let l:content = substitute(l:content, '[ \r]', '', 'g') + let l:content = substitute(l:content, ']*>', "\n", 'g') + let l:content = substitute(l:content, '<[^>]\+>', '', 'g') + let l:content = join(filter(split(l:content, "\n"), 'len(v:val)>0'), "\n") + call emmet#util#cache(l:url, l:content) endif - - let content = substitute(content, "、\n", "、", "g") - let clines = split(content, '\n') - let lines = filter(clines, 'len(substitute(v:val,".",".","g"))<=wcount') - if len(lines) == 0 - let lines = clines + + let l:content = substitute(l:content, "、\n", "、", "g") + let l:clines = split(l:content, '\n') + let l:lines = filter(l:clines, 'len(substitute(v:val,".",".","g"))<=l:wcount') + if len(l:lines) == 0 + let l:lines = l:clines endif - let r = emmet#util#rand() - return lines[r % len(lines)] + let l:r = emmet#util#rand() + return l:lines[l:r % len(l:lines)] endfunction diff --git a/autoload/emmet/util.vim b/autoload/emmet/util.vim index c76dc3c..4891778 100644 --- a/autoload/emmet/util.vim +++ b/autoload/emmet/util.vim @@ -12,10 +12,10 @@ " begin::end " -------------------- 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]) 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 " change_content : change content in region @@ -37,36 +37,36 @@ endfunction " baz:end " -------------------- function! emmet#util#setContent(region, content) abort - let newlines = split(a:content, '\n', 1) - let oldlines = getline(a:region[0][0], a:region[1][0]) + let l:newlines = split(a:content, '\n', 1) + let l:oldlines = getline(a:region[0][0], a:region[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]) - if len(newlines) == 0 - let tmp = '' + if len(l:newlines) == 0 + let l:tmp = '' 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 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 - call setline(line('.'), tmp) - elseif len(newlines) == 1 + call setline(line('.'), l:tmp) + elseif len(l:newlines) == 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 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 - call setline(line('.'), newlines[0]) + call setline(line('.'), l:newlines[0]) else 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 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 - call setline(line('.'), newlines[0]) - call append(line('.'), newlines[1:]) + call setline(line('.'), l:newlines[0]) + call append(line('.'), l:newlines[1:]) endif endfunction @@ -93,8 +93,8 @@ endfunction " this function return 0 or 1 function! emmet#util#cursorInRegion(region) abort if !emmet#util#regionIsValid(a:region) | return 0 | endif - let cur = emmet#util#getcurpos()[1:2] - return emmet#util#pointInRegion(cur, a:region) + let l:cur = emmet#util#getcurpos()[1:2] + return emmet#util#pointInRegion(l:cur, a:region) endfunction " region_is_valid : check region is valid @@ -107,11 +107,11 @@ endfunction " search_region : make region from pattern which is composing start/end " this function return array of position function! emmet#util#searchRegion(start, end) abort - let b = searchpairpos(a:start, '', a:end, 'bcnW') - if b == [0, 0] + let l:b = searchpairpos(a:start, '', a:end, 'bcnW') + if l:b == [0, 0] return [searchpairpos(a:start, '', a:end, 'bnW'), searchpairpos(a:start, '\%#', a:end, 'nW')] else - return [b, searchpairpos(a:start, '', a:end. '', 'nW')] + return [l:b, searchpairpos(a:start, '', a:end. '', 'nW')] endif endfunction @@ -121,14 +121,14 @@ function! emmet#util#getContent(region) abort if !emmet#util#regionIsValid(a:region) return '' 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] - 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 - let lines[0] = lines[0][a:region[0][1]-1:] - let lines[-1] = lines[-1][:a:region[1][1]-1] + let l:lines[0] = l:lines[0][a:region[0][1]-1:] + let l:lines[-1] = l:lines[-1][:a:region[1][1]-1] endif - return join(lines, "\n") + return join(l:lines, "\n") endfunction " region_in_region : check region is in the region @@ -150,145 +150,145 @@ endfunction " html utils "============================================================================== function! emmet#util#getContentFromURL(url) abort - let 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' - let pos = stridx(res, "\r\n\r\n") - if pos != -1 - let res = strpart(res, pos+4) + let l:res = system(printf('%s -i %s', g:emmet_curl_command, shellescape(substitute(a:url, '#.*', '', '')))) + while l:res =~# '^HTTP/1.\d 3' || l:res =~# '^HTTP/1\.\d 200 Connection established' || l:res =~# '^HTTP/1\.\d 100 Continue' + let l:pos = stridx(l:res, "\r\n\r\n") + if l:pos != -1 + let l:res = strpart(l:res, l:pos+4) else - let pos = stridx(res, "\n\n") - let res = strpart(res, pos+2) + let l:pos = stridx(l:res, "\n\n") + let l:res = strpart(l:res, l:pos+2) endif endwhile - let pos = stridx(res, "\r\n\r\n") - if pos != -1 - let content = strpart(res, pos+4) + let l:pos = stridx(l:res, "\r\n\r\n") + if l:pos != -1 + let l:content = strpart(l:res, l:pos+4) else - let pos = stridx(res, "\n\n") - let content = strpart(res, pos+2) + let l:pos = stridx(l:res, "\n\n") + let l:content = strpart(l:res, l:pos+2) endif - let header = res[:pos-1] - let charset = matchstr(content, ']\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>') - if len(charset) == 0 - let charset = matchstr(content, ']*>') + let l:header = l:res[:l:pos-1] + let l:charset = matchstr(l:content, ']\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>') + if len(l:charset) == 0 + let l:charset = matchstr(l:content, ']*>') endif - if len(charset) == 0 - let charset = matchstr(header, '\nContent-Type:.* charset=[''"]\?\zs[^''";\n]\+\ze') + if len(l:charset) == 0 + let l:charset = matchstr(l:header, '\nContent-Type:.* charset=[''"]\?\zs[^''";\n]\+\ze') endif - if len(charset) == 0 - let s1 = len(split(content, '?')) - let utf8 = iconv(content, 'utf-8', &encoding) - let s2 = len(split(utf8, '?')) - return (s2 == s1 || s2 >= s1 * 2) ? utf8 : content + if len(l:charset) == 0 + let l:s1 = len(split(l:content, '?')) + let l:utf8 = iconv(l:content, 'utf-8', &encoding) + let l:s2 = len(split(l:utf8, '?')) + return (l:s2 == l:s1 || l:s2 >= l:s1 * 2) ? l:utf8 : l:content endif - return iconv(content, charset, &encoding) + return iconv(l:content, l:charset, &encoding) endfunction function! emmet#util#getTextFromHTML(buf) abort - let threshold_len = 100 - let threshold_per = 0.1 - let buf = a:buf + let l:threshold_len = 100 + let l:threshold_per = 0.1 + let l:buf = a:buf - let buf = strpart(buf, stridx(buf, '')) - let buf = substitute(buf, ']*>.\{-}', '', 'g') - let buf = substitute(buf, ']*>.\{-}', '', 'g') - let res = '' - let max = 0 - let mx = '\(]\{-}>\)\|\(<\/td>\)\|\(]\{-}>\)\|\(<\/div>\)' - let m = split(buf, mx) - for str in m - let c = split(str, '<[^>]*?>') - let str = substitute(str, '<[^>]\{-}>', ' ', 'g') - let str = substitute(str, '>', '>', 'g') - let str = substitute(str, '<', '<', 'g') - let str = substitute(str, '"', '"', 'g') - let str = substitute(str, ''', '''', 'g') - let str = substitute(str, ' ', ' ', 'g') - let str = substitute(str, '¥', '\¥', 'g') - let str = substitute(str, '&', '\&', 'g') - let str = substitute(str, '^\s*\(.*\)\s*$', '\1', '') - let str = substitute(str, '\s\+', ' ', 'g') - let l = len(str) - if l > threshold_len - let per = (l+0.0) / len(c) - if max < l && per > threshold_per - let max = l - let res = str + let l:buf = strpart(l:buf, stridx(l:buf, '')) + let l:buf = substitute(l:buf, ']*>.\{-}', '', 'g') + let l:buf = substitute(l:buf, ']*>.\{-}', '', 'g') + let l:res = '' + let l:max = 0 + let l:mx = '\(]\{-}>\)\|\(<\/td>\)\|\(]\{-}>\)\|\(<\/div>\)' + let l:m = split(l:buf, l:mx) + for l:str in l:m + let l:c = split(l:str, '<[^>]*?>') + let l:str = substitute(l:str, '<[^>]\{-}>', ' ', 'g') + let l:str = substitute(l:str, '>', '>', 'g') + let l:str = substitute(l:str, '<', '<', 'g') + let l:str = substitute(l:str, '"', '"', 'g') + let l:str = substitute(l:str, ''', '''', 'g') + let l:str = substitute(l:str, ' ', ' ', 'g') + let l:str = substitute(l:str, '¥', '\¥', 'g') + let l:str = substitute(l:str, '&', '\&', 'g') + let l:str = substitute(l:str, '^\s*\(.*\)\s*$', '\1', '') + let l:str = substitute(l:str, '\s\+', ' ', 'g') + let l:l = len(l:str) + if l:l > l:threshold_len + let l:per = (l:l+0.0) / len(l:c) + if l:max < l:l && l:per > l:threshold_per + let l:max = l:l + let l:res = l:str endif endif endfor - let res = substitute(res, '^\s*\(.*\)\s*$', '\1', 'g') - return res + let l:res = substitute(l:res, '^\s*\(.*\)\s*$', '\1', 'g') + return l:res endfunction function! emmet#util#getImageSize(fn) abort - let fn = a:fn + let l:fn = a:fn if emmet#util#isImageMagickInstalled() - return emmet#util#imageSizeWithImageMagick(fn) + return emmet#util#imageSizeWithImageMagick(l:fn) endif - if filereadable(fn) - let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') + if filereadable(l:fn) + let l:hex = substitute(system('xxd -p "'.l:fn.'"'), '\n', '', 'g') else - if fn !~# '^\w\+://' - let path = fnamemodify(expand('%'), ':p:gs?\\?/?') + if l:fn !~# '^\w\+://' + let l:path = fnamemodify(expand('%'), ':p:gs?\\?/?') if has('win32') || has('win64') | - let path = tolower(path) + let l:path = tolower(l:path) endif - for k in keys(g:emmet_docroot) - let root = fnamemodify(k, ':p:gs?\\?/?') + for l:k in keys(g:emmet_docroot) + let l:root = fnamemodify(l:k, ':p:gs?\\?/?') if has('win32') || has('win64') | - let root = tolower(root) + let l:root = tolower(l:root) endif - if stridx(path, root) == 0 - let v = g:emmet_docroot[k] - let fn = (len(v) == 0 ? k : v) . fn + if stridx(l:path, l:root) == 0 + let l:v = g:emmet_docroot[l:k] + let l:fn = (len(l:v) == 0 ? l:k : l:v) . l:fn break endif endfor endif - let hex = substitute(system(g:emmet_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g') + let l:hex = substitute(system(g:emmet_curl_command.' "'.l:fn.'" | xxd -p'), '\n', '', 'g') endif - let [width, height] = [-1, -1] - if hex =~# '^89504e470d0a1a0a' - let width = eval('0x'.hex[32:39]) - let height = eval('0x'.hex[40:47]) + let [l:width, l:height] = [-1, -1] + if l:hex =~# '^89504e470d0a1a0a' + let l:width = eval('0x'.l:hex[32:39]) + let l:height = eval('0x'.l:hex[40:47]) endif - if hex =~# '^ffd8' - let pos = 4 - while pos < len(hex) - let bs = hex[pos+0:pos+3] - let pos += 4 - if bs ==# 'ffc0' || bs ==# 'ffc2' - let pos += 6 - let height = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) - let pos += 4 - let width = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) + if l:hex =~# '^ffd8' + let l:pos = 4 + while l:pos < len(l:hex) + let l:bs = l:hex[l:pos+0:l:pos+3] + let l:pos += 4 + if l:bs ==# 'ffc0' || l:bs ==# 'ffc2' + let l:pos += 6 + 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 l:pos += 4 + 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 - elseif bs =~# 'ffd[9a]' + elseif l:bs =~# 'ffd[9a]' break - elseif 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 + elseif l:bs =~# 'ff\(e[0-9a-e]\|fe\|db\|dd\|c4\)' + 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 endwhile endif - if hex =~# '^47494638' - let width = eval('0x'.hex[14:15].hex[12:13]) - let height = eval('0x'.hex[18:19].hex[16:17]) + if l:hex =~# '^47494638' + let l:width = eval('0x'.l:hex[14:15].l:hex[12:13]) + let l:height = eval('0x'.l:hex[18:19].l:hex[16:17]) endif - return [width, height] + return [l:width, l:height] endfunction function! emmet#util#imageSizeWithImageMagick(fn) abort - let img_info = system('identify -format "%wx%h" "'.a:fn.'"') - let img_size = split(substitute(img_info, '\n', '', ''), 'x') - if len(img_size) != 2 + let l:img_info = system('identify -format "%wx%h" "'.a:fn.'"') + let l:img_size = split(substitute(l:img_info, '\n', '', ''), 'x') + if len(l:img_size) != 2 return [-1, -1] endif - return img_size + return l:img_size endfunction function! emmet#util#isImageMagickInstalled() abort @@ -299,78 +299,78 @@ function! emmet#util#isImageMagickInstalled() abort endfunction function! s:b64encode(bytes, table, pad) - let b64 = [] - for i in range(0, len(a:bytes) - 1, 3) - let n = a:bytes[i] * 0x10000 - \ + get(a:bytes, i + 1, 0) * 0x100 - \ + get(a:bytes, i + 2, 0) - call add(b64, a:table[n / 0x40000]) - call add(b64, a:table[n / 0x1000 % 0x40]) - call add(b64, a:table[n / 0x40 % 0x40]) - call add(b64, a:table[n % 0x40]) + let l:b64 = [] + for l:i in range(0, len(a:bytes) - 1, 3) + let l:n = a:bytes[l:i] * 0x10000 + \ + get(a:bytes, l:i + 1, 0) * 0x100 + \ + get(a:bytes, l:i + 2, 0) + call add(l:b64, a:table[l:n / 0x40000]) + call add(l:b64, a:table[l:n / 0x1000 % 0x40]) + call add(l:b64, a:table[l:n / 0x40 % 0x40]) + call add(l:b64, a:table[l:n % 0x40]) endfor if len(a:bytes) % 3 == 2 - let b64[-1] = a:pad + let l:b64[-1] = a:pad elseif len(a:bytes) % 3 == 1 - let b64[-1] = a:pad - let b64[-2] = a:pad + let l:b64[-1] = a:pad + let l:b64[-2] = a:pad endif - return b64 + return l:b64 endfunction function! emmet#util#imageEncodeDecode(fn, flag) abort - let fn = a:fn + let l:fn = a:fn - if filereadable(fn) - let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') + if filereadable(l:fn) + let l:hex = substitute(system('xxd -p "'.l:fn.'"'), '\n', '', 'g') else - if fn !~# '^\w\+://' - let path = fnamemodify(expand('%'), ':p:gs?\\?/?') + if l:fn !~# '^\w\+://' + let l:path = fnamemodify(expand('%'), ':p:gs?\\?/?') if has('win32') || has('win64') | - let path = tolower(path) + let l:path = tolower(l:path) endif - for k in keys(g:emmet_docroot) - let root = fnamemodify(k, ':p:gs?\\?/?') + for l:k in keys(g:emmet_docroot) + let l:root = fnamemodify(l:k, ':p:gs?\\?/?') if has('win32') || has('win64') | - let root = tolower(root) + let l:root = tolower(l:root) endif - if stridx(path, root) == 0 - let v = g:emmet_docroot[k] - let fn = (len(v) == 0 ? k : v) . fn + if stridx(l:path, l:root) == 0 + let l:v = g:emmet_docroot[l:k] + let l:fn = (len(l:v) == 0 ? l:k : l:v) . l:fn break endif endfor endif - let hex = substitute(system(g:emmet_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g') + let l:hex = substitute(system(g:emmet_curl_command.' "'.l:fn.'" | xxd -p'), '\n', '', 'g') endif - let bin = map(split(hex, '..\zs'), 'eval("0x" . v:val)') - let table = split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', '\zs') - let ret = 'data:image/' - if hex =~# '^89504e470d0a1a0a' - let ret .= 'png' - elseif hex =~# '^ffd8' - let ret .= 'jpeg' - elseif hex =~# '^47494638' - let ret .= 'gif' - elseif hex =~# '^00000020667479706176696600000000' - let ret .= 'avif' + let l:bin = map(split(l:hex, '..\zs'), 'eval("0x" . v:val)') + let l:table = split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', '\zs') + let l:ret = 'data:image/' + if l:hex =~# '^89504e470d0a1a0a' + let l:ret .= 'png' + elseif l:hex =~# '^ffd8' + let l:ret .= 'jpeg' + elseif l:hex =~# '^47494638' + let l:ret .= 'gif' + elseif l:hex =~# '^00000020667479706176696600000000' + let l:ret .= 'avif' else - let ret .= 'unknown' + let l:ret .= 'unknown' endif - return ret . ';base64,' . join(s:b64encode(bin, table, '='), '') + return l:ret . ';base64,' . join(s:b64encode(l:bin, l:table, '='), '') endfunction function! emmet#util#unique(arr) abort - let m = {} - let r = [] - for i in a:arr - if !has_key(m, i) - let m[i] = 1 - call add(r, i) + let l:m = {} + let l:r = [] + for l:i in a:arr + if !has_key(l:m, l:i) + let l:m[l:i] = 1 + call add(l:r, l:i) endif endfor - return r + return l:r endfunction let s:seed = localtime() @@ -384,27 +384,27 @@ function! emmet#util#rand() abort endfunction function! emmet#util#cache(name, ...) abort - let content = get(a:000, 0, '') - let dir = expand('~/.emmet/cache') - if !isdirectory(dir) - call mkdir(dir, 'p', 0700) + let l:content = get(a:000, 0, '') + let l:dir = expand('~/.emmet/cache') + if !isdirectory(l:dir) + call mkdir(l:dir, 'p', 0700) endif - let file = dir . '/' . substitute(a:name, '\W', '_', 'g') - if len(content) == 0 - if !filereadable(file) + let l:file = l:dir . '/' . substitute(a:name, '\W', '_', 'g') + if len(l:content) == 0 + if !filereadable(l:file) return '' endif - return join(readfile(file), "\n") + return join(readfile(l:file), "\n") endif - call writefile(split(content, "\n"), file) + call writefile(split(l:content, "\n"), l:file) endfunction function! emmet#util#getcurpos() abort - let pos = getpos('.') - if mode(0) ==# 'i' && pos[2] > 0 - let pos[2] -=1 + let l:pos = getpos('.') + if mode(0) ==# 'i' && l:pos[2] > 0 + let l:pos[2] -=1 endif - return pos + return l:pos endfunction function! emmet#util#closePopup() abort diff --git a/plugin/emmet.vim b/plugin/emmet.vim index 334bcfb..f011c2d 100644 --- a/plugin/emmet.vim +++ b/plugin/emmet.vim @@ -96,8 +96,8 @@ if !exists('g:user_emmet_leader_key') endif function! s:install_plugin(mode, buffer) - let buffer = a:buffer ? '' : '' - let items = [ + let l:buffer = a:buffer ? '' : '' + let l:items = [ \ {'mode': 'i', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': '=emmet#util#closePopup()=emmet#expandAbbr(0,"")'}, \ {'mode': 'n', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(3,"")'}, \ {'mode': 'v', 'var': 'user_emmet_expandabbr_key', 'key': ',', 'plug': 'emmet-expand-abbr', 'func': ':call emmet#expandAbbr(2,"")'}, @@ -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()'}, \] - let only_plug = get(g:, 'emmet_install_only_plug', 0) - for item in items - if a:mode !=# 'a' && stridx(a:mode, item.mode) == -1 + let l:only_plug = get(g:, 'emmet_install_only_plug', 0) + for l:item in l:items + if a:mode !=# 'a' && stridx(a:mode, l:item.mode) == -1 continue endif - exe item.mode . 'noremap '. buffer .' (' . item.plug . ') ' . item.func - if item.var != '' && !only_plug - if exists('g:' . item.var) - let key = eval('g:' . item.var) + exe l:item.mode . 'noremap '. l:buffer .' (' . l:item.plug . ') ' . l:item.func + if l:item.var != '' && !l:only_plug + if exists('g:' . l:item.var) + let l:key = eval('g:' . l:item.var) else - let key = g:user_emmet_leader_key . item.key + let l:key = g:user_emmet_leader_key . l:item.key endif - if !hasmapto('(' . item.plug . ')', item.mode) && !len(maparg(key, item.mode)) - exe item.mode . 'map ' . buffer . ' ' . key . ' (' . item.plug . ')' + if !hasmapto('(' . l:item.plug . ')', l:item.mode) && !len(maparg(l:key, l:item.mode)) + exe l:item.mode . 'map ' . l:buffer . ' ' . l:key . ' (' . l:item.plug . ')' endif endif endfor