forked from VimPlug/emmet-vim
Add custom_expand
This commit is contained in:
@@ -321,12 +321,21 @@ function! zencoding#getDollarValueByKey(key)
|
||||
let key = a:key
|
||||
let ftsetting = get(s:zen_settings, zencoding#getFileType())
|
||||
if type(ftsetting) == 4 && has_key(ftsetting, key)
|
||||
let value = get(ftsetting, key)
|
||||
if type(value) == 1 | let ret = value | endif
|
||||
let V = get(ftsetting, key)
|
||||
if type(V) == 1 | return V | endif
|
||||
endif
|
||||
if type(ret) != 1 && has_key(s:zen_settings, key)
|
||||
let value = get(s:zen_settings, key)
|
||||
if type(value) == 1 | return value | endif
|
||||
let V = get(s:zen_settings, key)
|
||||
if type(V) == 1 | return V | endif
|
||||
endif
|
||||
if has_key(s:zen_settings, 'custom_expands') && type(s:zen_settings['custom_expands']) == 4
|
||||
for k in keys(s:zen_settings['custom_expands'])
|
||||
if key =~ k
|
||||
let V = get(s:zen_settings['custom_expands'], k)
|
||||
if type(V) == 1 | return V | endif
|
||||
if type(V) == 2 | return V(key) | endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
return ret
|
||||
endfunction
|
||||
@@ -340,7 +349,7 @@ function! zencoding#reExpandDollarExpr(expand, times)
|
||||
let pair = get(dollar_exprs, n)
|
||||
let pat = get(pair, 'expr')
|
||||
let sub = get(pair, 'value')
|
||||
let expand = substitute(expand, pat, sub, 'g')
|
||||
let expand = substitute(expand, pat, sub, '')
|
||||
endfor
|
||||
return zencoding#reExpandDollarExpr(expand, a:times + 1)
|
||||
endif
|
||||
@@ -518,7 +527,6 @@ function! zencoding#expandAbbr(mode, abbr) range
|
||||
let expand = zencoding#expandDollarExpr(expand)
|
||||
let expand = zencoding#expandCursorExpr(expand, a:mode)
|
||||
if len(expand)
|
||||
let expand = substitute(expand, '\${\%(lorem\|lipsum\)\(\d*\)}', '\=zencoding#util#lorem(submatch(1))', 'g')
|
||||
if has_key(s:zen_settings, 'timezone') && len(s:zen_settings.timezone)
|
||||
let expand = substitute(expand, '${datetime}', strftime("%Y-%m-%dT%H:%M:%S") . s:zen_settings.timezone, 'g')
|
||||
else
|
||||
@@ -764,6 +772,9 @@ unlet! s:zen_settings
|
||||
let s:zen_settings = {
|
||||
\ 'lang': "en",
|
||||
\ 'charset': "UTF-8",
|
||||
\ 'custom_expands' : {
|
||||
\ '^\%(lorem\|lipsum\)\(\d*\)$' : function('zencoding#lorem#en#expand'),
|
||||
\ },
|
||||
\ 'css': {
|
||||
\ 'snippets': {
|
||||
\ '@i': '@import url(|);',
|
||||
|
||||
@@ -118,16 +118,23 @@ function! zencoding#lang#html#parseIntoTree(abbr, type)
|
||||
let current.name = ''
|
||||
endif
|
||||
|
||||
if tag_name =~ '^\(lorem\|lipsum\)\d*$'
|
||||
if parent.name == ''
|
||||
let div = zencoding#lang#html#parseTag('<div/>')
|
||||
let div.value = '{\${' . tag_name . '}}'
|
||||
let current.snippet = zencoding#toString(div, type, 0, [])
|
||||
else
|
||||
let current.snippet = '${' . tag_name . '}'
|
||||
endif
|
||||
let current.name = ''
|
||||
let custom_expands = zencoding#getResource(type, 'custom_expands', {})
|
||||
if empty(custom_expands) && has_key(settings, 'custom_expands')
|
||||
let custom_expands = settings['custom_expands']
|
||||
endif
|
||||
for k in keys(custom_expands)
|
||||
if tag_name =~ k
|
||||
if parent.name == ''
|
||||
let div = zencoding#lang#html#parseTag('<div/>')
|
||||
let div.value = '{\${' . tag_name . '}}'
|
||||
let current.snippet = zencoding#toString(div, type, 0, [])
|
||||
else
|
||||
let current.snippet = '${' . tag_name . '}'
|
||||
endif
|
||||
let current.name = ''
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
" default_attributes
|
||||
let default_attributes = zencoding#getResource(type, 'default_attributes', {})
|
||||
|
||||
65
autoload/zencoding/lorem/en.vim
Normal file
65
autoload/zencoding/lorem/en.vim
Normal file
@@ -0,0 +1,65 @@
|
||||
function! zencoding#lorem#en#expand(command)
|
||||
let wcount = matchstr(a:command, '^\%(lorem\|lipsum\)\(\d*\)}$', '\1', '')
|
||||
let wcount = wcount > 0 ? wcount : 30
|
||||
|
||||
let common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit']
|
||||
let words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
|
||||
\ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
|
||||
\ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
|
||||
\ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
|
||||
\ 'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum',
|
||||
\ 'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus',
|
||||
\ 'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus',
|
||||
\ 'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum',
|
||||
\ 'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem',
|
||||
\ 'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus',
|
||||
\ 'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente',
|
||||
\ 'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet',
|
||||
\ 'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta',
|
||||
\ 'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima',
|
||||
\ 'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim',
|
||||
\ 'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores',
|
||||
\ 'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias',
|
||||
\ 'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea',
|
||||
\ 'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt',
|
||||
\ 'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate',
|
||||
\ 'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius',
|
||||
\ 'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos',
|
||||
\ 'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore',
|
||||
\ 'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo',
|
||||
\ 'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi',
|
||||
\ 'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam',
|
||||
\ 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique',
|
||||
\ 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere',
|
||||
\ 'maxime', 'corrupti']
|
||||
let ret = []
|
||||
let sentence = 0
|
||||
for i in range(wcount)
|
||||
let arr = common
|
||||
if sentence > 0
|
||||
let arr += words
|
||||
endif
|
||||
let r = zencoding#util#rand()
|
||||
let word = arr[r % len(arr)]
|
||||
if sentence == 0
|
||||
let word = substitute(word, '^.', '\U&', '')
|
||||
endif
|
||||
let sentence += 1
|
||||
call add(ret, word)
|
||||
if (sentence > 5 && zencoding#util#rand() < 10000) || i == wcount - 1
|
||||
if i == wcount - 1
|
||||
let endc = "?!..."[zencoding#util#rand() % 5]
|
||||
call add(ret, endc)
|
||||
else
|
||||
let endc = "?!,..."[zencoding#util#rand() % 6]
|
||||
call add(ret, endc . ' ')
|
||||
endif
|
||||
if endc != ','
|
||||
let sentence = 0
|
||||
endif
|
||||
else
|
||||
call add(ret, ' ')
|
||||
endif
|
||||
endfor
|
||||
return join(ret, '')
|
||||
endfunction
|
||||
@@ -146,9 +146,10 @@ endfunction
|
||||
"==============================================================================
|
||||
function! zencoding#util#getContentFromURL(url)
|
||||
let res = system(printf("%s %s", g:zencoding_curl_command, shellescape(substitute(a:url, '#.*', '', ''))))
|
||||
let charset = matchstr(res, '<meta[^>]\+content=["''][^;"'']\+;\s\+charset=\zs[^;"'']\+\ze["'']>')
|
||||
let charset = matchstr(res, '<meta[^>]\+content=["''][^;"'']\+;\s*charset=\zs[^;"'']\+\ze["''][^>]*>')
|
||||
let g:hoge = charset
|
||||
if len(charset) == 0
|
||||
let charset = matchstr(res, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]\+>')
|
||||
let charset = matchstr(res, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]*>')
|
||||
endif
|
||||
if len(charset) == 0
|
||||
let s1 = len(split(res, '?'))
|
||||
@@ -268,75 +269,27 @@ function! zencoding#util#unique(arr)
|
||||
endfunction
|
||||
|
||||
let s:seed = localtime()
|
||||
function! s:srand(seed)
|
||||
function! zencoding#util#srand(seed)
|
||||
let s:seed = a:seed
|
||||
endfunction
|
||||
|
||||
function! s:rand()
|
||||
function! zencoding#util#rand()
|
||||
let s:seed = s:seed * 214013 + 2531011
|
||||
return (s:seed < 0 ? s:seed - 0x80000000 : s:seed) / 0x10000 % 0x8000
|
||||
endfunction
|
||||
|
||||
function! zencoding#util#lorem(count)
|
||||
let common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit']
|
||||
let words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
|
||||
\ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
|
||||
\ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
|
||||
\ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
|
||||
\ 'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum',
|
||||
\ 'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus',
|
||||
\ 'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus',
|
||||
\ 'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum',
|
||||
\ 'placeat', 'aliquid', 'fuga', 'provident', 'praesentium', 'rem',
|
||||
\ 'necessitatibus', 'suscipit', 'adipisci', 'quidem', 'possimus',
|
||||
\ 'voluptas', 'debitis', 'sint', 'accusantium', 'unde', 'sapiente',
|
||||
\ 'voluptate', 'qui', 'aspernatur', 'laudantium', 'soluta', 'amet',
|
||||
\ 'quo', 'aliquam', 'saepe', 'culpa', 'libero', 'ipsa', 'dicta',
|
||||
\ 'reiciendis', 'nesciunt', 'doloribus', 'autem', 'impedit', 'minima',
|
||||
\ 'maiores', 'repudiandae', 'ipsam', 'obcaecati', 'ullam', 'enim',
|
||||
\ 'totam', 'delectus', 'ducimus', 'quis', 'voluptates', 'dolores',
|
||||
\ 'molestiae', 'harum', 'dolorem', 'quia', 'voluptatem', 'molestias',
|
||||
\ 'magni', 'distinctio', 'omnis', 'illum', 'dolorum', 'voluptatum', 'ea',
|
||||
\ 'quas', 'quam', 'corporis', 'quae', 'blanditiis', 'atque', 'deserunt',
|
||||
\ 'laboriosam', 'earum', 'consequuntur', 'hic', 'cupiditate',
|
||||
\ 'quibusdam', 'accusamus', 'ut', 'rerum', 'error', 'minus', 'eius',
|
||||
\ 'ab', 'ad', 'nemo', 'fugit', 'officia', 'at', 'in', 'id', 'quos',
|
||||
\ 'reprehenderit', 'numquam', 'iste', 'fugiat', 'sit', 'inventore',
|
||||
\ 'beatae', 'repellendus', 'magnam', 'recusandae', 'quod', 'explicabo',
|
||||
\ 'doloremque', 'aperiam', 'consequatur', 'asperiores', 'commodi',
|
||||
\ 'optio', 'dolor', 'labore', 'temporibus', 'repellat', 'veniam',
|
||||
\ 'architecto', 'est', 'esse', 'mollitia', 'nulla', 'a', 'similique',
|
||||
\ 'eos', 'alias', 'dolore', 'tenetur', 'deleniti', 'porro', 'facere',
|
||||
\ 'maxime', 'corrupti']
|
||||
let ret = []
|
||||
let sentence = 0
|
||||
let c = a:count > 0 ? a:count : 30
|
||||
for i in range(c)
|
||||
let arr = common
|
||||
if sentence > 0
|
||||
let arr += words
|
||||
function! zencoding#util#cache(name, ...)
|
||||
let content = get(a:000, 0, "")
|
||||
let dir = expand("~/.zencoding/cache")
|
||||
if !isdirectory(dir)
|
||||
call mkdir(dir, "p", 0700)
|
||||
endif
|
||||
let file = dir . "/" . substitute(a:name, '\W', '_', 'g')
|
||||
if len(content) == 0
|
||||
if !filereadable(file)
|
||||
return ""
|
||||
endif
|
||||
let r = s:rand()
|
||||
let word = arr[r % len(arr)]
|
||||
if sentence == 0
|
||||
let word = substitute(word, '^.', '\U&', '')
|
||||
endif
|
||||
let sentence += 1
|
||||
call add(ret, word)
|
||||
if (sentence > 5 && s:rand() < 10000) || i == c - 1
|
||||
if i == c - 1
|
||||
let endc = "?!..."[s:rand() % 5]
|
||||
call add(ret, endc)
|
||||
else
|
||||
let endc = "?!,..."[s:rand() % 6]
|
||||
call add(ret, endc . ' ')
|
||||
endif
|
||||
if endc != ','
|
||||
let sentence = 0
|
||||
endif
|
||||
else
|
||||
call add(ret, ' ')
|
||||
endif
|
||||
endfor
|
||||
return join(ret, '')
|
||||
return join(readfile(file), "\n")
|
||||
endif
|
||||
call writefile(split(content, "\n"), file)
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user