1"
2" Filename: cream-loremipsum.vim
3" Updated:  2009-11-09, 09:11pm
4"
5" Cream -- An easy-to-use configuration of the famous Vim text editor
6" (http://cream.sourceforge.net) Copyright (C) 2001-2011 Steve Hall
7"
8" License:
9" This program is free software; you can redistribute it and/or modify
10" it under the terms of the GNU General Public License as published by
11" the Free Software Foundation; either version 3 of the License, or
12" (at your option) any later version.
13" (http://www.gnu.org/licenses/gpl.html)
14"
15" This program is distributed in the hope that it will be useful, but
16" WITHOUT ANY WARRANTY; without even the implied warranty of
17" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18" General Public License for more details.
19"
20" You should have received a copy of the GNU General Public License
21" along with this program; if not, write to the Free Software
22" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23" 02111-1307, USA.
24"
25
26" Lorem Ipsum: Text filler from the 1500's classic.
27"
28
29" Cream_loremipsum() {{{1
30function! Cream_loremipsum()
31" Insert Latin at the cursor as user requests number of paragraphs.
32
33	if !exists("s:cnt")
34		let s:cnt = 1
35	endif
36
37	" request
38	let n = Inputdialog("Please enter the number of paragraphs to enter:", s:cnt)
39	" do nothing on cancel
40	if     n == "{cancel}"
41		return
42	" warn only numbers allowed
43	elseif match(n, '[^0-9]') != -1
44		call confirm(
45			\ "Only numbers are allowed.\n" .
46			\ "\n", "&Ok", 1, "Error")
47	" quit if 0
48	elseif n == 0
49		return
50	else
51		" remember it
52		let s:cnt = n
53	endif
54
55	let str = ""
56	let i = 0
57	while i < n
58		let str = str . Cream_loremipsum_getpara()
59		" add returns if not at end
60		if i-1 != n
61			let str = str . "\n\n"
62		endif
63		let i = i + 1
64	endwhile
65	let @x = str
66	normal "xP
67
68endfunction
69
70" Cream_loremipsum_getpara() {{{1
71function! Cream_loremipsum_getpara()
72" Return paragraph of 2-6 sentences.
73
74	let para = ""
75	let l = Urndm(2, 6)
76	let i = 0
77	while i < l
78		let para = para . Cream_loremipsum_getsent() . " "
79		let i = i + 1
80	endwhile
81	return substitute(para, ' $', '', '')
82
83endfunction
84
85" Cream_loremipsum_getsent() {{{1
86function! Cream_loremipsum_getsent()
87" Return consecutive sentences of lorem ipsum.
88
89	" init
90	if !exists("g:CREAM_LOREMIPSUM")
91		let g:CREAM_LOREMIPSUM = 1
92	" loop on twice the number we have
93	elseif g:CREAM_LOREMIPSUM >= 14
94		let g:CREAM_LOREMIPSUM = 1
95	else
96		let g:CREAM_LOREMIPSUM = g:CREAM_LOREMIPSUM + 1
97	endif
98
99	let rnd = g:CREAM_LOREMIPSUM
100
101	" Source: http://www.lipsum.com/
102
103	" The standard Lorem Ipsum passage, used since the 1500s
104	if     rnd == 1 | return "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
105	elseif rnd == 2 | return "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
106	elseif rnd == 3 | return "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
107	elseif rnd == 4 | return "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
108
109	" Section 1.10.32 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
110	elseif rnd == 5 | return "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo."
111	elseif rnd == 6 | return "Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt."
112	elseif rnd == 7 | return "Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem."
113	elseif rnd == 8 | return "Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur?"
114	elseif rnd == 9 | return "Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"
115
116	" Section 1.10.33 of "de Finibus Bonorum et Malorum", written by Cicero in 45 BC
117	elseif rnd == 10 | return "At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga."
118	elseif rnd == 11 | return "Et harum quidem rerum facilis est et expedita distinctio."
119	elseif rnd == 12 | return "Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus."
120	elseif rnd == 13 | return "Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae."
121	elseif rnd == 14 | return "Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat."
122
123	endif
124
125
126endfunction
127" 1}}}
128
129" Cream Gibberish
130"
131" Description: Text filler from random characters. One of the dangers
132" of generating random text is that it might produce actual words.
133" This, in combination with a lengthy set of rules to get the text to
134" look valid mostly rules out using these for the purpose of filler
135" text.
136
137" Cream_gibberish() {{{1
138function! Cream_gibberish(paragraphs)
139" {paragraphs} is the number of paragraphs to return.
140
141	" initialize
142	let s:lastchar = ""
143	let s:lastword = ""
144	let s:lastsent = ""
145	let s:lastpara = ""
146
147	let str = ""
148	let i = 0
149	while i < a:paragraphs
150		let str = str . s:Cream_getpara() . "\n\n"
151		let i = i + 1
152	endwhile
153
154	return str
155
156endfunction
157
158" s:Cream_getpara() {{{1
159function! s:Cream_getpara()
160" Return paragraph of length 3-8 sentances.
161
162	let para = ""
163	let l = Urndm(3, 8)
164	let i = 0
165	while i < l
166		let para = s:Cream_getsent() . " " . para
167		let i = i + 1
168	endwhile
169	return para
170
171endfunction
172
173" s:Cream_getsent() {{{1
174function! s:Cream_getsent()
175" Return sentence of length 5-24 words.
176
177	let sent = ""
178	let l = Urndm(5, 24)
179	let i = 0
180	while i < l
181		let sent = sent . " " . s:Cream_getword()
182		" capitalize first word (and strip leading space ;)
183		if i == 0
184		   let sent = substitute(sent, '^ \(.\)', '\u\1', "")
185		endif
186		let i = i + 1
187	endwhile
188	return sent . "."
189
190endfunction
191
192" s:Cream_getword() {{{1
193function! s:Cream_getword()
194" Return word.
195" o Length 2-12 characters along a bell curve with an
196"   average of 5.
197" o No characters repeating.
198" o
199"
200
201	let word = ""
202	let len = Urndm(1, 3) + Urndm(1, 5) + Urndm(0, 2)
203	let i = 0
204	while i < len
205		" rule check
206		let valid = 0
207		while valid == 0
208			let prev = matchstr(word, '.$')
209			let char = s:Cream_getchar()
210			" don't let chars repeat
211			if     prev == char
212			" rarely (1:3) let vowels repeat
213			elseif s:Cream_isvowel(prev) == 1 && s:Cream_isvowel(char) == 1 && Urndm(1, 3) > 1
214			" rarely (1:3) let consonents repeat
215			elseif s:Cream_isvowel(prev) == 0 && s:Cream_isvowel(char) == 0 && Urndm(1, 3) > 1
216			" rarely (1:6) let vowels begin words
217			elseif i == 0 && s:Cream_isvowel(char) == 1 && Urndm(1, 6) > 1
218			" rarely (1:10) allow weird adjacencies
219			elseif s:Cream_isweird(prev, char) == 1 && Urndm(1, 10) > 1
220
221			" rarely (1:5) end word with non-characteristic letter
222			elseif ((i + 1) == len) && s:Cream_isbadendchar(char) == 1 && Urndm(1, 5) > 1
223				"" strip previous letter and de-increment
224				"let word = substitute(word, '\(.*\).$', '\1', '')
225				""let i = i - 1
226
227				" try again
228				let char = s:Cream_getchar()
229				let valid = 1
230			else
231				let valid = 1
232			endif
233		endwhile
234		let word = word . char
235		let i = i + 1
236	endwhile
237	return word
238
239endfunction
240
241" s:Cream_isvowel() {{{1
242function! s:Cream_isvowel(char)
243	if     a:char =~ '[aeiou]'
244		return 1
245	elseif a:char =~ '[^aeiou]'
246		return 0
247	endif
248	return -1
249endfunction
250
251" s:Cream_isbadendchar() {{{1
252function! s:Cream_isbadendchar(char)
253	if a:char =~ '[aceijoquvz]'
254		return 1
255	endif
256endfunction
257
258" s:Cream_isweird() {{{1
259function! s:Cream_isweird(prev, char)
260" avoids unrealistic adjacencies
261
262	if     1 == 2 | return 1
263	elseif a:prev == "n" && a:char == "l" | return 1
264	elseif a:prev == "b"
265		if  a:char == "c"
266		\||	a:char == "d"
267		\||	a:char == "f"
268		\||	a:char == "g"
269		\||	a:char == "h"
270		\||	a:char == "j"
271		\||	a:char == "k"
272		\||	a:char == "l"
273		\||	a:char == "m"
274		\||	a:char == "n"
275		\||	a:char == "p"
276		\||	a:char == "q"
277		\||	a:char == "s"
278		\||	a:char == "t"
279		\||	a:char == "v"
280		\||	a:char == "w"
281		\||	a:char == "x"
282		\||	a:char == "z"
283			return 1
284		endif
285
286	elseif a:prev == "d" && a:char == "b" | return 1
287	elseif a:prev == "g" && a:char == "p" | return 1
288
289	elseif a:prev == "h"
290		if  a:char == "b"
291		\||	a:char == "c"
292		\||	a:char == "d"
293		\||	a:char == "f"
294		\||	a:char == "g"
295		\||	a:char == "h"
296		\||	a:char == "j"
297		\||	a:char == "k"
298		\||	a:char == "l"
299		\||	a:char == "m"
300		\||	a:char == "n"
301		\||	a:char == "p"
302		\||	a:char == "q"
303		\||	a:char == "r"
304		\||	a:char == "s"
305		\||	a:char == "t"
306		\||	a:char == "v"
307		\||	a:char == "w"
308		\||	a:char == "x"
309		\||	a:char == "z"
310			return 1
311		endif
312
313	elseif a:prev == "k"
314		if  a:char == "b"
315		\||	a:char == "c"
316		\||	a:char == "d"
317		\||	a:char == "f"
318		\||	a:char == "g"
319		\||	a:char == "h"
320		\||	a:char == "j"
321		\||	a:char == "k"
322		\||	a:char == "m"
323		\||	a:char == "p"
324		\||	a:char == "q"
325		\||	a:char == "s"
326		\||	a:char == "t"
327		\||	a:char == "v"
328		\||	a:char == "w"
329		\||	a:char == "x"
330		\||	a:char == "z"
331			return 1
332		endif
333
334	elseif a:prev == "k" && a:char == "t" | return 1
335	elseif a:prev == "l" && a:char == "g" | return 1
336	elseif a:prev == "n" && a:char == "r" | return 1
337	elseif a:prev == "r" && a:char == "g" | return 1
338	elseif a:prev == "t"
339		if  a:char == "b"
340		\||	a:char == "c"
341		\||	a:char == "d"
342		\||	a:char == "f"
343		\||	a:char == "g"
344		\||	a:char == "j"
345		\||	a:char == "k"
346		\||	a:char == "m"
347		\||	a:char == "n"
348		\||	a:char == "p"
349		\||	a:char == "q"
350		\||	a:char == "s"
351		\||	a:char == "v"
352		\||	a:char == "w"
353		\||	a:char == "x"
354		\||	a:char == "z"
355			return 1
356		endif
357	elseif a:prev == "v" && a:char == "m" | return 1
358	elseif a:prev == "y" && a:char == "g" | return 1
359	endif
360endfunction
361
362function! s:Cream_getchar()
363" Return character based on frequency in English.
364
365	let rndm = Urndm(0, 10000)
366	if rndm > 8883 | return "e" | endif
367	if rndm > 8034 | return "a" | endif
368	if rndm > 7276 | return "r" | endif
369	if rndm > 6521 | return "i" | endif
370	if rndm > 5805 | return "o" | endif
371	if rndm > 5110 | return "t" | endif
372	if rndm > 4444 | return "n" | endif
373	if rndm > 3871 | return "s" | endif
374	if rndm > 3322 | return "l" | endif
375	if rndm > 2868 | return "c" | endif
376	if rndm > 2505 | return "u" | endif
377	if rndm > 2166 | return "d" | endif
378	if rndm > 1850 | return "p" | endif
379	if rndm > 1548 | return "m" | endif
380	if rndm > 1248 | return "h" | endif
381	if rndm > 1001 | return "g" | endif
382	if rndm >  794 | return "b" | endif
383	if rndm >  613 | return "f" | endif
384	if rndm >  435 | return "y" | endif
385	if rndm >  306 | return "w" | endif
386	if rndm >  196 | return "k" | endif
387	if rndm >   95 | return "v" | endif
388	if rndm >   66 | return "x" | endif
389	if rndm >   39 | return "z" | endif
390	if rndm >   19 | return "j" | endif
391	return "qu"
392
393endfunction
394
395" 1}}}
396" vim:foldmethod=marker
397