1"
2" Filename: cream-playpen.vim
3"
4" Description: Experiments, things in flux or unresolved.
5"
6" Cream -- An easy-to-use configuration of the famous Vim text editor
7" [ http://cream.sourceforge.net ] Copyright (C) 2001-2011 Steve Hall
8"
9" License:
10" This program is free software; you can redistribute it and/or modify
11" it under the terms of the GNU General Public License as published by
12" the Free Software Foundation; either version 3 of the License, or
13" (at your option) any later version.
14" [ http://www.gnu.org/licenses/gpl.html ]
15"
16" This program is distributed in the hope that it will be useful, but
17" WITHOUT ANY WARRANTY; without even the implied warranty of
18" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19" General Public License for more details.
20"
21" You should have received a copy of the GNU General Public License
22" along with this program; if not, write to the Free Software
23" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24" 02111-1307, USA.
25"
26
27if !exists("g:cream_dev")
28	finish
29endif
30
31" ShortenPath() {{{1
32function! ShortenPath(mode)
33    if a:mode != "v"
34        return
35    endif
36    " reselect
37    normal gv
38    " yank
39    normal "xy
40    " convert to 8.3
41    let @x = fnamemodify(@x, ":p:8")
42    " paste back over
43    normal gv
44    normal "xp
45endfunction
46"vmap <silent> <F12> :<C-u>call ShortenPath("v")<CR>
47
48
49" C:\Program Files\cowsaregreat.butnottoeat
50
51
52" remote read/write
53" FTP spell check retrieval {{{1
54function! Cream_get_ftp_listing(file)
55" Return a string of FTP files delineated by newlines.
56"
57" TODO:
58" o Depending on platform, Netrw will deliver listings in different
59"   formats. Need to investigate and handle.
60"
61
62	" hide Netrw menu
63	let g:netrw_menu = 0
64
65	" open list in new buffer
66	call Cream_file_new()
67	execute "edit " . a:file
68
69	" process into list
70	set modifiable
71	" remove comments
72	silent! %substitute/^".*$//geI
73	" remove dot files
74	silent! %substitute/^\..*$//geI
75	" remove last "yanked" line
76	silent! %substitute/^\d\+ lines yanked$//geI
77	" remove empty lines
78	silent! %substitute/\n\s*\n*$//ge
79	silent! %substitute/^\n\+//ge
80	" yank processed buffer
81	silent! normal gg
82	silent! normal V
83	silent! normal G
84	silent! normal "xy
85	" close buffer
86	bwipeout!
87	return @x
88
89endfunction
90function! Cream_spell_dictlangs()
91
92	let @x = Cream_get_ftp_listing('ftp://ftp.vim.org/pub/vim/runtime/spell/')
93
94	" put into new file
95	call Cream_file_new()
96	silent! normal "xP
97
98	" convert to list of languages
99	" remove READMEs
100	silent! %substitute/^README.*$//geI
101	" remove suggestion files
102	silent! %substitute/^.\+\.sug$//geI
103
104	"" remove .spl extensions
105	"%substitute/\.spl$//geI
106	" remove everything but language
107	silent! %substitute/^\(..\).\+$/\1/geI
108
109	" remove empty lines
110	silent! %substitute/\n\s*\n*$//ge
111	silent! %substitute/^\n\+//ge
112
113	" unique
114	call Uniq(1, line('$'))
115
116	" remove empty lines
117	silent! %substitute/\n\s*\n*$//ge
118	silent! %substitute/^\n\+//ge
119
120endfunction
121"imap <silent> <F12> <C-b>:call Cream_spell_dictlangs()<CR>
122
123" Cream remote read/write {{{1
124" NOTES {{{2
125" We have never had success getting Netrw to work, thus this attempt.
126" Netrw also attempts too much, it confuses basic up/down
127" functionality with mappings, buffers, browsing, etc.
128"
129" Goals:
130"
131" o Parse standard URI:
132"
133"     ftp://anonymous:vim7user@ftp.vim.org/pub/vim/README
134"
135"   for:
136"
137"   * protocol (ftp, http)
138"   * username
139"   * password
140"   * hostname
141"   * path
142"   * filename
143"
144"   Need a "hard" and "soft" version, the first which assumes a
145"   properly formed URI, and the second to remove offending
146"   accommodations like surrounding quotes, brackets, line endings and
147"   embedded whitespace.
148"
149" o Be able to store URI components in
150"   * global vars (encoded username and passwords only)
151"   * session vars
152"   * prompt user for temporary use if none found
153"
154" o API
155"   * Read remote file
156"   * Get listing of remote path
157"
158"
159" References:
160"
161" o http://en.wikipedia.org/wiki/Uniform_Resource_Identifier
162" o http://www.gbiv.com/protocols/uri/rfc/rfc3986.html
163" o http://www.zvon.org/tmRFC/RFC2396/Output/chapter12.html
164
165" Cream_remote_parse_URI() {{{2
166function! Cream_remote_parse_URI(uri)
167" Return a dictionary of URI components:
168"
169"   ftp://anonymous:vim7user@ftp.vim.org:port/pub/vim/README#02
170"   ¯¯¯   ¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ ¯¯
171"   1     2         3        4           5   6        7      8
172"
173"   1. protocol:    dict["prot"] (required)
174"   2. username:    dict["user"]
175"   3. password:    dict["pass"]
176"   4. hostname:    dict["host"] (required)
177"   5. port:        dict["port"]
178"   6. path:        dict["path"]
179"   7. filename:    dict["file"]
180"   8. anchor:      dict["anch"]
181"
182" Notes:
183"
184" o valid field chars: [[:alnum:]-\._~]
185"
186" Tests:
187"
188" call Cream_remote_parse_URI("ftp://ftp.vim.org")
189" call Cream_remote_parse_URI("ftp://ftp.vim.org/pub/vim/README")
190" call Cream_remote_parse_URI("ftp://anonymous:vim7user@ftp.vim.org:port/pub/vim/README")
191" call Cream_remote_parse_URI("ftp://127.0.0.1")
192"
193
194	let uri = a:uri
195
196	let prot = matchstr(uri, '^[^:/?#]\+\ze:')
197	" temp var to hold user, pass, host, port
198	let uphp = matchstr(uri, '^'.prot.'://'.'\zs[^/?#]\+')
199	let user = matchstr(uphp, '^.*\ze:.*@')
200	let pass = matchstr(uphp, '^.*:\zs.*\ze@')
201	let port = matchstr(uphp, '^'.user.':\='.pass.'@\=.*:\zs.*$')
202	let host = matchstr(uphp, '^'.user.':\='.pass.'@\=\zs[^:]\+\ze:\='.port.'$')
203
204	" find path begin (watch for paths matching host!)
205	let path = matchstr(uri, host.':\='.port.'\zs/.*$')
206	let anch = matchstr(path, '#\zs[^:/?#]*$')
207	let file = matchstr(path, '/\zs[^:/?#]*\ze#\='.anch.'$')
208	" now trim off file and anchor
209	let path = matchstr(path, '.*\ze'.file.'#\='.anch.'$')
210
211	" validation
212	if   host == ""
213		call confirm(
214			\ "Improperly formed URI: host.\n" .
215			\ "\n", "&Ok", 1, "Info")
216		return
217	endif
218	if   prot == ""
219		call confirm(
220			\ "Improperly formed URI: protocol.\n" .
221			\ "\n", "&Ok", 1, "Info")
222		return
223	endif
224	if   file == "" && anch != ""
225		call confirm(
226			\ "Improperly formed URI: anchor with no file.\n" .
227			\ "\n", "&Ok", 1, "Info")
228		return
229	endif
230	if   user == "" && pass != ""
231		call confirm(
232			\ "Improperly formed URI: password with no username.\n" .
233			\ "\n", "&Ok", 1, "Info")
234		return
235	endif
236
237	" put into list
238	let dict = {
239		\ "prot": prot,
240		\ "user": user,
241		\ "pass": pass,
242		\ "host": host,
243		\ "port": port,
244		\ "path": path,
245		\ "file": file,
246		\ "anch": anch
247		\ }
248
249	""*** DEBUG:
250	"let n = confirm(
251	"    \ "DEBUG:" . Cream_str_pad(" ", 150) .
252	"    \ "\n" .
253	"    \ "  prot  = \"" . dict["prot"] . "\"\n" .
254	"    \ "  user  = \"" . dict["user"] . "\"\n" .
255	"    \ "  pass  = \"" . dict["pass"] . "\"\n" .
256	"    \ "  host  = \"" . dict["host"] . "\"\n" .
257	"    \ "  port  = \"" . dict["port"] . "\"\n" .
258	"    \ "  path  = \"" . dict["path"] . "\"\n" .
259	"    \ "  file  = \"" . dict["file"] . "\"\n" .
260	"    \ "  anch  = \"" . dict["anch"] . "\"\n" .
261	"    \ "\n", "&Ok\n&Cancel", 1, "Info")
262	"if n != 1
263	"    return
264	"endif
265	""***
266
267	return dict
268
269endfunction
270
271" Cream_remote_parse_URI_test() {{{2
272function! Cream_remote_parse_URI_test()
273
274	let dict = Cream_remote_parse_URI("ftp://anonymous:vim7user@ftp.vim.org:port/pub/vim/README#cow")
275
276	""*** DEBUG:
277	"let n = confirm(
278	"    \ "DEBUG:" . Cream_str_pad(" ", 150) .
279	"    \ "\n" .
280	"    \ "  prot  = \"" . dict.prot . "\"\n" .
281	"    \ "  user  = \"" . dict.user . "\"\n" .
282	"    \ "  pass  = \"" . dict.pass . "\"\n" .
283	"    \ "  host  = \"" . dict.host . "\"\n" .
284	"    \ "  port  = \"" . dict.port . "\"\n" .
285	"    \ "  path  = \"" . dict.path . "\"\n" .
286	"    \ "  file  = \"" . dict.file . "\"\n" .
287	"    \ "  anch  = \"" . dict.anch . "\"\n" .
288	"    \ "\n", "&Ok\n&Cancel", 1, "Info")
289	"if n != 1
290	"    return
291	"endif
292	""***
293
294endfunction
295
296" Cream_remote_ftp_down() {{{2
297function! Cream_remote_ftp_down()
298" Download an explicitly named file.
299
300	let user = "anonymous"
301	let verbose = "-d stdout"
302	let host = "ftp.vim.com"
303	let getfile = "/pub/vim/runtime/spell"
304	let dir = g:cream_user
305	let progressmeter = "-v"
306	let noprgressmeter = "-V"
307
308	" set directory to download into
309	execute "cd " . dir
310	" do it (prompts for password)
311	execute "!ncftpget " . progressmeter . " -u " . user . " " . verbose . " " . host . " . " . "'" . getfile . "'"
312
313endfunction
314
315" 2}}}
316" Color_NavajoNight() {{{2
317function! Color_NavajoNight()
318" Change the current color scheme via accessing a remote script.
319	enew
320	execute 'Nread http://cream.cvs.sourceforge.net/*checkout*/cream/cream/cream-colors-zenburn.vim'
321	execute "saveas " . tempname()
322	source %
323endfunction
324" map <silent> <F12>      :call Color_NavajoNight()<CR>
325"imap <silent> <F12> <C-b>:call Color_NavajoNight()<CR>
326"vmap <silent> <F12> :<C-u>call Color_NavajoNight()<CR>
327" 1}}}
328" In progress...
329" password encrypting {{{1
330function! Cream_encrypt_input()
331
332	let pw = inputsecret("Enter string to encrypt: ")
333	if pw != ""
334		let pw = String2Hex(pw)
335		call Inputdialog("", pw)
336	endif
337
338endfunction
339"imap <silent> <F12><F12> <C-b>:call Cream_encrypt_input()<CR>
340
341
342" 1}}}
343" TODO: move to add-ons
344" Draw directory structure or genealogy tree {{{1
345function! Cream_DrawTree()
346
347	let @x = "\n"
348	let @x = @x . "NAME\n"
349	let @x = @x . " +-NAME\n"
350	let @x = @x . " |  +-NAME\n"
351	let @x = @x . " |  |  +-NAME\n"
352	let @x = @x . " |  |  |  +-NAME\n"
353	let @x = @x . " |  |  |  |  +-NAME\n"
354	let @x = @x . " |  |  |  |\n"
355	let @x = @x . " |  |  |  +-NAME\n"
356	let @x = @x . " |  |  |\n"
357	let @x = @x . " |  |  +-NAME\n"
358	let @x = @x . " |  |\n"
359	let @x = @x . " |  +-NAME\n"
360	let @x = @x . " |\n"
361	let @x = @x . " +-NAME\n"
362	let @x = @x . "\n"
363
364	put x
365
366endfunction
367
368" 1}}}
369" non-Cream reliant functions
370" Tabpage naming (non-Cream environment) {{{1
371"function! TabpageName(mode)
372"    if     a:mode == 1
373"        return fnamemodify(expand("%"), ":p:h")
374"    elseif a:mode == 2
375"        let name = fnamemodify(expand("%"), ":p:t")
376"        if name == ""
377"            return "(Untitled)"
378"        endif
379"        return name
380"    endif
381"endfunction
382"function! TabpageState()
383"    if &modified != 0
384"        return '*'
385"    else
386"        return ''
387"    endif
388"endfunction
389"set guitablabel=%{TabpageName(2)}%{TabpageState()}
390
391" Cream_copy_char_above() {{{1
392function! Cream_copy_char_above()
393	" position correction
394	if getline('.') == ""
395		let col = 0
396	else
397		let col = col('.')
398	endif
399
400	let str = getline(line('.') - 1)
401	let chr = matchstr(str, '.', col)
402	execute "normal a" . chr
403endfunction
404"imap <silent> <F12> <C-b>:call Cream_copy_char_above()<CR>
405
406" :Buffers {{{1
407function! Buffers()
408" same output as :buffers except omits help, directories, and
409" new unmodified buffers
410
411	redir @x
412	silent! buffers
413	redir END
414	let @x = @x . "\n"
415
416	let buf = 1
417	let str = ""
418	while buf <= bufnr('$')
419		if  bufexists(buf)
420		\&& getbufvar(buf, "&buftype") != "help"
421		\&& !isdirectory(bufname(buf))
422		\&&	s:IsNewUnMod(buf) != 1
423			let pos1    = match(@x, '\n\s\+' . buf . '[ u]')
424			"let pos1str = matchstr(@x, '\n\s\+' . buf . '[ u]')
425			let pos2    = match(@x, '\n', pos1 + 1)
426			"let pos2str = matchstr(@x, '\n', pos1 + 1)
427			let str = str . strpart(@x, pos1, pos2 - pos1)
428		endif
429		let buf = buf + 1
430	endwhile
431
432	echo ":Buffers" . str
433
434endfunction
435
436function! s:IsNewUnMod(buf)
437	if  bufname(a:buf) == ""
438	\&& getbufvar(a:buf, "&modified") == 0
439	\&& bufexists(a:buf) == 1
440		return 1
441	endif
442endfunction
443
444command! Buffers call Buffers()
445
446" Associate Mime Type With Windows Registry {{{1
447"
448" From: Ben Peterson, Dan Sharp on vim-dev@vim.org list
449" Date: 2003-01-14, 11:00am
450" RE: Associating extensions to Vim (was RE: Win32 improvement: ...)
451"
452" Description:
453"
454" associate/unassociated vim with the extension of the current file
455" 	:associate %:e
456" 	:noassociate %:e
457
458function! s:Associate(ext, remove)
459" Arguments:
460"   ext      extension to associate
461"   remove   1 to associate, 0 to remove
462"
463	if a:remove
464		silent exec '!assoc ' . a:ext . '='
465	else
466		silent exec '!assoc ' . a:ext . '=OpenInVim'
467		execute "silent !ftype OpenInVim=" . $VIMRUNTIME . "\\gvim.exe" . "\"$*\""
468	endif
469endfunction
470
471command! Associate call s:Associate('.' . expand("%:e"), 0)
472command! DeAssociate call s:Associate('.' . expand("%:e"), 1)
473
474command! -nargs=1 AssociateArg call s:Associate('.' . <args>, 0)
475command! -nargs=1 DeAssociateArg call s:Associate('.' . <args>, 1)
476
477" Variably Toggleable Invisibles {{{1
478
479"function! MyInvisibles(which)
480"
481"    if a:which == 1
482"        set nolist
483"        return
484"    else
485"        set list
486"    endif
487"
488"    " reset
489"    set listchars=
490"    execute "set listchars+=precedes:" . nr2char(95)
491"    execute "set listchars+=extends:" . nr2char(95)
492"
493"    if a:which >= 2
494"        execute "set listchars+=tab:" . nr2char(187) . '\ '
495"    else
496"        execute 'set listchars+=tab:\ \ '
497"    endif
498"    if a:which >= 3
499"        execute "set listchars+=eol:" . nr2char(182)
500"    endif
501"    if a:which >= 4
502"        execute "set listchars+=trail:" . nr2char(183)
503"    endif
504"
505"endfunction
506"imap <silent> <F4>             <C-b>:call MyInvisibles(1)<CR>
507"imap <silent> <F4><F4>         <C-b>:call MyInvisibles(2)<CR>
508"imap <silent> <F4><F4><F4>     <C-b>:call MyInvisibles(3)<CR>
509"imap <silent> <F4><F4><F4><F4> <C-b>:call MyInvisibles(4)<CR>
510
511" highlighting attribute removals {{{1
512function! Highlight_remove_attr(attr)
513" remove attribute from current color scheme
514" see ":help attr-list" for terms accepted
515
516	if  a:attr != "bold"
517	\&& a:attr != "underline"
518	\&& a:attr != "reverse"
519	\&& a:attr != "inverse"
520	\&& a:attr != "italic"
521	\&& a:attr != "standout"
522		echo "Invalid argument to Highlight_remove_attr()."
523		return -1
524	endif
525
526	" get current highlight configuration
527	redir @x
528	silent! highlight
529	redir END
530	" open temp buffer
531	new
532	" paste in
533	put x
534
535	" convert to vim syntax (from Mkcolorscheme.vim,
536	"   http://vim.sourceforge.net/scripts/script.php?script_id=85)
537	" delete empty and links lines
538	silent! g/^$\| links /d
539	" remove the xxx's
540	silent! %s/ xxx / /
541	" add highlight commands
542	silent! %s/^/highlight /
543	" protect spaces in some font names
544	silent! %s/font=\(.*\)/font='\1'/
545
546	" substitute attribute with "NONE"
547	execute 'silent! %s/' . a:attr . '\([\w,]*\)/NONE\1/geI'
548	" yank entire buffer
549	normal ggVG
550	" copy
551	normal "xy
552	" run
553	execute @x
554
555	" remove temp buffer
556	bwipeout!
557
558endfunction
559
560" 1}}}
561" Cream functionalities (non-default)
562" Cream_fileformat_unix() {{{1
563
564function! Cream_fileformat_unix()
565" Ensure buffers are always unix format, even on windows.
566
567	" get buffer number
568	let mybufnr = bufnr("%")
569	" only if buffer is unnamed and doesn't exist
570	if  bufname(mybufnr) == ""
571	\&& bufexists(mybufnr) == 1
572
573		" remember unmodified state
574		if getbufvar(mybufnr, "&modified") == 0
575			let mod = 1
576		endif
577
578		set ff=unix
579
580		" recover unmodifed state
581		if exists("mod")
582			set nomodified
583		endif
584	endif
585
586endfunction
587"" Uncomment to activate
588"set encoding=utf8
589"call Cream_listchars_init()
590"autocmd VimEnter,BufEnter * call Cream_fileformat_unix()
591
592" 1}}}
593" Examples
594" Justify selection bug {{{1
595
596"set insertmode
597"imap <F12> <C-b>:call JustifyRight()<CR>
598"function! JustifyRight()
599
600"    " remember
601"    let mytextwidth = &textwidth
602"    let myexpandtab = &expandtab
603"    " sets
604"    set textwidth=70
605"    set expandtab
606
607"    " select inner paragraph
608"    normal vip
609
610"    " get range (marks "'<" and "'>" are scoped pre-function call,
611"    " can't use!)
612"    let myfirstline = line(".")
613"    normal o
614"    let mylastline = line(".")
615"    normal o
616
617"    " put first range value first (necessary?)
618"    if mylastline < myfirstline
619"        let tmp = myfirstline
620"        let myfirstline = mylastline
621"        let mylastline = tmp
622"    endif
623
624"    " right justify
625"    execute "silent! " . myfirstline . "," . mylastline . "right"
626
627"    "*** BROKEN:
628"    "startinsert
629"    "normal i
630"    execute "normal \<Esc>"
631"    "***
632
633"    " restore
634"    let &textwidth = mytextwidth
635"    let &expandtab = myexpandtab
636
637"endfunction
638
639
640" Why <C-l><Esc> is evil. {{{1
641
642"function! MyFunction()
643"
644"    "-------- Test area ----------
645"    "23456789012345678901234567890
646"    "23456789012345678901234567890
647"    "23456789012345678901234567890
648"    "23456789012345678901234567890
649"    "-------- Test area ----------
650"
651"    " insert "Cow"
652"    normal iCow
653"    " back up
654"    normal hh
655"    " scroll screen up one line
656"    execute "normal \<C-e>"
657"    " move cursor back down one
658"    normal gj
659"endfunction
660
661" incorrect:
662"nmap <F12>           :call MyFunction()<CR>
663"imap <F12>      <C-l>:call MyFunction()<CR><Esc>
664
665" correct:
666"nmap <F12>           :call MyFunction()<CR>
667"imap <F12> <C-b>:call MyFunction()<CR>
668
669
670" 1}}}
671" Tests
672" Hooks {{{1
673function! Cream_hook_open(fname)
674
675	" tests
676	let match = 0
677
678	" TEST 1: extension is "COW"
679	if fnamemodify(a:fname, ':e') =~ "COW"
680		let match = 1
681	endif
682
683	" TEST 2: last four chars of filename is "_NEW"
684	" strip extension
685	let str = fnamemodify(a:fname, ':r')
686	" test last four chars
687	if strpart(str, strlen(str) - 4) == "_NEW"
688		let match = 1
689	endif
690
691	" OTHER TESTS
692
693	" no match
694	if match == 0
695		" quit and continue normal open
696		return 0
697	endif
698
699	" match
700	let n = confirm(
701		\ "Restriction match. Open read-only?\n" .
702		\ "\n", "Read-only\n&Cancel", 1, "Info")
703	if n == 1
704		call Cream_file_open_readonly(a:fname)
705	endif
706	" return -1 to stop normal open process
707	return -1
708
709endfunction
710
711" Remaining key maps {{{1
712" functional {{{2
713
714" Minus/Equals
715imap <silent> <C-->       <C-b>:call TestCow("C--")<CR>
716imap <silent> <C-_>       <C-b>:call TestCow("C-_")<CR>
717imap <silent> <M-->       <C-b>:call TestCow("M--")<CR>
718" Comma/Period
719imap <silent> <M-<>       <C-b>:call TestCow("M-\<")<CR>
720imap <silent> <M->>       <C-b>:call TestCow("M->")<CR>
721
722
723" non-functional {{{2
724" These mappings aren't advisable due to keyboard and OS
725" standardization issues.
726
727"" Brackets
728"imap <silent> <C-[>       <C-b>:call TestCow()<CR>
729"imap <silent> <C-S-]>     <C-b>:call TestCow()<CR>
730"imap <silent> <C-S-[>     <C-b>:call TestCow()<CR>
731"imap <silent> <C-}>       <C-b>:call TestCow()<CR>
732"imap <silent> <C-{>       <C-b>:call TestCow()<CR>
733
734"" Parenthesis
735"imap <silent> <C-S-0>     <C-b>:call TestCow()<CR>
736"imap <silent> <C-)>       <C-b>:call TestCow()<CR>
737"imap <silent> <C-S-9>     <C-b>:call TestCow()<CR>
738"imap <silent> <M-S-9>     <C-b>:call TestCow()<CR>
739"imap <silent> <M-S-(>     <C-b>:call TestCow()<CR>
740"imap <silent> <C-M-(>     <C-b>:call TestCow()<CR>
741"imap <silent> <C-M-9>     <C-b>:call TestCow()<CR>
742"imap <silent> <C-(>       <C-b>:call TestCow()<CR>
743
744"" Minus/Equals
745"imap <silent> <C-=>       <C-b>:call TestCow()<CR>
746"imap <silent> <C-+>       <C-b>:call TestCow()<CR>
747"imap <silent> <C-S-=>     <C-b>:call TestCow()<CR>
748
749"" Backslash/Bar
750"imap <silent> <C-Bar>  <C-b>:call TestCow()<CR>
751"imap <silent> <C-S-\>     <C-b>:call TestCow()<CR>
752"imap <silent> <C-\|>      <C-b>:call TestCow()<CR>
753"imap <silent> <C-|>     <C-b>:call TestCow()<CR>
754"imap <silent> |     <C-b>:call TestCow()<CR>
755"imap <silent> <C-M-\>     <C-b>:call TestCow()<CR>
756
757"" Enter
758"inoremap <silent> <C-m>    <C-b>:call TestCow("C-m")<CR>
759"imap <silent> <S-Return>   <C-b>:call TestCow("S-Return")<CR>
760"imap <silent> <M-Return>   <C-b>:call TestCow("M-Return")<CR>
761"imap <silent> <M-S-Return> <C-b>:call TestCow("M-S-Return")<CR>
762"imap <silent> <C-M-Return> <C-b>:call TestCow("C-M-Return")<CR>
763"imap <silent> <M-Enter>    <C-b>:call TestCow("M-Enter")<CR>
764"imap <silent> <M-S-Enter>  <C-b>:call TestCow("M-S-Enter")<CR>
765"imap <silent> <C-M-Enter>  <C-b>:call TestCow("C-M-Enter")<CR>
766"imap <silent> <M-CR>       <C-b>:call TestCow("M-CR")<CR>
767"imap <silent> <M-S-CR>     <C-b>:call TestCow("M-S-CR")<CR>
768"imap <silent> <C-M-CR>     <C-b>:call TestCow("C-M-CR")<CR>
769
770"" Space
771"imap <silent> <C-M-Space>  <C-b>:call TestCow()<CR>
772"imap <silent> <M-S-Space>  <C-b>:call TestCow()<CR>
773
774"" Letters
775"imap <silent> <C-j>       <C-b>:call TestCow("C-j")<CR>
776
777"imap <silent> <C-i>       <C-b>:echo "C-i"<CR>
778"imap <silent> <Tab>       <C-r>=Tab()<CR>
779"function! Tab()
780"    return nr2char(9)
781"endfunction
782
783" 2}}}
784
785" What exactly is in [[:punct:]] {{{1
786
787function! Cream_whatis(collection)
788" see :help /collection
789" use "call Cream_whatis('[[:punct:]]')" or the like
790
791	let mycollection = ""
792	let i = 0
793	while i < 256
794		if match(nr2char(i), a:collection) == 0
795			let mycollection = mycollection . i . ":  " . nr2char(i) . "\t"
796		endif
797		if i % 10 == 0
798			let mycollection = mycollection . "\n"
799		endif
800		let i = i + 1
801	endwhile
802
803	echo mycollection
804
805endfunction
806
807" Find the <SID> of a specific script {{{1
808
809"function! GetSID(script_name)
810"" retrieve vim <SID> for a specific script
811"" Source: http://groups.yahoo.com/group/vim/message/34855
812"" Author: Sylvain Viart <viart.sylvain (at) videotron.ca>
813"" Date:   2002-12-01
814"    let old_reg_r = @r
815"    redir @r
816"    silent scriptnames
817"    redir END
818
819"    let regex = substitute(a:script_name, '[/\\]', '.', 'g')
820"    let regex = "\\s\\+[0-9]\\+:\\s*[^\n]*" . regex
821"    let l = matchstr(@r, regex)
822"    let sid = matchstr(l, '[0-9]\+')
823
824"    let @r = old_reg_r
825"    return sid
826"endfunction
827
828
829"" in the sourced script
830"function! <SID>GetVar(varname)
831"    execute "let v = s:" . a:varname
832"    return v
833"endfunction
834
835"" and then when you want a variable:
836"let sid = GetSID('golbal/var.vim')
837"" call the script function with the specified argument
838"execute "let v = \<SNR>" . sid . "_Getvar(" . varname . ")"
839
840
841" Progress bar from 1-100% {{{1
842function! BarTest()
843	let i = 0
844	while i < 101
845		call ProgressBar(i, "    Loading files... ", "=", 0)
846		sleep 5m
847		let i = i + 1
848	endwhile
849endfunction
850
851
852" 1}}}
853" vim:foldmethod=marker
854