utils 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Rakefile +68 -0
  2. data/VERSION +1 -0
  3. data/bin/chroot-exec +12 -0
  4. data/bin/chroot-libs +18 -0
  5. data/bin/classify +37 -0
  6. data/bin/discover +137 -0
  7. data/bin/edit +74 -0
  8. data/bin/errf +32 -0
  9. data/bin/git-empty +8 -0
  10. data/bin/myex +90 -0
  11. data/bin/number_files +26 -0
  12. data/bin/same_files +37 -0
  13. data/bin/search +205 -0
  14. data/bin/sedit +3 -0
  15. data/bin/sshscreen +68 -0
  16. data/bin/term +21 -0
  17. data/bin/unquarantine_apps +8 -0
  18. data/bin/untest +17 -0
  19. data/bin/utils-install-config +10 -0
  20. data/bin/vacuum_firefox_sqlite +22 -0
  21. data/bin/xmp +74 -0
  22. data/lib/utils.rb +8 -0
  23. data/lib/utils/config.rb +23 -0
  24. data/lib/utils/config/gdb/asm +179 -0
  25. data/lib/utils/config/gdb/ruby +528 -0
  26. data/lib/utils/config/gdbinit +8 -0
  27. data/lib/utils/config/irbrc +455 -0
  28. data/lib/utils/config/rdebugrc +2 -0
  29. data/lib/utils/config/screenrc +143 -0
  30. data/lib/utils/config/vim/autoload/Align.vim +1029 -0
  31. data/lib/utils/config/vim/autoload/AlignMaps.vim +330 -0
  32. data/lib/utils/config/vim/autoload/rails.vim +4744 -0
  33. data/lib/utils/config/vim/autoload/rubycomplete.vim +801 -0
  34. data/lib/utils/config/vim/autoload/sqlcomplete.vim +741 -0
  35. data/lib/utils/config/vim/autoload/vimball.vim +750 -0
  36. data/lib/utils/config/vim/colors/flori.vim +113 -0
  37. data/lib/utils/config/vim/compiler/eruby.vim +40 -0
  38. data/lib/utils/config/vim/compiler/ruby.vim +67 -0
  39. data/lib/utils/config/vim/compiler/rubyunit.vim +34 -0
  40. data/lib/utils/config/vim/ftdetect/ragel.vim +2 -0
  41. data/lib/utils/config/vim/ftdetect/ruby.vim +17 -0
  42. data/lib/utils/config/vim/ftplugin/eruby.vim +100 -0
  43. data/lib/utils/config/vim/ftplugin/ruby.vim +260 -0
  44. data/lib/utils/config/vim/ftplugin/xml.vim +941 -0
  45. data/lib/utils/config/vim/indent/IndentAnything_html.vim +35 -0
  46. data/lib/utils/config/vim/indent/eruby.vim +77 -0
  47. data/lib/utils/config/vim/indent/javascript.vim +116 -0
  48. data/lib/utils/config/vim/indent/ruby.vim +377 -0
  49. data/lib/utils/config/vim/plugin/AlignMapsPlugin.vim +242 -0
  50. data/lib/utils/config/vim/plugin/AlignPlugin.vim +41 -0
  51. data/lib/utils/config/vim/plugin/Decho.vim +592 -0
  52. data/lib/utils/config/vim/plugin/IndentAnything.vim +675 -0
  53. data/lib/utils/config/vim/plugin/bufexplorer.vim +1144 -0
  54. data/lib/utils/config/vim/plugin/cecutil.vim +482 -0
  55. data/lib/utils/config/vim/plugin/fugitive.vim +1703 -0
  56. data/lib/utils/config/vim/plugin/lusty-explorer.vim +1509 -0
  57. data/lib/utils/config/vim/plugin/rails.vim +340 -0
  58. data/lib/utils/config/vim/plugin/rubyextra.vim +193 -0
  59. data/lib/utils/config/vim/plugin/surround.vim +628 -0
  60. data/lib/utils/config/vim/plugin/taglist.vim +4546 -0
  61. data/lib/utils/config/vim/plugin/test/IndentAnything/test.js +131 -0
  62. data/lib/utils/config/vim/plugin/vimballPlugin.vim +40 -0
  63. data/lib/utils/config/vim/syntax/Decho.vim +101 -0
  64. data/lib/utils/config/vim/syntax/eruby.vim +73 -0
  65. data/lib/utils/config/vim/syntax/javascript.vim +246 -0
  66. data/lib/utils/config/vim/syntax/ragel.vim +165 -0
  67. data/lib/utils/config/vim/syntax/ruby.vim +367 -0
  68. data/lib/utils/config/vimrc +461 -0
  69. data/lib/utils/file.rb +49 -0
  70. data/lib/utils/find.rb +54 -0
  71. data/lib/utils/md5.rb +23 -0
  72. data/lib/utils/patterns.rb +34 -0
  73. data/lib/utils/version.rb +8 -0
  74. data/utils.gemspec +33 -0
  75. metadata +183 -0
@@ -0,0 +1,340 @@
1
+ " rails.vim - Detect a rails application
2
+ " Author: Tim Pope <vimNOSPAM@tpope.org>
3
+ " GetLatestVimScripts: 1567 1 :AutoInstall: rails.vim
4
+ " URL: http://rails.vim.tpope.net/
5
+
6
+ " Install this file as plugin/rails.vim. See doc/rails.txt for details. (Grab
7
+ " it from the URL above if you don't have it.) To access it from Vim, see
8
+ " :help add-local-help (hint: :helptags ~/.vim/doc) Afterwards, you should be
9
+ " able to do :help rails
10
+
11
+ if exists('g:loaded_rails') || &cp || v:version < 700
12
+ finish
13
+ endif
14
+ let g:loaded_rails = 1
15
+
16
+ " Utility Functions {{{1
17
+
18
+ function! s:error(str)
19
+ echohl ErrorMsg
20
+ echomsg a:str
21
+ echohl None
22
+ let v:errmsg = a:str
23
+ endfunction
24
+
25
+ function! s:autoload(...)
26
+ if !exists("g:autoloaded_rails") && v:version >= 700
27
+ runtime! autoload/rails.vim
28
+ endif
29
+ if exists("g:autoloaded_rails")
30
+ if a:0
31
+ exe a:1
32
+ endif
33
+ return 1
34
+ endif
35
+ if !exists("g:rails_no_autoload_warning")
36
+ let g:rails_no_autoload_warning = 1
37
+ if v:version >= 700
38
+ call s:error("Disabling rails.vim: autoload/rails.vim is missing")
39
+ else
40
+ call s:error("Disabling rails.vim: Vim version 7 or higher required")
41
+ endif
42
+ endif
43
+ return ""
44
+ endfunction
45
+
46
+ " }}}1
47
+ " Configuration {{{
48
+
49
+ function! s:SetOptDefault(opt,val)
50
+ if !exists("g:".a:opt)
51
+ let g:{a:opt} = a:val
52
+ endif
53
+ endfunction
54
+
55
+ call s:SetOptDefault("rails_statusline",1)
56
+ call s:SetOptDefault("rails_syntax",1)
57
+ call s:SetOptDefault("rails_mappings",1)
58
+ call s:SetOptDefault("rails_abbreviations",1)
59
+ call s:SetOptDefault("rails_ctags_arguments","--languages=-javascript")
60
+ call s:SetOptDefault("rails_default_file","README")
61
+ call s:SetOptDefault("rails_root_url",'http://localhost:3000/')
62
+ call s:SetOptDefault("rails_modelines",0)
63
+ call s:SetOptDefault("rails_menu",!has('mac'))
64
+ call s:SetOptDefault("rails_gnu_screen",1)
65
+ call s:SetOptDefault("rails_history_size",5)
66
+ call s:SetOptDefault("rails_generators","controller\ngenerator\nhelper\nintegration_test\nmailer\nmetal\nmigration\nmodel\nobserver\nperformance_test\nplugin\nresource\nscaffold\nscaffold_controller\nsession_migration\nstylesheets")
67
+ if exists("g:loaded_dbext") && executable("sqlite3") && ! executable("sqlite")
68
+ " Since dbext can't find it by itself
69
+ call s:SetOptDefault("dbext_default_SQLITE_bin","sqlite3")
70
+ endif
71
+
72
+ " }}}1
73
+ " Detection {{{1
74
+
75
+ function! s:escvar(r)
76
+ let r = fnamemodify(a:r,':~')
77
+ let r = substitute(r,'\W','\="_".char2nr(submatch(0))."_"','g')
78
+ let r = substitute(r,'^\d','_&','')
79
+ return r
80
+ endfunction
81
+
82
+ function! s:Detect(filename)
83
+ let fn = substitute(fnamemodify(a:filename,":p"),'\c^file://','','')
84
+ let sep = matchstr(fn,'^[^\\/]\{3,\}\zs[\\/]')
85
+ if sep != ""
86
+ let fn = getcwd().sep.fn
87
+ endif
88
+ if fn =~ '[\/]config[\/]environment\.rb$'
89
+ return s:BufInit(strpart(fn,0,strlen(fn)-22))
90
+ endif
91
+ if isdirectory(fn)
92
+ let fn = fnamemodify(fn,':s?[\/]$??')
93
+ else
94
+ let fn = fnamemodify(fn,':s?\(.*\)[\/][^\/]*$?\1?')
95
+ endif
96
+ let ofn = ""
97
+ let nfn = fn
98
+ while nfn != ofn && nfn != ""
99
+ if exists("s:_".s:escvar(nfn))
100
+ return s:BufInit(nfn)
101
+ endif
102
+ let ofn = nfn
103
+ let nfn = fnamemodify(nfn,':h')
104
+ endwhile
105
+ let ofn = ""
106
+ while fn != ofn
107
+ if filereadable(fn . "/config/environment.rb")
108
+ return s:BufInit(fn)
109
+ endif
110
+ let ofn = fn
111
+ let fn = fnamemodify(ofn,':s?\(.*\)[\/]\(app\|config\|db\|doc\|features\|lib\|log\|public\|script\|spec\|stories\|test\|tmp\|vendor\)\($\|[\/].*$\)?\1?')
112
+ endwhile
113
+ return 0
114
+ endfunction
115
+
116
+ function! s:BufInit(path)
117
+ let s:_{s:escvar(a:path)} = 1
118
+ if s:autoload()
119
+ return RailsBufInit(a:path)
120
+ endif
121
+ endfunction
122
+
123
+ " }}}1
124
+ " Initialization {{{1
125
+
126
+ augroup railsPluginDetect
127
+ autocmd!
128
+ autocmd BufNewFile,BufRead * call s:Detect(expand("<afile>:p"))
129
+ autocmd VimEnter * if expand("<amatch>") == "" && !exists("b:rails_root") | call s:Detect(getcwd()) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
130
+ autocmd FileType netrw if !exists("b:rails_root") | call s:Detect(expand("<afile>:p")) | endif | if exists("b:rails_root") | silent doau User BufEnterRails | endif
131
+ autocmd BufEnter * if exists("b:rails_root")|silent doau User BufEnterRails|endif
132
+ autocmd BufLeave * if exists("b:rails_root")|silent doau User BufLeaveRails|endif
133
+ autocmd Syntax railslog if s:autoload()|call rails#log_syntax()|endif
134
+ augroup END
135
+
136
+ command! -bar -bang -nargs=* -complete=dir Rails :if s:autoload()|call rails#new_app_command(<bang>0,<f-args>)|endif
137
+
138
+ " }}}1
139
+ " abolish.vim support {{{1
140
+
141
+ function! s:function(name)
142
+ return function(substitute(a:name,'^s:',matchstr(expand('<sfile>'), '<SNR>\d\+_'),''))
143
+ endfunction
144
+
145
+ augroup railsPluginAbolish
146
+ autocmd!
147
+ autocmd VimEnter * call s:abolish_setup()
148
+ augroup END
149
+
150
+ function! s:abolish_setup()
151
+ if exists('g:Abolish') && has_key(g:Abolish,'Coercions')
152
+ if !has_key(g:Abolish.Coercions,'l')
153
+ let g:Abolish.Coercions.l = s:function('s:abolish_l')
154
+ endif
155
+ if !has_key(g:Abolish.Coercions,'t')
156
+ let g:Abolish.Coercions.t = s:function('s:abolish_t')
157
+ endif
158
+ endif
159
+ endfunction
160
+
161
+ function! s:abolish_l(word)
162
+ let singular = rails#singularize(a:word)
163
+ return a:word ==? singular ? rails#pluralize(a:word) : singular
164
+ endfunction
165
+
166
+ function! s:abolish_t(word)
167
+ if a:word =~# '\u'
168
+ return rails#pluralize(rails#underscore(a:word))
169
+ else
170
+ return rails#singularize(rails#camelize(a:word))
171
+ endif
172
+ endfunction
173
+
174
+ " }}}1
175
+ " Menus {{{1
176
+
177
+ if !(g:rails_menu && has("menu"))
178
+ finish
179
+ endif
180
+
181
+ function! s:sub(str,pat,rep)
182
+ return substitute(a:str,'\v\C'.a:pat,a:rep,'')
183
+ endfunction
184
+
185
+ function! s:gsub(str,pat,rep)
186
+ return substitute(a:str,'\v\C'.a:pat,a:rep,'g')
187
+ endfunction
188
+
189
+ function! s:menucmd(priority)
190
+ return 'anoremenu <script> '.(exists("$CREAM") ? 87 : '').s:gsub(g:rails_installed_menu,'[^.]','').'.'.a:priority.' '
191
+ endfunction
192
+
193
+ function! s:CreateMenus() abort
194
+ if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
195
+ exe "aunmenu ".s:gsub(g:rails_installed_menu,'\&','')
196
+ unlet g:rails_installed_menu
197
+ endif
198
+ if has("menu") && (exists("g:did_install_default_menus") || exists("$CREAM")) && g:rails_menu
199
+ if g:rails_menu > 1
200
+ let g:rails_installed_menu = '&Rails'
201
+ else
202
+ let g:rails_installed_menu = '&Plugin.&Rails'
203
+ endif
204
+ let dots = s:gsub(g:rails_installed_menu,'[^.]','')
205
+ let menucmd = s:menucmd(200)
206
+ if exists("$CREAM")
207
+ exe menucmd.g:rails_installed_menu.'.-PSep- :'
208
+ exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ Alt+] :R<CR>'
209
+ exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ Alt+[ :A<CR>'
210
+ exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ Ctrl+Enter :Rfind<CR>'
211
+ else
212
+ exe menucmd.g:rails_installed_menu.'.-PSep- :'
213
+ exe menucmd.g:rails_installed_menu.'.&Related\ file\ :R\ /\ ]f :R<CR>'
214
+ exe menucmd.g:rails_installed_menu.'.&Alternate\ file\ :A\ /\ [f :A<CR>'
215
+ exe menucmd.g:rails_installed_menu.'.&File\ under\ cursor\ gf :Rfind<CR>'
216
+ endif
217
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Controller :Rcontroller application<CR>'
218
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Helper :Rhelper application<CR>'
219
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Javascript :Rjavascript application<CR>'
220
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &Layout :Rlayout application<CR>'
221
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.Application\ &README :R doc/README_FOR_APP<CR>'
222
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.&Environment :Renvironment<CR>'
223
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.&Database\ Configuration :R config/database.yml<CR>'
224
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.Database\ &Schema :Rmigration 0<CR>'
225
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.R&outes :Rinitializer<CR>'
226
+ exe menucmd.g:rails_installed_menu.'.&Other\ files.&Test\ Helper :Rintegrationtest<CR>'
227
+ exe menucmd.g:rails_installed_menu.'.-FSep- :'
228
+ exe menucmd.g:rails_installed_menu.'.Ra&ke\ :Rake :Rake<CR>'
229
+ let menucmd = substitute(menucmd,'200 $','500 ','')
230
+ exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Start\ :Rserver :Rserver<CR>'
231
+ exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Force\ start\ :Rserver! :Rserver!<CR>'
232
+ exe menucmd.g:rails_installed_menu.'.&Server\ :Rserver.&Kill\ :Rserver!\ - :Rserver! -<CR>'
233
+ exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.&Evaluate\ Ruby\.\.\.\ :Rp :call <SID>menuprompt("Rp","Code to execute and output: ")<CR>'
234
+ exe menucmd.g:rails_installed_menu.'.&Console\ :Rscript :Rscript console<CR>'
235
+ exe menucmd.g:rails_installed_menu.'.&Preview\ :Rpreview :Rpreview<CR>'
236
+ exe menucmd.g:rails_installed_menu.'.&Log\ file\ :Rlog :Rlog<CR>'
237
+ exe substitute(s:sub(menucmd,'anoremenu','vnoremenu'),'<script>','<script> <silent>','').g:rails_installed_menu.'.E&xtract\ as\ partial\ :Rextract :call <SID>menuprompt("'."'".'<,'."'".'>Rextract","Partial name (e.g., template or /controller/template): ")<CR>'
238
+ exe menucmd.g:rails_installed_menu.'.&Migration\ writer\ :Rinvert :Rinvert<CR>'
239
+ exe menucmd.' '.g:rails_installed_menu.'.-HSep- :'
240
+ exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.&Help\ :help\ rails :if <SID>autoload()<Bar>exe RailsHelpCommand("")<Bar>endif<CR>'
241
+ exe substitute(menucmd,'<script>','<script> <silent>','').g:rails_installed_menu.'.Abo&ut\ :if <SID>autoload()<Bar>exe RailsHelpCommand("about")<Bar>endif<CR>'
242
+ let g:rails_did_menus = 1
243
+ call s:ProjectMenu()
244
+ call s:menuBufLeave()
245
+ if exists("b:rails_root")
246
+ call s:menuBufEnter()
247
+ endif
248
+ endif
249
+ endfunction
250
+
251
+ function! s:ProjectMenu()
252
+ if exists("g:rails_did_menus") && g:rails_history_size > 0
253
+ if !exists("g:RAILS_HISTORY")
254
+ let g:RAILS_HISTORY = ""
255
+ endif
256
+ let history = g:RAILS_HISTORY
257
+ let menu = s:gsub(g:rails_installed_menu,'\&','')
258
+ silent! exe "aunmenu <script> ".menu.".Projects"
259
+ let dots = s:gsub(menu,'[^.]','')
260
+ exe 'anoremenu <script> <silent> '.(exists("$CREAM") ? '87' : '').dots.'.100 '.menu.'.Pro&jects.&New\.\.\.\ :Rails :call <SID>menuprompt("Rails","New application path and additional arguments: ")<CR>'
261
+ exe 'anoremenu <script> '.menu.'.Pro&jects.-FSep- :'
262
+ while history =~ '\n'
263
+ let proj = matchstr(history,'^.\{-\}\ze\n')
264
+ let history = s:sub(history,'^.{-}\n','')
265
+ exe 'anoremenu <script> '.menu.'.Pro&jects.'.s:gsub(proj,'[.\\ ]','\\&').' :e '.s:gsub(proj."/".g:rails_default_file,'[ !%#]','\\&')."<CR>"
266
+ endwhile
267
+ endif
268
+ endfunction
269
+
270
+ function! s:menuBufEnter()
271
+ if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
272
+ let menu = s:gsub(g:rails_installed_menu,'\&','')
273
+ exe 'amenu enable '.menu.'.*'
274
+ if RailsFileType() !~ '^view\>'
275
+ exe 'vmenu disable '.menu.'.Extract\ as\ partial'
276
+ endif
277
+ if RailsFileType() !~ '^\%(db-\)\=migration$' || RailsFilePath() =~ '\<db/schema\.rb$'
278
+ exe 'amenu disable '.menu.'.Migration\ writer'
279
+ endif
280
+ call s:ProjectMenu()
281
+ silent! exe 'aunmenu '.menu.'.Rake\ tasks'
282
+ silent! exe 'aunmenu '.menu.'.Generate'
283
+ silent! exe 'aunmenu '.menu.'.Destroy'
284
+ if rails#app().cache.needs('rake_tasks') || empty(rails#app().rake_tasks())
285
+ exe substitute(s:menucmd(300),'<script>','<script> <silent>','').g:rails_installed_menu.'.Rake\ &tasks\ :Rake.Fill\ this\ menu :call rails#app().rake_tasks()<Bar>call <SID>menuBufLeave()<Bar>call <SID>menuBufEnter()<CR>'
286
+ else
287
+ let i = 0
288
+ while i < len(rails#app().rake_tasks())
289
+ let task = rails#app().rake_tasks()[i]
290
+ exe s:menucmd(300).g:rails_installed_menu.'.Rake\ &tasks\ :Rake.'.s:sub(task,':',':.').' :Rake '.task.'<CR>'
291
+ let i += 1
292
+ endwhile
293
+ endif
294
+ let i = 0
295
+ let menucmd = substitute(s:menucmd(400),'<script>','<script> <silent>','').g:rails_installed_menu
296
+ while i < len(rails#app().generators())
297
+ let generator = rails#app().generators()[i]
298
+ exe menucmd.'.&Generate\ :Rgen.'.s:gsub(generator,'_','\\ ').' :call <SID>menuprompt("Rgenerate '.generator.'","Arguments for script/generate '.generator.': ")<CR>'
299
+ exe menucmd.'.&Destroy\ :Rdestroy.'.s:gsub(generator,'_','\\ ').' :call <SID>menuprompt("Rdestroy '.generator.'","Arguments for script/destroy '.generator.': ")<CR>'
300
+ let i += 1
301
+ endwhile
302
+ endif
303
+ endfunction
304
+
305
+ function! s:menuBufLeave()
306
+ if exists("g:rails_installed_menu") && g:rails_installed_menu != ""
307
+ let menu = s:gsub(g:rails_installed_menu,'\&','')
308
+ exe 'amenu disable '.menu.'.*'
309
+ exe 'amenu enable '.menu.'.Help\ '
310
+ exe 'amenu enable '.menu.'.About\ '
311
+ exe 'amenu enable '.menu.'.Projects'
312
+ silent! exe 'aunmenu '.menu.'.Rake\ tasks'
313
+ silent! exe 'aunmenu '.menu.'.Generate'
314
+ silent! exe 'aunmenu '.menu.'.Destroy'
315
+ exe s:menucmd(300).g:rails_installed_menu.'.Rake\ tasks\ :Rake.-TSep- :'
316
+ exe s:menucmd(400).g:rails_installed_menu.'.&Generate\ :Rgen.-GSep- :'
317
+ exe s:menucmd(400).g:rails_installed_menu.'.&Destroy\ :Rdestroy.-DSep- :'
318
+ endif
319
+ endfunction
320
+
321
+ function! s:menuprompt(vimcmd,prompt)
322
+ let res = inputdialog(a:prompt,'','!!!')
323
+ if res == '!!!'
324
+ return ""
325
+ endif
326
+ exe a:vimcmd." ".res
327
+ endfunction
328
+
329
+ call s:CreateMenus()
330
+
331
+ augroup railsPluginMenu
332
+ autocmd!
333
+ autocmd User BufEnterRails call s:menuBufEnter()
334
+ autocmd User BufLeaveRails call s:menuBufLeave()
335
+ " g:RAILS_HISTORY hasn't been set when s:InitPlugin() is called.
336
+ autocmd VimEnter * call s:ProjectMenu()
337
+ augroup END
338
+
339
+ " }}}1
340
+ " vim:set sw=2 sts=2:
@@ -0,0 +1,193 @@
1
+ " Some Stuff for Ruby folding & formatting
2
+
3
+ " Folding
4
+ map <SID>xx <SID>xx
5
+ let s:sid = maparg("<SID>xx")
6
+ unmap <SID>xx
7
+ let s:sid = substitute(s:sid, 'xx', '', '')
8
+
9
+ "{{{ FoldText
10
+ function! s:Num2S(num, len)
11
+ let filler = " "
12
+ let text = '' . a:num
13
+ return strpart(filler, 1, a:len - strlen(text)) . text
14
+ endfunction
15
+
16
+ execute 'set foldtext=' . s:sid . 'MyNewFoldText()'
17
+ function! <SID>MyNewFoldText()
18
+ let line = getline(v:foldstart)
19
+ let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
20
+ let diff = v:foldend - v:foldstart
21
+ let sdiff = s:Num2S(diff, 4)
22
+ return '+ [' . sdiff . ']' . sub
23
+ endfunction
24
+
25
+ "{{{~foldsearch adapted from t77: Fold on search result (Fs <pattern>)
26
+ "Fs pattern Fold search
27
+ "Str (structure) ruby program pattern based on module class and def
28
+ "Strlm (structure) lm file pattern based on <!1!> etc.
29
+ "Vimtip put to good use by Ralph Amissah zxy@irc.freenode.net
30
+ "Modified by Mauricio Fernandez <mfp@acm.org>
31
+ function! Foldsearch(search)
32
+ setlocal fdm=manual
33
+ let origlineno = line(".")
34
+ normal zE
35
+ normal G$
36
+ let folded = 0 "flag to set when a fold is found
37
+ let flags = "w" "allow wrapping in the search
38
+ let line1 = 0 "set marker for beginning of fold
39
+ if a:search == ""
40
+ if exists("b:foldsearchexpr")
41
+ let searchre = b:foldsearchexpr
42
+ else
43
+ "Default value, suitable for Ruby scripts
44
+ "\(^\s*\(\(def\|class\|module\)\s\)\)\|^\s*[#%"0-9]\{0,4\}\s*{\({{\|!!\)
45
+ let searchre = '\v(^\s*(def|class|module|attr_reader|attr_accessor|alias_method)\s' .
46
+ \ '|^\s*\w+attr_(reader|accessor)\s|^\s*[#%"0-9]{0,4}\s*\{(\{\{|!!))' .
47
+ \ '|^\s*[A-Z]\w+\s*\='
48
+ let b:foldsearchexpr = searchre
49
+ endif
50
+ else
51
+ let searchre = a:search
52
+ endif
53
+ while search(searchre, flags) > 0
54
+ let line2 = line(".")
55
+ if (line2 -1 > line1)
56
+ execute ":" . line1 . "," . (line2-1) . "fold"
57
+ let folded = 1 "at least one fold has been found
58
+ endif
59
+ let line1 = line2 "update marker
60
+ let flags = "W" "turn off wrapping
61
+ endwhile
62
+ normal $G
63
+ let line2 = line(".")
64
+ if (line2 > line1 && folded == 1)
65
+ execute ":". line1 . "," . line2 . "fold"
66
+ endif
67
+ execute "normal " . origlineno . "G"
68
+ endfunction
69
+
70
+ "{{{~folds Fold Patterns
71
+ " Command is executed as ':Fs pattern'"
72
+ command! -nargs=? -complete=command Fs call Foldsearch(<q-args>)
73
+ command! -nargs=? -complete=command Fold call Foldsearch(<q-args>)
74
+ "command! R Fs \(^\s*\(\(def\|class\|module\)\s\)\)\|^\s*[#%"0-9]\{0,4\}\s*{\({{\|!!\)
75
+ command! R Fs
76
+
77
+ "{{{ Ruby block delimiter conversion: do end <=> { }
78
+ "Copyright © 2005 Mauricio Fernandez
79
+ "Subject to same licensing terms as Ruby.
80
+ " requires matchit and friends
81
+ " since it uses the % and = bindings
82
+ function! s:String_Strip(str)
83
+ let s = substitute(a:str, '\v^\s*', '', '')
84
+ return substitute(s, '\v\s*$', '', '')
85
+ endfunction
86
+
87
+ function! s:RubyBlockBraceToDoEnd(lineno)
88
+ " { } => do end
89
+ let oldz = getreg("z")
90
+ call setreg("z", "")
91
+ execute 'normal ^f{%l"zd$'
92
+ let suffix = s:String_Strip(getreg("z"))
93
+ call setreg("z", oldz)
94
+ let orig = getline(".")
95
+ let repl = substitute(orig, '\v\s*\{\s*(\|[^|]*\|)?.*', ' do \1', '')
96
+ call setline(".", repl)
97
+ let nextline = substitute(orig, '\v[^{]*\v\s*\{\s*(\|[^|]*\|)?', '', '')
98
+ let nextline = substitute(nextline, '\}[^}]*$', '', '')
99
+ let numlines = 0
100
+
101
+
102
+ " uncomment one of the following:
103
+
104
+ " (1) just insert the body without splitting the lines on ;
105
+ "call append(a:lineno, nextline)
106
+ "call append(a:lineno+1, 'end' . suffix)
107
+ "
108
+
109
+ " (2) try to split on ; ...
110
+ call append(a:lineno, 'end' . suffix)
111
+ " this is what we would want to do:
112
+ "let nextline = substitute(nextline, ';', "\n", 'g')
113
+
114
+ while stridx(nextline, ";") != -1
115
+ let eom = stridx(nextline, ";")
116
+ let line = s:String_Strip(strpart(nextline, 0, eom))
117
+ call append(a:lineno + numlines, line)
118
+ let numlines = numlines + 1
119
+ let nextline = strpart(nextline, eom+1, strlen(nextline) - eom - 1)
120
+ endwhile
121
+ let nextline = s:String_Strip(nextline)
122
+ if strlen(nextline) > 0
123
+ call append(a:lineno + numlines, nextline)
124
+ let numlines = numlines + 1
125
+ endif
126
+
127
+ " this is what it all began with...
128
+ "execute 'normal :s/\v\s*\{\s*(\|.*\|)?/ do \1\r/
129
+ '
130
+ "execute 'normal g_cw
131
+ end'
132
+ execute 'normal V' . (1 + numlines) . 'j='
133
+ "echo "{ } => do end"
134
+ endfunction
135
+
136
+ function! s:RubyBlockDoEndToBrace(_firstline, _lastline)
137
+ " do end => { }
138
+ let linenum = a:_firstline + 1
139
+ let orig = getline(".")
140
+ while linenum < a:_lastline - 1
141
+ let addline = getline(linenum)
142
+ if '\v^\s*$' !~ addline
143
+ let addline = substitute(addline, '\v^\s*', '', '')
144
+ let addline = substitute(addline, '\s*$', '; ', '')
145
+ let orig = orig . addline
146
+ endif
147
+ let linenum = linenum + 1
148
+ endwhile
149
+ let l = substitute(getline(a:_lastline-1), '\v^\s*', '', '')
150
+ let l = substitute(l, '\s*$', '', '')
151
+ let orig = orig . l
152
+ let l = substitute(getline(a:_lastline), '\v^\s*end(\.|\s|$)@=', ' }', '')
153
+ let l = substitute(l, '\s*$', '', '')
154
+ let orig = orig . l
155
+
156
+ "echo orig
157
+ "input(orig)
158
+ let repl = substitute(orig, '\v\s*do\s*(\|[^|]*\|)?', ' { \1 ', '')
159
+ "execute 'normal d' . (a:_lastline - a:_firstline) . 'j'
160
+ execute ':' . a:_firstline . ',' . a:_lastline . 'd'
161
+ call append(a:_firstline - 1, repl)
162
+ execute ':' . a:_firstline
163
+ "echo "do end => { }"
164
+ endfunction
165
+
166
+ map <SID>xx <SID>xx
167
+ let s:sid = maparg("<SID>xx")
168
+ unmap <SID>xx
169
+ let s:sid = substitute(s:sid, 'xx', '', '')
170
+
171
+ function! <SID>RubyBlockSwitchDelimiters() range
172
+ set nofoldenable
173
+ if a:firstline == a:lastline
174
+ let braceidx = match(getline("."), '{')
175
+ let doidx = match(getline("."), '\<do\>')
176
+ if braceidx != -1 && (doidx == -1 || braceidx < doidx)
177
+ call s:RubyBlockBraceToDoEnd(a:firstline)
178
+ elseif doidx != -1
179
+ execute 'normal /\<do\>' . "\n" . 'V%:call ' .
180
+ \ s:sid . 'RubyBlockSwitchDelimiters()' . "\n"
181
+ else
182
+ echo "No block found"
183
+ end
184
+ else
185
+ call s:RubyBlockDoEndToBrace(a:firstline, a:lastline)
186
+ endif
187
+ "execute 'normal V2k='
188
+ "execute 'normal v5j'
189
+ endfunction
190
+
191
+ " Visual \B
192
+ command! -range B <line1>,<line2>call <SID>RubyBlockSwitchDelimiters()
193
+ vmap <Leader>B :call <SID>RubyBlockSwitchDelimiters()<cr>