mv zencoding/xxx.vim to zencoding/lang/xxx.vim

This commit is contained in:
mattn
2012-05-30 19:02:10 +09:00
parent b18d8ce9ab
commit 98f716c4d1
5 changed files with 43 additions and 37 deletions

View File

@@ -1,7 +1,7 @@
"============================================================================= "=============================================================================
" zencoding.vim " zencoding.vim
" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com> " Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
" Last Change: 29-May-2012. " Last Change: 30-May-2012.
let s:save_cpo = &cpo let s:save_cpo = &cpo
set cpo&vim set cpo&vim
@@ -51,7 +51,7 @@ function! zencoding#parseIntoTree(abbr, type)
let abbr = a:abbr let abbr = a:abbr
let type = a:type let type = a:type
let rtype = len(globpath(&rtp, 'autoload/zencoding/'.type.'.vim')) ? type : 'html' let rtype = len(globpath(&rtp, 'autoload/zencoding/'.type.'.vim')) ? type : 'html'
return zencoding#{rtype}#parseIntoTree(abbr, type) return zencoding#lang#{rtype}#parseIntoTree(abbr, type)
endfunction endfunction
function! s:parseTag(tag) function! s:parseTag(tag)
@@ -141,7 +141,7 @@ function! zencoding#toString(...)
while itemno < current.multiplier while itemno < current.multiplier
if len(current.name) if len(current.name)
let rtype = len(globpath(&rtp, 'autoload/zencoding/'.type.'.vim')) ? type : 'html' let rtype = len(globpath(&rtp, 'autoload/zencoding/'.type.'.vim')) ? type : 'html'
let inner = zencoding#{rtype}#toString(s:zen_settings, current, type, inline, filters, itemno, indent) let inner = zencoding#lang#{rtype}#toString(s:zen_settings, current, type, inline, filters, itemno, indent)
if current.multiplier > 1 if current.multiplier > 1
let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g') let inner = substitute(inner, '\$#', '$line'.(itemno+1).'$', 'g')
endif endif
@@ -344,7 +344,7 @@ function! zencoding#expandAbbr(mode) range
let part = substitute(part, '^.*<.\{-}>', '', '') let part = substitute(part, '^.*<.\{-}>', '', '')
endwhile endwhile
let rtype = len(globpath(&rtp, 'autoload/zencoding/'.type.'.vim')) ? type : 'html' let rtype = len(globpath(&rtp, 'autoload/zencoding/'.type.'.vim')) ? type : 'html'
let part = zencoding#{rtype}#findTokens(part) let part = zencoding#lang#{rtype}#findTokens(part)
elseif zencoding#isExtends(type, "css") elseif zencoding#isExtends(type, "css")
let part = substitute(part, '^.*[;{]\s*', '', '') let part = substitute(part, '^.*[;{]\s*', '', '')
endif endif
@@ -438,28 +438,15 @@ function! zencoding#moveNextPrev(flag)
endif endif
endfunction endfunction
function! zencoding#imageSize() function! zencoding#getImageSize(fn)
let img_region = s:search_region('<img\s', '>') let fn = a:fn
if !s:region_is_valid(img_region) || !s:cursor_in_region(img_region)
return
endif
let content = s:get_content(img_region)
if content !~ '^<img[^><]\+>$'
return
endif
let current = s:parseTag(content)
let fn = current.attr.src
if fn !~ '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn)
endif
let [type, width, height] = ['', -1, -1]
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
let hex = substitute(system(g:zencoding_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g') let hex = substitute(system(g:zencoding_curl_command.' "'.fn.'" | xxd -p'), '\n', '', 'g')
endif endif
let [type, width, height] = ['', -1, -1]
if hex =~ '^89504e470d0a1a0a' if hex =~ '^89504e470d0a1a0a'
let type = 'png' let type = 'png'
let width = eval('0x'.hex[32:39]) let width = eval('0x'.hex[32:39])
@@ -477,6 +464,25 @@ function! zencoding#imageSize()
let height = eval('0x'.hex[18:19].hex[16:17]) let height = eval('0x'.hex[18:19].hex[16:17])
endif endif
return [width, height]
endfunction
function! zencoding#imageSize()
let img_region = s:search_region('<img\s', '>')
if !s:region_is_valid(img_region) || !s:cursor_in_region(img_region)
return
endif
let content = s:get_content(img_region)
if content !~ '^<img[^><]\+>$'
return
endif
let current = s:parseTag(content)
let fn = current.attr.src
if fn !~ '^\(/\|http\)'
let fn = simplify(expand('%:h') . '/' . fn)
endif
let [width, height] = zencoding#getImageSize(fn)
if width == -1 && height == -1 if width == -1 && height == -1
return return
endif endif

View File

@@ -1,8 +1,8 @@
function! zencoding#css#findTokens(str) function! zencoding#lang#css#findTokens(str)
return substitute(a:str, '^.*[;{]\s*', '', '') return substitute(a:str, '^.*[;{]\s*', '', '')
endfunction endfunction
function! zencoding#css#parseIntoTree(abbr, type) function! zencoding#lang#css#parseIntoTree(abbr, type)
let abbr = a:abbr let abbr = a:abbr
let type = a:type let type = a:type
@@ -49,6 +49,6 @@ function! zencoding#css#parseIntoTree(abbr, type)
return root return root
endfunction endfunction
function! zencoding#css#toString(settings, current, type, inline, filters, itemno, indent) function! zencoding#lang#css#toString(settings, current, type, inline, filters, itemno, indent)
return '' return ''
endfunction endfunction

View File

@@ -1,12 +1,12 @@
function! zencoding#haml#findTokens(str) function! zencoding#lang#haml#findTokens(str)
return zencoding#html#findTokens(a:str) return zencoding#html#findTokens(a:str)
endfunction endfunction
function! zencoding#haml#parseIntoTree(abbr, type) function! zencoding#lang#haml#parseIntoTree(abbr, type)
return zencoding#html#parseIntoTree(a:abbr, a:type) return zencoding#lang#html#parseIntoTree(a:abbr, a:type)
endfunction endfunction
function! zencoding#haml#toString(settings, current, type, inline, filters, itemno, indent) function! zencoding#lang#haml#toString(settings, current, type, inline, filters, itemno, indent)
let settings = a:settings let settings = a:settings
let current = a:current let current = a:current
let type = a:type let type = a:type

View File

@@ -5,7 +5,7 @@ let s:mx = '\([+>]\|<\+\)\{-}\s*\((*\)\{-}\s*\([@#.]\{-}[a-zA-Z\!][a-zA-Z0-9:_\!
\ .'\%(\.{[{}a-zA-Z0-9_\-\$]\+\|' \ .'\%(\.{[{}a-zA-Z0-9_\-\$]\+\|'
\ .'\.[a-zA-Z0-9_\-\$]\+\)\)*\)\%(\({[^}]\+}\+\)\)\{0,1}\%(\*\([0-9]\+\)\)\{0,1}\(\%()\%(\*[0-9]\+\)\{0,1}\)*\)' \ .'\.[a-zA-Z0-9_\-\$]\+\)\)*\)\%(\({[^}]\+}\+\)\)\{0,1}\%(\*\([0-9]\+\)\)\{0,1}\(\%()\%(\*[0-9]\+\)\{0,1}\)*\)'
function! zencoding#html#findTokens(str) function! zencoding#lang#html#findTokens(str)
let str = a:str let str = a:str
let [pos, last_pos] = [0, 0] let [pos, last_pos] = [0, 0]
while len(str) > 0 while len(str) > 0
@@ -22,7 +22,7 @@ function! zencoding#html#findTokens(str)
return a:str[last_pos :-1] return a:str[last_pos :-1]
endfunction endfunction
function! zencoding#html#parseIntoTree(abbr, type) function! zencoding#lang#html#parseIntoTree(abbr, type)
let abbr = a:abbr let abbr = a:abbr
let type = a:type let type = a:type
@@ -271,7 +271,7 @@ function! zencoding#html#parseIntoTree(abbr, type)
return root return root
endfunction endfunction
function! zencoding#html#toString(settings, current, type, inline, filters, itemno, indent) function! zencoding#lang#html#toString(settings, current, type, inline, filters, itemno, indent)
let settings = a:settings let settings = a:settings
let current = a:current let current = a:current
let type = a:type let type = a:type
@@ -282,10 +282,10 @@ function! zencoding#html#toString(settings, current, type, inline, filters, item
let str = "" let str = ""
if zencoding#useFilter(filters, 'haml') if zencoding#useFilter(filters, 'haml')
return zencoding#haml#toString(settings, current, type, inline, filters, itemno, indent) return zencoding#lang#haml#toString(settings, current, type, inline, filters, itemno, indent)
endif endif
if zencoding#useFilter(filters, 'slim') if zencoding#useFilter(filters, 'slim')
return zencoding#slim#toString(settings, current, type, inline, filters, itemno, indent) return zencoding#lang#slim#toString(settings, current, type, inline, filters, itemno, indent)
endif endif
let comment_indent = '' let comment_indent = ''

View File

@@ -1,12 +1,12 @@
function! zencoding#slim#findTokens(str) function! zencoding#lang#slim#findTokens(str)
return zencoding#html#findTokens(a:str) return zencoding#lang#html#findTokens(a:str)
endfunction endfunction
function! zencoding#slim#parseIntoTree(abbr, type) function! zencoding#lang#slim#parseIntoTree(abbr, type)
return zencoding#html#parseIntoTree(a:abbr, a:type) return zencoding#lang#html#parseIntoTree(a:abbr, a:type)
endfunction endfunction
function! zencoding#slim#toString(settings, current, type, inline, filters, itemno, indent) function! zencoding#lang#slim#toString(settings, current, type, inline, filters, itemno, indent)
let settings = a:settings let settings = a:settings
let current = a:current let current = a:current
let type = a:type let type = a:type