mirror of
https://github.com/mattn/emmet-vim.git
synced 2025-12-07 03:04:27 +08:00
Add custom_expand
This commit is contained in:
@@ -321,12 +321,21 @@ function! zencoding#getDollarValueByKey(key)
|
|||||||
let key = a:key
|
let key = a:key
|
||||||
let ftsetting = get(s:zen_settings, zencoding#getFileType())
|
let ftsetting = get(s:zen_settings, zencoding#getFileType())
|
||||||
if type(ftsetting) == 4 && has_key(ftsetting, key)
|
if type(ftsetting) == 4 && has_key(ftsetting, key)
|
||||||
let value = get(ftsetting, key)
|
let V = get(ftsetting, key)
|
||||||
if type(value) == 1 | let ret = value | endif
|
if type(V) == 1 | return V | endif
|
||||||
endif
|
endif
|
||||||
if type(ret) != 1 && has_key(s:zen_settings, key)
|
if type(ret) != 1 && has_key(s:zen_settings, key)
|
||||||
let value = get(s:zen_settings, key)
|
let V = get(s:zen_settings, key)
|
||||||
if type(value) == 1 | return value | endif
|
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
|
endif
|
||||||
return ret
|
return ret
|
||||||
endfunction
|
endfunction
|
||||||
@@ -340,7 +349,7 @@ function! zencoding#reExpandDollarExpr(expand, times)
|
|||||||
let pair = get(dollar_exprs, n)
|
let pair = get(dollar_exprs, n)
|
||||||
let pat = get(pair, 'expr')
|
let pat = get(pair, 'expr')
|
||||||
let sub = get(pair, 'value')
|
let sub = get(pair, 'value')
|
||||||
let expand = substitute(expand, pat, sub, 'g')
|
let expand = substitute(expand, pat, sub, '')
|
||||||
endfor
|
endfor
|
||||||
return zencoding#reExpandDollarExpr(expand, a:times + 1)
|
return zencoding#reExpandDollarExpr(expand, a:times + 1)
|
||||||
endif
|
endif
|
||||||
@@ -518,7 +527,6 @@ function! zencoding#expandAbbr(mode, abbr) range
|
|||||||
let expand = zencoding#expandDollarExpr(expand)
|
let expand = zencoding#expandDollarExpr(expand)
|
||||||
let expand = zencoding#expandCursorExpr(expand, a:mode)
|
let expand = zencoding#expandCursorExpr(expand, a:mode)
|
||||||
if len(expand)
|
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)
|
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')
|
let expand = substitute(expand, '${datetime}', strftime("%Y-%m-%dT%H:%M:%S") . s:zen_settings.timezone, 'g')
|
||||||
else
|
else
|
||||||
@@ -764,6 +772,9 @@ unlet! s:zen_settings
|
|||||||
let s:zen_settings = {
|
let s:zen_settings = {
|
||||||
\ 'lang': "en",
|
\ 'lang': "en",
|
||||||
\ 'charset': "UTF-8",
|
\ 'charset': "UTF-8",
|
||||||
|
\ 'custom_expands' : {
|
||||||
|
\ '^\%(lorem\|lipsum\)\(\d*\)$' : function('zencoding#lorem#en#expand'),
|
||||||
|
\ },
|
||||||
\ 'css': {
|
\ 'css': {
|
||||||
\ 'snippets': {
|
\ 'snippets': {
|
||||||
\ '@i': '@import url(|);',
|
\ '@i': '@import url(|);',
|
||||||
|
|||||||
@@ -118,16 +118,23 @@ function! zencoding#lang#html#parseIntoTree(abbr, type)
|
|||||||
let current.name = ''
|
let current.name = ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if tag_name =~ '^\(lorem\|lipsum\)\d*$'
|
let custom_expands = zencoding#getResource(type, 'custom_expands', {})
|
||||||
if parent.name == ''
|
if empty(custom_expands) && has_key(settings, 'custom_expands')
|
||||||
let div = zencoding#lang#html#parseTag('<div/>')
|
let custom_expands = settings['custom_expands']
|
||||||
let div.value = '{\${' . tag_name . '}}'
|
|
||||||
let current.snippet = zencoding#toString(div, type, 0, [])
|
|
||||||
else
|
|
||||||
let current.snippet = '${' . tag_name . '}'
|
|
||||||
endif
|
|
||||||
let current.name = ''
|
|
||||||
endif
|
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
|
" default_attributes
|
||||||
let default_attributes = zencoding#getResource(type, '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)
|
function! zencoding#util#getContentFromURL(url)
|
||||||
let res = system(printf("%s %s", g:zencoding_curl_command, shellescape(substitute(a: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
|
if len(charset) == 0
|
||||||
let charset = matchstr(res, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]\+>')
|
let charset = matchstr(res, '<meta\s\+charset=["'']\?\zs[^"'']\+\ze["'']\?[^>]*>')
|
||||||
endif
|
endif
|
||||||
if len(charset) == 0
|
if len(charset) == 0
|
||||||
let s1 = len(split(res, '?'))
|
let s1 = len(split(res, '?'))
|
||||||
@@ -268,75 +269,27 @@ function! zencoding#util#unique(arr)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:seed = localtime()
|
let s:seed = localtime()
|
||||||
function! s:srand(seed)
|
function! zencoding#util#srand(seed)
|
||||||
let s:seed = a:seed
|
let s:seed = a:seed
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:rand()
|
function! zencoding#util#rand()
|
||||||
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! zencoding#util#lorem(count)
|
function! zencoding#util#cache(name, ...)
|
||||||
let common = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipisicing', 'elit']
|
let content = get(a:000, 0, "")
|
||||||
let words = ['exercitationem', 'perferendis', 'perspiciatis', 'laborum', 'eveniet',
|
let dir = expand("~/.zencoding/cache")
|
||||||
\ 'sunt', 'iure', 'nam', 'nobis', 'eum', 'cum', 'officiis', 'excepturi',
|
if !isdirectory(dir)
|
||||||
\ 'odio', 'consectetur', 'quasi', 'aut', 'quisquam', 'vel', 'eligendi',
|
call mkdir(dir, "p", 0700)
|
||||||
\ 'itaque', 'non', 'odit', 'tempore', 'quaerat', 'dignissimos',
|
endif
|
||||||
\ 'facilis', 'neque', 'nihil', 'expedita', 'vitae', 'vero', 'ipsum',
|
let file = dir . "/" . substitute(a:name, '\W', '_', 'g')
|
||||||
\ 'nisi', 'animi', 'cumque', 'pariatur', 'velit', 'modi', 'natus',
|
if len(content) == 0
|
||||||
\ 'iusto', 'eaque', 'sequi', 'illo', 'sed', 'ex', 'et', 'voluptatibus',
|
if !filereadable(file)
|
||||||
\ 'tempora', 'veritatis', 'ratione', 'assumenda', 'incidunt', 'nostrum',
|
return ""
|
||||||
\ '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
|
|
||||||
endif
|
endif
|
||||||
let r = s:rand()
|
return join(readfile(file), "\n")
|
||||||
let word = arr[r % len(arr)]
|
endif
|
||||||
if sentence == 0
|
call writefile(split(content, "\n"), file)
|
||||||
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, '')
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user