Fixes against errors/warnings in vint

This commit is contained in:
mattn
2014-12-17 17:26:10 +09:00
parent edf74342b5
commit 47b54c2e5e
11 changed files with 253 additions and 254 deletions

View File

@@ -44,6 +44,8 @@ function! emmet#getIndentation(...) abort
endif endif
if has_key(s:emmet_settings, type) && has_key(s:emmet_settings[type], 'indentation') if has_key(s:emmet_settings, type) && has_key(s:emmet_settings[type], 'indentation')
let indent = s:emmet_settings[type].indentation let indent = s:emmet_settings[type].indentation
elseif has_key(s:emmet_settings.variables, 'indentation')
let indent = s:emmet_settings.variables.indentation
elseif has_key(s:emmet_settings, 'indentation') elseif has_key(s:emmet_settings, 'indentation')
let indent = s:emmet_settings.indentation let indent = s:emmet_settings.indentation
else else
@@ -436,9 +438,10 @@ function! emmet#expandCursorExpr(expand, mode) abort
let expand .= '${cursor}' let expand .= '${cursor}'
endif endif
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}', '$cursor$', '')
let expand = substitute(expand, '\${cursor}', '', 'g') let expand = substitute(expand, '\${cursor}', '', 'g')
let expand = substitute(expand, '\${\d\+:\?\([^}]\+\)}', '$select$\1$select$', 'g')
let expand = substitute(expand, '\${cursor}', '', 'g') let expand = substitute(expand, '\${cursor}', '', 'g')
return expand return expand
endfunction endfunction
@@ -668,17 +671,14 @@ function! emmet#expandAbbr(mode, abbr) range abort
silent! foldopen silent! foldopen
endif endif
let pos = emmet#util#getcurpos() let pos = emmet#util#getcurpos()
if getline('.')[col('.')-1:] =~# '^\$select' let use_selection = emmet#getResource(type, 'use_selection', 0)
if use_selection && getline('.')[col('.')-1:] =~# '^\$select'
let pos[2] += 1 let pos[2] += 1
silent! s/\$select\$// silent! s/\$select\$//
if emmet#getResource(type, 'use_selection', 0)
let next = searchpos('.\ze\$select\$', 'nW') let next = searchpos('.\ze\$select\$', 'nW')
silent! %s/\$\(cursor\|select\)\$//g silent! %s/\$\(cursor\|select\)\$//g
call emmet#util#selectRegion([pos[1:2], next]) call emmet#util#selectRegion([pos[1:2], next])
return "\<esc>gv" return "\<esc>gv"
endif
silent! %s/\$\(cursor\|select\)\$//g
silent! call setpos('.', pos)
else else
silent! %s/\$\(cursor\|select\)\$//g silent! %s/\$\(cursor\|select\)\$//g
silent! call setpos('.', pos) silent! call setpos('.', pos)
@@ -883,7 +883,6 @@ function! emmet#expandWord(abbr, type, orig) abort
if a:orig ==# 0 if a:orig ==# 0
let expand = emmet#expandDollarExpr(expand) let expand = emmet#expandDollarExpr(expand)
let expand = substitute(expand, '\${cursor}', '', 'g') let expand = substitute(expand, '\${cursor}', '', 'g')
let expand = substitute(expand, '\${\d\+\(:[^}]\+\|\)}', '\1', 'g')
endif endif
return expand return expand
endfunction endfunction

View File

@@ -1,5 +1,5 @@
let s:exists = {} let s:exists = {}
function! emmet#lang#exists(type) function! emmet#lang#exists(type) abort
if len(a:type) == 0 if len(a:type) == 0
return 0 return 0
elseif has_key(s:exists, a:type) elseif has_key(s:exists, a:type)

View File

@@ -1,12 +1,12 @@
function! emmet#lang#haml#findTokens(str) function! emmet#lang#haml#findTokens(str) abort
return emmet#lang#html#findTokens(a:str) return emmet#lang#html#findTokens(a:str)
endfunction endfunction
function! emmet#lang#haml#parseIntoTree(abbr, type) function! emmet#lang#haml#parseIntoTree(abbr, type) abort
return emmet#lang#html#parseIntoTree(a:abbr, a:type) return emmet#lang#html#parseIntoTree(a:abbr, a:type)
endfunction endfunction
function! emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) function! emmet#lang#haml#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let settings = a:settings
let current = a:current let current = a:current
let type = a:type let type = a:type
@@ -16,7 +16,7 @@ function! emmet#lang#haml#toString(settings, current, type, inline, filters, ite
let indent = emmet#getIndentation(type) let indent = emmet#getIndentation(type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
let attribute_style = emmet#getResource('haml', 'attribute_style', 'hash') let attribute_style = emmet#getResource('haml', 'attribute_style', 'hash')
let str = "" let str = ''
let current_name = current.name let current_name = current.name
if dollar_expr if dollar_expr
@@ -31,49 +31,49 @@ function! emmet#lang#haml#toString(settings, current, type, inline, filters, ite
endif endif
let Val = current.attr[attr] let Val = current.attr[attr]
if type(Val) == 2 && Val == function('emmet#types#true') if type(Val) == 2 && Val == function('emmet#types#true')
if attribute_style == 'hash' if attribute_style ==# 'hash'
let tmp .= ' :' . attr . ' => true' let tmp .= ' :' . attr . ' => true'
elseif attribute_style == 'html' elseif attribute_style ==# 'html'
let tmp .= attr . '=true' let tmp .= attr . '=true'
end end
else else
if dollar_expr if dollar_expr
while Val =~ '\$\([^#{]\|$\)' while Val =~# '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let attr = substitute(attr, '\$$', itemno+1, '')
endif endif
let valtmp = substitute(Val, '\${cursor}', '', '') let valtmp = substitute(Val, '\${cursor}', '', '')
if attr == 'id' && len(valtmp) > 0 if attr ==# 'id' && len(valtmp) > 0
let str .= '#' . Val let str .= '#' . Val
elseif attr == 'class' && len(valtmp) > 0 elseif attr ==# 'class' && len(valtmp) > 0
let str .= '.' . substitute(Val, ' ', '.', 'g') let str .= '.' . substitute(Val, ' ', '.', 'g')
else else
if len(tmp) > 0 if len(tmp) > 0
if attribute_style == 'hash' if attribute_style ==# 'hash'
let tmp .= ',' let tmp .= ','
elseif attribute_style == 'html' elseif attribute_style ==# 'html'
let tmp .= ' ' let tmp .= ' '
endif endif
endif endif
let Val = substitute(Val, '\${cursor}', '', '') let Val = substitute(Val, '\${cursor}', '', '')
if attribute_style == 'hash' if attribute_style ==# 'hash'
let tmp .= ' :' . attr . ' => "' . Val . '"' let tmp .= ' :' . attr . ' => "' . Val . '"'
elseif attribute_style == 'html' elseif attribute_style ==# 'html'
let tmp .= attr . '="' . Val . '"' let tmp .= attr . '="' . Val . '"'
end end
endif endif
endif endif
endfor endfor
if len(tmp) if len(tmp)
if attribute_style == 'hash' if attribute_style ==# 'hash'
let str .= '{' . tmp . ' }' let str .= '{' . tmp . ' }'
elseif attribute_style == 'html' elseif attribute_style ==# 'html'
let str .= '(' . tmp . ')' let str .= '(' . tmp . ')'
end end
endif endif
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0 if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0
let str .= "/" let str .= '/'
endif endif
let inner = '' let inner = ''
@@ -87,10 +87,10 @@ function! emmet#lang#haml#toString(settings, current, type, inline, filters, ite
endif endif
let lines = split(text, "\n") let lines = split(text, "\n")
if len(lines) == 1 if len(lines) == 1
let str .= " " . text let str .= ' ' . text
else else
for line in lines for line in lines
let str .= "\n" . indent . line . " |" let str .= "\n" . indent . line . ' |'
endfor endfor
endif endif
elseif len(current.child) == 0 elseif len(current.child) == 0
@@ -105,10 +105,10 @@ function! emmet#lang#haml#toString(settings, current, type, inline, filters, ite
endif endif
let lines = split(text, "\n") let lines = split(text, "\n")
if len(lines) == 1 if len(lines) == 1
let str .= " " . text let str .= ' ' . text
else else
for line in lines for line in lines
let str .= "\n" . indent . line . " |" let str .= "\n" . indent . line . ' |'
endfor endfor
endif endif
elseif len(current.child) > 0 elseif len(current.child) > 0
@@ -116,7 +116,7 @@ function! emmet#lang#haml#toString(settings, current, type, inline, filters, ite
let inner .= emmet#toString(child, type, inline, filters, itemno, indent) let inner .= emmet#toString(child, type, inline, filters, itemno, indent)
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g') let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
let str .= "\n" . indent . inner let str .= "\n" . indent . inner
endif endif
else else
@@ -131,16 +131,16 @@ function! emmet#lang#haml#toString(settings, current, type, inline, filters, ite
return str return str
endfunction endfunction
function! emmet#lang#haml#imageSize() function! emmet#lang#haml#imageSize() abort
let line = getline('.') let line = getline('.')
let current = emmet#lang#haml#parseTag(line) let current = emmet#lang#haml#parseTag(line)
if empty(current) || !has_key(current.attr, 'src') if empty(current) || !has_key(current.attr, 'src')
return return
endif endif
let fn = current.attr.src let fn = current.attr.src
if fn =~ '^\s*$' if fn =~# '^\s*$'
return return
elseif fn !~ '^\(/\|http\)' elseif fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let fn = simplify(expand('%:h') . '/' . fn)
endif endif
@@ -153,13 +153,13 @@ function! emmet#lang#haml#imageSize()
let current.attrs_order += ['width', 'height'] let current.attrs_order += ['width', 'height']
let haml = emmet#toString(current, 'haml', 1) let haml = emmet#toString(current, 'haml', 1)
let haml = substitute(haml, '\${cursor}', '', '') let haml = substitute(haml, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", "", "g")) call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", '', 'g'))
endfunction endfunction
function! emmet#lang#haml#encodeImage() function! emmet#lang#haml#encodeImage() abort
endfunction endfunction
function! emmet#lang#haml#parseTag(tag) function! emmet#lang#haml#parseTag(tag) abort
let current = emmet#newNode() let current = emmet#newNode()
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)' let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
let match = matchstr(a:tag, mx) let match = matchstr(a:tag, mx)
@@ -168,7 +168,7 @@ function! emmet#lang#haml#parseTag(tag)
let mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)' let mx = '\([a-zA-Z0-9]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
while len(attrs) > 0 while len(attrs) > 0
let match = matchstr(attrs, mx) let match = matchstr(attrs, mx)
if len(match) == 0 if len(match) ==# 0
break break
endif endif
let attr_match = matchlist(match, mx) let attr_match = matchlist(match, mx)
@@ -181,17 +181,17 @@ function! emmet#lang#haml#parseTag(tag)
return current return current
endfunction endfunction
function! emmet#lang#haml#toggleComment() function! emmet#lang#haml#toggleComment() abort
let line = getline('.') let line = getline('.')
let space = matchstr(line, '^\s*') let space = matchstr(line, '^\s*')
if line =~ '^\s*-#' if line =~# '^\s*-#'
call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*')) call setline('.', space . matchstr(line[len(space)+2:], '^\s*\zs.*'))
elseif line =~ '^\s*%[a-z]' elseif line =~# '^\s*%[a-z]'
call setline('.', space . '-# ' . line[len(space):]) call setline('.', space . '-# ' . line[len(space):])
endif endif
endfunction endfunction
function! emmet#lang#haml#balanceTag(flag) range function! emmet#lang#haml#balanceTag(flag) range abort
let block = emmet#util#getVisualBlock() let block = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
@@ -256,11 +256,11 @@ function! emmet#lang#haml#balanceTag(flag) range
endif endif
endfunction endfunction
function! emmet#lang#haml#moveNextPrevItem(flag) function! emmet#lang#haml#moveNextPrevItem(flag) abort
return emmet#lang#haml#moveNextPrev(a:flag) return emmet#lang#haml#moveNextPrev(a:flag)
endfunction endfunction
function! emmet#lang#haml#moveNextPrev(flag) function! emmet#lang#haml#moveNextPrev(flag) abort
let pos = search('""', a:flag ? 'Wb' : 'W') let pos = search('""', a:flag ? 'Wb' : 'W')
if pos != 0 if pos != 0
silent! normal! l silent! normal! l
@@ -268,11 +268,11 @@ function! emmet#lang#haml#moveNextPrev(flag)
endif endif
endfunction endfunction
function! emmet#lang#haml#splitJoinTag() function! emmet#lang#haml#splitJoinTag() abort
let n = line('.') let n = line('.')
let sml = len(matchstr(getline(n), '^\s*%[a-z]')) let sml = len(matchstr(getline(n), '^\s*%[a-z]'))
while n > 0 while n > 0
if getline(n) =~ '^\s*\ze%[a-z]' if getline(n) =~# '^\s*\ze%[a-z]'
if len(matchstr(getline(n), '^\s*%[a-z]')) < sml if len(matchstr(getline(n), '^\s*%[a-z]')) < sml
break break
endif endif
@@ -287,7 +287,7 @@ function! emmet#lang#haml#splitJoinTag()
if l <= ml if l <= ml
break break
endif endif
exe n "delete" exe n 'delete'
endwhile endwhile
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, sn, 1, 0])
else else
@@ -308,11 +308,11 @@ function! emmet#lang#haml#splitJoinTag()
endwhile endwhile
endfunction endfunction
function! emmet#lang#haml#removeTag() function! emmet#lang#haml#removeTag() abort
let n = line('.') let n = line('.')
let ml = 0 let ml = 0
while n > 0 while n > 0
if getline(n) =~ '^\s*\ze[a-z]' if getline(n) =~# '^\s*\ze[a-z]'
let ml = len(matchstr(getline(n), '^\s*%[a-z]')) let ml = len(matchstr(getline(n), '^\s*%[a-z]'))
break break
endif endif
@@ -328,8 +328,8 @@ function! emmet#lang#haml#removeTag()
let n += 1 let n += 1
endwhile endwhile
if sn == n if sn == n
exe "delete" exe 'delete'
else else
exe sn "," (n-1) "delete" exe sn ',' (n-1) 'delete'
endif endif
endfunction endfunction

View File

@@ -12,7 +12,7 @@ let s:mx = '\([+>]\|[<^]\+\)\{-}\s*'
\ .'\%(\(@-\{0,1}[0-9]*\)\{0,1}\*\([0-9]\+\)\)\{0,1}' \ .'\%(\(@-\{0,1}[0-9]*\)\{0,1}\*\([0-9]\+\)\)\{0,1}'
\ .'\(\%()\%(\(@-\{0,1}[0-9]*\)\{0,1}\*[0-9]\+\)\{0,1}\)*\)' \ .'\(\%()\%(\(@-\{0,1}[0-9]*\)\{0,1}\*[0-9]\+\)\{0,1}\)*\)'
function! emmet#lang#html#findTokens(str) function! emmet#lang#html#findTokens(str) abort
let str = a:str let str = a:str
let [pos, last_pos] = [0, 0] let [pos, last_pos] = [0, 0]
while 1 while 1
@@ -25,23 +25,23 @@ function! emmet#lang#html#findTokens(str)
let last_pos = pos let last_pos = pos
while len(str) > 0 while len(str) > 0
let token = matchstr(str, s:mx, pos) let token = matchstr(str, s:mx, pos)
if token == '' if token ==# ''
break break
endif endif
if token =~ '^\s' if token =~# '^\s'
let token = matchstr(token, '^\s*\zs.*') let token = matchstr(token, '^\s*\zs.*')
let last_pos = stridx(str, token, pos) let last_pos = stridx(str, token, pos)
endif endif
let pos = stridx(str, token, pos) + len(token) let pos = stridx(str, token, pos) + len(token)
endwhile endwhile
let str = a:str[last_pos :-1] let str = a:str[last_pos :-1]
if str =~ '^\w\+="[^"]*$' if str =~# '^\w\+="[^"]*$'
return '' return ''
endif endif
return str return str
endfunction endfunction
function! emmet#lang#html#parseIntoTree(abbr, type) function! emmet#lang#html#parseIntoTree(abbr, type) abort
let abbr = a:abbr let abbr = a:abbr
let type = a:type let type = a:type
@@ -82,23 +82,23 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
if len(str) == 0 if len(str) == 0
break break
endif endif
if tag_name =~ '^#' if tag_name =~# '^#'
let attributes = tag_name . attributes let attributes = tag_name . attributes
let tag_name = 'div' let tag_name = 'div'
endif endif
if tag_name =~ '[^!]!$' if tag_name =~# '[^!]!$'
let tag_name = tag_name[:-2] let tag_name = tag_name[:-2]
let important = 1 let important = 1
endif endif
if tag_name =~ '^\.' if tag_name =~# '^\.'
let attributes = tag_name . attributes let attributes = tag_name . attributes
let tag_name = 'div' let tag_name = 'div'
endif endif
if tag_name =~ '^\[.*\]$' if tag_name =~# '^\[.*\]$'
let attributes = tag_name . attributes let attributes = tag_name . attributes
let tag_name = 'div' let tag_name = 'div'
endif endif
let basedirect = basevalue[1] == '-' ? -1 : 1 let basedirect = basevalue[1] ==# '-' ? -1 : 1
let basevalue = 0 + abs(basevalue[1:]) let basevalue = 0 + abs(basevalue[1:])
if multiplier <= 0 | let multiplier = 1 | endif if multiplier <= 0 | let multiplier = 1 | endif
@@ -140,7 +140,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
let custom_expands = settings['custom_expands'] let custom_expands = settings['custom_expands']
endif endif
for k in keys(custom_expands) for k in keys(custom_expands)
if tag_name =~ k if tag_name =~# k
let current.snippet = '${' . tag_name . '}' let current.snippet = '${' . tag_name . '}'
let current.name = '' let current.name = ''
break break
@@ -192,20 +192,20 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
while len(attr) while len(attr)
let item = matchstr(attr, '\(\%(\%(#[{}a-zA-Z0-9_\-\$]\+\)\|\%(\[\%("[^"]*"\|[^"\]]*\)\+\]\)\|\%(\.[{}a-zA-Z0-9_\-\$]\+\)*\)\)') let item = matchstr(attr, '\(\%(\%(#[{}a-zA-Z0-9_\-\$]\+\)\|\%(\[\%("[^"]*"\|[^"\]]*\)\+\]\)\|\%(\.[{}a-zA-Z0-9_\-\$]\+\)*\)\)')
if g:emmet_debug > 1 if g:emmet_debug > 1
echomsg "attr=" . item echomsg 'attr=' . item
endif endif
if len(item) == 0 if len(item) == 0
break break
endif endif
if item[0] == '#' if item[0] ==# '#'
let current.attr.id = item[1:] let current.attr.id = item[1:]
endif endif
if item[0] == '.' if item[0] ==# '.'
let current.attr.class = substitute(item[1:], '\.', ' ', 'g') let current.attr.class = substitute(item[1:], '\.', ' ', 'g')
endif endif
if item[0] == '[' if item[0] ==# '['
let atts = item[1:-2] let atts = item[1:-2]
if matchstr(atts, '^\s*\zs[0-9a-zA-Z-:]\+\(="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\)') == '' if matchstr(atts, '^\s*\zs[0-9a-zA-Z-:]\+\(="[^"]*"\|=''[^'']*''\|=[^ ''"]\+\)') ==# ''
let ks = [] let ks = []
if has_key(default_attributes, current.name) if has_key(default_attributes, current.name)
let dfa = default_attributes[current.name] let dfa = default_attributes[current.name]
@@ -217,7 +217,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
if len(ks) > 0 if len(ks) > 0
let current.attr[ks[0]] = atts let current.attr[ks[0]] = atts
else else
let current.attr[atts] = "" let current.attr[atts] = ''
endif endif
else else
while len(atts) while len(atts)
@@ -227,11 +227,11 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
endif endif
let key = split(amat, '=')[0] let key = split(amat, '=')[0]
let Val = amat[len(key)+1:] let Val = amat[len(key)+1:]
if key =~ '\.$' && Val == '' if key =~# '\.$' && Val ==# ''
let key = key[:-2] let key = key[:-2]
unlet Val unlet Val
let Val = function('emmet#types#true') let Val = function('emmet#types#true')
elseif Val =~ '^["'']' elseif Val =~# '^["'']'
let Val = Val[1:-2] let Val = Val[1:-2]
endif endif
let current.attr[key] = Val let current.attr[key] = Val
@@ -248,7 +248,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
endif endif
" parse text " parse text
if tag_name =~ '^{.*}$' if tag_name =~# '^{.*}$'
let current.name = '' let current.name = ''
let current.value = tag_name let current.value = tag_name
else else
@@ -260,7 +260,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
" parse step inside/outside " parse step inside/outside
if !empty(last) if !empty(last)
if operator =~ '>' if operator =~# '>'
unlet! parent unlet! parent
let parent = last let parent = last
let current.parent = last let current.parent = last
@@ -273,7 +273,7 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
let current.parent = parent let current.parent = parent
let current.pos = 1 let current.pos = 1
endif endif
if operator =~ '[<^]' if operator =~# '[<^]'
for c in range(len(operator)) for c in range(len(operator))
let tmp = parent.parent let tmp = parent.parent
if empty(tmp) if empty(tmp)
@@ -288,17 +288,17 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
let last = current let last = current
" parse block " parse block
if block_start =~ '(' if block_start =~# '('
if operator =~ '>' if operator =~# '>'
let last.pos += 1 let last.pos += 1
endif endif
for n in range(len(block_start)) for n in range(len(block_start))
let pos += [last.pos] let pos += [last.pos]
endfor endfor
endif endif
if block_end =~ ')' if block_end =~# ')'
for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',') for n in split(substitute(substitute(block_end, ' ', '', 'g'), ')', ',),', 'g'), ',')
if n == ')' if n ==# ')'
if len(pos) > 0 && last.pos >= pos[-1] if len(pos) > 0 && last.pos >= pos[-1]
for c in range(last.pos - pos[-1]) for c in range(last.pos - pos[-1])
let tmp = parent.parent let tmp = parent.parent
@@ -333,24 +333,24 @@ function! emmet#lang#html#parseIntoTree(abbr, type)
let abbr = abbr[stridx(abbr, match) + len(match):] let abbr = abbr[stridx(abbr, match) + len(match):]
if g:emmet_debug > 1 if g:emmet_debug > 1
echomsg "str=".str echomsg 'str='.str
echomsg "block_start=".block_start echomsg 'block_start='.block_start
echomsg "tag_name=".tag_name echomsg 'tag_name='.tag_name
echomsg "operator=".operator echomsg 'operator='.operator
echomsg "attributes=".attributes echomsg 'attributes='.attributes
echomsg "value=".value echomsg 'value='.value
echomsg "basevalue=".basevalue echomsg 'basevalue='.basevalue
echomsg "multiplier=".multiplier echomsg 'multiplier='.multiplier
echomsg "block_end=".block_end echomsg 'block_end='.block_end
echomsg "abbr=".abbr echomsg 'abbr='.abbr
echomsg "pos=".string(pos) echomsg 'pos='.string(pos)
echomsg "---" echomsg '---'
endif endif
endwhile endwhile
return root return root
endfunction endfunction
function! s:dollar_add(base,no) function! s:dollar_add(base,no) abort
if a:base > 0 if a:base > 0
return a:base + a:no - 1 return a:base + a:no - 1
elseif a:base < 0 elseif a:base < 0
@@ -360,7 +360,7 @@ function! s:dollar_add(base,no)
endif endif
endfunction endfunction
function! emmet#lang#html#toString(settings, current, type, inline, filters, itemno, indent) function! emmet#lang#html#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let settings = a:settings
let current = a:current let current = a:current
let type = a:type let type = a:type
@@ -418,12 +418,12 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
let str .= ' ' . attr . '=' . q . attr . q let str .= ' ' . attr . '=' . q . attr . q
endif endif
if emmet#useFilter(filters, 'c') if emmet#useFilter(filters, 'c')
if attr == 'id' | let comment .= '#' . Val | endif if attr ==# 'id' | let comment .= '#' . Val | endif
if attr == 'class' | let comment .= '.' . Val | endif if attr ==# 'class' | let comment .= '.' . Val | endif
endif endif
else else
if dollar_expr if dollar_expr
while Val =~ '\$\([^#{]\|$\)' while Val =~# '\$\([^#{]\|$\)'
" TODO: regexp engine specified " TODO: regexp engine specified
if exists('&regexpengine') if exists('&regexpengine')
let Val = substitute(Val, '\%#=1\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let Val = substitute(Val, '\%#=1\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
@@ -433,7 +433,7 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let attr = substitute(attr, '\$$', itemno+1, '')
endif endif
if attr == 'class' && emmet#useFilter(filters, 'bem') if attr ==# 'class' && emmet#useFilter(filters, 'bem')
let vals = split(Val, '\s\+') let vals = split(Val, '\s\+')
let Val = '' let Val = ''
let lead = '' let lead = ''
@@ -441,10 +441,10 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
if len(Val) > 0 if len(Val) > 0
let Val .= ' ' let Val .= ' '
endif endif
if _val =~ '^\a_' if _val =~# '^\a_'
let lead = _val[0] let lead = _val[0]
let Val .= lead . ' ' . _val let Val .= lead . ' ' . _val
elseif _val =~ '^_' elseif _val =~# '^_'
if len(lead) == 0 if len(lead) == 0
let pattr = current.parent.attr let pattr = current.parent.attr
if has_key(pattr, 'class') if has_key(pattr, 'class')
@@ -459,19 +459,19 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
endif endif
let str .= ' ' . attr . '=' . q . Val . q let str .= ' ' . attr . '=' . q . Val . q
if emmet#useFilter(filters, 'c') if emmet#useFilter(filters, 'c')
if attr == 'id' | let comment .= '#' . Val | endif if attr ==# 'id' | let comment .= '#' . Val | endif
if attr == 'class' | let comment .= '.' . Val | endif if attr ==# 'class' | let comment .= '.' . Val | endif
endif endif
endif endif
unlet Val unlet Val
endfor endfor
if len(comment) > 0 && ct == 'both' if len(comment) > 0 && ct ==# 'both'
let str = "<!-- " . comment . " -->\n" . str let str = '<!-- ' . comment . " -->\n" . str
endif endif
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1
let str .= settings.html.empty_element_suffix let str .= settings.html.empty_element_suffix
else else
let str .= ">" let str .= '>'
let text = current.value[1:-2] let text = current.value[1:-2]
if dollar_expr if dollar_expr
" TODO: regexp engine specified " TODO: regexp engine specified
@@ -504,7 +504,7 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
endif endif
endif endif
let inner = emmet#toString(child, type, 0, filters, itemno, indent) let inner = emmet#toString(child, type, 0, filters, itemno, indent)
let inner = substitute(inner, "^\n", "", 'g') let inner = substitute(inner, "^\n", '', 'g')
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g') let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
let str .= inner let str .= inner
@@ -515,13 +515,13 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
if dr if dr
let str .= "\n" let str .= "\n"
endif endif
let str .= "</" . current_name . ">" let str .= '</' . current_name . '>'
endif endif
if len(comment) > 0 if len(comment) > 0
if ct == "lastonly" if ct ==# 'lastonly'
let str .= "<!-- " . comment . " -->" let str .= '<!-- ' . comment . ' -->'
else else
let str .= "\n<!-- /" . comment . " -->" let str .= "\n<!-- /" . comment . ' -->'
endif endif
endif endif
if len(current_name) > 0 && current.multiplier > 0 || stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1 if len(current_name) > 0 && current.multiplier > 0 || stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1
@@ -530,13 +530,13 @@ function! emmet#lang#html#toString(settings, current, type, inline, filters, ite
return str return str
endfunction endfunction
function! emmet#lang#html#imageSize() function! emmet#lang#html#imageSize() abort
let img_region = emmet#util#searchRegion('<img\s', '>') let img_region = emmet#util#searchRegion('<img\s', '>')
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region) if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region)
return return
endif endif
let content = emmet#util#getContent(img_region) let content = emmet#util#getContent(img_region)
if content !~ '^<img[^><]\+>$' if content !~# '^<img[^><]\+>$'
return return
endif endif
let current = emmet#lang#html#parseTag(content) let current = emmet#lang#html#parseTag(content)
@@ -544,9 +544,9 @@ function! emmet#lang#html#imageSize()
return return
endif endif
let fn = current.attr.src let fn = current.attr.src
if fn =~ '^\s*$' if fn =~# '^\s*$'
return return
elseif fn !~ '^\(/\|http\)' elseif fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let fn = simplify(expand('%:h') . '/' . fn)
endif endif
@@ -562,13 +562,13 @@ function! emmet#lang#html#imageSize()
call emmet#util#setContent(img_region, html) call emmet#util#setContent(img_region, html)
endfunction endfunction
function! emmet#lang#html#encodeImage() function! emmet#lang#html#encodeImage() abort
let img_region = emmet#util#searchRegion('<img\s', '>') let img_region = emmet#util#searchRegion('<img\s', '>')
if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region) if !emmet#util#regionIsValid(img_region) || !emmet#util#cursorInRegion(img_region)
return return
endif endif
let content = emmet#util#getContent(img_region) let content = emmet#util#getContent(img_region)
if content !~ '^<img[^><]\+>$' if content !~# '^<img[^><]\+>$'
return return
endif endif
let current = emmet#lang#html#parseTag(content) let current = emmet#lang#html#parseTag(content)
@@ -576,7 +576,7 @@ function! emmet#lang#html#encodeImage()
return return
endif endif
let fn = current.attr.src let fn = current.attr.src
if fn !~ '^\(/\|http\)' if fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let fn = simplify(expand('%:h') . '/' . fn)
endif endif
@@ -590,7 +590,7 @@ function! emmet#lang#html#encodeImage()
call emmet#util#setContent(img_region, html) call emmet#util#setContent(img_region, html)
endfunction endfunction
function! emmet#lang#html#parseTag(tag) function! emmet#lang#html#parseTag(tag) abort
let current = emmet#newNode() 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 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 match = matchstr(a:tag, mx)
@@ -612,7 +612,7 @@ function! emmet#lang#html#parseTag(tag)
return current return current
endfunction endfunction
function! emmet#lang#html#toggleComment() function! emmet#lang#html#toggleComment() abort
let orgpos = emmet#util#getcurpos() let orgpos = emmet#util#getcurpos()
let curpos = emmet#util#getcurpos() let curpos = emmet#util#getcurpos()
let mx = '<\%#[^>]*>' let mx = '<\%#[^>]*>'
@@ -639,12 +639,12 @@ function! emmet#lang#html#toggleComment()
let pos2 = block[1] let pos2 = block[1]
let content = emmet#util#getContent(block) let content = emmet#util#getContent(block)
let tag_name = matchstr(content, '^<\zs/\{0,1}[^ \r\n>]\+') let tag_name = matchstr(content, '^<\zs/\{0,1}[^ \r\n>]\+')
if tag_name[0] == '/' if tag_name[0] ==# '/'
call setpos('.', [0, pos1[0], pos1[1], 0]) call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^>]*>', '', '</' . tag_name[1:] . '>', 'bnW') let pos2 = searchpairpos('<'. tag_name[1:] . '\>[^>]*>', '', '</' . tag_name[1:] . '>', 'bnW')
let pos1 = searchpos('>', 'cneW') let pos1 = searchpos('>', 'cneW')
let block = [pos2, pos1] let block = [pos2, pos1]
elseif tag_name =~ '/$' elseif tag_name =~# '/$'
if !emmet#util#pointInRegion(orgpos[1:2], block) if !emmet#util#pointInRegion(orgpos[1:2], block)
" it's broken tree " it's broken tree
call setpos('.', orgpos) call setpos('.', orgpos)
@@ -678,7 +678,7 @@ function! emmet#lang#html#toggleComment()
endwhile endwhile
endfunction endfunction
function! emmet#lang#html#balanceTag(flag) range function! emmet#lang#html#balanceTag(flag) range abort
let vblock = emmet#util#getVisualBlock() let vblock = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
@@ -743,13 +743,13 @@ function! emmet#lang#html#balanceTag(flag) range
endwhile endwhile
endif endif
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
silent! exe "normal! gv" silent! exe 'normal! gv'
else else
call setpos('.', curpos) call setpos('.', curpos)
endif endif
endfunction endfunction
function! emmet#lang#html#moveNextPrevItem(flag) function! emmet#lang#html#moveNextPrevItem(flag) abort
silent! exe "normal \<esc>" silent! exe "normal \<esc>"
let mx = '\%([0-9a-zA-Z-:]\+\%(="[^"]*"\|=''[^'']*''\|[^ ''">\]]*\)\{0,1}\)' let mx = '\%([0-9a-zA-Z-:]\+\%(="[^"]*"\|=''[^'']*''\|[^ ''">\]]*\)\{0,1}\)'
let pos = searchpos('\s'.mx.'\zs', '') let pos = searchpos('\s'.mx.'\zs', '')
@@ -758,7 +758,7 @@ function! emmet#lang#html#moveNextPrevItem(flag)
endif endif
endfunction endfunction
function! emmet#lang#html#moveNextPrev(flag) function! emmet#lang#html#moveNextPrev(flag) abort
let pos = search('\%(</\w\+\)\@<!\zs><\/\|\(""\)\|^\(\s*\)$', a:flag ? 'Wpb' : 'Wp') let pos = search('\%(</\w\+\)\@<!\zs><\/\|\(""\)\|^\(\s*\)$', a:flag ? 'Wpb' : 'Wp')
if pos == 3 if pos == 3
startinsert! startinsert!
@@ -768,7 +768,7 @@ function! emmet#lang#html#moveNextPrev(flag)
endif endif
endfunction endfunction
function! emmet#lang#html#splitJoinTag() function! emmet#lang#html#splitJoinTag() abort
let curpos = emmet#util#getcurpos() let curpos = emmet#util#getcurpos()
while 1 while 1
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>' let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
@@ -776,13 +776,13 @@ function! emmet#lang#html#splitJoinTag()
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) 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 tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\).*$', '\1', '')
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]] let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
if content[-2:] == '/>' && emmet#util#cursorInRegion(block) if content[-2:] ==# '/>' && emmet#util#cursorInRegion(block)
let content = content[:-3] . "></" . tag_name . '>' let content = content[:-3] . '></' . tag_name . '>'
call emmet#util#setContent(block, content) call emmet#util#setContent(block, content)
call setpos('.', [0, block[0][0], block[0][1], 0]) call setpos('.', [0, block[0][0], block[0][1], 0])
return return
else else
if tag_name[0] == '/' if tag_name[0] ==# '/'
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW') let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
call setpos('.', [0, pos1[0], pos1[1], 0]) call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW') let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
@@ -791,7 +791,7 @@ function! emmet#lang#html#splitJoinTag()
endif endif
let block = [pos1, pos2] let block = [pos1, pos2]
let content = emmet#util#getContent(block) let content = emmet#util#getContent(block)
if emmet#util#pointInRegion(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>' if emmet#util#pointInRegion(curpos[1:2], block) && content[1:] !~# '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
let content = matchstr(content, mx)[:-2] . '/>' let content = matchstr(content, mx)[:-2] . '/>'
call emmet#util#setContent(block, content) call emmet#util#setContent(block, content)
call setpos('.', [0, block[0][0], block[0][1], 0]) call setpos('.', [0, block[0][0], block[0][1], 0])
@@ -808,7 +808,7 @@ function! emmet#lang#html#splitJoinTag()
endwhile endwhile
endfunction endfunction
function! emmet#lang#html#removeTag() function! emmet#lang#html#removeTag() abort
let curpos = emmet#util#getcurpos() let curpos = emmet#util#getcurpos()
while 1 while 1
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*' let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*'
@@ -816,12 +816,12 @@ function! emmet#lang#html#removeTag()
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx) let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
let tag_name = matchstr(content, '^<\zs/\{0,1}[a-zA-Z0-9:_\-]*') let tag_name = matchstr(content, '^<\zs/\{0,1}[a-zA-Z0-9:_\-]*')
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]] let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
if content[-2:] == '/>' && emmet#util#cursorInRegion(block) if content[-2:] ==# '/>' && emmet#util#cursorInRegion(block)
call emmet#util#setContent(block, '') call emmet#util#setContent(block, '')
call setpos('.', [0, block[0][0], block[0][1], 0]) call setpos('.', [0, block[0][0], block[0][1], 0])
return return
else else
if tag_name[0] == '/' if tag_name[0] ==# '/'
let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW') let pos1 = searchpos('<' . tag_name[1:] . '[^a-zA-Z0-9]', 'bcnW')
call setpos('.', [0, pos1[0], pos1[1], 0]) call setpos('.', [0, pos1[0], pos1[1], 0])
let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW') let pos2 = searchpos('</' . tag_name[1:] . '>', 'cneW')
@@ -830,7 +830,7 @@ function! emmet#lang#html#removeTag()
endif endif
let block = [pos1, pos2] let block = [pos1, pos2]
let content = emmet#util#getContent(block) let content = emmet#util#getContent(block)
if emmet#util#pointInRegion(curpos[1:2], block) && content[1:] !~ '^<' . tag_name . '[^a-zA-Z0-9]' if emmet#util#pointInRegion(curpos[1:2], block) && content[1:] !~# '^<' . tag_name . '[^a-zA-Z0-9]'
call emmet#util#setContent(block, '') call emmet#util#setContent(block, '')
call setpos('.', [0, block[0][0], block[0][1], 0]) call setpos('.', [0, block[0][0], block[0][1], 0])
return return

View File

@@ -1,47 +1,47 @@
function! emmet#lang#less#findTokens(str) function! emmet#lang#less#findTokens(str) abort
return emmet#lang#html#findTokens(a:str) return emmet#lang#html#findTokens(a:str)
endfunction endfunction
function! emmet#lang#less#parseIntoTree(abbr, type) function! emmet#lang#less#parseIntoTree(abbr, type) abort
return emmet#lang#scss#parseIntoTree(a:abbr, a:type) return emmet#lang#scss#parseIntoTree(a:abbr, a:type)
endfunction endfunction
function! emmet#lang#less#toString(settings, current, type, inline, filters, itemno, indent) function! emmet#lang#less#toString(settings, current, type, inline, filters, itemno, indent) abort
return emmet#lang#scss#toString(a:settings, a:current, a:type, a:inline, a:filters, a:itemno, a:indent) return emmet#lang#scss#toString(a:settings, a:current, a:type, a:inline, a:filters, a:itemno, a:indent)
endfunction endfunction
function! emmet#lang#less#imageSize() function! emmet#lang#less#imageSize() abort
call emmet#lang#css#imageSize() call emmet#lang#css#imageSize()
endfunction endfunction
function! emmet#lang#less#encodeImage() function! emmet#lang#less#encodeImage() abort
return emmet#lang#css#encodeImage() return emmet#lang#css#encodeImage()
endfunction endfunction
function! emmet#lang#less#parseTag(tag) function! emmet#lang#less#parseTag(tag) abort
return emmet#lang#css#parseTag(a:tag) return emmet#lang#css#parseTag(a:tag)
endfunction endfunction
function! emmet#lang#less#toggleComment() function! emmet#lang#less#toggleComment() abort
call emmet#lang#css#toggleComment() call emmet#lang#css#toggleComment()
endfunction endfunction
function! emmet#lang#less#balanceTag(flag) range function! emmet#lang#less#balanceTag(flag) range abort
call emmet#lang#scss#balanceTag(a:flag) call emmet#lang#scss#balanceTag(a:flag)
endfunction endfunction
function! emmet#lang#less#moveNextPrevItem(flag) function! emmet#lang#less#moveNextPrevItem(flag) abort
return emmet#lang#less#moveNextPrev(a:flag) return emmet#lang#less#moveNextPrev(a:flag)
endfunction endfunction
function! emmet#lang#less#moveNextPrev(flag) function! emmet#lang#less#moveNextPrev(flag) abort
call emmet#lang#scss#moveNextPrev(a:flag) call emmet#lang#scss#moveNextPrev(a:flag)
endfunction endfunction
function! emmet#lang#less#splitJoinTag() function! emmet#lang#less#splitJoinTag() abort
call emmet#lang#css#splitJoinTag() call emmet#lang#css#splitJoinTag()
endfunction endfunction
function! emmet#lang#less#removeTag() function! emmet#lang#less#removeTag() abort
call emmet#lang#css#removeTag() call emmet#lang#css#removeTag()
endfunction endfunction

View File

@@ -1,12 +1,12 @@
function! emmet#lang#sass#findTokens(str) function! emmet#lang#sass#findTokens(str) abort
return emmet#lang#css#findTokens(a:str) return emmet#lang#css#findTokens(a:str)
endfunction endfunction
function! emmet#lang#sass#parseIntoTree(abbr, type) function! emmet#lang#sass#parseIntoTree(abbr, type) abort
return emmet#lang#html#parseIntoTree(a:abbr, a:type) return emmet#lang#html#parseIntoTree(a:abbr, a:type)
endfunction endfunction
function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) function! emmet#lang#sass#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let settings = a:settings
let current = a:current let current = a:current
let type = a:type let type = a:type
@@ -14,7 +14,7 @@ function! emmet#lang#sass#toString(settings, current, type, inline, filters, ite
let filters = a:filters let filters = a:filters
let itemno = a:itemno let itemno = a:itemno
let indent = a:indent let indent = a:indent
let str = "" let str = ''
let current_name = current.name let current_name = current.name
let current_name = substitute(current.name, '\$$', itemno+1, '') let current_name = substitute(current.name, '\$$', itemno+1, '')
@@ -23,13 +23,13 @@ function! emmet#lang#sass#toString(settings, current, type, inline, filters, ite
let tmp = '' let tmp = ''
for attr in keys(current.attr) for attr in keys(current.attr)
let val = current.attr[attr] let val = current.attr[attr]
while val =~ '\$\([^#{]\|$\)' while val =~# '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let attr = substitute(attr, '\$$', itemno+1, '')
if attr == 'id' if attr ==# 'id'
let str .= '#' . val let str .= '#' . val
elseif attr == 'class' elseif attr ==# 'class'
let str .= '.' . val let str .= '.' . val
else else
let tmp .= attr . ': ' . val let tmp .= attr . ': ' . val
@@ -62,19 +62,19 @@ function! emmet#lang#sass#toString(settings, current, type, inline, filters, ite
return str return str
endfunction endfunction
function! emmet#lang#sass#imageSize() function! emmet#lang#sass#imageSize() abort
endfunction endfunction
function! emmet#lang#sass#encodeImage() function! emmet#lang#sass#encodeImage() abort
endfunction endfunction
function! emmet#lang#sass#parseTag(tag) function! emmet#lang#sass#parseTag(tag) abort
endfunction endfunction
function! emmet#lang#sass#toggleComment() function! emmet#lang#sass#toggleComment() abort
endfunction endfunction
function! emmet#lang#sass#balanceTag(flag) range function! emmet#lang#sass#balanceTag(flag) range abort
let block = emmet#util#getVisualBlock() let block = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
@@ -139,11 +139,11 @@ function! emmet#lang#sass#balanceTag(flag) range
endif endif
endfunction endfunction
function! emmet#lang#sass#moveNextPrevItem(flag) function! emmet#lang#sass#moveNextPrevItem(flag) abort
return emmet#lang#sass#moveNextPrev(a:flag) return emmet#lang#sass#moveNextPrev(a:flag)
endfunction endfunction
function! emmet#lang#sass#moveNextPrev(flag) function! emmet#lang#sass#moveNextPrev(flag) abort
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
if pos == 2 if pos == 2
startinsert! startinsert!
@@ -153,8 +153,8 @@ function! emmet#lang#sass#moveNextPrev(flag)
endif endif
endfunction endfunction
function! emmet#lang#sass#splitJoinTag() function! emmet#lang#sass#splitJoinTag() abort
endfunction endfunction
function! emmet#lang#sass#removeTag() function! emmet#lang#sass#removeTag() abort
endfunction endfunction

View File

@@ -1,16 +1,16 @@
function! emmet#lang#scss#findTokens(str) function! emmet#lang#scss#findTokens(str) abort
return emmet#lang#css#findTokens(a:str) return emmet#lang#css#findTokens(a:str)
endfunction endfunction
function! emmet#lang#scss#parseIntoTree(abbr, type) function! emmet#lang#scss#parseIntoTree(abbr, type) abort
if a:abbr =~ '>' if a:abbr =~# '>'
return emmet#lang#html#parseIntoTree(a:abbr, a:type) return emmet#lang#html#parseIntoTree(a:abbr, a:type)
else else
return emmet#lang#css#parseIntoTree(a:abbr, a:type) return emmet#lang#css#parseIntoTree(a:abbr, a:type)
endif endif
endfunction endfunction
function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) function! emmet#lang#scss#toString(settings, current, type, inline, filters, itemno, indent) abort
let settings = a:settings let settings = a:settings
let current = a:current let current = a:current
let type = a:type let type = a:type
@@ -18,7 +18,7 @@ function! emmet#lang#scss#toString(settings, current, type, inline, filters, ite
let filters = a:filters let filters = a:filters
let itemno = a:itemno let itemno = a:itemno
let indent = a:indent let indent = a:indent
let str = "" let str = ''
let current_name = substitute(current.name, '\$$', itemno+1, '') let current_name = substitute(current.name, '\$$', itemno+1, '')
if len(current.name) > 0 if len(current.name) > 0
@@ -26,13 +26,13 @@ function! emmet#lang#scss#toString(settings, current, type, inline, filters, ite
let tmp = '' let tmp = ''
for attr in keys(current.attr) for attr in keys(current.attr)
let val = current.attr[attr] let val = current.attr[attr]
while val =~ '\$\([^#{]\|$\)' while val =~# '\$\([^#{]\|$\)'
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile endwhile
let attr = substitute(attr, '\$$', itemno+1, '') let attr = substitute(attr, '\$$', itemno+1, '')
if attr == 'id' if attr ==# 'id'
let str .= '#' . val let str .= '#' . val
elseif attr == 'class' elseif attr ==# 'class'
let str .= '.' . val let str .= '.' . val
else else
let tmp .= attr . ': ' . val . ';' let tmp .= attr . ': ' . val . ';'
@@ -52,7 +52,7 @@ function! emmet#lang#scss#toString(settings, current, type, inline, filters, ite
let inner .= emmet#toString(child, type, inline, filters, itemno) let inner .= emmet#toString(child, type, inline, filters, itemno)
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g') let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
let str .= indent . inner . "\n}\n" let str .= indent . inner . "\n}\n"
else else
return emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent) return emmet#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
@@ -60,23 +60,23 @@ function! emmet#lang#scss#toString(settings, current, type, inline, filters, ite
return str return str
endfunction endfunction
function! emmet#lang#scss#imageSize() function! emmet#lang#scss#imageSize() abort
call emmet#lang#css#imageSize() call emmet#lang#css#imageSize()
endfunction endfunction
function! emmet#lang#scss#encodeImage() function! emmet#lang#scss#encodeImage() abort
return emmet#lang#css#encodeImage() return emmet#lang#css#encodeImage()
endfunction endfunction
function! emmet#lang#scss#parseTag(tag) function! emmet#lang#scss#parseTag(tag) abort
return emmet#lang#css#parseTag(a:tag) return emmet#lang#css#parseTag(a:tag)
endfunction endfunction
function! emmet#lang#scss#toggleComment() function! emmet#lang#scss#toggleComment() abort
call emmet#lang#css#toggleComment() call emmet#lang#css#toggleComment()
endfunction endfunction
function! emmet#lang#scss#balanceTag(flag) range function! emmet#lang#scss#balanceTag(flag) range abort
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
call setpos('.', curpos) call setpos('.', curpos)
@@ -102,24 +102,24 @@ function! emmet#lang#scss#balanceTag(flag) range
endif endif
endif endif
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
silent! exe "normal! gv" silent! exe 'normal! gv'
else else
call setpos('.', curpos) call setpos('.', curpos)
endif endif
endfunction endfunction
function! emmet#lang#scss#moveNextPrevItem(flag) function! emmet#lang#scss#moveNextPrevItem(flag) abort
return emmet#lang#scss#moveNextPrev(a:flag) return emmet#lang#scss#moveNextPrev(a:flag)
endfunction endfunction
function! emmet#lang#scss#moveNextPrev(flag) function! emmet#lang#scss#moveNextPrev(flag) abort
call emmet#lang#css#moveNextPrev(a:flag) call emmet#lang#css#moveNextPrev(a:flag)
endfunction endfunction
function! emmet#lang#scss#splitJoinTag() function! emmet#lang#scss#splitJoinTag() abort
call emmet#lang#css#splitJoinTag() call emmet#lang#css#splitJoinTag()
endfunction endfunction
function! emmet#lang#scss#removeTag() function! emmet#lang#scss#removeTag() abort
call emmet#lang#css#removeTag() call emmet#lang#css#removeTag()
endfunction endfunction

View File

@@ -1,12 +1,12 @@
function! emmet#lang#slim#findTokens(str) function! emmet#lang#slim#findTokens(str) abort
return emmet#lang#html#findTokens(a:str) return emmet#lang#html#findTokens(a:str)
endfunction endfunction
function! emmet#lang#slim#parseIntoTree(abbr, type) function! emmet#lang#slim#parseIntoTree(abbr, type) abort
return emmet#lang#html#parseIntoTree(a:abbr, a:type) return emmet#lang#html#parseIntoTree(a:abbr, a:type)
endfunction endfunction
function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) function! emmet#lang#slim#toString(settings, current, type, inline, filters, itemno, indent) abort
let current = a:current let current = a:current
let type = a:type let type = a:type
let inline = a:inline let inline = a:inline
@@ -14,7 +14,7 @@ function! emmet#lang#slim#toString(settings, current, type, inline, filters, ite
let itemno = a:itemno let itemno = a:itemno
let indent = emmet#getIndentation(type) let indent = emmet#getIndentation(type)
let dollar_expr = emmet#getResource(type, 'dollar_expr', 1) let dollar_expr = emmet#getResource(type, 'dollar_expr', 1)
let str = "" let str = ''
let current_name = current.name let current_name = current.name
if dollar_expr if dollar_expr
@@ -31,7 +31,7 @@ function! emmet#lang#slim#toString(settings, current, type, inline, filters, ite
let str .= ' ' . attr . '=true' let str .= ' ' . attr . '=true'
else else
if dollar_expr if dollar_expr
while Val =~ '\$\([^#{]\|$\)' while Val =~# '\$\([^#{]\|$\)'
let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g') let Val = substitute(Val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
endwhile endwhile
endif endif
@@ -51,7 +51,7 @@ function! emmet#lang#slim#toString(settings, current, type, inline, filters, ite
let str = substitute(str, '\$#', text, 'g') let str = substitute(str, '\$#', text, 'g')
endif endif
for line in split(text, "\n") for line in split(text, "\n")
let str .= indent . "| " . line . "\n" let str .= indent . '| ' . line . "\n"
endfor endfor
elseif len(current.child) == 0 elseif len(current.child) == 0
let str .= '${cursor}' let str .= '${cursor}'
@@ -65,14 +65,14 @@ function! emmet#lang#slim#toString(settings, current, type, inline, filters, ite
let text = substitute(text, '\\\$', '$', 'g') let text = substitute(text, '\\\$', '$', 'g')
endif endif
for line in split(text, "\n") for line in split(text, "\n")
let str .= indent . "| " . line . "\n" let str .= indent . '| ' . line . "\n"
endfor endfor
elseif len(current.child) > 0 elseif len(current.child) > 0
for child in current.child for child in current.child
let inner .= emmet#toString(child, type, inline, filters, itemno, indent) let inner .= emmet#toString(child, type, inline, filters, itemno, indent)
endfor endfor
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g') let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g') let inner = substitute(inner, "\n" . escape(indent, '\') . '$', '', 'g')
let str .= "\n" . indent . inner let str .= "\n" . indent . inner
endif endif
else else
@@ -83,22 +83,22 @@ function! emmet#lang#slim#toString(settings, current, type, inline, filters, ite
let str = substitute(str, '\\\$', '$', 'g') let str = substitute(str, '\\\$', '$', 'g')
endif endif
endif endif
if str !~ "\n$" if str !~# "\n$"
let str .= "\n" let str .= "\n"
endif endif
return str return str
endfunction endfunction
function! emmet#lang#slim#imageSize() function! emmet#lang#slim#imageSize() abort
let line = getline('.') let line = getline('.')
let current = emmet#lang#slim#parseTag(line) let current = emmet#lang#slim#parseTag(line)
if empty(current) || !has_key(current.attr, 'src') if empty(current) || !has_key(current.attr, 'src')
return return
endif endif
let fn = current.attr.src let fn = current.attr.src
if fn =~ '^\s*$' if fn =~# '^\s*$'
return return
elseif fn !~ '^\(/\|http\)' elseif fn !~# '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn) let fn = simplify(expand('%:h') . '/' . fn)
endif endif
@@ -111,13 +111,13 @@ function! emmet#lang#slim#imageSize()
let current.attrs_order += ['width', 'height'] let current.attrs_order += ['width', 'height']
let slim = emmet#toString(current, 'slim', 1) let slim = emmet#toString(current, 'slim', 1)
let slim = substitute(slim, '\${cursor}', '', '') let slim = substitute(slim, '\${cursor}', '', '')
call setline('.', substitute(matchstr(line, '^\s*') . slim, "\n", "", "g")) call setline('.', substitute(matchstr(line, '^\s*') . slim, "\n", '', 'g'))
endfunction endfunction
function! emmet#lang#slim#encodeImage() function! emmet#lang#slim#encodeImage() abort
endfunction endfunction
function! emmet#lang#slim#parseTag(tag) function! emmet#lang#slim#parseTag(tag) abort
let current = emmet#newNode() let current = emmet#newNode()
let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)' let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)'
let match = matchstr(a:tag, mx) let match = matchstr(a:tag, mx)
@@ -139,17 +139,17 @@ function! emmet#lang#slim#parseTag(tag)
return current return current
endfunction endfunction
function! emmet#lang#slim#toggleComment() function! emmet#lang#slim#toggleComment() abort
let line = getline('.') let line = getline('.')
let space = matchstr(line, '^\s*') let space = matchstr(line, '^\s*')
if line =~ '^\s*/' if line =~# '^\s*/'
call setline('.', space . line[len(space)+1:]) call setline('.', space . line[len(space)+1:])
elseif line =~ '^\s*[a-z]' elseif line =~# '^\s*[a-z]'
call setline('.', space . '/' . line[len(space):]) call setline('.', space . '/' . line[len(space):])
endif endif
endfunction endfunction
function! emmet#lang#slim#balanceTag(flag) range function! emmet#lang#slim#balanceTag(flag) range abort
let block = emmet#util#getVisualBlock() let block = emmet#util#getVisualBlock()
if a:flag == -2 || a:flag == 2 if a:flag == -2 || a:flag == 2
let curpos = [0, line("'<"), col("'<"), 0] let curpos = [0, line("'<"), col("'<"), 0]
@@ -214,11 +214,11 @@ function! emmet#lang#slim#balanceTag(flag) range
endif endif
endfunction endfunction
function! emmet#lang#slim#moveNextPrevItem(flag) function! emmet#lang#slim#moveNextPrevItem(flag) abort
return emmet#lang#slim#moveNextPrev(a:flag) return emmet#lang#slim#moveNextPrev(a:flag)
endfunction endfunction
function! emmet#lang#slim#moveNextPrev(flag) function! emmet#lang#slim#moveNextPrev(flag) abort
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp') let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
if pos == 2 if pos == 2
startinsert! startinsert!
@@ -228,18 +228,18 @@ function! emmet#lang#slim#moveNextPrev(flag)
endif endif
endfunction endfunction
function! emmet#lang#slim#splitJoinTag() function! emmet#lang#slim#splitJoinTag() abort
let n = line('.') let n = line('.')
while n > 0 while n > 0
if getline(n) =~ '^\s*\ze[a-z]' if getline(n) =~# '^\s*\ze[a-z]'
let sn = n let sn = n
let n += 1 let n += 1
if getline(n) =~ '^\s*|' if getline(n) =~# '^\s*|'
while n <= line('$') while n <= line('$')
if getline(n) !~ '^\s*|' if getline(n) !~# '^\s*|'
break break
endif endif
exe n "delete" exe n 'delete'
endwhile endwhile
call setpos('.', [0, sn, 1, 0]) call setpos('.', [0, sn, 1, 0])
else else
@@ -254,11 +254,11 @@ function! emmet#lang#slim#splitJoinTag()
endwhile endwhile
endfunction endfunction
function! emmet#lang#slim#removeTag() function! emmet#lang#slim#removeTag() abort
let n = line('.') let n = line('.')
let ml = 0 let ml = 0
while n > 0 while n > 0
if getline(n) =~ '^\s*\ze[a-z]' if getline(n) =~# '^\s*\ze[a-z]'
let ml = len(matchstr(getline(n), '^\s*[a-z]')) let ml = len(matchstr(getline(n), '^\s*[a-z]'))
break break
endif endif
@@ -274,8 +274,8 @@ function! emmet#lang#slim#removeTag()
let n += 1 let n += 1
endwhile endwhile
if sn == n if sn == n
exe "delete" exe 'delete'
else else
exe sn "," (n-1) "delete" exe sn ',' (n-1) 'delete'
endif endif
endfunction endfunction

View File

@@ -1,4 +1,4 @@
function! emmet#lorem#en#expand(command) function! emmet#lorem#en#expand(command) abort
let wcount = matchstr(a:command, '\(\d*\)$') let wcount = matchstr(a:command, '\(\d*\)$')
let wcount = wcount > 0 ? wcount : 30 let wcount = wcount > 0 ? wcount : 30
@@ -48,13 +48,13 @@ function! emmet#lorem#en#expand(command)
call add(ret, word) call add(ret, word)
if (sentence > 5 && emmet#util#rand() < 10000) || i == wcount - 1 if (sentence > 5 && emmet#util#rand() < 10000) || i == wcount - 1
if i == wcount - 1 if i == wcount - 1
let endc = "?!..."[emmet#util#rand() % 5] let endc = '?!...'[emmet#util#rand() % 5]
call add(ret, endc) call add(ret, endc)
else else
let endc = "?!,..."[emmet#util#rand() % 6] let endc = '?!,...'[emmet#util#rand() % 6]
call add(ret, endc . ' ') call add(ret, endc . ' ')
endif endif
if endc != ',' if endc !=# ','
let sentence = 0 let sentence = 0
endif endif
else else

View File

@@ -1,6 +1,6 @@
scriptencoding utf-8 scriptencoding utf-8
function! emmet#lorem#ja#expand(command) function! emmet#lorem#ja#expand(command) abort
let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '') let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '')
let wcount = wcount > 0 ? wcount : 30 let wcount = wcount > 0 ? wcount : 30

View File

@@ -11,10 +11,10 @@
" -------------------- " --------------------
" begin::end " begin::end
" -------------------- " --------------------
function! emmet#util#deleteContent(region) function! emmet#util#deleteContent(region) abort
let lines = getline(a:region[0][0], a:region[1][0]) let lines = getline(a:region[0][0], a:region[1][0])
call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
silent! exe "delete ".(a:region[1][0] - a:region[0][0]) silent! exe 'delete '.(a:region[1][0] - a:region[0][0])
call setline(line('.'), lines[0][:a:region[0][1]-2] . lines[-1][a:region[1][1]]) call setline(line('.'), lines[0][:a:region[0][1]-2] . lines[-1][a:region[1][1]])
endfunction endfunction
@@ -36,11 +36,11 @@ endfunction
" bar " bar
" baz:end " baz:end
" -------------------- " --------------------
function! emmet#util#setContent(region, content) function! emmet#util#setContent(region, content) abort
let newlines = split(a:content, '\n', 1) let newlines = split(a:content, '\n', 1)
let oldlines = getline(a:region[0][0], a:region[1][0]) let oldlines = getline(a:region[0][0], a:region[1][0])
call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
silent! exe "delete ".(a:region[1][0] - a:region[0][0]) silent! exe 'delete '.(a:region[1][0] - a:region[0][0])
if len(newlines) == 0 if len(newlines) == 0
let tmp = '' let tmp = ''
if a:region[0][1] > 1 if a:region[0][1] > 1
@@ -72,7 +72,7 @@ endfunction
" select_region : select region " select_region : select region
" this function make a selection of region " this function make a selection of region
function! emmet#util#selectRegion(region) function! emmet#util#selectRegion(region) abort
call setpos('.', [0, a:region[1][0], a:region[1][1], 0]) call setpos('.', [0, a:region[1][0], a:region[1][1], 0])
normal! v normal! v
call setpos('.', [0, a:region[0][0], a:region[0][1], 0]) call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
@@ -80,7 +80,7 @@ endfunction
" point_in_region : check point is in the region " point_in_region : check point is in the region
" this function return 0 or 1 " this function return 0 or 1
function! emmet#util#pointInRegion(point, region) function! emmet#util#pointInRegion(point, region) abort
if !emmet#util#regionIsValid(a:region) | return 0 | endif if !emmet#util#regionIsValid(a:region) | return 0 | endif
if a:region[0][0] > a:point[0] | return 0 | endif if a:region[0][0] > a:point[0] | return 0 | endif
if a:region[1][0] < a:point[0] | return 0 | endif if a:region[1][0] < a:point[0] | return 0 | endif
@@ -91,7 +91,7 @@ endfunction
" cursor_in_region : check cursor is in the region " cursor_in_region : check cursor is in the region
" this function return 0 or 1 " this function return 0 or 1
function! emmet#util#cursorInRegion(region) function! emmet#util#cursorInRegion(region) abort
if !emmet#util#regionIsValid(a:region) | return 0 | endif if !emmet#util#regionIsValid(a:region) | return 0 | endif
let cur = emmet#util#getcurpos()[1:2] let cur = emmet#util#getcurpos()[1:2]
return emmet#util#pointInRegion(cur, a:region) return emmet#util#pointInRegion(cur, a:region)
@@ -99,14 +99,14 @@ endfunction
" region_is_valid : check region is valid " region_is_valid : check region is valid
" this function return 0 or 1 " this function return 0 or 1
function! emmet#util#regionIsValid(region) function! emmet#util#regionIsValid(region) abort
if a:region[0][0] == 0 || a:region[1][0] == 0 | return 0 | endif if a:region[0][0] == 0 || a:region[1][0] == 0 | return 0 | endif
return 1 return 1
endfunction endfunction
" search_region : make region from pattern which is composing start/end " search_region : make region from pattern which is composing start/end
" this function return array of position " this function return array of position
function! emmet#util#searchRegion(start, end) function! emmet#util#searchRegion(start, end) abort
let b = searchpairpos(a:start, '', a:end, 'bcnW') let b = searchpairpos(a:start, '', a:end, 'bcnW')
if b == [0, 0] if b == [0, 0]
return [searchpairpos(a:start, '', a:end, 'bnW'), searchpairpos(a:start, '\%#', a:end, 'nW')] return [searchpairpos(a:start, '', a:end, 'bnW'), searchpairpos(a:start, '\%#', a:end, 'nW')]
@@ -117,7 +117,7 @@ endfunction
" get_content : get content in region " get_content : get content in region
" this function return string in region " this function return string in region
function! emmet#util#getContent(region) function! emmet#util#getContent(region) abort
if !emmet#util#regionIsValid(a:region) if !emmet#util#regionIsValid(a:region)
return '' return ''
endif endif
@@ -133,7 +133,7 @@ endfunction
" region_in_region : check region is in the region " region_in_region : check region is in the region
" this function return 0 or 1 " this function return 0 or 1
function! emmet#util#regionInRegion(outer, inner) function! emmet#util#regionInRegion(outer, inner) abort
if !emmet#util#regionIsValid(a:inner) || !emmet#util#regionIsValid(a:outer) if !emmet#util#regionIsValid(a:inner) || !emmet#util#regionIsValid(a:outer)
return 0 return 0
endif endif
@@ -142,16 +142,16 @@ endfunction
" get_visualblock : get region of visual block " get_visualblock : get region of visual block
" this function return region of visual block " this function return region of visual block
function! emmet#util#getVisualBlock() function! emmet#util#getVisualBlock() abort
return [[line("'<"), col("'<")], [line("'>"), col("'>")]] return [[line("'<"), col("'<")], [line("'>"), col("'>")]]
endfunction endfunction
"============================================================================== "==============================================================================
" html utils " html utils
"============================================================================== "==============================================================================
function! emmet#util#getContentFromURL(url) function! emmet#util#getContentFromURL(url) abort
let res = system(printf("%s -i %s", g:emmet_curl_command, shellescape(substitute(a:url, '#.*', '', '')))) 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' 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") let pos = stridx(res, "\r\n\r\n")
if pos != -1 if pos != -1
let res = strpart(res, pos+4) let res = strpart(res, pos+4)
@@ -184,7 +184,7 @@ function! emmet#util#getContentFromURL(url)
return iconv(content, charset, &encoding) return iconv(content, charset, &encoding)
endfunction endfunction
function! emmet#util#getTextFromHTML(buf) function! emmet#util#getTextFromHTML(buf) abort
let threshold_len = 100 let threshold_len = 100
let threshold_per = 0.1 let threshold_per = 0.1
let buf = a:buf let buf = a:buf
@@ -202,7 +202,7 @@ function! emmet#util#getTextFromHTML(buf)
let str = substitute(str, '&gt;', '>', 'g') let str = substitute(str, '&gt;', '>', 'g')
let str = substitute(str, '&lt;', '<', 'g') let str = substitute(str, '&lt;', '<', 'g')
let str = substitute(str, '&quot;', '"', 'g') let str = substitute(str, '&quot;', '"', 'g')
let str = substitute(str, '&apos;', "'", 'g') let str = substitute(str, '&apos;', '''', 'g')
let str = substitute(str, '&nbsp;', ' ', 'g') let str = substitute(str, '&nbsp;', ' ', 'g')
let str = substitute(str, '&yen;', '\&#65509;', 'g') let str = substitute(str, '&yen;', '\&#65509;', 'g')
let str = substitute(str, '&amp;', '\&', 'g') let str = substitute(str, '&amp;', '\&', 'g')
@@ -221,7 +221,7 @@ function! emmet#util#getTextFromHTML(buf)
return res return res
endfunction endfunction
function! emmet#util#getImageSize(fn) function! emmet#util#getImageSize(fn) abort
let fn = a:fn let fn = a:fn
if emmet#util#isImageMagickInstalled() if emmet#util#isImageMagickInstalled()
@@ -231,7 +231,7 @@ function! emmet#util#getImageSize(fn)
if filereadable(fn) if filereadable(fn)
let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g') let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g')
else else
if fn !~ '^\w\+://' if fn !~# '^\w\+://'
let path = fnamemodify(expand('%'), ':p:gs?\\?/?') let path = fnamemodify(expand('%'), ':p:gs?\\?/?')
if has('win32') || has('win64') | if has('win32') || has('win64') |
let path = tolower(path) let path = tolower(path)
@@ -252,29 +252,29 @@ function! emmet#util#getImageSize(fn)
endif endif
let [width, height] = [-1, -1] let [width, height] = [-1, -1]
if hex =~ '^89504e470d0a1a0a' if hex =~# '^89504e470d0a1a0a'
let width = eval('0x'.hex[32:39]) let width = eval('0x'.hex[32:39])
let height = eval('0x'.hex[40:47]) let height = eval('0x'.hex[40:47])
endif endif
if hex =~ '^ffd8' if hex =~# '^ffd8'
let pos = 4 let pos = 4
while pos < len(hex) while pos < len(hex)
let bs = hex[pos+0:pos+3] let bs = hex[pos+0:pos+3]
let pos += 4 let pos += 4
if bs == 'ffc0' || bs == 'ffc2' if bs ==# 'ffc0' || bs ==# 'ffc2'
let pos += 6 let pos += 6
let height = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) let height = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])
let pos += 4 let pos += 4
let width = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3]) let width = eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])
break break
elseif bs =~ 'ffd[9a]' elseif bs =~# 'ffd[9a]'
break break
elseif bs =~ 'ff\(e[0-9a-e]\|fe\|db\|dd\|c4\)' 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 let pos += (eval('0x'.hex[pos+0:pos+1])*256 + eval('0x'.hex[pos+2:pos+3])) * 2
endif endif
endwhile endwhile
endif endif
if hex =~ '^47494638' if hex =~# '^47494638'
let width = eval('0x'.hex[14:15].hex[12:13]) let width = eval('0x'.hex[14:15].hex[12:13])
let height = eval('0x'.hex[18:19].hex[16:17]) let height = eval('0x'.hex[18:19].hex[16:17])
endif endif
@@ -282,7 +282,7 @@ function! emmet#util#getImageSize(fn)
return [width, height] return [width, height]
endfunction endfunction
function! emmet#util#imageSizeWithImageMagick(fn) function! emmet#util#imageSizeWithImageMagick(fn) abort
let img_info = system('identify -format "%wx%h" "'.a:fn.'"') let img_info = system('identify -format "%wx%h" "'.a:fn.'"')
let img_size = split(substitute(img_info, '\n', '', ''), 'x') let img_size = split(substitute(img_info, '\n', '', ''), 'x')
if len(img_size) != 2 if len(img_size) != 2
@@ -291,14 +291,14 @@ function! emmet#util#imageSizeWithImageMagick(fn)
return img_size return img_size
endfunction endfunction
function! emmet#util#isImageMagickInstalled() function! emmet#util#isImageMagickInstalled() abort
if !get(s:, 'emmet_use_identify', 1) if !get(s:, 'emmet_use_identify', 1)
return 0 return 0
endif endif
return executable('identify') return executable('identify')
endfunction endfunction
function! emmet#util#unique(arr) function! emmet#util#unique(arr) abort
let m = {} let m = {}
let r = [] let r = []
for i in a:arr for i in a:arr
@@ -311,39 +311,39 @@ function! emmet#util#unique(arr)
endfunction endfunction
let s:seed = localtime() let s:seed = localtime()
function! emmet#util#srand(seed) function! emmet#util#srand(seed) abort
let s:seed = a:seed let s:seed = a:seed
endfunction endfunction
function! emmet#util#rand() function! emmet#util#rand() abort
let s:seed = s:seed * 214013 + 2531011 let s:seed = s:seed * 214013 + 2531011
return (s:seed < 0 ? s:seed - 0x80000000 : s:seed) / 0x10000 % 0x8000 return (s:seed < 0 ? s:seed - 0x80000000 : s:seed) / 0x10000 % 0x8000
endfunction endfunction
function! emmet#util#cache(name, ...) function! emmet#util#cache(name, ...) abort
let content = get(a:000, 0, "") let content = get(a:000, 0, '')
let dir = expand("~/.emmet/cache") let dir = expand('~/.emmet/cache')
if !isdirectory(dir) if !isdirectory(dir)
call mkdir(dir, "p", 0700) call mkdir(dir, 'p', 0700)
endif endif
let file = dir . "/" . substitute(a:name, '\W', '_', 'g') let file = dir . '/' . substitute(a:name, '\W', '_', 'g')
if len(content) == 0 if len(content) == 0
if !filereadable(file) if !filereadable(file)
return "" return ''
endif endif
return join(readfile(file), "\n") return join(readfile(file), "\n")
endif endif
call writefile(split(content, "\n"), file) call writefile(split(content, "\n"), file)
endfunction endfunction
function! emmet#util#getcurpos() function! emmet#util#getcurpos() abort
let pos = getpos('.') let pos = getpos('.')
if mode(0) == 'i' && pos[2] > 0 if mode(0) ==# 'i' && pos[2] > 0
let pos[2] -=1 let pos[2] -=1
endif endif
return pos return pos
endfunction endfunction
function! emmet#util#closePopup() function! emmet#util#closePopup() abort
return pumvisible() ? "\<c-e>" : "" return pumvisible() ? "\<c-e>" : ''
endfunction endfunction