utils 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +68 -0
- data/VERSION +1 -0
- data/bin/chroot-exec +12 -0
- data/bin/chroot-libs +18 -0
- data/bin/classify +37 -0
- data/bin/discover +137 -0
- data/bin/edit +74 -0
- data/bin/errf +32 -0
- data/bin/git-empty +8 -0
- data/bin/myex +90 -0
- data/bin/number_files +26 -0
- data/bin/same_files +37 -0
- data/bin/search +205 -0
- data/bin/sedit +3 -0
- data/bin/sshscreen +68 -0
- data/bin/term +21 -0
- data/bin/unquarantine_apps +8 -0
- data/bin/untest +17 -0
- data/bin/utils-install-config +10 -0
- data/bin/vacuum_firefox_sqlite +22 -0
- data/bin/xmp +74 -0
- data/lib/utils.rb +8 -0
- data/lib/utils/config.rb +23 -0
- data/lib/utils/config/gdb/asm +179 -0
- data/lib/utils/config/gdb/ruby +528 -0
- data/lib/utils/config/gdbinit +8 -0
- data/lib/utils/config/irbrc +455 -0
- data/lib/utils/config/rdebugrc +2 -0
- data/lib/utils/config/screenrc +143 -0
- data/lib/utils/config/vim/autoload/Align.vim +1029 -0
- data/lib/utils/config/vim/autoload/AlignMaps.vim +330 -0
- data/lib/utils/config/vim/autoload/rails.vim +4744 -0
- data/lib/utils/config/vim/autoload/rubycomplete.vim +801 -0
- data/lib/utils/config/vim/autoload/sqlcomplete.vim +741 -0
- data/lib/utils/config/vim/autoload/vimball.vim +750 -0
- data/lib/utils/config/vim/colors/flori.vim +113 -0
- data/lib/utils/config/vim/compiler/eruby.vim +40 -0
- data/lib/utils/config/vim/compiler/ruby.vim +67 -0
- data/lib/utils/config/vim/compiler/rubyunit.vim +34 -0
- data/lib/utils/config/vim/ftdetect/ragel.vim +2 -0
- data/lib/utils/config/vim/ftdetect/ruby.vim +17 -0
- data/lib/utils/config/vim/ftplugin/eruby.vim +100 -0
- data/lib/utils/config/vim/ftplugin/ruby.vim +260 -0
- data/lib/utils/config/vim/ftplugin/xml.vim +941 -0
- data/lib/utils/config/vim/indent/IndentAnything_html.vim +35 -0
- data/lib/utils/config/vim/indent/eruby.vim +77 -0
- data/lib/utils/config/vim/indent/javascript.vim +116 -0
- data/lib/utils/config/vim/indent/ruby.vim +377 -0
- data/lib/utils/config/vim/plugin/AlignMapsPlugin.vim +242 -0
- data/lib/utils/config/vim/plugin/AlignPlugin.vim +41 -0
- data/lib/utils/config/vim/plugin/Decho.vim +592 -0
- data/lib/utils/config/vim/plugin/IndentAnything.vim +675 -0
- data/lib/utils/config/vim/plugin/bufexplorer.vim +1144 -0
- data/lib/utils/config/vim/plugin/cecutil.vim +482 -0
- data/lib/utils/config/vim/plugin/fugitive.vim +1703 -0
- data/lib/utils/config/vim/plugin/lusty-explorer.vim +1509 -0
- data/lib/utils/config/vim/plugin/rails.vim +340 -0
- data/lib/utils/config/vim/plugin/rubyextra.vim +193 -0
- data/lib/utils/config/vim/plugin/surround.vim +628 -0
- data/lib/utils/config/vim/plugin/taglist.vim +4546 -0
- data/lib/utils/config/vim/plugin/test/IndentAnything/test.js +131 -0
- data/lib/utils/config/vim/plugin/vimballPlugin.vim +40 -0
- data/lib/utils/config/vim/syntax/Decho.vim +101 -0
- data/lib/utils/config/vim/syntax/eruby.vim +73 -0
- data/lib/utils/config/vim/syntax/javascript.vim +246 -0
- data/lib/utils/config/vim/syntax/ragel.vim +165 -0
- data/lib/utils/config/vim/syntax/ruby.vim +367 -0
- data/lib/utils/config/vimrc +461 -0
- data/lib/utils/file.rb +49 -0
- data/lib/utils/find.rb +54 -0
- data/lib/utils/md5.rb +23 -0
- data/lib/utils/patterns.rb +34 -0
- data/lib/utils/version.rb +8 -0
- data/utils.gemspec +33 -0
- metadata +183 -0
@@ -0,0 +1,1144 @@
|
|
1
|
+
"==============================================================================
|
2
|
+
" Copyright: Copyright (C) 2001-2010 Jeff Lanzarotta
|
3
|
+
" Permission is hereby granted to use and distribute this code,
|
4
|
+
" with or without modifications, provided that this copyright
|
5
|
+
" notice is copied with it. Like anything else that's free,
|
6
|
+
" bufexplorer.vim is provided *as is* and comes with no
|
7
|
+
" warranty of any kind, either expressed or implied. In no
|
8
|
+
" event will the copyright holder be liable for any damages
|
9
|
+
" resulting from the use of this software.
|
10
|
+
" Name Of File: bufexplorer.vim
|
11
|
+
" Description: Buffer Explorer Vim Plugin
|
12
|
+
" Maintainer: Jeff Lanzarotta (delux256-vim at yahoo dot com)
|
13
|
+
" Last Changed: Tuesday, 16 Feb 2010
|
14
|
+
" Version: See g:bufexplorer_version for version number.
|
15
|
+
" Usage: This file should reside in the plugin directory and be
|
16
|
+
" automatically sourced.
|
17
|
+
"
|
18
|
+
" You may use the default keymappings of
|
19
|
+
"
|
20
|
+
" <Leader>be - Opens BE.
|
21
|
+
" <Leader>bs - Opens horizontally window BE.
|
22
|
+
" <Leader>bv - Opens vertically window BE.
|
23
|
+
"
|
24
|
+
" Or you can use
|
25
|
+
"
|
26
|
+
" ":BufExplorer" - Opens BE.
|
27
|
+
" ":BufExplorerHorizontalSplit" - Opens horizontally window BE.
|
28
|
+
" ":BufExplorerVerticalSplit" - Opens vertically window BE.
|
29
|
+
"
|
30
|
+
" For more help see supplied documentation.
|
31
|
+
" History: See supplied documentation.
|
32
|
+
"==============================================================================
|
33
|
+
|
34
|
+
" Exit quickly if already running or when 'compatible' is set. {{{1
|
35
|
+
if exists("g:bufexplorer_version") || &cp
|
36
|
+
finish
|
37
|
+
endif
|
38
|
+
"1}}}
|
39
|
+
|
40
|
+
" Version number
|
41
|
+
let g:bufexplorer_version = "7.2.7"
|
42
|
+
|
43
|
+
" Check for Vim version 700 or greater {{{1
|
44
|
+
if v:version < 700
|
45
|
+
echo "Sorry, bufexplorer ".g:bufexplorer_version."\nONLY runs with Vim 7.0 and greater."
|
46
|
+
finish
|
47
|
+
endif
|
48
|
+
|
49
|
+
" Public Interface {{{1
|
50
|
+
if maparg("<Leader>be") =~ 'BufExplorer'
|
51
|
+
nunmap <Leader>be
|
52
|
+
endif
|
53
|
+
|
54
|
+
if maparg("<Leader>bs") =~ 'BufExplorerHorizontalSplit'
|
55
|
+
nunmap <Leader>bs
|
56
|
+
endif
|
57
|
+
|
58
|
+
if maparg("<Leader>bv") =~ 'BufExplorerVerticalSplit'
|
59
|
+
nunmap <Leader>bv
|
60
|
+
endif
|
61
|
+
|
62
|
+
nmap <script> <silent> <unique> <Leader>be :BufExplorer<CR>
|
63
|
+
nmap <script> <silent> <unique> <Leader>bs :BufExplorerHorizontalSplit<CR>
|
64
|
+
nmap <script> <silent> <unique> <Leader>bv :BufExplorerVerticalSplit<CR>
|
65
|
+
|
66
|
+
" Create commands {{{1
|
67
|
+
command! BufExplorer :call StartBufExplorer(has ("gui") ? "drop" : "hide edit")
|
68
|
+
command! BufExplorerHorizontalSplit :call BufExplorerHorizontalSplit()
|
69
|
+
command! BufExplorerVerticalSplit :call BufExplorerVerticalSplit()
|
70
|
+
|
71
|
+
" BESet {{{1
|
72
|
+
function! s:BESet(var, default)
|
73
|
+
if !exists(a:var)
|
74
|
+
if type(a:default)
|
75
|
+
exec "let" a:var "=" string(a:default)
|
76
|
+
else
|
77
|
+
exec "let" a:var "=" a:default
|
78
|
+
endif
|
79
|
+
|
80
|
+
return 1
|
81
|
+
endif
|
82
|
+
|
83
|
+
return 0
|
84
|
+
endfunction
|
85
|
+
|
86
|
+
" BEReset {{{1
|
87
|
+
function! s:BEReset()
|
88
|
+
" Build initial MRUList. This makes sure all the files specified on the
|
89
|
+
" command line are picked up correctly.
|
90
|
+
let s:MRUList = range(1, bufnr('$'))
|
91
|
+
|
92
|
+
" Initialize one tab space array, ignore zero-based tabpagenr
|
93
|
+
" since all tabpagenr's start at 1.
|
94
|
+
" -1 signifies this is the first time we are referencing this
|
95
|
+
" tabpagenr.
|
96
|
+
let s:tabSpace = [ [-1], [-1] ]
|
97
|
+
endfunction
|
98
|
+
|
99
|
+
" Setup the autocommands that handle the MRUList and other stuff. {{{1
|
100
|
+
" This is only done once when Vim starts up.
|
101
|
+
augroup BufExplorerVimEnter
|
102
|
+
autocmd!
|
103
|
+
autocmd VimEnter * call s:BESetup()
|
104
|
+
augroup END
|
105
|
+
|
106
|
+
" BESetup {{{1
|
107
|
+
function! s:BESetup()
|
108
|
+
call s:BEReset()
|
109
|
+
|
110
|
+
" Now that the MRUList is created, add the other autocmds.
|
111
|
+
augroup BufExplorer
|
112
|
+
" Deleting autocommands in case the script is reloaded
|
113
|
+
autocmd!
|
114
|
+
autocmd TabEnter * call s:BETabEnter()
|
115
|
+
autocmd BufNew * call s:BEAddBuffer()
|
116
|
+
autocmd BufEnter * call s:BEActivateBuffer()
|
117
|
+
|
118
|
+
autocmd BufWipeOut * call s:BEDeactivateBuffer(1)
|
119
|
+
autocmd BufDelete * call s:BEDeactivateBuffer(0)
|
120
|
+
|
121
|
+
autocmd BufWinEnter \[BufExplorer\] call s:BEInitialize()
|
122
|
+
autocmd BufWinLeave \[BufExplorer\] call s:BECleanup()
|
123
|
+
autocmd SessionLoadPost * call s:BEReset()
|
124
|
+
augroup END
|
125
|
+
|
126
|
+
" Remove the VimEnter event as it is no longer needed
|
127
|
+
augroup SelectBufVimEnter
|
128
|
+
autocmd!
|
129
|
+
augroup END
|
130
|
+
endfunction
|
131
|
+
|
132
|
+
" BETabEnter {{{1
|
133
|
+
function! s:BETabEnter()
|
134
|
+
" Make s:tabSpace 1-based
|
135
|
+
if empty(s:tabSpace) || len(s:tabSpace) < (tabpagenr() + 1)
|
136
|
+
call add(s:tabSpace, [-1])
|
137
|
+
endif
|
138
|
+
endfunction
|
139
|
+
|
140
|
+
" BEAddBuffer {{{1
|
141
|
+
function! s:BEAddBuffer()
|
142
|
+
if !exists('s:raw_buffer_listing') || empty(s:raw_buffer_listing)
|
143
|
+
silent let s:raw_buffer_listing = s:BEGetBufferInfo(0)
|
144
|
+
else
|
145
|
+
" We cannot use :buffers! or :ls! to gather information
|
146
|
+
" about this buffer since it was only just added.
|
147
|
+
" Any changes to the buffer (setlocal buftype, ...)
|
148
|
+
" happens after this event fires.
|
149
|
+
"
|
150
|
+
" So we will indicate the :buffers! command must be re-run.
|
151
|
+
" This should help with the performance of the plugin.
|
152
|
+
|
153
|
+
" There are some checks which can be performed
|
154
|
+
" before deciding to refresh the buffer list.
|
155
|
+
let bufnr = expand('<abuf>') + 0
|
156
|
+
|
157
|
+
if s:BEIgnoreBuffer(bufnr) == 1
|
158
|
+
return
|
159
|
+
else
|
160
|
+
let s:refreshBufferList = 1
|
161
|
+
endif
|
162
|
+
endif
|
163
|
+
|
164
|
+
call s:BEActivateBuffer()
|
165
|
+
endfunction
|
166
|
+
|
167
|
+
" ActivateBuffer {{{1
|
168
|
+
function! s:BEActivateBuffer()
|
169
|
+
let b = bufnr("%")
|
170
|
+
let l = get(s:tabSpace, tabpagenr(), [])
|
171
|
+
|
172
|
+
if s:BEIgnoreBuffer(b) == 1
|
173
|
+
return
|
174
|
+
endif
|
175
|
+
|
176
|
+
if !empty(l) && l[0] == '-1'
|
177
|
+
" The first time we add a tab Vim uses the current
|
178
|
+
" buffer as it's starting page, even though we are about
|
179
|
+
" to edit a new page (BufEnter triggers after), so
|
180
|
+
" remove the -1 entry indicating we have covered this case.
|
181
|
+
let l = []
|
182
|
+
let s:tabSpace[tabpagenr()] = l
|
183
|
+
elseif empty(l) || index(l, b) == -1
|
184
|
+
" Add new buffer to this tab buffer list
|
185
|
+
let l = add(l, b)
|
186
|
+
let s:tabSpace[tabpagenr()] = l
|
187
|
+
|
188
|
+
if g:bufExplorerOnlyOneTab == 1
|
189
|
+
" If a buffer can only be available in 1 tab page
|
190
|
+
" ensure this buffer is not present in any other tabs
|
191
|
+
let tabidx = 1
|
192
|
+
while tabidx < len(s:tabSpace)
|
193
|
+
if tabidx != tabpagenr()
|
194
|
+
let bufidx = index(s:tabSpace[tabidx], b)
|
195
|
+
if bufidx != -1
|
196
|
+
call remove(s:tabSpace[tabidx], bufidx)
|
197
|
+
endif
|
198
|
+
endif
|
199
|
+
let tabidx = tabidx + 1
|
200
|
+
endwhile
|
201
|
+
endif
|
202
|
+
endif
|
203
|
+
|
204
|
+
call s:BEMRUPush(b)
|
205
|
+
|
206
|
+
if exists('s:raw_buffer_listing') && !empty(s:raw_buffer_listing)
|
207
|
+
" Check if the buffer exists, but was deleted previously
|
208
|
+
" Careful use of ' and " so we do not have to escape all the \'s
|
209
|
+
" Regex: ^\s*bu\>
|
210
|
+
" ^ - Starting at the beginning of the string
|
211
|
+
" \s* - optional whitespace
|
212
|
+
" b - Vim's buffer number
|
213
|
+
" u\> - the buffer must be unlisted
|
214
|
+
let shortlist = filter(copy(s:raw_buffer_listing), "v:val.attributes =~ '".'^\s*'.b.'u\>'."'")
|
215
|
+
|
216
|
+
if !empty(shortlist)
|
217
|
+
" If it is unlisted (ie deleted), but now we editing it again
|
218
|
+
" rebuild the buffer list.
|
219
|
+
let s:refreshBufferList = 1
|
220
|
+
endif
|
221
|
+
endif
|
222
|
+
endfunction
|
223
|
+
|
224
|
+
" BEDeactivateBuffer {{{1
|
225
|
+
function! s:BEDeactivateBuffer(remove)
|
226
|
+
let _bufnr = str2nr(expand("<abuf>"))
|
227
|
+
|
228
|
+
call s:BEMRUPop(_bufnr)
|
229
|
+
|
230
|
+
if a:remove
|
231
|
+
call s:BEDeleteBufferListing(_bufnr)
|
232
|
+
else
|
233
|
+
let s:refreshBufferList = 1
|
234
|
+
endif
|
235
|
+
endfunction
|
236
|
+
|
237
|
+
" BEMRUPop {{{1
|
238
|
+
function! s:BEMRUPop(buf)
|
239
|
+
call filter(s:MRUList, 'v:val != '.a:buf)
|
240
|
+
endfunction
|
241
|
+
|
242
|
+
" BEMRUPush {{{1
|
243
|
+
function! s:BEMRUPush(buf)
|
244
|
+
if s:BEIgnoreBuffer(a:buf) == 1
|
245
|
+
return
|
246
|
+
endif
|
247
|
+
|
248
|
+
" Remove the buffer number from the list if it already exists.
|
249
|
+
call s:BEMRUPop(a:buf)
|
250
|
+
|
251
|
+
" Add the buffer number to the head of the list.
|
252
|
+
call insert(s:MRUList,a:buf)
|
253
|
+
endfunction
|
254
|
+
|
255
|
+
" BEInitialize {{{1
|
256
|
+
function! s:BEInitialize()
|
257
|
+
let s:_insertmode = &insertmode
|
258
|
+
set noinsertmode
|
259
|
+
|
260
|
+
let s:_showcmd = &showcmd
|
261
|
+
set noshowcmd
|
262
|
+
|
263
|
+
let s:_cpo = &cpo
|
264
|
+
set cpo&vim
|
265
|
+
|
266
|
+
let s:_report = &report
|
267
|
+
let &report = 10000
|
268
|
+
|
269
|
+
let s:_list = &list
|
270
|
+
set nolist
|
271
|
+
|
272
|
+
setlocal nonumber
|
273
|
+
setlocal foldcolumn=0
|
274
|
+
setlocal nofoldenable
|
275
|
+
setlocal cursorline
|
276
|
+
setlocal nospell
|
277
|
+
setlocal nobuflisted
|
278
|
+
|
279
|
+
let s:running = 1
|
280
|
+
endfunction
|
281
|
+
|
282
|
+
" BEIgnoreBuffer
|
283
|
+
function! s:BEIgnoreBuffer(buf)
|
284
|
+
" Check to see if this buffer should be ignore by BufExplorer.
|
285
|
+
|
286
|
+
" Skip temporary buffers with buftype set.
|
287
|
+
if empty(getbufvar(a:buf, "&buftype") == 0)
|
288
|
+
return 1
|
289
|
+
endif
|
290
|
+
|
291
|
+
" Skip unlisted buffers.
|
292
|
+
if buflisted(a:buf) == 0
|
293
|
+
return 1
|
294
|
+
endif
|
295
|
+
|
296
|
+
" Skip buffers with no name.
|
297
|
+
if empty(bufname(a:buf)) == 1
|
298
|
+
return 1
|
299
|
+
endif
|
300
|
+
|
301
|
+
" Do not add the BufExplorer window to the list.
|
302
|
+
if fnamemodify(bufname(a:buf), ":t") == s:name
|
303
|
+
return 1
|
304
|
+
endif
|
305
|
+
|
306
|
+
if index(s:MRU_Exclude_List, bufname(a:buf)) >= 0
|
307
|
+
return 1
|
308
|
+
end
|
309
|
+
|
310
|
+
return 0
|
311
|
+
endfunction
|
312
|
+
|
313
|
+
" BECleanup {{{1
|
314
|
+
function! s:BECleanup()
|
315
|
+
let &insertmode = s:_insertmode
|
316
|
+
let &showcmd = s:_showcmd
|
317
|
+
let &cpo = s:_cpo
|
318
|
+
let &report = s:_report
|
319
|
+
let &list = s:_list
|
320
|
+
let s:running = 0
|
321
|
+
let s:splitMode = ""
|
322
|
+
|
323
|
+
delmarks!
|
324
|
+
endfunction
|
325
|
+
|
326
|
+
" BufExplorerHorizontalSplit {{{1
|
327
|
+
function! BufExplorerHorizontalSplit()
|
328
|
+
let s:splitMode = "sp"
|
329
|
+
exec "BufExplorer"
|
330
|
+
endfunction
|
331
|
+
|
332
|
+
" BufExplorerVerticalSplit {{{1
|
333
|
+
function! BufExplorerVerticalSplit()
|
334
|
+
let s:splitMode = "vsp"
|
335
|
+
exec "BufExplorer"
|
336
|
+
endfunction
|
337
|
+
|
338
|
+
" StartBufExplorer {{{1
|
339
|
+
function! StartBufExplorer(open)
|
340
|
+
let name = s:name
|
341
|
+
|
342
|
+
if !has("win32")
|
343
|
+
" On non-Windows boxes, escape the name so that is shows up correctly.
|
344
|
+
let name = escape(name, "[]")
|
345
|
+
endif
|
346
|
+
|
347
|
+
" Make sure there is only one explorer open at a time.
|
348
|
+
if s:running == 1
|
349
|
+
" Go to the open buffer.
|
350
|
+
if has("gui")
|
351
|
+
exec "drop" name
|
352
|
+
endif
|
353
|
+
|
354
|
+
return
|
355
|
+
endif
|
356
|
+
|
357
|
+
" Add zero to ensure the variable is treated as a Number.
|
358
|
+
let s:originBuffer = bufnr("%") + 0
|
359
|
+
|
360
|
+
" Create or rebuild the raw buffer list if necessary.
|
361
|
+
if !exists('s:raw_buffer_listing') ||
|
362
|
+
\ empty(s:raw_buffer_listing) ||
|
363
|
+
\ s:refreshBufferList == 1
|
364
|
+
silent let s:raw_buffer_listing = s:BEGetBufferInfo(0)
|
365
|
+
endif
|
366
|
+
|
367
|
+
let copy = copy(s:raw_buffer_listing)
|
368
|
+
|
369
|
+
if (g:bufExplorerShowUnlisted == 0)
|
370
|
+
call filter(copy, 'v:val.attributes !~ "u"')
|
371
|
+
endif
|
372
|
+
|
373
|
+
" We may have to split the current window.
|
374
|
+
if (s:splitMode != "")
|
375
|
+
" Save off the original settings.
|
376
|
+
let [_splitbelow, _splitright] = [&splitbelow, &splitright]
|
377
|
+
|
378
|
+
" Set the setting to ours.
|
379
|
+
let [&splitbelow, &splitright] = [g:bufExplorerSplitBelow, g:bufExplorerSplitRight]
|
380
|
+
|
381
|
+
" Do it.
|
382
|
+
exe 'keepalt '.s:splitMode
|
383
|
+
|
384
|
+
" Restore the original settings.
|
385
|
+
let [&splitbelow, &splitright] = [_splitbelow, _splitright]
|
386
|
+
endif
|
387
|
+
|
388
|
+
if !exists("b:displayMode") || b:displayMode != "winmanager"
|
389
|
+
" Do not use keepalt when opening bufexplorer to allow the buffer that we are
|
390
|
+
" leaving to become the new alternate buffer
|
391
|
+
exec "silent keepjumps ".a:open." ".name
|
392
|
+
endif
|
393
|
+
|
394
|
+
call s:BEDisplayBufferList()
|
395
|
+
endfunction
|
396
|
+
|
397
|
+
" BEDisplayBufferList {{{1
|
398
|
+
function! s:BEDisplayBufferList()
|
399
|
+
" Do not set bufhidden since it wipes out
|
400
|
+
" the data if we switch away from the buffer
|
401
|
+
" using CTRL-^
|
402
|
+
setlocal buftype=nofile
|
403
|
+
setlocal modifiable
|
404
|
+
setlocal noswapfile
|
405
|
+
setlocal nowrap
|
406
|
+
|
407
|
+
" Delete all previous lines to the black hole register
|
408
|
+
call cursor(1,1)
|
409
|
+
exec 'silent! normal! "_dG'
|
410
|
+
|
411
|
+
call s:BESetupSyntax()
|
412
|
+
call s:BEMapKeys()
|
413
|
+
call setline(1, s:BECreateHelp())
|
414
|
+
call s:BEBuildBufferList()
|
415
|
+
call cursor(s:firstBufferLine, 1)
|
416
|
+
|
417
|
+
if !g:bufExplorerResize
|
418
|
+
normal! zz
|
419
|
+
endif
|
420
|
+
|
421
|
+
setlocal nomodifiable
|
422
|
+
endfunction
|
423
|
+
|
424
|
+
" BEMapKeys {{{1
|
425
|
+
function! s:BEMapKeys()
|
426
|
+
if exists("b:displayMode") && b:displayMode == "winmanager"
|
427
|
+
nnoremap <buffer> <silent> <tab> :call <SID>BESelectBuffer("tab")<cr>
|
428
|
+
endif
|
429
|
+
|
430
|
+
nnoremap <buffer> <silent> <F1> :call <SID>BEToggleHelp()<cr>
|
431
|
+
nnoremap <buffer> <silent> <2-leftmouse> :call <SID>BESelectBuffer()<cr>
|
432
|
+
nnoremap <buffer> <silent> <cr> :call <SID>BESelectBuffer()<cr>
|
433
|
+
nnoremap <buffer> <silent> o :call <SID>BESelectBuffer()<cr>
|
434
|
+
nnoremap <buffer> <silent> t :call <SID>BESelectBuffer("tab")<cr>
|
435
|
+
nnoremap <buffer> <silent> <s-cr> :call <SID>BESelectBuffer("tab")<cr>
|
436
|
+
|
437
|
+
nnoremap <buffer> <silent> d :call <SID>BERemoveBuffer("delete", "n")<cr>
|
438
|
+
xnoremap <buffer> <silent> d :call <SID>BERemoveBuffer("delete", "v")<cr>
|
439
|
+
nnoremap <buffer> <silent> D :call <SID>BERemoveBuffer("wipe", "n")<cr>
|
440
|
+
xnoremap <buffer> <silent> D :call <SID>BERemoveBuffer("wipe", "v")<cr>
|
441
|
+
|
442
|
+
nnoremap <buffer> <silent> m :call <SID>BEMRUListShow()<cr>
|
443
|
+
nnoremap <buffer> <silent> p :call <SID>BEToggleSplitOutPathName()<cr>
|
444
|
+
nnoremap <buffer> <silent> q :call <SID>BEClose("quit")<cr>
|
445
|
+
nnoremap <buffer> <silent> r :call <SID>BESortReverse()<cr>
|
446
|
+
nnoremap <buffer> <silent> R :call <SID>BEToggleShowRelativePath()<cr>
|
447
|
+
nnoremap <buffer> <silent> s :call <SID>BESortSelect()<cr>
|
448
|
+
nnoremap <buffer> <silent> S :call <SID>BEReverseSortSelect()<cr>
|
449
|
+
nnoremap <buffer> <silent> u :call <SID>BEToggleShowUnlisted()<cr>
|
450
|
+
nnoremap <buffer> <silent> f :call <SID>BEToggleFindActive()<cr>
|
451
|
+
nnoremap <buffer> <silent> T :call <SID>BEToggleShowTabBuffer()<cr>
|
452
|
+
nnoremap <buffer> <silent> B :call <SID>BEToggleOnlyOneTab()<cr>
|
453
|
+
|
454
|
+
for k in ["G", "n", "N", "L", "M", "H"]
|
455
|
+
exec "nnoremap <buffer> <silent>" k ":keepjumps normal!" k."<cr>"
|
456
|
+
endfor
|
457
|
+
endfunction
|
458
|
+
|
459
|
+
" BESetupSyntax {{{1
|
460
|
+
function! s:BESetupSyntax()
|
461
|
+
if has("syntax")
|
462
|
+
syn match bufExplorerHelp "^\".*" contains=bufExplorerSortBy,bufExplorerMapping,bufExplorerTitle,bufExplorerSortType,bufExplorerToggleSplit,bufExplorerToggleOpen
|
463
|
+
syn match bufExplorerOpenIn "Open in \w\+ window" contained
|
464
|
+
syn match bufExplorerSplit "\w\+ split" contained
|
465
|
+
syn match bufExplorerSortBy "Sorted by .*" contained contains=bufExplorerOpenIn,bufExplorerSplit
|
466
|
+
syn match bufExplorerMapping "\" \zs.\+\ze :" contained
|
467
|
+
syn match bufExplorerTitle "Buffer Explorer.*" contained
|
468
|
+
syn match bufExplorerSortType "'\w\{-}'" contained
|
469
|
+
syn match bufExplorerBufNbr /^\s*\d\+/
|
470
|
+
syn match bufExplorerToggleSplit "toggle split type" contained
|
471
|
+
syn match bufExplorerToggleOpen "toggle open mode" contained
|
472
|
+
syn match bufExplorerModBuf /^\s*\d\+.\{4}+.*/
|
473
|
+
syn match bufExplorerLockedBuf /^\s*\d\+.\{3}[\-=].*/
|
474
|
+
syn match bufExplorerHidBuf /^\s*\d\+.\{2}h.*/
|
475
|
+
syn match bufExplorerActBuf /^\s*\d\+.\{2}a.*/
|
476
|
+
syn match bufExplorerCurBuf /^\s*\d\+.%.*/
|
477
|
+
syn match bufExplorerAltBuf /^\s*\d\+.#.*/
|
478
|
+
syn match bufExplorerUnlBuf /^\s*\d\+u.*/
|
479
|
+
|
480
|
+
hi def link bufExplorerBufNbr Number
|
481
|
+
hi def link bufExplorerMapping NonText
|
482
|
+
hi def link bufExplorerHelp Special
|
483
|
+
hi def link bufExplorerOpenIn Identifier
|
484
|
+
hi def link bufExplorerSortBy String
|
485
|
+
hi def link bufExplorerSplit NonText
|
486
|
+
hi def link bufExplorerTitle NonText
|
487
|
+
hi def link bufExplorerSortType bufExplorerSortBy
|
488
|
+
hi def link bufExplorerToggleSplit bufExplorerSplit
|
489
|
+
hi def link bufExplorerToggleOpen bufExplorerOpenIn
|
490
|
+
|
491
|
+
hi def link bufExplorerActBuf Identifier
|
492
|
+
hi def link bufExplorerAltBuf String
|
493
|
+
hi def link bufExplorerCurBuf Type
|
494
|
+
hi def link bufExplorerHidBuf Constant
|
495
|
+
hi def link bufExplorerLockedBuf Special
|
496
|
+
hi def link bufExplorerModBuf Exception
|
497
|
+
hi def link bufExplorerUnlBuf Comment
|
498
|
+
endif
|
499
|
+
endfunction
|
500
|
+
|
501
|
+
" BEToggleHelp {{{1
|
502
|
+
function! s:BEToggleHelp()
|
503
|
+
let g:bufExplorerDetailedHelp = !g:bufExplorerDetailedHelp
|
504
|
+
|
505
|
+
setlocal modifiable
|
506
|
+
|
507
|
+
" Save position.
|
508
|
+
normal! ma
|
509
|
+
|
510
|
+
" Remove old header.
|
511
|
+
if (s:firstBufferLine > 1)
|
512
|
+
exec "keepjumps 1,".(s:firstBufferLine - 1) "d _"
|
513
|
+
endif
|
514
|
+
|
515
|
+
call append(0, s:BECreateHelp())
|
516
|
+
|
517
|
+
silent! normal! g`a
|
518
|
+
delmarks a
|
519
|
+
|
520
|
+
setlocal nomodifiable
|
521
|
+
|
522
|
+
if exists("b:displayMode") && b:displayMode == "winmanager"
|
523
|
+
call WinManagerForceReSize("BufExplorer")
|
524
|
+
endif
|
525
|
+
endfunction
|
526
|
+
|
527
|
+
" BEGetHelpStatus {{{1
|
528
|
+
function! s:BEGetHelpStatus()
|
529
|
+
let ret = '" Sorted by '.((g:bufExplorerReverseSort == 1) ? "reverse " : "").g:bufExplorerSortBy
|
530
|
+
let ret .= ' | '.((g:bufExplorerFindActive == 0) ? "Don't " : "")."Locate buffer"
|
531
|
+
let ret .= ((g:bufExplorerShowUnlisted == 0) ? "" : " | Show unlisted")
|
532
|
+
let ret .= ((g:bufExplorerShowTabBuffer == 0) ? "" : " | Show buffers/tab")
|
533
|
+
let ret .= ((g:bufExplorerOnlyOneTab == 1) ? "" : " | One tab / buffer")
|
534
|
+
let ret .= ' | '.((g:bufExplorerShowRelativePath == 0) ? "Absolute" : "Relative")
|
535
|
+
let ret .= ' '.((g:bufExplorerSplitOutPathName == 0) ? "Full" : "Split")." path"
|
536
|
+
|
537
|
+
return ret
|
538
|
+
endfunction
|
539
|
+
|
540
|
+
" BECreateHelp {{{1
|
541
|
+
function! s:BECreateHelp()
|
542
|
+
if g:bufExplorerDefaultHelp == 0 && g:bufExplorerDetailedHelp == 0
|
543
|
+
let s:firstBufferLine = 1
|
544
|
+
return []
|
545
|
+
endif
|
546
|
+
|
547
|
+
let header = []
|
548
|
+
|
549
|
+
if g:bufExplorerDetailedHelp == 1
|
550
|
+
call add(header, '" Buffer Explorer ('.g:bufexplorer_version.')')
|
551
|
+
call add(header, '" --------------------------')
|
552
|
+
call add(header, '" <F1> : toggle this help')
|
553
|
+
call add(header, '" <enter> or o or Mouse-Double-Click : open buffer under cursor')
|
554
|
+
call add(header, '" <shift-enter> or t : open buffer in another tab')
|
555
|
+
call add(header, '" d : delete buffer')
|
556
|
+
call add(header, '" D : wipe buffer')
|
557
|
+
call add(header, '" f : toggle find active buffer')
|
558
|
+
call add(header, '" p : toggle spliting of file and path name')
|
559
|
+
call add(header, '" q : quit')
|
560
|
+
call add(header, '" r : reverse sort')
|
561
|
+
call add(header, '" R : toggle showing relative or full paths')
|
562
|
+
call add(header, '" s : cycle thru "sort by" fields '.string(s:sort_by).'')
|
563
|
+
call add(header, '" S : reverse cycle thru "sort by" fields')
|
564
|
+
call add(header, '" T : toggle if to show only buffers for this tab or not')
|
565
|
+
call add(header, '" u : toggle showing unlisted buffers')
|
566
|
+
else
|
567
|
+
call add(header, '" Press <F1> for Help')
|
568
|
+
endif
|
569
|
+
|
570
|
+
if (!exists("b:displayMode") || b:displayMode != "winmanager") || (b:displayMode == "winmanager" && g:bufExplorerDetailedHelp == 1)
|
571
|
+
call add(header, s:BEGetHelpStatus())
|
572
|
+
call add(header, '"=')
|
573
|
+
endif
|
574
|
+
|
575
|
+
let s:firstBufferLine = len(header) + 1
|
576
|
+
|
577
|
+
return header
|
578
|
+
endfunction
|
579
|
+
|
580
|
+
" BEGetBufferInfo {{{1
|
581
|
+
function! s:BEGetBufferInfo(bufnr)
|
582
|
+
redir => bufoutput
|
583
|
+
buffers!
|
584
|
+
redir END
|
585
|
+
|
586
|
+
if (a:bufnr > 0)
|
587
|
+
" Since we are only interested in this specified buffer
|
588
|
+
" remove the other buffers listed
|
589
|
+
let bufoutput = substitute(bufoutput."\n", '^.*\n\(\s*'.a:bufnr.'\>.\{-}\)\n.*', '\1', '')
|
590
|
+
endif
|
591
|
+
|
592
|
+
let [all, allwidths, listedwidths] = [[], {}, {}]
|
593
|
+
|
594
|
+
for n in keys(s:types)
|
595
|
+
let allwidths[n] = []
|
596
|
+
let listedwidths[n] = []
|
597
|
+
endfor
|
598
|
+
|
599
|
+
for buf in split(bufoutput, '\n')
|
600
|
+
let bits = split(buf, '"')
|
601
|
+
if len(bits) < 3
|
602
|
+
continue
|
603
|
+
endif
|
604
|
+
|
605
|
+
let b = {"attributes": bits[0], "line": substitute(bits[2], '\s*', '', '')}
|
606
|
+
|
607
|
+
for [key, val] in items(s:types)
|
608
|
+
let b[key] = fnamemodify(bits[1], val)
|
609
|
+
endfor
|
610
|
+
|
611
|
+
if getftype(b.fullname) == "dir" && g:bufExplorerShowDirectories == 1
|
612
|
+
let b.shortname = "<DIRECTORY>"
|
613
|
+
endif
|
614
|
+
|
615
|
+
call add(all, b)
|
616
|
+
|
617
|
+
for n in keys(s:types)
|
618
|
+
call add(allwidths[n], len(b[n]))
|
619
|
+
|
620
|
+
if b.attributes !~ "u"
|
621
|
+
call add(listedwidths[n], len(b[n]))
|
622
|
+
endif
|
623
|
+
endfor
|
624
|
+
endfor
|
625
|
+
|
626
|
+
let [s:allpads, s:listedpads] = [{}, {}]
|
627
|
+
|
628
|
+
for n in keys(s:types)
|
629
|
+
let s:allpads[n] = repeat(' ', max(allwidths[n]))
|
630
|
+
let s:listedpads[n] = repeat(' ', max(listedwidths[n]))
|
631
|
+
endfor
|
632
|
+
|
633
|
+
let s:refreshBufferList = 1
|
634
|
+
|
635
|
+
return all
|
636
|
+
endfunction
|
637
|
+
|
638
|
+
" BEBuildBufferList {{{1
|
639
|
+
function! s:BEBuildBufferList()
|
640
|
+
let lines = []
|
641
|
+
|
642
|
+
" Loop through every buffer.
|
643
|
+
for buf in s:raw_buffer_listing
|
644
|
+
if (!g:bufExplorerShowUnlisted && buf.attributes =~ "u")
|
645
|
+
" Skip unlisted buffers if we are not to show them.
|
646
|
+
continue
|
647
|
+
endif
|
648
|
+
|
649
|
+
if (g:bufExplorerShowTabBuffer)
|
650
|
+
let show_buffer = 0
|
651
|
+
|
652
|
+
for bufnr in s:tabSpace[tabpagenr()]
|
653
|
+
if (buf.attributes =~ '^\s*'.bufnr.'\>')
|
654
|
+
" Only buffers shown on the current tabpagenr
|
655
|
+
let show_buffer = 1
|
656
|
+
break
|
657
|
+
endif
|
658
|
+
endfor
|
659
|
+
|
660
|
+
if show_buffer == 0
|
661
|
+
continue
|
662
|
+
endif
|
663
|
+
endif
|
664
|
+
|
665
|
+
let line = buf.attributes." "
|
666
|
+
|
667
|
+
if g:bufExplorerSplitOutPathName
|
668
|
+
let type = (g:bufExplorerShowRelativePath) ? "relativepath" : "path"
|
669
|
+
let path = buf[type]
|
670
|
+
let pad = (g:bufExplorerShowUnlisted) ? s:allpads.shortname : s:listedpads.shortname
|
671
|
+
let line .= buf.shortname." ".strpart(pad.path, len(buf.shortname))
|
672
|
+
else
|
673
|
+
let type = (g:bufExplorerShowRelativePath) ? "relativename" : "fullname"
|
674
|
+
let path = buf[type]
|
675
|
+
let line .= path
|
676
|
+
endif
|
677
|
+
|
678
|
+
let pads = (g:bufExplorerShowUnlisted) ? s:allpads : s:listedpads
|
679
|
+
|
680
|
+
if !empty(pads[type])
|
681
|
+
let line .= strpart(pads[type], len(path))." "
|
682
|
+
endif
|
683
|
+
|
684
|
+
let line .= buf.line
|
685
|
+
|
686
|
+
call add(lines, line)
|
687
|
+
endfor
|
688
|
+
|
689
|
+
call setline(s:firstBufferLine, lines)
|
690
|
+
|
691
|
+
call s:BESortListing()
|
692
|
+
endfunction
|
693
|
+
|
694
|
+
" BESelectBuffer {{{1
|
695
|
+
function! s:BESelectBuffer(...)
|
696
|
+
" Sometimes messages are not cleared when we get here so it looks like an error has
|
697
|
+
" occurred when it really has not.
|
698
|
+
echo ""
|
699
|
+
|
700
|
+
" Are we on a line with a file name?
|
701
|
+
if line('.') < s:firstBufferLine
|
702
|
+
exec "normal! \<cr>"
|
703
|
+
return
|
704
|
+
endif
|
705
|
+
|
706
|
+
let _bufNbr = str2nr(getline('.'))
|
707
|
+
|
708
|
+
" Check and see if we are running BE via WinManager.
|
709
|
+
if exists("b:displayMode") && b:displayMode == "winmanager"
|
710
|
+
let bufname = expand("#"._bufNbr.":p")
|
711
|
+
|
712
|
+
if (a:0 == 1) && (a:1 == "tab")
|
713
|
+
call WinManagerFileEdit(bufname, 1)
|
714
|
+
else
|
715
|
+
call WinManagerFileEdit(bufname, 0)
|
716
|
+
endif
|
717
|
+
|
718
|
+
return
|
719
|
+
endif
|
720
|
+
|
721
|
+
if bufexists(_bufNbr)
|
722
|
+
if bufnr("#") == _bufNbr
|
723
|
+
return s:BEClose("")
|
724
|
+
endif
|
725
|
+
|
726
|
+
" Are we suppose to open the selected buffer in a tab?
|
727
|
+
if (a:0 == 1) && (a:1 == "tab")
|
728
|
+
" Yes, we are to open the selected buffer in a tab.
|
729
|
+
|
730
|
+
" Restore [BufExplorer] buffer.
|
731
|
+
exec "keepjumps silent buffer!".s:originBuffer
|
732
|
+
|
733
|
+
" Get the tab number where this buffer is located at.
|
734
|
+
let tabNbr = s:BEGetTabNbr(_bufNbr)
|
735
|
+
|
736
|
+
" Was the tab found?
|
737
|
+
if tabNbr == 0
|
738
|
+
" _bufNbr is not opened in any tabs. Open a new tab with the selected buffer in it.
|
739
|
+
exec "999tab split +buffer" . _bufNbr
|
740
|
+
else
|
741
|
+
" The _bufNbr is already opened in tab, go to that tab.
|
742
|
+
exec tabNbr . "tabnext"
|
743
|
+
|
744
|
+
" Focus window.
|
745
|
+
exec s:BEGetWinNbr(tabNbr, _bufNbr) . "wincmd w"
|
746
|
+
endif
|
747
|
+
else
|
748
|
+
"No, the use did not ask to open the selected buffer in a tab.
|
749
|
+
|
750
|
+
" Are we suppose to move to the tab where this active buffer is?
|
751
|
+
if bufloaded(_bufNbr) && g:bufExplorerFindActive
|
752
|
+
" Close the BE window.
|
753
|
+
call s:BEClose("")
|
754
|
+
|
755
|
+
" Get the tab number where this buffer is located at.
|
756
|
+
let tabNbr = s:BEGetTabNbr(_bufNbr)
|
757
|
+
|
758
|
+
" Was the tab found?
|
759
|
+
if tabNbr != 0
|
760
|
+
" The buffer is located in a tab. Go to that tab number.
|
761
|
+
exec tabNbr . "tabnext"
|
762
|
+
else
|
763
|
+
" Nope, the buffer is not in a tab, simple switch to that buffer.
|
764
|
+
let bufname = expand("#"._bufNbr.":p")
|
765
|
+
exec bufname ? "drop ".escape(bufname, " ") : "buffer "._bufNbr
|
766
|
+
endif
|
767
|
+
endif
|
768
|
+
|
769
|
+
" Switch to the buffer.
|
770
|
+
exec "keepalt keepjumps silent b!" _bufNbr
|
771
|
+
endif
|
772
|
+
|
773
|
+
" Make the buffer 'listed' again.
|
774
|
+
call setbufvar(_bufNbr, "&buflisted", "1")
|
775
|
+
else
|
776
|
+
call s:BEError("Sorry, that buffer no longer exists, please select another")
|
777
|
+
call s:BEDeleteBuffer(_bufNbr, "wipe")
|
778
|
+
endif
|
779
|
+
endfunction
|
780
|
+
|
781
|
+
" BEDeleteBufferListing {{{1
|
782
|
+
function! s:BEDeleteBufferListing(buf)
|
783
|
+
if exists('s:raw_buffer_listing') && !empty(s:raw_buffer_listing)
|
784
|
+
" Delete the buffer from the raw buffer list.
|
785
|
+
" Careful use of ' and " so we do not have to escape all the \'s
|
786
|
+
" Regex: ^\s*\(10\|20\)\>
|
787
|
+
" ^ - Starting at the beginning of the string
|
788
|
+
" \s* - optional whitespace
|
789
|
+
" \(10\|20\) - either a 10 or a 20
|
790
|
+
" \> - end of word (so it can't make 100 or 201)
|
791
|
+
call filter(s:raw_buffer_listing, "v:val.attributes !~ '".'^\s*\('.substitute(a:buf, ' ', '\\|', 'g').'\)\>'."'")
|
792
|
+
endif
|
793
|
+
endfunction
|
794
|
+
|
795
|
+
" BERemoveBuffer {{{1
|
796
|
+
function! s:BERemoveBuffer(type, mode) range
|
797
|
+
" Are we on a line with a file name?
|
798
|
+
if line('.') < s:firstBufferLine
|
799
|
+
return
|
800
|
+
endif
|
801
|
+
|
802
|
+
" These commands are to temporarily suspend the activity of winmanager.
|
803
|
+
if exists("b:displayMode") && b:displayMode == "winmanager"
|
804
|
+
call WinManagerSuspendAUs()
|
805
|
+
endif
|
806
|
+
|
807
|
+
let _bufNbrs = ''
|
808
|
+
|
809
|
+
for lineNum in range(a:firstline, a:lastline)
|
810
|
+
let line = getline(lineNum)
|
811
|
+
|
812
|
+
if line =~ '^\s*\(\d\+\)'
|
813
|
+
" Regex: ^\s*\(10\|20\)\>
|
814
|
+
" ^ - Starting at the beginning of the string
|
815
|
+
" \s* - optional whitespace
|
816
|
+
" \zs - start the match here
|
817
|
+
" \d\+ - any digits
|
818
|
+
" \> - end of word (so it can't make 100 or 201)
|
819
|
+
let bufNbr = matchstr(line, '^\s*\zs\d\+\>')
|
820
|
+
|
821
|
+
" Add 0 to bufNbr to ensure Vim treats it as a Number
|
822
|
+
" for use with the getbufvar() function
|
823
|
+
if bufNbr !~ '^\d\+$' || getbufvar(bufNbr+0, '&modified') != 0
|
824
|
+
call s:BEError("Sorry, no write since last change for buffer ".bufNbr.", unable to delete")
|
825
|
+
else
|
826
|
+
let _bufNbrs = _bufNbrs . (_bufNbrs==''?'':' '). bufNbr
|
827
|
+
endif
|
828
|
+
endif
|
829
|
+
endfor
|
830
|
+
|
831
|
+
" Okay, everything is good, delete or wipe the buffers.
|
832
|
+
call s:BEDeleteBuffer(_bufNbrs, a:type)
|
833
|
+
|
834
|
+
" Reactivate winmanager autocommand activity.
|
835
|
+
if exists("b:displayMode") && b:displayMode == "winmanager"
|
836
|
+
call WinManagerForceReSize("BufExplorer")
|
837
|
+
call WinManagerResumeAUs()
|
838
|
+
endif
|
839
|
+
endfunction
|
840
|
+
|
841
|
+
" BEDeleteBuffer {{{1
|
842
|
+
function! s:BEDeleteBuffer(bufNbr, mode)
|
843
|
+
" This routine assumes that the buffer to be removed is on the current line.
|
844
|
+
try
|
845
|
+
if a:mode == "wipe"
|
846
|
+
exe "bwipe" a:bufNbr
|
847
|
+
else
|
848
|
+
exe "bdelete" a:bufNbr
|
849
|
+
endif
|
850
|
+
|
851
|
+
setlocal modifiable
|
852
|
+
|
853
|
+
" Remove each of the lines beginning with the buffer numbers we are removing
|
854
|
+
" Regex: ^\s*\(10\|20\)\>
|
855
|
+
" ^ - Starting at the beginning of the string
|
856
|
+
" \s* - optional whitespace
|
857
|
+
" \(10\|20\) - either a 10 or a 20
|
858
|
+
" \> - end of word (so it can't make 100 or 201)
|
859
|
+
exec 'silent! g/^\s*\('.substitute(a:bufNbr, ' ', '\\|', 'g').'\)\>/d_'
|
860
|
+
|
861
|
+
setlocal nomodifiable
|
862
|
+
|
863
|
+
call s:BEDeleteBufferListing(a:bufNbr)
|
864
|
+
catch
|
865
|
+
call s:BEError(v:exception)
|
866
|
+
endtry
|
867
|
+
endfunction
|
868
|
+
|
869
|
+
" BEClose {{{1
|
870
|
+
function! s:BEClose(mode)
|
871
|
+
" Get only the listed buffers.
|
872
|
+
let listed = filter(copy(s:MRUList), "buflisted(v:val)")
|
873
|
+
|
874
|
+
" If we needed to split the main window, close the split one.
|
875
|
+
" if (s:splitMode)
|
876
|
+
if (s:splitMode != "" && a:mode == "quit")
|
877
|
+
exec "wincmd c"
|
878
|
+
endif
|
879
|
+
|
880
|
+
if len(listed) == 0
|
881
|
+
exe "enew"
|
882
|
+
else
|
883
|
+
for b in reverse(listed[0:1])
|
884
|
+
exec "keepjumps silent b ".b
|
885
|
+
endfor
|
886
|
+
endif
|
887
|
+
endfunction
|
888
|
+
|
889
|
+
" BEToggleSplitOutPathName {{{1
|
890
|
+
function! s:BEToggleSplitOutPathName()
|
891
|
+
let g:bufExplorerSplitOutPathName = !g:bufExplorerSplitOutPathName
|
892
|
+
call s:BERebuildBufferList()
|
893
|
+
call s:BEUpdateHelpStatus()
|
894
|
+
endfunction
|
895
|
+
|
896
|
+
" BEToggleShowRelativePath {{{1
|
897
|
+
function! s:BEToggleShowRelativePath()
|
898
|
+
let g:bufExplorerShowRelativePath = !g:bufExplorerShowRelativePath
|
899
|
+
call s:BERebuildBufferList()
|
900
|
+
call s:BEUpdateHelpStatus()
|
901
|
+
endfunction
|
902
|
+
|
903
|
+
" BEToggleShowUnlisted {{{1
|
904
|
+
function! s:BEToggleShowUnlisted()
|
905
|
+
let g:bufExplorerShowUnlisted = !g:bufExplorerShowUnlisted
|
906
|
+
let num_bufs = s:BERebuildBufferList(g:bufExplorerShowUnlisted == 0)
|
907
|
+
call s:BEUpdateHelpStatus()
|
908
|
+
endfunction
|
909
|
+
|
910
|
+
" BEToggleFindActive {{{1
|
911
|
+
function! s:BEToggleFindActive()
|
912
|
+
let g:bufExplorerFindActive = !g:bufExplorerFindActive
|
913
|
+
call s:BEUpdateHelpStatus()
|
914
|
+
endfunction
|
915
|
+
|
916
|
+
" BEToggleShowTabBuffer {{{1
|
917
|
+
function! s:BEToggleShowTabBuffer()
|
918
|
+
let g:bufExplorerShowTabBuffer = !g:bufExplorerShowTabBuffer
|
919
|
+
call s:BEDisplayBufferList()
|
920
|
+
endfunction
|
921
|
+
|
922
|
+
" BEToggleOnlyOneTab {{{1
|
923
|
+
function! s:BEToggleOnlyOneTab()
|
924
|
+
let g:bufExplorerOnlyOneTab = !g:bufExplorerOnlyOneTab
|
925
|
+
call s:BEDisplayBufferList()
|
926
|
+
endfunction
|
927
|
+
|
928
|
+
" BERebuildBufferList {{{1
|
929
|
+
function! s:BERebuildBufferList(...)
|
930
|
+
setlocal modifiable
|
931
|
+
|
932
|
+
let curPos = getpos('.')
|
933
|
+
|
934
|
+
if a:0
|
935
|
+
" Clear the list first.
|
936
|
+
exec "keepjumps ".s:firstBufferLine.',$d "_'
|
937
|
+
endif
|
938
|
+
|
939
|
+
let num_bufs = s:BEBuildBufferList()
|
940
|
+
|
941
|
+
call setpos('.', curPos)
|
942
|
+
|
943
|
+
setlocal nomodifiable
|
944
|
+
|
945
|
+
return num_bufs
|
946
|
+
endfunction
|
947
|
+
|
948
|
+
" BEUpdateHelpStatus {{{1
|
949
|
+
function! s:BEUpdateHelpStatus()
|
950
|
+
setlocal modifiable
|
951
|
+
|
952
|
+
let text = s:BEGetHelpStatus()
|
953
|
+
call setline(s:firstBufferLine - 2, text)
|
954
|
+
|
955
|
+
setlocal nomodifiable
|
956
|
+
endfunction
|
957
|
+
|
958
|
+
" BEMRUCmp {{{1
|
959
|
+
function! s:BEMRUCmp(line1, line2)
|
960
|
+
return index(s:MRUList, str2nr(a:line1)) - index(s:MRUList, str2nr(a:line2))
|
961
|
+
endfunction
|
962
|
+
|
963
|
+
" BESortReverse {{{1
|
964
|
+
function! s:BESortReverse()
|
965
|
+
let g:bufExplorerReverseSort = !g:bufExplorerReverseSort
|
966
|
+
|
967
|
+
call s:BEReSortListing()
|
968
|
+
endfunction
|
969
|
+
|
970
|
+
" BESortSelect {{{1
|
971
|
+
function! s:BESortSelect()
|
972
|
+
let g:bufExplorerSortBy = get(s:sort_by, index(s:sort_by, g:bufExplorerSortBy) + 1, s:sort_by[0])
|
973
|
+
|
974
|
+
call s:BEReSortListing()
|
975
|
+
endfunction
|
976
|
+
|
977
|
+
" BEReverseSortSelect {{{1
|
978
|
+
function! s:BEReverseSortSelect()
|
979
|
+
let g:bufExplorerSortBy = get(s:sort_by, (index(s:sort_by, g:bufExplorerSortBy) + len(s:sort_by) - 1) % len(s:sort_by), s:sort_by[0])
|
980
|
+
|
981
|
+
call s:BEReSortListing()
|
982
|
+
endfunction
|
983
|
+
|
984
|
+
" BEReSortListing {{{1
|
985
|
+
function! s:BEReSortListing()
|
986
|
+
setlocal modifiable
|
987
|
+
|
988
|
+
let curPos = getpos('.')
|
989
|
+
|
990
|
+
call s:BESortListing()
|
991
|
+
call s:BEUpdateHelpStatus()
|
992
|
+
|
993
|
+
call setpos('.', curPos)
|
994
|
+
|
995
|
+
setlocal nomodifiable
|
996
|
+
endfunction
|
997
|
+
|
998
|
+
" BESortListing {{{1
|
999
|
+
function! s:BESortListing()
|
1000
|
+
let sort = s:firstBufferLine.",$sort".((g:bufExplorerReverseSort == 1) ? "!": "")
|
1001
|
+
|
1002
|
+
if g:bufExplorerSortBy == "number"
|
1003
|
+
" Easiest case.
|
1004
|
+
exec sort 'n'
|
1005
|
+
elseif g:bufExplorerSortBy == "name"
|
1006
|
+
if g:bufExplorerSplitOutPathName
|
1007
|
+
exec sort 'ir /\d.\{7}\zs\f\+\ze/'
|
1008
|
+
else
|
1009
|
+
exec sort 'ir /\zs[^\/\\]\+\ze\s*line/'
|
1010
|
+
endif
|
1011
|
+
elseif g:bufExplorerSortBy == "fullpath"
|
1012
|
+
if g:bufExplorerSplitOutPathName
|
1013
|
+
" Sort twice - first on the file name then on the path.
|
1014
|
+
exec sort 'ir /\d.\{7}\zs\f\+\ze/'
|
1015
|
+
endif
|
1016
|
+
|
1017
|
+
exec sort 'ir /\zs\f\+\ze\s\+line/'
|
1018
|
+
elseif g:bufExplorerSortBy == "extension"
|
1019
|
+
exec sort 'ir /\.\zs\w\+\ze\s/'
|
1020
|
+
elseif g:bufExplorerSortBy == "mru"
|
1021
|
+
let l = getline(s:firstBufferLine, "$")
|
1022
|
+
|
1023
|
+
call sort(l, "<SID>BEMRUCmp")
|
1024
|
+
|
1025
|
+
if g:bufExplorerReverseSort
|
1026
|
+
call reverse(l)
|
1027
|
+
endif
|
1028
|
+
|
1029
|
+
call setline(s:firstBufferLine, l)
|
1030
|
+
endif
|
1031
|
+
endfunction
|
1032
|
+
|
1033
|
+
" BEMRUListShow {{{1
|
1034
|
+
function! s:BEMRUListShow()
|
1035
|
+
echomsg "MRUList=".string(s:MRUList)
|
1036
|
+
endfunction
|
1037
|
+
|
1038
|
+
" BEError {{{1
|
1039
|
+
function! s:BEError(msg)
|
1040
|
+
echohl ErrorMsg | echo a:msg | echohl none
|
1041
|
+
endfunction
|
1042
|
+
|
1043
|
+
" BEWarning {{{1
|
1044
|
+
function! s:BEWarning(msg)
|
1045
|
+
echohl WarningMsg | echo a:msg | echohl none
|
1046
|
+
endfunction
|
1047
|
+
|
1048
|
+
" GetTabNbr {{{1
|
1049
|
+
function! s:BEGetTabNbr(bufNbr)
|
1050
|
+
" Searching buffer bufno, in tabs.
|
1051
|
+
for i in range(tabpagenr("$"))
|
1052
|
+
if index(tabpagebuflist(i + 1), a:bufNbr) != -1
|
1053
|
+
return i + 1
|
1054
|
+
endif
|
1055
|
+
endfor
|
1056
|
+
|
1057
|
+
return 0
|
1058
|
+
endfunction
|
1059
|
+
|
1060
|
+
" GetWinNbr" {{{1
|
1061
|
+
function! s:BEGetWinNbr(tabNbr, bufNbr)
|
1062
|
+
" window number in tabpage.
|
1063
|
+
return index(tabpagebuflist(a:tabNbr), a:bufNbr) + 1
|
1064
|
+
endfunction
|
1065
|
+
|
1066
|
+
" Winmanager Integration {{{1
|
1067
|
+
let g:BufExplorer_title = "\[Buf\ List\]"
|
1068
|
+
call s:BESet("g:bufExplorerResize", 1)
|
1069
|
+
call s:BESet("g:bufExplorerMaxHeight", 25) " Handles dynamic resizing of the window.
|
1070
|
+
|
1071
|
+
" Function to start display. Set the mode to 'winmanager' for this buffer.
|
1072
|
+
" This is to figure out how this plugin was called. In a standalone fashion
|
1073
|
+
" or by winmanager.
|
1074
|
+
function! BufExplorer_Start()
|
1075
|
+
let b:displayMode = "winmanager"
|
1076
|
+
call StartBufExplorer("e")
|
1077
|
+
endfunction
|
1078
|
+
|
1079
|
+
" Returns whether the display is okay or not.
|
1080
|
+
function! BufExplorer_IsValid()
|
1081
|
+
return 0
|
1082
|
+
endfunction
|
1083
|
+
|
1084
|
+
" Handles dynamic refreshing of the window.
|
1085
|
+
function! BufExplorer_Refresh()
|
1086
|
+
let b:displayMode = "winmanager"
|
1087
|
+
call StartBufExplorer("e")
|
1088
|
+
endfunction
|
1089
|
+
|
1090
|
+
function! BufExplorer_ReSize()
|
1091
|
+
if !g:bufExplorerResize
|
1092
|
+
return
|
1093
|
+
endif
|
1094
|
+
|
1095
|
+
let nlines = min([line("$"), g:bufExplorerMaxHeight])
|
1096
|
+
|
1097
|
+
exe nlines." wincmd _"
|
1098
|
+
|
1099
|
+
" The following lines restore the layout so that the last file line is also
|
1100
|
+
" the last window line. Sometimes, when a line is deleted, although the
|
1101
|
+
" window size is exactly equal to the number of lines in the file, some of
|
1102
|
+
" the lines are pushed up and we see some lagging '~'s.
|
1103
|
+
let pres = getpos(".")
|
1104
|
+
|
1105
|
+
exe $
|
1106
|
+
|
1107
|
+
let _scr = &scrolloff
|
1108
|
+
let &scrolloff = 0
|
1109
|
+
|
1110
|
+
normal! z-
|
1111
|
+
|
1112
|
+
let &scrolloff = _scr
|
1113
|
+
|
1114
|
+
call setpos(".", pres)
|
1115
|
+
endfunction
|
1116
|
+
|
1117
|
+
" Default values {{{1
|
1118
|
+
call s:BESet("g:bufExplorerDefaultHelp", 1) " Show default help?
|
1119
|
+
call s:BESet("g:bufExplorerDetailedHelp", 0) " Show detailed help?
|
1120
|
+
call s:BESet("g:bufExplorerFindActive", 1) " When selecting an active buffer, take you to the window where it is active?
|
1121
|
+
call s:BESet("g:bufExplorerReverseSort", 0) " sort reverse?
|
1122
|
+
call s:BESet("g:bufExplorerShowDirectories", 1) " (Dir's are added by commands like ':e .')
|
1123
|
+
call s:BESet("g:bufExplorerShowRelativePath", 0) " Show listings with relative or absolute paths?
|
1124
|
+
call s:BESet("g:bufExplorerShowUnlisted", 0) " Show unlisted buffers?
|
1125
|
+
call s:BESet("g:bufExplorerSortBy", "mru") " Sorting methods are in s:sort_by:
|
1126
|
+
call s:BESet("g:bufExplorerSplitOutPathName", 1) " Split out path and file name?
|
1127
|
+
call s:BESet("g:bufExplorerSplitRight", &splitright) " Should vertical splits be on the right or left of current window?
|
1128
|
+
call s:BESet("g:bufExplorerSplitBelow", &splitbelow) " Should horizontal splits be below or above current window?
|
1129
|
+
call s:BESet("g:bufExplorerShowTabBuffer", 0) " Show only buffer(s) for this tab?
|
1130
|
+
call s:BESet("g:bufExplorerOnlyOneTab", 1) " If ShowTabBuffer = 1, only store the most recent tab for this buffer.
|
1131
|
+
|
1132
|
+
" Global variables {{{1
|
1133
|
+
call s:BEReset()
|
1134
|
+
let s:running = 0
|
1135
|
+
let s:sort_by = ["number", "name", "fullpath", "mru", "extension"]
|
1136
|
+
let s:types = {"fullname": ':p', "path": ':p:h', "relativename": ':~:.', "relativepath": ':~:.:h', "shortname": ':t'}
|
1137
|
+
let s:originBuffer = 0
|
1138
|
+
let s:splitMode = ""
|
1139
|
+
let s:name = '[BufExplorer]'
|
1140
|
+
let s:refreshBufferList = 1
|
1141
|
+
let s:MRU_Exclude_List = ["[BufExplorer]","__MRU_Files__"]
|
1142
|
+
"1}}}
|
1143
|
+
|
1144
|
+
" vim:ft=vim foldmethod=marker sw=2
|