mirror of
https://github.com/amix/vimrc
synced 2025-07-01 20:55:00 +08:00
Updated all plugins that are non-forked. Added some new plugins.
Added update_plugins.py which can fetch new plugins from GitHub. New plugins added: zencoding, vim-indent-object, taglist, nginx.vim
This commit is contained in:
1486
sources_forked/zencoding/autoload/zencoding.vim
Executable file
1486
sources_forked/zencoding/autoload/zencoding.vim
Executable file
File diff suppressed because it is too large
Load Diff
11
sources_forked/zencoding/autoload/zencoding/lang.vim
Executable file
11
sources_forked/zencoding/autoload/zencoding/lang.vim
Executable file
@ -0,0 +1,11 @@
|
||||
let s:exists = {}
|
||||
function zencoding#lang#exists(type)
|
||||
if len(a:type) == 0
|
||||
return 0
|
||||
elseif has_key(s:exists, a:type)
|
||||
return s:exists[a:type]
|
||||
endif
|
||||
let s:exists[a:type] = len(globpath(&rtp, 'autoload/zencoding/lang/'.a:type.'.vim')) > 0
|
||||
return s:exists[a:type]
|
||||
endfunction
|
||||
|
228
sources_forked/zencoding/autoload/zencoding/lang/css.vim
Executable file
228
sources_forked/zencoding/autoload/zencoding/lang/css.vim
Executable file
@ -0,0 +1,228 @@
|
||||
function! zencoding#lang#css#findTokens(str)
|
||||
return substitute(a:str, '^.*[;{]\s*', '', '')
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#parseIntoTree(abbr, type)
|
||||
let abbr = a:abbr
|
||||
let type = a:type
|
||||
let prefix = 0
|
||||
let value = ''
|
||||
|
||||
let settings = zencoding#getSettings()
|
||||
let indent = zencoding#getIndentation(type)
|
||||
|
||||
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0 }
|
||||
|
||||
" emmet
|
||||
let tokens = split(abbr, '+\ze[^)!]')
|
||||
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.-]\+[pe]\{0,1}-\{0,1}\|-auto\)*\)$')
|
||||
if len(prop)
|
||||
let token = substitute(prop[1], '^(\(.*\))', '\1', '')
|
||||
if token =~ '^-'
|
||||
let prefix = 1
|
||||
let token = token[1:]
|
||||
endif
|
||||
let value = ''
|
||||
for v in split(prop[2], '\d\zs-')
|
||||
if len(value) > 0
|
||||
let value .= ' '
|
||||
endif
|
||||
if token =~ '^[z]'
|
||||
" TODO
|
||||
let value .= substitute(v, '[^0-9.]*$', '', '')
|
||||
elseif v =~ 'p$'
|
||||
let value .= substitute(v, 'p$', '%', '')
|
||||
elseif v =~ 'e$'
|
||||
let value .= substitute(v, 'e$', 'em', '')
|
||||
elseif v =~ '\.'
|
||||
let value .= v . 'em'
|
||||
elseif v == 'auto'
|
||||
let value .= v
|
||||
else
|
||||
let value .= v . 'px'
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
let tag_name = token
|
||||
if tag_name =~ '.!$'
|
||||
let tag_name = tag_name[:-2]
|
||||
let important = 1
|
||||
else
|
||||
let important = 0
|
||||
endif
|
||||
" make default node
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': important }
|
||||
let current.name = tag_name
|
||||
|
||||
" aliases
|
||||
let aliases = zencoding#getResource(type, 'aliases', {})
|
||||
if has_key(aliases, tag_name)
|
||||
let current.name = aliases[tag_name]
|
||||
endif
|
||||
let use_pipe_for_cursor = zencoding#getResource(type, 'use_pipe_for_cursor', 1)
|
||||
|
||||
" snippets
|
||||
let snippets = zencoding#getResource(type, 'snippets', {})
|
||||
if !empty(snippets) && has_key(snippets, tag_name)
|
||||
let snippet = snippets[tag_name]
|
||||
if use_pipe_for_cursor
|
||||
let snippet = substitute(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 && stridx(value, '${cursor}') == -1
|
||||
let current.snippet = substitute(current.snippet, '${cursor}', '', 'g') . '${cursor}'
|
||||
endif
|
||||
if n < len(tokens) - 1
|
||||
let current.snippet .= "\n"
|
||||
endif
|
||||
endif
|
||||
|
||||
let current.pos = 0
|
||||
let lg = matchlist(token, '^\%(linear-gradient\|lg\)(\s*\(\w\+\)\s*,\s*\([^,]\+\)\s*,\s*\([^)]\+\)\s*)$')
|
||||
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 = snippet
|
||||
call add(root.child, current)
|
||||
else
|
||||
call add(root.child, current)
|
||||
endif
|
||||
endfor
|
||||
return root
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
let current = a:current
|
||||
let value = current.value[1:-2]
|
||||
if zencoding#useFilter(a:filters, 'fc')
|
||||
let value = substitute(value, '\([^:]\+\):\([^;]*;\)', '\1: \2', 'g')
|
||||
else
|
||||
let value = substitute(value, '\([^:]\+\):\([^;]*;\)', '\1:\2', 'g')
|
||||
endif
|
||||
if current.important
|
||||
let value = substitute(value, ';', ' !important;', '')
|
||||
endif
|
||||
return value
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#imageSize()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#parseTag(tag)
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#toggleComment()
|
||||
let line = getline('.')
|
||||
let mx = '^\(\s*\)/\*\s*\(.*\)\s*\*/\s*$'
|
||||
if line =~ '{\s*$'
|
||||
let block = zencoding#util#searchRegion('/\*', '\*/\zs')
|
||||
if zencoding#util#regionIsValid(block)
|
||||
let content = zencoding#util#getContent(block)
|
||||
let content = substitute(content, '/\*\s\(.*\)\s\*/', '\1', '')
|
||||
call zencoding#util#setContent(block, content)
|
||||
else
|
||||
let node = expand('<cword>')
|
||||
if len(node)
|
||||
exe "normal ciw\<c-r>='/* '.node.' */'\<cr>"
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if line =~ mx
|
||||
let space = substitute(matchstr(line, mx), mx, '\1', '')
|
||||
let line = substitute(matchstr(line, mx), mx, '\2', '')
|
||||
let line = space . substitute(line, '^\s*\|\s*$', '\1', 'g')
|
||||
else
|
||||
let mx = '^\(\s*\)\(.*\)\s*$'
|
||||
let line = substitute(line, mx, '\1/* \2 */', '')
|
||||
endif
|
||||
call setline('.', line)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#balanceTag(flag) range
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
let block = zencoding#util#getVisualBlock()
|
||||
if !zencoding#util#regionIsValid(block)
|
||||
if a:flag > 0
|
||||
let block = zencoding#util#searchRegion('^', ';')
|
||||
if zencoding#util#regionIsValid(block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
else
|
||||
if a:flag > 0
|
||||
let content = zencoding#util#getContent(block)
|
||||
if content !~ '^{.*}$'
|
||||
let block = zencoding#util#searchRegion('{', '}')
|
||||
if zencoding#util#regionIsValid(block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
else
|
||||
let pos = searchpos('.*;', 'nW')
|
||||
if pos[0] != 0
|
||||
call setpos('.', [0, pos[0], pos[1], 0])
|
||||
let block = zencoding#util#searchRegion('^', ';')
|
||||
if zencoding#util#regionIsValid(block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe "normal! gv"
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#moveNextPrev(flag)
|
||||
let pos = search('""\|()\|\(:\s*\zs$\)', a:flag ? 'Wbp' : 'Wp')
|
||||
if pos == 2
|
||||
startinsert!
|
||||
else
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#splitJoinTag()
|
||||
" nothing to do
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#css#removeTag()
|
||||
" nothing to do
|
||||
endfunction
|
310
sources_forked/zencoding/autoload/zencoding/lang/haml.vim
Executable file
310
sources_forked/zencoding/autoload/zencoding/lang/haml.vim
Executable file
@ -0,0 +1,310 @@
|
||||
function! zencoding#lang#haml#findTokens(str)
|
||||
return zencoding#lang#html#findTokens(a:str)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#parseIntoTree(abbr, type)
|
||||
return zencoding#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
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 = zencoding#getResource(type, 'dollar_expr', 1)
|
||||
let str = ""
|
||||
|
||||
let comment_indent = ''
|
||||
let comment = ''
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
endif
|
||||
if len(current.name) > 0
|
||||
let str .= '%' . current_name
|
||||
let tmp = ''
|
||||
for attr in current.attrs_order
|
||||
if !has_key(current.attr, attr)
|
||||
continue
|
||||
endif
|
||||
let val = current.attr[attr]
|
||||
if dollar_expr
|
||||
while val =~ '\$\([^#{]\|$\)'
|
||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', 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')
|
||||
else
|
||||
if len(tmp) > 0 | let tmp .= ',' | endif
|
||||
let val = substitute(val, '\${cursor}', '', '')
|
||||
let tmp .= ' :' . attr . ' => "' . val . '"'
|
||||
endif
|
||||
endfor
|
||||
if len(tmp)
|
||||
let str .= '{' . tmp . ' }'
|
||||
endif
|
||||
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1 && len(current.value) == 0
|
||||
let str .= "/"
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
if len(current.value) > 0
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
let str = substitute(str, '\$#', text, 'g')
|
||||
endif
|
||||
let lines = split(text, "\n")
|
||||
if len(lines) == 1
|
||||
let str .= " " . text
|
||||
else
|
||||
for line in lines
|
||||
let str .= "\n" . indent . line . " |"
|
||||
endfor
|
||||
endif
|
||||
elseif len(current.child) == 0
|
||||
let str .= '${cursor}'
|
||||
endif
|
||||
if len(current.child) == 1 && len(current.child[0].name) == 0
|
||||
let text = current.child[0].value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
endif
|
||||
let lines = split(text, "\n")
|
||||
if len(lines) == 1
|
||||
let str .= " " . text
|
||||
else
|
||||
for line in lines
|
||||
let str .= "\n" . indent . line . " |"
|
||||
endfor
|
||||
endif
|
||||
elseif len(current.child) > 0
|
||||
for child in current.child
|
||||
let inner .= zencoding#toString(child, type, inline, filters, itemno)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g')
|
||||
let str .= "\n" . indent . inner
|
||||
endif
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
endif
|
||||
endif
|
||||
let str .= "\n"
|
||||
return str
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#imageSize()
|
||||
let line = getline('.')
|
||||
let current = zencoding#lang#haml#parseTag(line)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn =~ '^\s*$'
|
||||
return
|
||||
elseif fn !~ '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
endif
|
||||
|
||||
let [width, height] = zencoding#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let current.attrs_order += ['width', 'height']
|
||||
let haml = zencoding#toString(current, 'haml', 1)
|
||||
let haml = substitute(haml, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(line, '^\s*') . haml, "\n", "", "g"))
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#parseTag(tag)
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'attrs_order': [] }
|
||||
let mx = '%\([a-zA-Z][a-zA-Z0-9]*\)\s*\%({\(.*\)}\)'
|
||||
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]\+\)\s*=>\s*\%(\([^"'' \t]\+\)\|"\([^"]\{-}\)"\|''\([^'']\{-}\)''\)'
|
||||
while len(attrs) > 0
|
||||
let match = matchstr(attrs, mx)
|
||||
if len(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):]
|
||||
endwhile
|
||||
return current
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#toggleComment()
|
||||
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):])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#balanceTag(flag) range
|
||||
let block = zencoding#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
let n = curpos[1]
|
||||
let ml = len(matchstr(getline(n), '^\s*'))
|
||||
|
||||
if a:flag > 0
|
||||
if a:flag == 1 || !zencoding#util#regionIsValid(block)
|
||||
let n = line('.')
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze%[a-z]'))
|
||||
if l > 0 && l < ml
|
||||
let ml = l
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
endwhile
|
||||
endif
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, 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
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*%[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#moveNextPrev(flag)
|
||||
let pos = search('""', a:flag ? 'Wb' : 'W')
|
||||
if pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#splitJoinTag()
|
||||
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
|
||||
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
|
||||
break
|
||||
endif
|
||||
exe n "delete"
|
||||
endwhile
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
else
|
||||
let tag = matchstr(getline(sn), '^\s*%\zs\(\w\+\)')
|
||||
let spaces = matchstr(getline(sn), '^\s*')
|
||||
let settings = zencoding#getSettings()
|
||||
if stridx(','.settings.html.inline_elements.',', ','.tag.',') == -1
|
||||
call append(sn, spaces . ' ')
|
||||
call setpos('.', [0, sn+1, 1, 0])
|
||||
else
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
endif
|
||||
startinsert!
|
||||
endif
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#haml#removeTag()
|
||||
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]'))
|
||||
break
|
||||
endif
|
||||
let 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
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
if sn == n
|
||||
exe "delete"
|
||||
else
|
||||
exe sn "," (n-1) "delete"
|
||||
endif
|
||||
endfunction
|
692
sources_forked/zencoding/autoload/zencoding/lang/html.vim
Executable file
692
sources_forked/zencoding/autoload/zencoding/lang/html.vim
Executable file
@ -0,0 +1,692 @@
|
||||
let s:mx = '\([+>]\|[<^]\+\)\{-}\s*'
|
||||
\ .'\((*\)\{-}\s*'
|
||||
\ .'\([@#.]\{-}[a-zA-Z\!][a-zA-Z0-9:_\!\-$]*\|{\%([^$}]\+\|\$#\|\${\w\+}\|\$\+\)*}[ \t\r\n}]*\)'
|
||||
\ .'\('
|
||||
\ .'\%('
|
||||
\ .'\%(#{[{}a-zA-Z0-9_\-\$]\+\|#[a-zA-Z0-9_\-\$]\+\)'
|
||||
\ .'\|\%(\[[^\]]\+\]\)'
|
||||
\ .'\|\%(\.{[{}a-zA-Z0-9_\-\$]\+\|\.[a-zA-Z0-9_\-\$]\+\)'
|
||||
\ .'\)*'
|
||||
\ .'\)'
|
||||
\ .'\%(\({\%([^$}]\+\|\$#\|\${\w\+}\|\$\+\)*}\)\)\{0,1}'
|
||||
\ .'\%(\*\([0-9]\+\)\)\{0,1}'
|
||||
\ .'\(\%()\%(\*[0-9]\+\)\{0,1}\)*\)'
|
||||
|
||||
function! zencoding#lang#html#findTokens(str)
|
||||
let str = a:str
|
||||
let [pos, last_pos] = [0, 0]
|
||||
while 1
|
||||
let tag = matchstr(str, '<[a-zA-Z].\{-}>', pos)
|
||||
if len(tag) == 0
|
||||
break
|
||||
endif
|
||||
let pos = stridx(str, tag, pos) + len(tag)
|
||||
endwhile
|
||||
let last_pos = pos
|
||||
while len(str) > 0
|
||||
let token = matchstr(str, s:mx, pos)
|
||||
if token == ''
|
||||
break
|
||||
endif
|
||||
if token =~ '^\s'
|
||||
let token = matchstr(token, '^\s*\zs.*')
|
||||
let last_pos = stridx(str, token, pos)
|
||||
endif
|
||||
let pos = stridx(str, token, pos) + len(token)
|
||||
endwhile
|
||||
return a:str[last_pos :-1]
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#parseIntoTree(abbr, type)
|
||||
let abbr = a:abbr
|
||||
let type = a:type
|
||||
|
||||
let settings = zencoding#getSettings()
|
||||
if !has_key(settings, type)
|
||||
let type = 'html'
|
||||
endif
|
||||
if len(type) == 0 | let type = 'html' | endif
|
||||
|
||||
let settings = zencoding#getSettings()
|
||||
let indent = zencoding#getIndentation(type)
|
||||
|
||||
" try 'foo' to (foo-x)
|
||||
let rabbr = zencoding#getExpandos(type, abbr)
|
||||
if rabbr == abbr
|
||||
" try 'foo+(' to (foo-x)
|
||||
let rabbr = substitute(abbr, '\%(+\|^\)\([a-zA-Z][a-zA-Z0-9+]\+\)+\([(){}>]\|$\)', '\="(".zencoding#getExpandos(type, submatch(1)).")".submatch(2)', 'i')
|
||||
endif
|
||||
let abbr = rabbr
|
||||
|
||||
let root = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0, 'attrs_order': ['id', 'class'] }
|
||||
let parent = root
|
||||
let last = root
|
||||
let pos = []
|
||||
while len(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 multiplier = 0 + substitute(match, s:mx, '\6', 'ig')
|
||||
let block_end = substitute(match, s:mx, '\7', 'ig')
|
||||
let important = 0
|
||||
if len(str) == 0
|
||||
break
|
||||
endif
|
||||
if tag_name =~ '^#'
|
||||
let attributes = tag_name . attributes
|
||||
let tag_name = 'div'
|
||||
endif
|
||||
if tag_name =~ '.!$'
|
||||
let tag_name = tag_name[:-2]
|
||||
let important = 1
|
||||
endif
|
||||
if tag_name =~ '^\.'
|
||||
let attributes = tag_name . attributes
|
||||
let tag_name = 'div'
|
||||
endif
|
||||
if multiplier <= 0 | let multiplier = 1 | endif
|
||||
|
||||
" make default node
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'important': 0, 'attrs_order': ['id', 'class'] }
|
||||
let current.name = tag_name
|
||||
|
||||
let current.important = important
|
||||
|
||||
" aliases
|
||||
let aliases = zencoding#getResource(type, 'aliases', {})
|
||||
if has_key(aliases, tag_name)
|
||||
let current.name = aliases[tag_name]
|
||||
endif
|
||||
|
||||
let use_pipe_for_cursor = zencoding#getResource(type, 'use_pipe_for_cursor', 1)
|
||||
|
||||
" snippets
|
||||
let snippets = zencoding#getResource(type, 'snippets', {})
|
||||
if !empty(snippets) && has_key(snippets, tag_name)
|
||||
let snippet = snippets[tag_name]
|
||||
if use_pipe_for_cursor
|
||||
let snippet = substitute(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 = ''
|
||||
endif
|
||||
|
||||
" default_attributes
|
||||
let default_attributes = zencoding#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)
|
||||
let current.attr[k] = len(a[k]) ? substitute(a[k], '|', '${cursor}', 'g') : '${cursor}'
|
||||
endfor
|
||||
else
|
||||
for k in keys(a)
|
||||
let current.attr[k] = a[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)
|
||||
let current.attr[k] = len(a[k]) ? substitute(a[k], '|', '${cursor}', 'g') : '${cursor}'
|
||||
endfor
|
||||
else
|
||||
for k in keys(a)
|
||||
let current.attr[k] = a[k]
|
||||
endfor
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if has_key(settings.html.default_attributes, current.name)
|
||||
let current.name = substitute(current.name, ':.*$', '', '')
|
||||
endif
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
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(item) == 0
|
||||
break
|
||||
endif
|
||||
if item[0] == '#'
|
||||
let current.attr.id = item[1:]
|
||||
endif
|
||||
if item[0] == '.'
|
||||
let current.attr.class = substitute(item[1:], '\.', ' ', 'g')
|
||||
endif
|
||||
if item[0] == '['
|
||||
let atts = item[1:-2]
|
||||
while len(atts)
|
||||
let amat = matchstr(atts, '\(\w\+\%(="[^"]*"\|=''[^'']*''\|[^ ''"\]]*\)\{0,1}\)')
|
||||
if len(amat) == 0
|
||||
break
|
||||
endif
|
||||
let key = split(amat, '=')[0]
|
||||
let val = amat[len(key)+1:]
|
||||
if val =~ '^["'']'
|
||||
let val = val[1:-2]
|
||||
endif
|
||||
let current.attr[key] = val
|
||||
if index(current.attrs_order, key) == -1
|
||||
let current.attrs_order += [key]
|
||||
endif
|
||||
let atts = atts[stridx(atts, amat) + len(amat):]
|
||||
endwhile
|
||||
endif
|
||||
let attr = substitute(strpart(attr, len(item)), '^\s*', '', '')
|
||||
endwhile
|
||||
endif
|
||||
|
||||
" parse text
|
||||
if tag_name =~ '^{.*}$'
|
||||
let current.name = ''
|
||||
let current.value = tag_name
|
||||
else
|
||||
let current.value = value
|
||||
endif
|
||||
let current.multiplier = 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
|
||||
else
|
||||
let current.parent = parent
|
||||
let current.pos = last.pos
|
||||
endif
|
||||
else
|
||||
let current.parent = parent
|
||||
let current.pos = 1
|
||||
endif
|
||||
if operator =~ '[<^]'
|
||||
for c in range(len(operator))
|
||||
let tmp = parent.parent
|
||||
if empty(tmp)
|
||||
break
|
||||
endif
|
||||
let parent = tmp
|
||||
let current.parent = tmp
|
||||
endfor
|
||||
endif
|
||||
|
||||
call add(parent.child, current)
|
||||
let last = current
|
||||
|
||||
" parse block
|
||||
if block_start =~ '('
|
||||
if operator =~ '>'
|
||||
let last.pos += 1
|
||||
endif
|
||||
for n in range(len(block_start))
|
||||
let pos += [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')
|
||||
break
|
||||
endif
|
||||
let parent = tmp
|
||||
endfor
|
||||
if len(pos) > 0
|
||||
call remove(pos, -1)
|
||||
endif
|
||||
let last = parent
|
||||
let last.pos += 1
|
||||
endif
|
||||
elseif len(n)
|
||||
let cl = last.child
|
||||
let cls = []
|
||||
for c in range(n[1:])
|
||||
let cls += cl
|
||||
endfor
|
||||
let last.child = cls
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
let abbr = abbr[stridx(abbr, match) + len(match):]
|
||||
|
||||
if g:zencoding_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 "multiplier=".multiplier
|
||||
echomsg "block_end=".block_end
|
||||
echomsg "abbr=".abbr
|
||||
echomsg "pos=".string(pos)
|
||||
echomsg "---"
|
||||
endif
|
||||
endwhile
|
||||
return root
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
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 = zencoding#getResource(type, 'dollar_expr', 1)
|
||||
|
||||
if zencoding#useFilter(filters, 'haml')
|
||||
return zencoding#lang#haml#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
endif
|
||||
if zencoding#useFilter(filters, 'slim')
|
||||
return zencoding#lang#slim#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
endif
|
||||
|
||||
let comment = ''
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current_name, '\$$', itemno+1, '')
|
||||
endif
|
||||
|
||||
let str = ''
|
||||
if len(current_name) == 0
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
endif
|
||||
return text
|
||||
endif
|
||||
if len(current_name) > 0
|
||||
let str .= '<' . current_name
|
||||
for attr in current.attrs_order
|
||||
if !has_key(current.attr, attr)
|
||||
continue
|
||||
endif
|
||||
let val = current.attr[attr]
|
||||
if dollar_expr
|
||||
while val =~ '\$\([^#{]\|$\)'
|
||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
endif
|
||||
let str .= ' ' . attr . '="' . val . '"'
|
||||
if zencoding#useFilter(filters, 'c')
|
||||
if attr == 'id' | let comment .= '#' . val | endif
|
||||
if attr == 'class' | let comment .= '.' . val | endif
|
||||
endif
|
||||
endfor
|
||||
if len(comment) > 0
|
||||
let str = "<!-- " . comment . " -->\n" . str
|
||||
endif
|
||||
if stridx(','.settings.html.empty_elements.',', ','.current_name.',') != -1
|
||||
let str .= settings.html.empty_element_suffix
|
||||
else
|
||||
let str .= ">"
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
let str = substitute(str, '\("\zs$#\ze"\|\s\zs\$#"\|"\$#\ze\s\)', text, 'g')
|
||||
endif
|
||||
let str .= text
|
||||
let nc = len(current.child)
|
||||
let dr = 0
|
||||
if nc > 0
|
||||
for n in range(nc)
|
||||
let child = current.child[n]
|
||||
if child.multiplier > 1
|
||||
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
|
||||
endif
|
||||
endif
|
||||
let inner = zencoding#toString(child, type, 0, filters, itemno)
|
||||
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
|
||||
endfor
|
||||
else
|
||||
let str .= '${cursor}'
|
||||
endif
|
||||
if dr
|
||||
let str .= "\n"
|
||||
endif
|
||||
let str .= "</" . current_name . ">"
|
||||
endif
|
||||
if len(comment) > 0
|
||||
let str .= "\n<!-- /" . comment . " -->"
|
||||
endif
|
||||
if len(current_name) > 0 && current.multiplier > 0 || stridx(','.settings.html.block_elements.',', ','.current_name.',') != -1
|
||||
let str .= "\n"
|
||||
endif
|
||||
return str
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#imageSize()
|
||||
let img_region = zencoding#util#searchRegion('<img\s', '>')
|
||||
if !zencoding#util#regionIsValid(img_region) || !zencoding#util#cursorInRegion(img_region)
|
||||
return
|
||||
endif
|
||||
let content = zencoding#util#getContent(img_region)
|
||||
if content !~ '^<img[^><]\+>$'
|
||||
return
|
||||
endif
|
||||
let current = zencoding#lang#html#parseTag(content)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn =~ '^\s*$'
|
||||
return
|
||||
elseif fn !~ '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
endif
|
||||
|
||||
let [width, height] = zencoding#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let current.attrs_order += ['width', 'height']
|
||||
let html = substitute(zencoding#toString(current, 'html', 1), '\n', '', '')
|
||||
let html = substitute(html, '\${cursor}', '', '')
|
||||
call zencoding#util#setContent(img_region, html)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#encodeImage()
|
||||
let img_region = zencoding#util#searchRegion('<img\s', '>')
|
||||
if !zencoding#util#regionIsValid(img_region) || !zencoding#util#cursorInRegion(img_region)
|
||||
return
|
||||
endif
|
||||
let content = zencoding#util#getContent(img_region)
|
||||
if content !~ '^<img[^><]\+>$'
|
||||
return
|
||||
endif
|
||||
let current = zencoding#lang#html#parseTag(content)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn !~ '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
endif
|
||||
|
||||
let [width, height] = zencoding#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let html = zencoding#toString(current, 'html', 1)
|
||||
call zencoding#util#setContent(img_region, html)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#parseTag(tag)
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'attrs_order': [] }
|
||||
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
|
||||
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):]
|
||||
endwhile
|
||||
return current
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#toggleComment()
|
||||
let orgpos = getpos('.')
|
||||
let curpos = getpos('.')
|
||||
let mx = '<\%#[^>]*>'
|
||||
while 1
|
||||
let block = zencoding#util#searchRegion('<!--', '-->')
|
||||
if zencoding#util#regionIsValid(block)
|
||||
let block[1][1] += 2
|
||||
let content = zencoding#util#getContent(block)
|
||||
let content = substitute(content, '^<!--\s\(.*\)\s-->$', '\1', '')
|
||||
call zencoding#util#setContent(block, content)
|
||||
silent! call setpos('.', orgpos)
|
||||
return
|
||||
endif
|
||||
let block = zencoding#util#searchRegion('<[^>]', '>')
|
||||
if !zencoding#util#regionIsValid(block)
|
||||
let pos1 = searchpos('<', 'bcW')
|
||||
if pos1[0] == 0 && pos1[1] == 0
|
||||
return
|
||||
endif
|
||||
let curpos = getpos('.')
|
||||
continue
|
||||
endif
|
||||
let pos1 = block[0]
|
||||
let pos2 = block[1]
|
||||
let content = zencoding#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:] . '>', '', '</' . tag_name[1:] . '>', 'bnW')
|
||||
let pos1 = searchpos('>', 'cneW')
|
||||
let block = [pos2, pos1]
|
||||
elseif tag_name =~ '/$'
|
||||
if !zencoding#util#pointInRegion(orgpos[1:2], block)
|
||||
" it's broken tree
|
||||
call setpos('.', orgpos)
|
||||
let block = zencoding#util#searchRegion('>', '<')
|
||||
let content = '><!-- ' . zencoding#util#getContent(block)[1:-2] . ' --><'
|
||||
call zencoding#util#setContent(block, content)
|
||||
silent! call setpos('.', orgpos)
|
||||
return
|
||||
endif
|
||||
else
|
||||
call setpos('.', [0, pos2[0], pos2[1], 0])
|
||||
let pos2 = searchpairpos('<'. tag_name . '>', '', '</' . tag_name . '>', 'nW')
|
||||
call setpos('.', [0, pos2[0], pos2[1], 0])
|
||||
let pos2 = searchpos('>', 'neW')
|
||||
let block = [pos1, pos2]
|
||||
endif
|
||||
if !zencoding#util#regionIsValid(block)
|
||||
silent! call setpos('.', orgpos)
|
||||
return
|
||||
endif
|
||||
if zencoding#util#pointInRegion(curpos[1:2], block)
|
||||
let content = '<!-- ' . zencoding#util#getContent(block) . ' -->'
|
||||
call zencoding#util#setContent(block, content)
|
||||
silent! call setpos('.', orgpos)
|
||||
return
|
||||
endif
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#balanceTag(flag) range
|
||||
let vblock = zencoding#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
let settings = zencoding#getSettings()
|
||||
|
||||
if a:flag > 0
|
||||
let mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
|
||||
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')
|
||||
else
|
||||
let pos2 = searchpairpos('<' . tag_name . '[^>]*>', '', '</'. tag_name . '>\zs', 'nW')
|
||||
endif
|
||||
let block = [pos1, pos2]
|
||||
if pos1[0] == 0 && pos1[1] == 0
|
||||
break
|
||||
endif
|
||||
if zencoding#util#pointInRegion(curpos[1:2], block) && zencoding#util#regionIsValid(block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
endwhile
|
||||
else
|
||||
let mx = '<\([a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
|
||||
while 1
|
||||
let pos1 = searchpos(mx, 'W')
|
||||
if pos1 == curpos[1:2]
|
||||
let pos1 = searchpos(mx . '\zs', 'W')
|
||||
let pos2 = searchpos('.\ze<', 'W')
|
||||
let block = [pos1, pos2]
|
||||
if zencoding#util#regionIsValid(block)
|
||||
call zencoding#util#selectRegion(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')
|
||||
else
|
||||
let pos2 = searchpairpos('<' . tag_name . '[^>]*>', '', '</'. tag_name . '>\zs', 'nW')
|
||||
endif
|
||||
let block = [pos1, pos2]
|
||||
if pos1[0] == 0 && pos1[1] == 0
|
||||
break
|
||||
endif
|
||||
if zencoding#util#regionIsValid(block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
endwhile
|
||||
endif
|
||||
call setpos('.', curpos)
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe "normal! gv"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#moveNextPrev(flag)
|
||||
let pos = search('\%(</\w\+\)\@<!\zs><\/\|\(""\)\|^\(\s*\)$', a:flag ? 'Wpb' : 'Wp')
|
||||
if pos == 3
|
||||
startinsert!
|
||||
elseif pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#splitJoinTag()
|
||||
let curpos = getpos('.')
|
||||
while 1
|
||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
|
||||
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:] == '/>' && zencoding#util#cursorInRegion(block)
|
||||
let content = content[:-3] . "></" . tag_name . '>'
|
||||
call zencoding#util#setContent(block, content)
|
||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||
return
|
||||
else
|
||||
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 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
||||
else
|
||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||
endif
|
||||
let block = [pos1, pos2]
|
||||
let content = zencoding#util#getContent(block)
|
||||
if zencoding#util#pointInRegion(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||
let content = matchstr(content, mx)[:-2] . '/>'
|
||||
call zencoding#util#setContent(block, content)
|
||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||
return
|
||||
else
|
||||
if block[0][0] > 0
|
||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#html#removeTag()
|
||||
let curpos = getpos('.')
|
||||
while 1
|
||||
let mx = '<\(/\{0,1}[a-zA-Z][a-zA-Z0-9:_\-]*\)[^>]*>'
|
||||
let pos1 = searchpos(mx, 'bcnW')
|
||||
let content = matchstr(getline(pos1[0])[pos1[1]-1:], mx)
|
||||
let tag_name = substitute(content, '^<\(/\{0,1}[a-zA-Z0-9:_\-]*\).*$', '\1', '')
|
||||
let block = [pos1, [pos1[0], pos1[1] + len(content) - 1]]
|
||||
if content[-2:] == '/>' && zencoding#util#cursorInRegion(block)
|
||||
call zencoding#util#setContent(block, '')
|
||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||
return
|
||||
else
|
||||
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 = searchpos('</' . tag_name[1:] . '>', 'cneW')
|
||||
else
|
||||
let pos2 = searchpos('</' . tag_name . '>', 'cneW')
|
||||
endif
|
||||
let block = [pos1, pos2]
|
||||
let content = zencoding#util#getContent(block)
|
||||
if zencoding#util#pointInRegion(curpos[1:2], block) && content[1:] !~ '<' . tag_name . '[^a-zA-Z0-9]*[^>]*>'
|
||||
call zencoding#util#setContent(block, '')
|
||||
call setpos('.', [0, block[0][0], block[0][1], 0])
|
||||
return
|
||||
else
|
||||
if block[0][0] > 0
|
||||
call setpos('.', [0, block[0][0]-1, block[0][1], 0])
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endwhile
|
||||
endfunction
|
158
sources_forked/zencoding/autoload/zencoding/lang/sass.vim
Executable file
158
sources_forked/zencoding/autoload/zencoding/lang/sass.vim
Executable file
@ -0,0 +1,158 @@
|
||||
function! zencoding#lang#sass#findTokens(str)
|
||||
return zencoding#lang#html#findTokens(a:str)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#parseIntoTree(abbr, type)
|
||||
if a:abbr =~ '>'
|
||||
return zencoding#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
else
|
||||
return zencoding#lang#css#parseIntoTree(a:abbr, a:type)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
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 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')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
if attr == 'id'
|
||||
let str .= '#' . val
|
||||
elseif attr == 'class'
|
||||
let str .= '.' . val
|
||||
else
|
||||
let tmp .= attr . ': ' . val
|
||||
endif
|
||||
endfor
|
||||
if len(tmp) > 0
|
||||
let str .= "\n"
|
||||
for line in split(tmp, "\n")
|
||||
let str .= indent . line . "\n"
|
||||
endfor
|
||||
else
|
||||
let str .= "\n"
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
for child in current.child
|
||||
let inner .= zencoding#toString(child, type, inline, filters, itemno)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . indent, 'g')
|
||||
let inner = substitute(inner, "\n" . indent . "$", "", 'g')
|
||||
let str .= indent . inner
|
||||
else
|
||||
let text = zencoding#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
let text = substitute(text, '\${cursor}', '', 'g')
|
||||
let text = substitute(text, '\s*;$', '', '')
|
||||
return text
|
||||
endif
|
||||
return str
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#imageSize()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#parseTag(tag)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#toggleComment()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#balanceTag(flag) range
|
||||
let block = zencoding#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
let n = curpos[1]
|
||||
let ml = len(matchstr(getline(n), '^\s*'))
|
||||
|
||||
if a:flag > 0
|
||||
if a:flag == 1 || !zencoding#util#regionIsValid(block)
|
||||
let n = line('.')
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l < ml
|
||||
let ml = l
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
endwhile
|
||||
endif
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, 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
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#moveNextPrev(flag)
|
||||
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
|
||||
if pos == 2
|
||||
startinsert!
|
||||
elseif pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#splitJoinTag()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#sass#removeTag()
|
||||
endfunction
|
121
sources_forked/zencoding/autoload/zencoding/lang/scss.vim
Executable file
121
sources_forked/zencoding/autoload/zencoding/lang/scss.vim
Executable file
@ -0,0 +1,121 @@
|
||||
function! zencoding#lang#scss#findTokens(str)
|
||||
return zencoding#lang#html#findTokens(a:str)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#parseIntoTree(abbr, type)
|
||||
if a:abbr =~ '>'
|
||||
return zencoding#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
else
|
||||
return zencoding#lang#css#parseIntoTree(a:abbr, a:type)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
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 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')
|
||||
endwhile
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
if attr == 'id'
|
||||
let str .= '#' . val
|
||||
elseif attr == 'class'
|
||||
let str .= '.' . val
|
||||
else
|
||||
let tmp .= attr . ': ' . val . ';'
|
||||
endif
|
||||
endfor
|
||||
if len(tmp) > 0
|
||||
let str .= " {\n"
|
||||
for line in split(tmp, "\n")
|
||||
let str .= indent . line . "\n"
|
||||
endfor
|
||||
else
|
||||
let str .= " {\n"
|
||||
endif
|
||||
|
||||
let inner = ''
|
||||
for child in current.child
|
||||
let inner .= zencoding#toString(child, type, inline, filters, itemno)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g')
|
||||
let str .= indent . inner . "\n}\n"
|
||||
else
|
||||
return zencoding#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
endif
|
||||
return str
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#imageSize()
|
||||
call zencoding#lang#css#imageSize()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#encodeImage()
|
||||
return zencoding#lang#css#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#parseTag(tag)
|
||||
return zencoding#lang#css#parseTag(a:tag)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#toggleComment()
|
||||
call zencoding#lang#css#toggleComment()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#balanceTag(flag) range
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
call setpos('.', curpos)
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
if a:flag < 0
|
||||
let ret = searchpair('}', '', '.\zs{')
|
||||
else
|
||||
let ret = searchpair('{', '', '}', 'bW')
|
||||
endif
|
||||
if ret > 0
|
||||
let pos1 = getpos('.')[1:2]
|
||||
if a:flag < 0
|
||||
let pos2 = searchpairpos('{', '', '}')
|
||||
else
|
||||
let pos2 = searchpairpos('{', '', '}')
|
||||
endif
|
||||
let block = [pos1, pos2]
|
||||
if zencoding#util#regionIsValid(block)
|
||||
call zencoding#util#selectRegion(block)
|
||||
return
|
||||
endif
|
||||
endif
|
||||
if a:flag == -2 || a:flag == 2
|
||||
silent! exe "normal! gv"
|
||||
else
|
||||
call setpos('.', curpos)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#moveNextPrev(flag)
|
||||
call zencoding#lang#css#moveNextPrev(a:flag)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#splitJoinTag()
|
||||
call zencoding#lang#css#splitJoinTag()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#scss#removeTag()
|
||||
call zencoding#lang#ss#removeTag()
|
||||
endfunction
|
276
sources_forked/zencoding/autoload/zencoding/lang/slim.vim
Executable file
276
sources_forked/zencoding/autoload/zencoding/lang/slim.vim
Executable file
@ -0,0 +1,276 @@
|
||||
function! zencoding#lang#slim#findTokens(str)
|
||||
return zencoding#lang#html#findTokens(a:str)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#parseIntoTree(abbr, type)
|
||||
return zencoding#lang#html#parseIntoTree(a:abbr, a:type)
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#toString(settings, current, type, inline, filters, itemno, indent)
|
||||
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 = zencoding#getResource(type, 'dollar_expr', 1)
|
||||
let str = ""
|
||||
|
||||
let comment_indent = ''
|
||||
let comment = ''
|
||||
let current_name = current.name
|
||||
if dollar_expr
|
||||
let current_name = substitute(current.name, '\$$', itemno+1, '')
|
||||
endif
|
||||
if len(current.name) > 0
|
||||
let str .= current_name
|
||||
for attr in current.attrs_order
|
||||
if !has_key(current.attr, attr)
|
||||
continue
|
||||
endif
|
||||
let val = current.attr[attr]
|
||||
if dollar_expr
|
||||
while val =~ '\$\([^#{]\|$\)'
|
||||
let val = substitute(val, '\(\$\+\)\([^{]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
endwhile
|
||||
endif
|
||||
let attr = substitute(attr, '\$$', itemno+1, '')
|
||||
let str .= ' ' . attr . '="' . val . '"'
|
||||
endfor
|
||||
|
||||
let inner = ''
|
||||
if len(current.value) > 0
|
||||
let str .= "\n"
|
||||
let text = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
let str = substitute(str, '\$#', text, 'g')
|
||||
endif
|
||||
for line in split(text, "\n")
|
||||
let str .= indent . "| " . line . "\n"
|
||||
endfor
|
||||
elseif len(current.child) == 0
|
||||
let str .= '${cursor}'
|
||||
endif
|
||||
if len(current.child) == 1 && len(current.child[0].name) == 0
|
||||
let str .= "\n"
|
||||
let text = current.child[0].value[1:-2]
|
||||
if dollar_expr
|
||||
let text = substitute(text, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let text = substitute(text, '\${nr}', "\n", 'g')
|
||||
let text = substitute(text, '\\\$', '$', 'g')
|
||||
endif
|
||||
for line in split(text, "\n")
|
||||
let str .= indent . "| " . line . "\n"
|
||||
endfor
|
||||
elseif len(current.child) > 0
|
||||
for child in current.child
|
||||
let inner .= zencoding#toString(child, type, inline, filters, itemno)
|
||||
endfor
|
||||
let inner = substitute(inner, "\n", "\n" . escape(indent, '\'), 'g')
|
||||
let inner = substitute(inner, "\n" . escape(indent, '\') . "$", "", 'g')
|
||||
let str .= "\n" . indent . inner
|
||||
endif
|
||||
else
|
||||
let str = current.value[1:-2]
|
||||
if dollar_expr
|
||||
let str = substitute(str, '\%(\\\)\@\<!\(\$\+\)\([^{#]\|$\)', '\=printf("%0".len(submatch(1))."d", itemno+1).submatch(2)', 'g')
|
||||
let str = substitute(str, '\${nr}', "\n", 'g')
|
||||
let str = substitute(str, '\\\$', '$', 'g')
|
||||
endif
|
||||
endif
|
||||
if str !~ "\n$"
|
||||
let str .= "\n"
|
||||
endif
|
||||
return str
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#imageSize()
|
||||
let line = getline('.')
|
||||
let current = zencoding#lang#slim#parseTag(line)
|
||||
if empty(current) || !has_key(current.attr, 'src')
|
||||
return
|
||||
endif
|
||||
let fn = current.attr.src
|
||||
if fn =~ '^\s*$'
|
||||
return
|
||||
elseif fn !~ '^\(/\|http\)'
|
||||
let fn = simplify(expand('%:h') . '/' . fn)
|
||||
endif
|
||||
|
||||
let [width, height] = zencoding#util#getImageSize(fn)
|
||||
if width == -1 && height == -1
|
||||
return
|
||||
endif
|
||||
let current.attr.width = width
|
||||
let current.attr.height = height
|
||||
let current.attrs_order += ['width', 'height']
|
||||
let slim = zencoding#toString(current, 'slim', 1)
|
||||
let slim = substitute(slim, '\${cursor}', '', '')
|
||||
call setline('.', substitute(matchstr(line, '^\s*') . slim, "\n", "", "g"))
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#encodeImage()
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#parseTag(tag)
|
||||
let current = { 'name': '', 'attr': {}, 'child': [], 'snippet': '', 'multiplier': 1, 'parent': {}, 'value': '', 'pos': 0, 'attrs_order': [] }
|
||||
let mx = '\([a-zA-Z][a-zA-Z0-9]*\)\s\+\(.*\)'
|
||||
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
|
||||
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):]
|
||||
endwhile
|
||||
return current
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#toggleComment()
|
||||
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):])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#balanceTag(flag) range
|
||||
let block = zencoding#util#getVisualBlock()
|
||||
if a:flag == -2 || a:flag == 2
|
||||
let curpos = [0, line("'<"), col("'<"), 0]
|
||||
else
|
||||
let curpos = getpos('.')
|
||||
endif
|
||||
let n = curpos[1]
|
||||
let ml = len(matchstr(getline(n), '^\s*'))
|
||||
|
||||
if a:flag > 0
|
||||
if a:flag == 1 || !zencoding#util#regionIsValid(block)
|
||||
let n = line('.')
|
||||
else
|
||||
while n > 0
|
||||
let l = len(matchstr(getline(n), '^\s*\ze[a-z]'))
|
||||
if l > 0 && l < ml
|
||||
let ml = l
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
endwhile
|
||||
endif
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, 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
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
let sn = n
|
||||
if n == 0
|
||||
let ml = 0
|
||||
endif
|
||||
while n < line('$')
|
||||
let l = len(matchstr(getline(n), '^\s*[a-z]'))
|
||||
if l > 0 && l <= ml
|
||||
let n -= 1
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
call setpos('.', [0, n, 1, 0])
|
||||
normal! V
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#moveNextPrev(flag)
|
||||
let pos = search('""\|\(^\s*|\s*\zs\)', a:flag ? 'Wpb' : 'Wp')
|
||||
if pos == 2
|
||||
startinsert!
|
||||
elseif pos != 0
|
||||
silent! normal! l
|
||||
startinsert
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#splitJoinTag()
|
||||
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*|'
|
||||
break
|
||||
endif
|
||||
exe n "delete"
|
||||
endwhile
|
||||
call setpos('.', [0, sn, 1, 0])
|
||||
else
|
||||
let spaces = matchstr(getline(sn), '^\s*')
|
||||
call append(sn, spaces . ' | ')
|
||||
call setpos('.', [0, sn+1, 1, 0])
|
||||
startinsert!
|
||||
endif
|
||||
break
|
||||
endif
|
||||
let n -= 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
function! zencoding#lang#slim#removeTag()
|
||||
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]'))
|
||||
break
|
||||
endif
|
||||
let 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
|
||||
break
|
||||
endif
|
||||
let n += 1
|
||||
endwhile
|
||||
if sn == n
|
||||
exe "delete"
|
||||
else
|
||||
exe sn "," (n-1) "delete"
|
||||
endif
|
||||
endfunction
|
249
sources_forked/zencoding/autoload/zencoding/util.vim
Executable file
249
sources_forked/zencoding/autoload/zencoding/util.vim
Executable file
@ -0,0 +1,249 @@
|
||||
"==============================================================================
|
||||
" region utils
|
||||
"==============================================================================
|
||||
" deleteContent : delete content in region
|
||||
" if region make from between '<foo>' and '</foo>'
|
||||
" --------------------
|
||||
" begin:<foo>
|
||||
" </foo>:end
|
||||
" --------------------
|
||||
" this function make the content as following
|
||||
" --------------------
|
||||
" begin::end
|
||||
" --------------------
|
||||
function! zencoding#util#deleteContent(region)
|
||||
let 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]])
|
||||
endfunction
|
||||
|
||||
" change_content : change content in region
|
||||
" if region make from between '<foo>' and '</foo>'
|
||||
" --------------------
|
||||
" begin:<foo>
|
||||
" </foo>:end
|
||||
" --------------------
|
||||
" and content is
|
||||
" --------------------
|
||||
" foo
|
||||
" bar
|
||||
" baz
|
||||
" --------------------
|
||||
" this function make the content as following
|
||||
" --------------------
|
||||
" begin:foo
|
||||
" bar
|
||||
" baz:end
|
||||
" --------------------
|
||||
function! zencoding#util#setContent(region, content)
|
||||
let newlines = split(a:content, '\n', 1)
|
||||
let 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 a:region[0][1] > 1
|
||||
let tmp = oldlines[0][:a:region[0][1]-2]
|
||||
endif
|
||||
if a:region[1][1] >= 1
|
||||
let tmp .= oldlines[-1][a:region[1][1]:]
|
||||
endif
|
||||
call setline(line('.'), tmp)
|
||||
elseif len(newlines) == 1
|
||||
if a:region[0][1] > 1
|
||||
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
|
||||
endif
|
||||
if a:region[1][1] >= 1
|
||||
let newlines[0] .= oldlines[-1][a:region[1][1]:]
|
||||
endif
|
||||
call setline(line('.'), newlines[0])
|
||||
else
|
||||
if a:region[0][1] > 1
|
||||
let newlines[0] = oldlines[0][:a:region[0][1]-2] . newlines[0]
|
||||
endif
|
||||
if a:region[1][1] >= 1
|
||||
let newlines[-1] .= oldlines[-1][a:region[1][1]:]
|
||||
endif
|
||||
call setline(line('.'), newlines[0])
|
||||
call append(line('.'), newlines[1:])
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" select_region : select region
|
||||
" this function make a selection of region
|
||||
function! zencoding#util#selectRegion(region)
|
||||
call setpos('.', [0, a:region[1][0], a:region[1][1], 0])
|
||||
normal! v
|
||||
call setpos('.', [0, a:region[0][0], a:region[0][1], 0])
|
||||
endfunction
|
||||
|
||||
" point_in_region : check point is in the region
|
||||
" this function return 0 or 1
|
||||
function! zencoding#util#pointInRegion(point, region)
|
||||
if !zencoding#util#regionIsValid(a:region) | 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[0][0] == a:point[0] && a:region[0][1] > a:point[1] | return 0 | endif
|
||||
if a:region[1][0] == a:point[0] && a:region[1][1] < a:point[1] | return 0 | endif
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
" cursor_in_region : check cursor is in the region
|
||||
" this function return 0 or 1
|
||||
function! zencoding#util#cursorInRegion(region)
|
||||
if !zencoding#util#regionIsValid(a:region) | return 0 | endif
|
||||
let cur = getpos('.')[1:2]
|
||||
return zencoding#util#pointInRegion(cur, a:region)
|
||||
endfunction
|
||||
|
||||
" region_is_valid : check region is valid
|
||||
" this function return 0 or 1
|
||||
function! zencoding#util#regionIsValid(region)
|
||||
if a:region[0][0] == 0 || a:region[1][0] == 0 | return 0 | endif
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
" search_region : make region from pattern which is composing start/end
|
||||
" this function return array of position
|
||||
function! zencoding#util#searchRegion(start, end)
|
||||
return [searchpairpos(a:start, '', a:end, 'bcnW'), searchpairpos(a:start, '\%#', a:end, 'nW')]
|
||||
endfunction
|
||||
|
||||
" get_content : get content in region
|
||||
" this function return string in region
|
||||
function! zencoding#util#getContent(region)
|
||||
if !zencoding#util#regionIsValid(a:region)
|
||||
return ''
|
||||
endif
|
||||
let 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]
|
||||
else
|
||||
let lines[0] = lines[0][a:region[0][1]-1:]
|
||||
let lines[-1] = lines[-1][:a:region[1][1]-1]
|
||||
endif
|
||||
return join(lines, "\n")
|
||||
endfunction
|
||||
|
||||
" region_in_region : check region is in the region
|
||||
" this function return 0 or 1
|
||||
function! zencoding#util#regionInRegion(outer, inner)
|
||||
if !zencoding#util#regionIsValid(a:inner) || !zencoding#util#regionIsValid(a:outer)
|
||||
return 0
|
||||
endif
|
||||
return zencoding#util#pointInRegion(a:inner[0], a:outer) && zencoding#util#pointInRegion(a:inner[1], a:outer)
|
||||
endfunction
|
||||
|
||||
" get_visualblock : get region of visual block
|
||||
" this function return region of visual block
|
||||
function! zencoding#util#getVisualBlock()
|
||||
return [[line("'<"), col("'<")], [line("'>"), col("'>")]]
|
||||
endfunction
|
||||
|
||||
"==============================================================================
|
||||
" html utils
|
||||
"==============================================================================
|
||||
function! zencoding#util#getContentFromURL(url)
|
||||
let res = system(printf("%s %s", g:zencoding_curl_command, shellescape(substitute(a:url, '#.*', '', ''))))
|
||||
let s1 = len(split(res, '?'))
|
||||
let utf8 = iconv(res, 'utf-8', &encoding)
|
||||
let s2 = len(split(utf8, '?'))
|
||||
return (s2 == s1 || s2 >= s1 * 2) ? utf8 : res
|
||||
endfunction
|
||||
|
||||
function! zencoding#util#getTextFromHTML(buf)
|
||||
let threshold_len = 100
|
||||
let threshold_per = 0.1
|
||||
let buf = a:buf
|
||||
|
||||
let buf = strpart(buf, stridx(buf, '</head>'))
|
||||
let buf = substitute(buf, '<style[^>]*>.\{-}</style>', '', 'g')
|
||||
let buf = substitute(buf, '<script[^>]*>.\{-}</script>', '', 'g')
|
||||
let res = ''
|
||||
let max = 0
|
||||
let mx = '\(<td[^>]\{-}>\)\|\(<\/td>\)\|\(<div[^>]\{-}>\)\|\(<\/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
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
let res = substitute(res, '^\s*\(.*\)\s*$', '\1', 'g')
|
||||
return res
|
||||
endfunction
|
||||
|
||||
function! zencoding#util#getImageSize(fn)
|
||||
let fn = a:fn
|
||||
|
||||
if zencoding#util#isImageMagickInstalled()
|
||||
return zencoding#util#imageSizeWithImageMagick(fn)
|
||||
endif
|
||||
|
||||
if filereadable(fn)
|
||||
let hex = substitute(system('xxd -p "'.fn.'"'), '\n', '', 'g')
|
||||
else
|
||||
let hex = substitute(system(g:zencoding_curl_command.' "'.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])
|
||||
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])
|
||||
break
|
||||
elseif 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
|
||||
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])
|
||||
endif
|
||||
|
||||
return [width, height]
|
||||
endfunction
|
||||
|
||||
function! zencoding#util#imageSizeWithImageMagick(fn)
|
||||
let img_info = system('identify -format "%wx%h" "'.a:fn.'"')
|
||||
let img_size = split(substitute(img_info, '\n', '', ''), 'x')
|
||||
let width = img_size[0]
|
||||
let height = img_size[1]
|
||||
return [width, height]
|
||||
endfunction
|
||||
|
||||
function! zencoding#util#isImageMagickInstalled()
|
||||
if !get(s:, 'zencoding_use_identify', 1)
|
||||
return 0
|
||||
endif
|
||||
return executable('identify')
|
||||
endfunction
|
Reference in New Issue
Block a user