diff --git a/autoload/zencoding.vim b/autoload/zencoding.vim index 916499e..63bf90e 100644 --- a/autoload/zencoding.vim +++ b/autoload/zencoding.vim @@ -1,7 +1,7 @@ "============================================================================= " zencoding.vim " Author: Yasuhiro Matsumoto -" Last Change: 24-Apr-2013. +" Last Change: 03-Jun-2013. let s:save_cpo = &cpo set cpo&vim @@ -443,6 +443,7 @@ function! zencoding#expandAbbr(mode, abbr) range let expand .= '${cursor}' endif endif + let expand = substitute(expand, '\${\%(lorem\|ipsum\)\(\d*\)}', '\=zencoding#util#lorem(submatch(1))', 'g') let expand = substitute(expand, '${lang}', s:zen_settings.lang, 'g') let expand = substitute(expand, '${charset}', s:zen_settings.charset, 'g') if has_key(s:zen_settings, 'timezone') && len(s:zen_settings.timezone) diff --git a/autoload/zencoding/lang/html.vim b/autoload/zencoding/lang/html.vim index 7e8880d..01efc3e 100644 --- a/autoload/zencoding/lang/html.vim +++ b/autoload/zencoding/lang/html.vim @@ -118,6 +118,11 @@ function! zencoding#lang#html#parseIntoTree(abbr, type) let current.name = '' endif + if tag_name =~ '^\(lorem\|ipsum\)\d*$' + let current.snippet = '${' . tag_name . '}' + let current.name = '' + endif + " default_attributes let default_attributes = zencoding#getResource(type, 'default_attributes', {}) if !empty(default_attributes) diff --git a/autoload/zencoding/util.vim b/autoload/zencoding/util.vim index 6608782..7841103 100644 --- a/autoload/zencoding/util.vim +++ b/autoload/zencoding/util.vim @@ -266,3 +266,77 @@ function! zencoding#util#unique(arr) endfor return r endfunction + +let s:seed = localtime() +function! s:srand(seed) + let s:seed = a:seed +endfunction + +function! s: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 + 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() % 6] + call add(ret, endc) + else + let endc = "?!..."[s:rand() % 5] + call add(ret, endc . ' ') + endif + if endc != ',' + let sentence = 0 + endif + else + call add(ret, ' ') + endif + endfor + return join(ret, '') +endfunction