utils 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -142,20 +142,20 @@ function! s:BEAddBuffer()
142
142
  if !exists('s:raw_buffer_listing') || empty(s:raw_buffer_listing)
143
143
  silent let s:raw_buffer_listing = s:BEGetBufferInfo(0)
144
144
  else
145
- " We cannot use :buffers! or :ls! to gather information
145
+ " We cannot use :buffers! or :ls! to gather information
146
146
  " about this buffer since it was only just added.
147
- " Any changes to the buffer (setlocal buftype, ...)
147
+ " Any changes to the buffer (setlocal buftype, ...)
148
148
  " happens after this event fires.
149
149
  "
150
150
  " So we will indicate the :buffers! command must be re-run.
151
151
  " This should help with the performance of the plugin.
152
152
 
153
- " There are some checks which can be performed
153
+ " There are some checks which can be performed
154
154
  " before deciding to refresh the buffer list.
155
155
  let bufnr = expand('<abuf>') + 0
156
156
 
157
157
  if s:BEIgnoreBuffer(bufnr) == 1
158
- return
158
+ return
159
159
  else
160
160
  let s:refreshBufferList = 1
161
161
  endif
@@ -174,7 +174,7 @@ function! s:BEActivateBuffer()
174
174
  endif
175
175
 
176
176
  if !empty(l) && l[0] == '-1'
177
- " The first time we add a tab Vim uses the current
177
+ " The first time we add a tab Vim uses the current
178
178
  " buffer as it's starting page, even though we are about
179
179
  " to edit a new page (BufEnter triggers after), so
180
180
  " remove the -1 entry indicating we have covered this case.
@@ -214,7 +214,7 @@ function! s:BEActivateBuffer()
214
214
  let shortlist = filter(copy(s:raw_buffer_listing), "v:val.attributes =~ '".'^\s*'.b.'u\>'."'")
215
215
 
216
216
  if !empty(shortlist)
217
- " If it is unlisted (ie deleted), but now we editing it again
217
+ " If it is unlisted (ie deleted), but now we editing it again
218
218
  " rebuild the buffer list.
219
219
  let s:refreshBufferList = 1
220
220
  endif
@@ -279,7 +279,7 @@ function! s:BEInitialize()
279
279
  let s:running = 1
280
280
  endfunction
281
281
 
282
- " BEIgnoreBuffer
282
+ " BEIgnoreBuffer
283
283
  function! s:BEIgnoreBuffer(buf)
284
284
  " Check to see if this buffer should be ignore by BufExplorer.
285
285
 
@@ -307,7 +307,7 @@ function! s:BEIgnoreBuffer(buf)
307
307
  return 1
308
308
  end
309
309
 
310
- return 0
310
+ return 0
311
311
  endfunction
312
312
 
313
313
  " BECleanup {{{1
@@ -358,7 +358,7 @@ function! StartBufExplorer(open)
358
358
  let s:originBuffer = bufnr("%") + 0
359
359
 
360
360
  " Create or rebuild the raw buffer list if necessary.
361
- if !exists('s:raw_buffer_listing') ||
361
+ if !exists('s:raw_buffer_listing') ||
362
362
  \ empty(s:raw_buffer_listing) ||
363
363
  \ s:refreshBufferList == 1
364
364
  silent let s:raw_buffer_listing = s:BEGetBufferInfo(0)
@@ -396,8 +396,8 @@ endfunction
396
396
 
397
397
  " BEDisplayBufferList {{{1
398
398
  function! s:BEDisplayBufferList()
399
- " Do not set bufhidden since it wipes out
400
- " the data if we switch away from the buffer
399
+ " Do not set bufhidden since it wipes out
400
+ " the data if we switch away from the buffer
401
401
  " using CTRL-^
402
402
  setlocal buftype=nofile
403
403
  setlocal modifiable
@@ -584,7 +584,7 @@ function! s:BEGetBufferInfo(bufnr)
584
584
  redir END
585
585
 
586
586
  if (a:bufnr > 0)
587
- " Since we are only interested in this specified buffer
587
+ " Since we are only interested in this specified buffer
588
588
  " remove the other buffers listed
589
589
  let bufoutput = substitute(bufoutput."\n", '^.*\n\(\s*'.a:bufnr.'\>.\{-}\)\n.*', '\1', '')
590
590
  endif
@@ -601,7 +601,7 @@ function! s:BEGetBufferInfo(bufnr)
601
601
  if len(bits) < 3
602
602
  continue
603
603
  endif
604
-
604
+
605
605
  let b = {"attributes": bits[0], "line": substitute(bits[2], '\s*', '', '')}
606
606
 
607
607
  for [key, val] in items(s:types)
@@ -657,7 +657,7 @@ function! s:BEBuildBufferList()
657
657
  endif
658
658
  endfor
659
659
 
660
- if show_buffer == 0
660
+ if show_buffer == 0
661
661
  continue
662
662
  endif
663
663
  endif
@@ -714,7 +714,7 @@ function! s:BESelectBuffer(...)
714
714
  else
715
715
  call WinManagerFileEdit(bufname, 0)
716
716
  endif
717
-
717
+
718
718
  return
719
719
  endif
720
720
 
@@ -823,7 +823,7 @@ function! s:BERemoveBuffer(type, mode) range
823
823
  if bufNbr !~ '^\d\+$' || getbufvar(bufNbr+0, '&modified') != 0
824
824
  call s:BEError("Sorry, no write since last change for buffer ".bufNbr.", unable to delete")
825
825
  else
826
- let _bufNbrs = _bufNbrs . (_bufNbrs==''?'':' '). bufNbr
826
+ let _bufNbrs = _bufNbrs . (_bufNbrs==''?'':' '). bufNbr
827
827
  endif
828
828
  endif
829
829
  endfor
@@ -345,22 +345,22 @@ endfun
345
345
 
346
346
  " ---------------------------------------------------------------------
347
347
  " ListWinPosn:
348
- "fun! ListWinPosn() " Decho
349
- " if !exists("b:cecutil_iwinposn") || b:cecutil_iwinposn == 0 " Decho
348
+ "fun! ListWinPosn() " Decho
349
+ " if !exists("b:cecutil_iwinposn") || b:cecutil_iwinposn == 0 " Decho
350
350
  " call Decho("nothing on SWP stack") " Decho
351
351
  " else " Decho
352
- " let jwinposn= b:cecutil_iwinposn " Decho
353
- " while jwinposn >= 1 " Decho
354
- " if exists("b:cecutil_winposn{jwinposn}") " Decho
355
- " call Decho("winposn{".jwinposn."}<".b:cecutil_winposn{jwinposn}.">") " Decho
356
- " else " Decho
357
- " call Decho("winposn{".jwinposn."} -- doesn't exist") " Decho
358
- " endif " Decho
359
- " let jwinposn= jwinposn - 1 " Decho
360
- " endwhile " Decho
352
+ " let jwinposn= b:cecutil_iwinposn " Decho
353
+ " while jwinposn >= 1 " Decho
354
+ " if exists("b:cecutil_winposn{jwinposn}") " Decho
355
+ " call Decho("winposn{".jwinposn."}<".b:cecutil_winposn{jwinposn}.">") " Decho
356
+ " else " Decho
357
+ " call Decho("winposn{".jwinposn."} -- doesn't exist") " Decho
358
+ " endif " Decho
359
+ " let jwinposn= jwinposn - 1 " Decho
360
+ " endwhile " Decho
361
361
  " endif " Decho
362
- "endfun " Decho
363
- "com! -nargs=0 LWP call ListWinPosn() " Decho
362
+ "endfun " Decho
363
+ "com! -nargs=0 LWP call ListWinPosn() " Decho
364
364
 
365
365
  " ---------------------------------------------------------------------
366
366
  " SaveUserMaps: this function sets up a script-variable (s:restoremap) {{{1
@@ -402,7 +402,7 @@ fun! SaveUserMaps(mapmode,maplead,mapchx,suffix)
402
402
  let dounmap= 0
403
403
  let mapmode= a:mapmode
404
404
  endif
405
-
405
+
406
406
  " save single map :...something...
407
407
  if strpart(a:mapchx,0,1) == ':'
408
408
  let amap= strpart(a:mapchx,1)
@@ -418,7 +418,7 @@ fun! SaveUserMaps(mapmode,maplead,mapchx,suffix)
418
418
  if dounmap
419
419
  exe "silent! ".mapmode."unmap ".amap
420
420
  endif
421
-
421
+
422
422
  " save single map <something>
423
423
  elseif strpart(a:mapchx,0,1) == '<'
424
424
  let amap = a:mapchx
@@ -433,7 +433,7 @@ fun! SaveUserMaps(mapmode,maplead,mapchx,suffix)
433
433
  if dounmap
434
434
  exe "silent! ".mapmode."unmap ".amap
435
435
  endif
436
-
436
+
437
437
  " save multiple maps
438
438
  else
439
439
  let i= 1
@@ -42,7 +42,7 @@ function! Foldsearch(search)
42
42
  else
43
43
  "Default value, suitable for Ruby scripts
44
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' .
45
+ let searchre = '\v(^\s*(def|class|module|attr_reader|attr_accessor|alias_method)\s' .
46
46
  \ '|^\s*\w+attr_(reader|accessor)\s|^\s*[#%"0-9]{0,4}\s*\{(\{\{|!!))' .
47
47
  \ '|^\s*[A-Z]\w+\s*\='
48
48
  let b:foldsearchexpr = searchre
@@ -72,12 +72,12 @@ endfunction
72
72
  command! -nargs=? -complete=command Fs call Foldsearch(<q-args>)
73
73
  command! -nargs=? -complete=command Fold call Foldsearch(<q-args>)
74
74
  "command! R Fs \(^\s*\(\(def\|class\|module\)\s\)\)\|^\s*[#%"0-9]\{0,4\}\s*{\({{\|!!\)
75
- command! R Fs
75
+ command! R Fs
76
76
 
77
77
  "{{{ Ruby block delimiter conversion: do end <=> { }
78
78
  "Copyright © 2005 Mauricio Fernandez
79
79
  "Subject to same licensing terms as Ruby.
80
- " requires matchit and friends
80
+ " requires matchit and friends
81
81
  " since it uses the % and = bindings
82
82
  function! s:String_Strip(str)
83
83
  let s = substitute(a:str, '\v^\s*', '', '')
@@ -97,24 +97,24 @@ function! s:RubyBlockBraceToDoEnd(lineno)
97
97
  let nextline = substitute(orig, '\v[^{]*\v\s*\{\s*(\|[^|]*\|)?', '', '')
98
98
  let nextline = substitute(nextline, '\}[^}]*$', '', '')
99
99
  let numlines = 0
100
-
100
+
101
101
 
102
102
  " uncomment one of the following:
103
-
103
+
104
104
  " (1) just insert the body without splitting the lines on ;
105
105
  "call append(a:lineno, nextline)
106
106
  "call append(a:lineno+1, 'end' . suffix)
107
107
  "
108
-
108
+
109
109
  " (2) try to split on ; ...
110
110
  call append(a:lineno, 'end' . suffix)
111
- " this is what we would want to do:
111
+ " this is what we would want to do:
112
112
  "let nextline = substitute(nextline, ';', "\n", 'g')
113
-
113
+
114
114
  while stridx(nextline, ";") != -1
115
115
  let eom = stridx(nextline, ";")
116
116
  let line = s:String_Strip(strpart(nextline, 0, eom))
117
- call append(a:lineno + numlines, line)
117
+ call append(a:lineno + numlines, line)
118
118
  let numlines = numlines + 1
119
119
  let nextline = strpart(nextline, eom+1, strlen(nextline) - eom - 1)
120
120
  endwhile
@@ -152,7 +152,7 @@ function! s:RubyBlockDoEndToBrace(_firstline, _lastline)
152
152
  let l = substitute(getline(a:_lastline), '\v^\s*end(\.|\s|$)@=', ' }', '')
153
153
  let l = substitute(l, '\s*$', '', '')
154
154
  let orig = orig . l
155
-
155
+
156
156
  "echo orig
157
157
  "input(orig)
158
158
  let repl = substitute(orig, '\v\s*do\s*(\|[^|]*\|)?', ' { \1 ', '')
@@ -176,7 +176,7 @@ function! <SID>RubyBlockSwitchDelimiters() range
176
176
  if braceidx != -1 && (doidx == -1 || braceidx < doidx)
177
177
  call s:RubyBlockBraceToDoEnd(a:firstline)
178
178
  elseif doidx != -1
179
- execute 'normal /\<do\>' . "\n" . 'V%:call ' .
179
+ execute 'normal /\<do\>' . "\n" . 'V%:call ' .
180
180
  \ s:sid . 'RubyBlockSwitchDelimiters()' . "\n"
181
181
  else
182
182
  echo "No block found"
@@ -212,7 +212,7 @@ if !exists('loaded_taglist')
212
212
  if !exists('Tlist_Auto_Highlight_Tag')
213
213
  let Tlist_Auto_Highlight_Tag = 1
214
214
  endif
215
-
215
+
216
216
  " Automatically highlight the current tag on entering a buffer
217
217
  if !exists('Tlist_Highlight_Tag_On_BufEnter')
218
218
  let Tlist_Highlight_Tag_On_BufEnter = 1
@@ -350,7 +350,7 @@ let loaded_taglist = 'available'
350
350
  " Variable name format:
351
351
  "
352
352
  " s:tlist_def_{vim_ftype}_settings
353
- "
353
+ "
354
354
  " vim_ftype - Filetype detected by Vim
355
355
  "
356
356
  " Value format:
@@ -670,7 +670,7 @@ function! s:Tlist_Log_Msg(msg)
670
670
  if len > 3000
671
671
  let s:tlist_msg = strpart(s:tlist_msg, len - 3000)
672
672
  endif
673
- let s:tlist_msg = s:tlist_msg . strftime('%H:%M:%S') . ': ' .
673
+ let s:tlist_msg = s:tlist_msg . strftime('%H:%M:%S') . ': ' .
674
674
  \ a:msg . "\n"
675
675
  endif
676
676
  endif
@@ -2419,7 +2419,7 @@ function! s:Tlist_Process_File(filename, ftype)
2419
2419
  let s:tlist_{fidx}_tag_count = tidx
2420
2420
  endif
2421
2421
 
2422
- call s:Tlist_Log_Msg('Processed ' . s:tlist_{fidx}_tag_count .
2422
+ call s:Tlist_Log_Msg('Processed ' . s:tlist_{fidx}_tag_count .
2423
2423
  \ ' tags in ' . a:filename)
2424
2424
 
2425
2425
  return fidx
@@ -37,7 +37,7 @@ if (foo)
37
37
  if (bar)
38
38
  /*
39
39
  * Comment on something. Comment on something. Comment on something.
40
- * Comment on something. Comment on something.
40
+ * Comment on something. Comment on something.
41
41
  *
42
42
  */
43
43
  yo;
@@ -67,7 +67,7 @@ while (false) /* never do it */
67
67
  ;
68
68
 
69
69
 
70
- /***
70
+ /***
71
71
  *
72
72
  * blah
73
73
  */
@@ -68,7 +68,7 @@ syntax keyword javaScriptPrototype prototype
68
68
 
69
69
  "" Programm Keywords
70
70
  syntax keyword javaScriptSource import export
71
- syntax keyword javaScriptType const this undefined var void yield
71
+ syntax keyword javaScriptType const this undefined var void yield
72
72
  syntax keyword javaScriptOperator delete new in instanceof let typeof
73
73
  syntax keyword javaScriptBoolean true false
74
74
  syntax keyword javaScriptNull null
@@ -138,7 +138,7 @@ endif "DOM/HTML/CSS
138
138
  syntax cluster javaScriptAll contains=javaScriptComment,javaScriptLineComment,javaScriptDocComment,javaScriptStringD,javaScriptStringS,javaScriptRegexpString,javaScriptNumber,javaScriptFloat,javaScriptLabel,javaScriptSource,javaScriptType,javaScriptOperator,javaScriptBoolean,javaScriptNull,javaScriptFunction,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptStatement,javaScriptGlobalObjects,javaScriptExceptions,javaScriptFutureKeys,javaScriptDomErrNo,javaScriptDomNodeConsts,javaScriptHtmlEvents,javaScriptDotNotation
139
139
  syntax region javaScriptBracket matchgroup=javaScriptBracket transparent start="\[" end="\]" contains=@javaScriptAll,javaScriptParensErrB,javaScriptParensErrC,javaScriptBracket,javaScriptParen,javaScriptBlock,@htmlPreproc
140
140
  syntax region javaScriptParen matchgroup=javaScriptParen transparent start="(" end=")" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrC,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
141
- syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
141
+ syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc
142
142
 
143
143
  "" catch errors caused by wrong parenthesis
144
144
  syntax match javaScriptParensError ")\|}\|\]"
@@ -33,10 +33,10 @@ syntax keyword ocKeyword and bitor xor compl bitand and_eq or_eq xor_eq not not_
33
33
  syntax keyword ocKeyword static_cast dynamic_cast
34
34
 
35
35
  " D Keywords
36
- syntax keyword ocType wchar dchar bit byte ubyte ushort uint ulong cent ucent
36
+ syntax keyword ocType wchar dchar bit byte ubyte ushort uint ulong cent ucent
37
37
  syntax keyword ocType cfloat ifloat cdouble idouble real creal ireal
38
38
  syntax keyword ocKeyword abstract alias align asm assert body cast debug delegate
39
- syntax keyword ocKeyword deprecated export final finally foreach function import in inout
39
+ syntax keyword ocKeyword deprecated export final finally foreach function import in inout
40
40
  syntax keyword ocKeyword interface invariant is mixin module out override package pragma
41
41
  syntax keyword ocKeyword super synchronized typeof unittest version with
42
42
 
@@ -161,5 +161,5 @@ hi link fsmKeyword Keyword
161
161
  hi link anyLabel Label
162
162
  hi link caseLabelKeyword Keyword
163
163
  hi link beginRL Type
164
-
164
+
165
165
  let b:current_syntax = "ragel"
@@ -255,7 +255,7 @@ if has("autocmd")
255
255
  autocmd FileType tex map <buffer> <F6> <ESC><F1>:!acroread `echo %\|sed -e 's/tex/pdf/'`<CR><CR>
256
256
  augroup END
257
257
 
258
- augroup c
258
+ augroup c
259
259
  autocmd!
260
260
  autocmd FileType c setl sw=4 ts=4 cinoptions= formatoptions=cqrol cindent
261
261
  autocmd FileType c map <buffer> <F1> <ESC>:make<CR>
@@ -0,0 +1,138 @@
1
+ module Utils
2
+ class Editor
3
+ def initialize
4
+ self.wait = false
5
+ self.pause_duration = 1
6
+ self.servername = "G#{ENV['USER'].upcase}"
7
+ yield self if block_given?
8
+ end
9
+
10
+ attr_accessor :pause_duration
11
+
12
+ attr_accessor :wait
13
+
14
+ attr_accessor :servername
15
+
16
+ alias wait? wait
17
+
18
+ def vim
19
+ @vim ||= case `uname -s`
20
+ when /\Adarwin/i
21
+ if File.directory?('/Applications')
22
+ '/Applications/MacVim.app/Contents/MacOS/Vim'
23
+ else
24
+ 'gvim'
25
+ end
26
+ else
27
+ 'gvim'
28
+ end
29
+ end
30
+
31
+ def cmd(*parts)
32
+ command = parts.inject([]) do |a, p|
33
+ case
34
+ when p == nil, p == []
35
+ a
36
+ when p.respond_to?(:to_ary)
37
+ a.concat p.to_ary
38
+ else
39
+ a << p.to_s
40
+ end
41
+ end
42
+ $DEBUG and warn command * ' '
43
+ system *command
44
+ end
45
+
46
+ def fullscreen=(enabled)
47
+ started? or start
48
+ sleep pause_duration
49
+ if enabled
50
+ edit_remote_send '<ESC>:set fullscreen<CR>'
51
+ else
52
+ edit_remote_send '<ESC>:set nofullscreen<CR>'
53
+ end
54
+ activate
55
+ end
56
+
57
+ def file_linenumber?(filename)
58
+ filename.match(/^\s*([^:]+):(\d+)/)
59
+ end
60
+
61
+ def edit(*filenames)
62
+ if filenames.size == 1
63
+ filename = filenames.first
64
+ if m = file_linenumber?(filename)
65
+ edit_file_linenumber(*m.captures)
66
+ else
67
+ edit_file(filename)
68
+ end
69
+ else
70
+ edit_file(*filenames)
71
+ end
72
+ end
73
+
74
+ def edit_file(*filenames)
75
+ edit_remote_file(*filenames)
76
+ end
77
+
78
+ def edit_file_linenumber(filename, linenumber)
79
+ if wait?
80
+ edit_remote(filename)
81
+ sleep pause_duration
82
+ edit_remote_send("<ESC>:#{linenumber}<CR>")
83
+ edit_remote_wait(filename)
84
+ else
85
+ edit_remote(filename)
86
+ sleep pause_duration
87
+ edit_remote_send("<ESC>:#{linenumber}<CR>")
88
+ end
89
+ end
90
+
91
+ def ensure_running
92
+ started? ? activate : start
93
+ self
94
+ end
95
+
96
+ def start
97
+ cmd(vim, '-g', '--servername', servername)
98
+ end
99
+
100
+ def stop
101
+ started? and edit_remote_send('<ESC>:qa<CR>')
102
+ end
103
+
104
+ def activate
105
+ edit_remote("stupid_trick#{rand}")
106
+ sleep pause_duration
107
+ edit_remote_send('<ESC>:bw<CR>')
108
+ end
109
+
110
+ def serverlist
111
+ @serverlist ||= `#{vim} -g --serverlist`.split
112
+ end
113
+
114
+ def started?(name = servername)
115
+ serverlist.member?(name)
116
+ end
117
+
118
+ def edit_remote(*args)
119
+ cmd(vim, '-g', '--servername', servername, '--remote', *args)
120
+ end
121
+
122
+ def edit_remote_wait(*args)
123
+ cmd(vim, '-g', '--servername', servername, '--remote-wait', *args)
124
+ end
125
+
126
+ def edit_remote_send(*args)
127
+ cmd(vim, '-g', '--servername', servername, '--remote-send', *args)
128
+ end
129
+
130
+ def edit_remote_file(*filenames)
131
+ if wait?
132
+ edit_remote_wait(*filenames)
133
+ else
134
+ edit_remote(*filenames)
135
+ end
136
+ end
137
+ end
138
+ end