forked from nerdEd/vim-config
/
tabbar.vim
1646 lines (1393 loc) · 53 KB
/
tabbar.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" Copyright: Copyright (C) 2005 Marius Groleo
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
" tabbar.vim is provided *AS IS* and comes with no warranty of
" any kind, either expressed or implied. In no event will the
" copyright holder be liable for any damamges resulting from the
" use of this software.
"
" Derived from Bindu Wavell miniBufExplorer.vim version 6.3.2
" Version: 0.7
" Maintainer: Marius Groleo < groleo@gmail.com >
" Description: TabBar buffer explorer Vim Plugin
" Name Of File: tabbar.vim
" DOCUMENTATION: is at line :1445
" press zR , in normal mode to OPEN all folds
" press zM , in normal mode to CLOSE all folds
" Already been loaded? ~~
if exists('Tb_loaded')
finish
else
let Tb_loaded= 1
endif "%%
" Debug Level ~~
" 0 = no logging
" 1-5 = errors ; 1 is the most important
" 5-9 = info ; 5 is the most important
" 10 = Entry/Exit
if !exists('g:Tb_DBG_LVL')
let g:Tb_DBG_LVL = 0
endif" %%
" Logging method ~~
" 0 = log to a window
" 1 = log with vim's echo facility
" 2 = log to a file named TabBar.DBG
" in the directory where vim was started
" THIS IS VERY SLOW
" 3 = log into g:Tb_DbgOutput
" global variable [This is the default]
if !exists('g:Tb_DebugMode')
let g:Tb_DebugMode = 0
endif" %%
" Mappings and Commands
" TabBar Keyboard Mappings ~~
if ! hasmapto('1') || !hasmapto('<M-1>')
"gui bindings containing META key, are different from terminal bindings
if has('gui_running')
"NORMAL mode bindings for gvim
noremap <unique> <script> <M-1> :call <SID>Bf_SwitchTo( 1)<CR>:<BS>
noremap <unique> <script> <M-2> :call <SID>Bf_SwitchTo( 2)<CR>:<BS>
noremap <unique> <script> <M-3> :call <SID>Bf_SwitchTo( 3)<CR>:<BS>
noremap <unique> <script> <M-4> :call <SID>Bf_SwitchTo( 4)<CR>:<BS>
noremap <unique> <script> <M-5> :call <SID>Bf_SwitchTo( 5)<CR>:<BS>
noremap <unique> <script> <M-6> :call <SID>Bf_SwitchTo( 6)<CR>:<BS>
noremap <unique> <script> <M-7> :call <SID>Bf_SwitchTo( 7)<CR>:<BS>
noremap <unique> <script> <M-8> :call <SID>Bf_SwitchTo( 8)<CR>:<BS>
noremap <unique> <script> <M-9> :call <SID>Bf_SwitchTo( 9)<CR>:<BS>
noremap <unique> <script> <M-0> :call <SID>Bf_SwitchTo( 10)<CR>:<BS>
"INSERT mode bindings for gvim
inoremap <unique> <script> <M-1> <esc>:call <SID>Bf_SwitchTo( 1)<CR>:<BS>a
inoremap <unique> <script> <M-2> <esc>:call <SID>Bf_SwitchTo( 2)<CR>:<BS>a
inoremap <unique> <script> <M-3> <esc>:call <SID>Bf_SwitchTo( 3)<CR>:<BS>a
inoremap <unique> <script> <M-4> <esc>:call <SID>Bf_SwitchTo( 4)<CR>:<BS>a
inoremap <unique> <script> <M-5> <esc>:call <SID>Bf_SwitchTo( 5)<CR>:<BS>a
inoremap <unique> <script> <M-6> <esc>:call <SID>Bf_SwitchTo( 6)<CR>:<BS>a
inoremap <unique> <script> <M-7> <esc>:call <SID>Bf_SwitchTo( 7)<CR>:<BS>a
inoremap <unique> <script> <M-8> <esc>:call <SID>Bf_SwitchTo( 8)<CR>:<BS>a
inoremap <unique> <script> <M-9> <esc>:call <SID>Bf_SwitchTo( 9)<CR>:<BS>a
inoremap <unique> <script> <M-0> <esc>:call <SID>Bf_SwitchTo( 10)<CR>:<BS>a
else
"NORMAL mode bindings for vim( dos32 )
noremap <unique> <script> ± :call <SID>Bf_SwitchTo( 1)<CR>:<BS>
noremap <unique> <script> ² :call <SID>Bf_SwitchTo( 2)<CR>:<BS>
noremap <unique> <script> ³ :call <SID>Bf_SwitchTo( 3)<CR>:<BS>
noremap <unique> <script> ´ :call <SID>Bf_SwitchTo( 4)<CR>:<BS>
noremap <unique> <script> µ :call <SID>Bf_SwitchTo( 5)<CR>:<BS>
noremap <unique> <script> ¶ :call <SID>Bf_SwitchTo( 6)<CR>:<BS>
noremap <unique> <script> · :call <SID>Bf_SwitchTo( 7)<CR>:<BS>
noremap <unique> <script> ¸ :call <SID>Bf_SwitchTo( 8)<CR>:<BS>
"else
"NORMAL mode bindings for vim( terminal)
noremap <unique> <script> 1 :call <SID>Bf_SwitchTo( 1)<CR>:<BS>
noremap <unique> <script> 2 :call <SID>Bf_SwitchTo( 2)<CR>:<BS>
noremap <unique> <script> 3 :call <SID>Bf_SwitchTo( 3)<CR>:<BS>
noremap <unique> <script> 4 :call <SID>Bf_SwitchTo( 4)<CR>:<BS>
noremap <unique> <script> 5 :call <SID>Bf_SwitchTo( 5)<CR>:<BS>
noremap <unique> <script> 6 :call <SID>Bf_SwitchTo( 6)<CR>:<BS>
noremap <unique> <script> 7 :call <SID>Bf_SwitchTo( 7)<CR>:<BS>
noremap <unique> <script> 8 :call <SID>Bf_SwitchTo( 8)<CR>:<BS>
noremap <unique> <script> 9 :call <SID>Bf_SwitchTo( 9)<CR>:<BS>
noremap <unique> <script> 0 :call <SID>Bf_SwitchTo( 10)<CR>:<BS>
"INSERT mode bindings for vim( terminal)
inoremap <unique> <script> 1 <esc>:call <SID>Bf_SwitchTo( 1)<CR>:<BS>a
inoremap <unique> <script> 2 <esc>:call <SID>Bf_SwitchTo( 2)<CR>:<BS>a
inoremap <unique> <script> 3 <esc>:call <SID>Bf_SwitchTo( 3)<CR>:<BS>a
inoremap <unique> <script> 4 <esc>:call <SID>Bf_SwitchTo( 4)<CR>:<BS>a
inoremap <unique> <script> 5 <esc>:call <SID>Bf_SwitchTo( 5)<CR>:<BS>a
inoremap <unique> <script> 6 <esc>:call <SID>Bf_SwitchTo( 6)<CR>:<BS>a
inoremap <unique> <script> 7 <esc>:call <SID>Bf_SwitchTo( 7)<CR>:<BS>a
inoremap <unique> <script> 8 <esc>:call <SID>Bf_SwitchTo( 8)<CR>:<BS>a
inoremap <unique> <script> 9 <esc>:call <SID>Bf_SwitchTo( 9)<CR>:<BS>a
inoremap <unique> <script> 0 <esc>:call <SID>Bf_SwitchTo( 10)<CR>:<BS>a
endif
endif " %%
" TabBar <Script> internal map ~~
noremap <unique> <script> <Plug>tbstart :call <SID>Tb_Start(1, -1)<CR>:<BS>
noremap <unique> <script> <Plug>tbstop :call <SID>Tb_Stop(1)<CR>:<BS>
noremap <unique> <script> <Plug>tbaut :call <SID>Tb_Aup(-1)<CR>:<BS>
noremap <unique> <script> <Plug>tbtoggle :call <SID>Tb_Toggle()<CR>:<BS>
" %%
" TabBar commands ~~
if !exists(':TbStart')
command! TbStart call <SID>Tb_Start(1, -1)
endif
if !exists(':TbStop')
command! TbStop call <SID>Tb_Stop(1)
endif
if !exists(':TbAup')
command! TbAup call <SID>Tb_AutoUpdt(-1)
endif
if !exists(':TbToggle')
command! TbToggle call <SID>Tb_Toggle()
endif
if !exists(':Tbbn')
command! Tbbn call <SID>Bf_Cycle(1)
endif
if !exists(':Tbp')
command! Tbbp call <SID>Bf_Cycle(0)
endif " %%
" Global Configuration Variables
" Allow auto update? ~~
" We start out with this off for startup, but once vim is running we
" turn this on.
if !exists('g:Tb_AutoUpdt')
let g:Tb_AutoUpdt = 0
endif " %%
" MoreThanOne? ~~
" Display Mini Buf Explorer when there are 'More Than One' eligible buffers
if !exists('g:Tb_MoreThanOne')
let g:Tb_MoreThanOne = 2
endif" %%
" Split below/above/left/right? ~~
" When opening a new -TabBar- window, split the new windows below or
" above the current window? 1 = below, 0 = above.
if !exists('g:Tb_SplitBelow')
let g:Tb_SplitBelow = &splitbelow
endif" %%
" Horizontal or Vertical explorer? ~~
" For folks that like vertical explorers, I'm caving in and providing for
" veritcal splits. If this is set to 0 then the current horizontal
" splitting logic will be run. If however you want a vertical split,
" assign the width (in characters) you wish to assign to the -TabBar- window.
if !exists('g:Tb_VSplit')
let g:Tb_VSplit = 0
endif" %%
" TabWrap? ~~
" By default line wrap is used (possibly breaking a tab name between two
" lines.) Turning this option on (setting it to 1) can take more screen
" space, but will make sure that each tab is on one and only one line.
if !exists('g:Tb_TabWrap')
let g:Tb_TabWrap = 0
endif" %%
" Switch buffers using Ctrl-Tab ?~~
if !exists('g:Tb_cTabSwitchBufs')
let g:Tb_cTabSwitchBufs = 1
endif" %%
" if cTabSwitchBufs is turned on then we turn off cTabSwitchWindows.~~
if g:Tb_cTabSwitchBufs == 1 || !exists('g:Tb_cTabSwitchWindows')
let g:Tb_cTabSwitchWindows = 0
endif" %%
" If we have enabled <C-TAB> and <C-S-TAB> to switch buffers~~
" in the current window then perform the remapping
if g:Tb_cTabSwitchBufs
noremap <C-TAB> :call <SID>Bf_Cycle(1)<CR>:<BS>
noremap <C-S-TAB> :call <SID>Bf_Cycle(0)<CR>:<BS>
endif "%%
" If we have enabled <C-TAB> and <C-S-TAB> to switch windows ~~
" then perform the remapping
if g:Tb_cTabSwitchWindows
noremap <C-TAB> <C-W>w
noremap <C-S-TAB> <C-W>W
endif "%%
" Modifiable Select Target ~~
if !exists('g:Tb_ModSelTarget')
let g:Tb_ModSelTarget = 0
endif "%%
" Force Syntax Enable ~~
if !exists('g:Tb_ForceSyntaxEnable')
let g:Tb_ForceSyntaxEnable = 0
endif "%%
" Single/Double Click? ~~
" flag that can be set to 1 in a users .vimrc to allow
" single click switching of tabs. By default we use
" double click for tab selection.
if !exists('g:Tb_UseSingleClick')
let g:Tb_UseSingleClick = 0
endif
"
" attempt to perform single click mapping, it would be much
" nicer if we could nnoremap <buffer> ... however vim does
" not fire the <buffer> <leftmouse> when you use the mouse
" to enter a buffer.
"
if g:Tb_UseSingleClick == 1
let s:clickmap = ':if bufname("%") == "-TabBar-" <bar> call <SID>Tb_Click() <bar> endif <CR>'
if maparg('<LEFTMOUSE>', 'n') == ''
" no mapping for leftmouse
exec ':nnoremap <silent> <LEFTMOUSE> <LEFTMOUSE>' . s:clickmap
else
" we have a mapping
let g:Tb_DoneClickSave = 1
let s:m = ':nnoremap <silent> <LEFTMOUSE> <LEFTMOUSE>'
let s:m = s:m . substitute(substitute(maparg('<LEFTMOUSE>', 'n'), '|', '<bar>', 'g'), '\c^<LEFTMOUSE>', '', '')
let s:m = s:m . s:clickmap
exec s:m
endif
endif " %%
"------------"
" Variables "
"------------"
" used to pass maxTabWidth info between functions
let s:maxTabWidth = 0
" Debug line counter
let s:DBG_LN_CNT = 0
" Global used to store the buffer list so we don't update the ~~
" UI unless the list has changed.
if !exists('g:Tb_VimBufList')
let g:Tb_VimBufList = ''
let g:Tb_BufferMap=''
endif "%%
" g:Tb_UpdtMutex: Variable used as a mutex so that we don't do lots~~
" of Tb_AutoUpdts at the same time.
if !exists('g:Tb_UpdtMutex')
let g:Tb_UpdtMutex = 0
endif "%%
" g:Tb_MaxHeight maxSize ~~
if !exists('g:Tb_MaxSize')
let g:Tb_MaxSize = 1
"TODO implement Tb_MaxHeight
endif "%%
" g:Tb_MaxHeight MinSize ~~
if !exists('g:Tb_MinSize')
let g:Tb_MinSize = 1
"TODO implement Tb_MaxHeight
endif "%%
" g:Tb_DbgOutput: In debug mode 3 this variable will hold the debug output~~
if !exists('g:Tb_DbgOutput')
let g:Tb_DbgOutput = ''
endif "%%
" g:Tb_ForceDisplay ~~
if !exists('g:Tb_ForceDisplay')
let g:Tb_ForceDisplay = 0
endif "%%
" Setup an autocommand group and some autocommands ~~
" that keep our explorer updated automatically.
augroup TabBar
autocmd TabBar BufDelete * call <SID>DEBUG('-=> BufDelete AutoCmd', 10) |call <SID>Tb_AutoUpdt(expand('<abuf>'))
autocmd TabBar BufEnter * call <SID>DEBUG('-=> BufEnter AutoCmd', 10) |call <SID>Tb_AutoUpdt(-1)
autocmd TabBar VimEnter * call <SID>DEBUG('-=> VimEnter AutoCmd', 10) |let g:Tb_AutoUpdt = 1 |call <SID>Tb_AutoUpdt(-1)
" %%
"------------"
" Functions "
"------------"
" Tb_Start - Sets up our explorer and causes it to be displayed ~~
function! <SID>Tb_Start(sticky, delBufNum)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Tb_Start()' ,10)
endif
if a:sticky == 1
let g:Tb_AutoUpdt = 1
endif
" Store the current buffer
let l:curBuf = bufnr('%')
" Prevent a report of our actions from showing up.
let l:save_rep = &report
let l:save_sc = &showcmd
let &report = 10000
set noshowcmd
call <SID>Win_FindOrCreate('-TabBar-', -1, 1)
" Make sure we are in our window
if bufname('%') != '-TabBar-'
call <SID>DEBUG('Tb_Start: called in invalid window',1)
let &report = l:save_rep
let &showcmd = l:save_sc
return
endif
" !!! We may want to make the following optional -- Bindu
" New windows don't cause all windows to be resized to equal sizes
set noequalalways
" !!! We may want to make the following optional -- Bindu
" We don't want the mouse to change focus without a click
set nomousefocus
" If folks turn numbering and columns on by default we will turn
" them off for the -TabBar- window
setlocal foldcolumn=0
setlocal nonumber
if has("syntax")
syn clear
syn match Tb_Normal '\[[^\]]*\]'
syn match Tb_Changed '\[[^\]]*\]+'
syn match Tb_VisibleNormal '\[[^\]]*\]\*+\='
syn match Tb_VisibleChanged '\[[^\]]*\]\*+'
if !exists("g:did_tabbar_syntax_inits")
let g:did_tabbar_syntax_inits = 1
highlight def link Tb_Normal Comment
highlight def link Tb_Changed String
highlight def link Tb_VisibleNormal StatusLineNC
highlight def link Tb_VisibleChanged Special
endif
endif
" If you press return in the -TabBar- then try
" to open the selected buffer in the previous window.
" Bf_CrSel = Buffer CR Select
nnoremap <buffer> <CR> :call <SID>Bf_CrSel()<CR>:<BS>
" If you Bf_DblClkSel in the -TabBar- then try
" to open the selected buffer in the previous window.
nnoremap <buffer> <2-LEFTMOUSE> :call <SID>Bf_DblClkSel()<CR>:<BS>
" delete the selected buffer.
nnoremap <buffer> d :call <SID>Bf_DelWithD()<CR>:<BS>
" If you press w in the -TabBar- then switch back
" to the previous window.
nnoremap <buffer> p :wincmd p<CR>:<BS>
" The following allows for quicker moving between buffer
" names in the -TabBar- window it also saves the last-pattern
" and restores it.
nnoremap <buffer> <TAB> :call search('\[[0-9]*:[^\]]*\]')<CR>:<BS>
nnoremap <buffer> <S-TAB> :call search('\[[0-9]*:[^\]]*\]','b')<CR>:<BS>
call <SID>Bf_SafePrint(a:delBufNum)
if (l:curBuf != -1)
call search('\['.l:curBuf.':'.expand('#'.l:curBuf.':t').'\]')
else
call <SID>DEBUG('Tb_Start: No current buffer to search for',9)
endif
let &report = l:save_rep
let &showcmd = l:save_sc
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Tb_Start()' ,10)
endif
endfunction " %%
" Tb_Stop - Looks for our explorer and closes the window if it is opened ~~
function! <SID>Tb_Stop( sticky)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Tb_Stop()' ,10)
endif
if a:sticky == 1
let g:Tb_AutoUpdt = 0
endif
let l:winNum = <SID>Win_Find('-TabBar-')
if l:winNum != -1
exec l:winNum.' wincmd w'
silent! close
wincmd p
endif
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Tb_Stop()' ,10)
endif
endfunction " %%
" Tb_Toggle - Looks for our explorer and opens/closes the window ~~
function! <SID>Tb_Toggle()
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Tb_Toggle()' ,10)
endif
let g:Tb_AutoUpdt = 0
let l:winNum = <SID>Win_Find('-TabBar-')
if l:winNum != -1
call <SID>Tb_Stop(1)
else
call <SID>Tb_Start(1, -1)
wincmd p
endif
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Tb_Toggle()' ,10)
endif
endfunction " %%
" Tb_Max - Returns the max of two numbers ~~
function! <SID>Tb_Max(argOne, argTwo)
if a:argOne > a:argTwo
return a:argOne
else
return a:argTwo
endif
endfunction " %%
" Tb_AutoUpdt - Function called by auto commands for auto updating -TabBar- ~~
" IF auto update is turned on AND
" we are in a real buffer AND
" we have enough eligible buffers THEN
" Update our explorer and get back to the current window
" If we get a buffer number for a buffer that
" is being deleted, we need to make sure and
" remove the buffer from the list of eligible
" buffers in case we are down to one eligible
" buffer, in which case we will want to close
" the -TabBar- window.
function! <SID>Tb_AutoUpdt(delBufNum)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Tb_AutoUpdt( delBufNum='.a:delBufNum.') : bufnr(%)='.bufnr('%').' : bufname(%)=['.bufname('%') . ']',10)
endif
if (g:Tb_UpdtMutex == 1)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: recursion stopped',9)
call <SID>DEBUG('EXIT : Tb_AutoUpdt()' ,10)
endif
return
else
let g:Tb_UpdtMutex = 1
endif
" Don't update the TabBar window
if (bufname('%') == '-TabBar-')
" If this is the only buffer left then toggle the buffer
if (winbufnr(2) == -1)
call <SID>Bf_Cycle(1)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: does not run for cycled windows', 9)
endif
else
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: does not run for the -TabBar- window', 9)
endif
endif
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Tb_AutoUpdt()' ,10)
endif
let g:Tb_UpdtMutex = 0
return
endif
if (a:delBufNum != -1)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: will make sure that buffer '.a:delBufNum.' is not included in the buffer list.', 5)
endif
endif
" Only allow updates when the Tb_AutoUpdt flag is set
" this allows us to stop updates on startup.
if g:Tb_AutoUpdt == 1
" Only show TabBar if we have a real buffer
if ((g:Tb_MoreThanOne == 0) || (bufnr('%') != -1 && bufname('%') != ""))
if <SID>Bf_Eligible(a:delBufNum) == 1
" if we don't have a window then create one
let l:bufnr = <SID>Win_Find('-TabBar-')
if (l:bufnr == -1)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: About to call Tb_Start (Create -TabBar-)', 9)
endif
call <SID>Tb_Start(0, a:delBufNum)
else
" otherwise only update the window if the contents have changed
let l:ListChanged = <SID>Bf_BuildList(a:delBufNum, 0)
if (l:ListChanged)
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: About to call Tb_Start (Update -TabBar-)', 9)
endif
call <SID>Tb_Start(0, a:delBufNum)
endif
endif
" go back to the working buffer
if (bufname('%') == '-TabBar-')
wincmd p
endif
else
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: Failed in eligible check', 9)
endif
call <SID>Tb_Stop(0)
endif
" VIM sometimes turns syntax highlighting off,
" we can force it on, but this may cause weird
" behavior so this is an optional hack to force
" syntax back on when we enter a buffer
if g:Tb_ForceSyntaxEnable
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: Enable Syntax', 9)
endif
exec 'syntax enable'
endif
else
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Tb_AutoUpdt: No buffers loaded...',9)
endif
endif
else
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Tb_AutoUpdt are turned off',9)
endif
endif
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Tb_AutoUpdt()' ,10)
endif
let g:Tb_UpdtMutex = 0
endfunction " %%
" Tb_Click - Handle mouse double click ~~
function! <SID>Tb_Click()
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Tb_Click()',10)
endif
call <SID>Bf_CrSel()
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Tb_Click()',10)
endif
endfunction " %%
"-------------------"
" Window operations "
"-------------------"
" Win_Find - Return the window number of a named buffer ~~
" If none is found then returns -1.
function! <SID>Win_Find(bufName)
"if g:Tb_DBG_LVL > 0
" call <SID>DEBUG('ENTER: Win_Find()',10)
"endif
" Try to find an existing window that contains
" our buffer.
let l:bufNr = bufnr(a:bufName)
if l:bufNr != -1
"if g:Tb_DBG_LVL > 0
" call <SID>DEBUG('Found buffer ('.a:bufName.'): '.l:bufNr,9)
"endif
let l:bufWinNr = bufwinnr(l:bufNr)
else
let l:bufWinNr = -1
endif
return l:bufWinNr
endfunction " %%
" Win_FindOrCreate - Attempts to find a window for a named buffer. ~~
"
" If it is found then moves there. Otherwise creates a new window and
" configures it and moves there.
"
" forceEdge, -1 use defaults, 0 below, 1 above
" isExplorer, 0 no, 1 yes
" 0 no, 1 yes
function! <SID>Win_FindOrCreate(bufName, forceEdge, isExplorer)
"if g:Tb_DBG_LVL > 0
" call <SID>DEBUG('ENTER: Win_FindOrCreate('.a:bufName.')',10)
"endif
" Save the user's split setting.
let l:saveSplitBelow = &splitbelow
" Set to our new values.
let &splitbelow = g:Tb_SplitBelow
" Try to find an existing explorer window
let l:winNum = <SID>Win_Find(a:bufName)
" If found goto the existing window, otherwise
" split open a new window.
if l:winNum != -1
" if g:Tb_DBG_LVL > 0
" call <SID>DEBUG('Found window ('.a:bufName.'): '.l:winNum,9)
" endif
exec l:winNum.' wincmd w'
let l:winFound = 1
else
"if g:Tb_SplitToEdge == 1 || a:forceEdge >= 0
if a:forceEdge >= 0
let l:edge = &splitbelow
if a:forceEdge >= 0
let l:edge = a:forceEdge
endif
if l:edge
if g:Tb_VSplit == 0
exec 'bo sp '.a:bufName
else
exec 'bo vsp '.a:bufName
endif
else
if g:Tb_VSplit == 0
exec 'to sp '.a:bufName
else
exec 'to vsp '.a:bufName
endif
endif
else
if g:Tb_VSplit == 0
exec 'sp '.a:bufName
else
" &splitbelow doesn't affect vertical splits
" so we have to do this explicitly.. ugh.
if &splitbelow
exec 'rightb vsp '.a:bufName
else
exec 'vsp '.a:bufName
endif
endif
endif
let g:Tb_ForceDisplay = 1
" Try to find an existing explorer window
let l:winNum = <SID>Win_Find(a:bufName)
if l:winNum != -1
"if g:Tb_DBG_LVL > 0
" call <SID>DEBUG('Created and then found window ('.a:bufName.'): '.l:winNum,9)
"endif
exec l:winNum.' wincmd w'
else
"if g:Tb_DBG_LVL > 0
" call <SID>DEBUG('Win_FindOrCreate failed to create window ('.a:bufName.').',1)
"endif
return
endif
if a:isExplorer
" Turn off the swapfile, set the buffer type so that it won't get written,
" and so that it will get deleted when it gets hidden and turn on word wrap.
setlocal noswapfile
setlocal buftype=nofile
setlocal bufhidden=delete
if g:Tb_VSplit == 0
setlocal wrap
else
setlocal nowrap
exec('setlocal winwidth='.g:Tb_MinSize)
endif
endif
"if g:Tb_DBG_LVL > 0
" call <SID>DEBUG('Window ('.a:bufName.') created: '.winnr(),9)
"endif
endif
" Restore the user's split setting.
let &splitbelow = l:saveSplitBelow
endfunction " %%
" Win_Resize - Set width/height of -TabBar- window ~~
"
" Makes sure we are in our explorer, then sets the height/width for our explorer
" window so that we can fit all of our information without taking extra lines.
function! <SID>Win_Resize()
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Win_Resize()',10)
endif
" Make sure we are in our window
if bufname('%') != '-TabBar-'
call <SID>DEBUG('EXIT : Win_Resize called in invalid window',1)
return
endif
let l:width = winwidth('.')
" Horizontal Resize
if g:Tb_VSplit == 0
if g:Tb_TabWrap == 0
let l:length = strlen(getline('.'))
let l:height = 0
if (l:width == 0)
let l:height = winheight('.')
else
let l:height = (l:length / l:width)
" handle truncation from div
if (l:length % l:width) != 0
let l:height = l:height + 1
endif
endif
else
exec("setlocal textwidth=".l:width)
normal gg
normal gq}
normal G
let l:height = line('.')
normal gg
endif
" enforce max window height
if g:Tb_MaxSize != 0
if g:Tb_MaxSize < l:height
let l:height = g:Tb_MaxSize
endif
endif
" enfore min window height
if l:height < g:Tb_MinSize || l:height == 0
let l:height = g:Tb_MinSize
endif
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Win_Resize to '.l:height.' lines',9)
endif
exec('resize '.l:height)
" Vertical Resize
else
if g:Tb_MaxSize != 0
let l:newWidth = s:maxTabWidth
if l:newWidth > g:Tb_MaxSize
let l:newWidth = g:Tb_MaxSize
endif
if l:newWidth < g:Tb_MinSize
let l:newWidth = g:Tb_MinSize
endif
else
let l:newWidth = g:Tb_VSplit
endif
if l:width != l:newWidth
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Win_Resize to '.l:newWidth.' columns',9)
endif
exec('vertical resize '.l:newWidth)
endif
endif
endfunction " %%
"-------------------"
" Buffer operations "
"-------------------"
" Bf_Choosed - From the -TabBar- window, return the bufnum for buf under cursor ~~
" If we are in our explorer window then return the buffer number
" for the buffer under the cursor.
function! <SID>Bf_Choosed()
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Bf_Choosed()',10)
endif
" Make sure we are in our window
if bufname('%') != '-TabBar-'
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Bf_Choosed: called in invalid window',1)
endif
return -1
endif
let l:save_reg = @"
let @" = ""
normal ""yi[
if @" != ""
let l:retv = substitute(@",'\([0-9]*\):.*', '\1', '') + 0
let @" = l:save_reg
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Bf_Choosed: l:retv='.l:retv,5)
endif
return l:retv
else
let @" = l:save_reg
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Bf_Choosed: return -1',1)
endif
return -1
endif
endfunction " %%
" Bf_DelWithD - From the -TabBar- window, delete selected buffer from list ~~
" After making sure that we are in our explorer, This will delete the buffer
" under the cursor. If the buffer under the cursor is being displayed in a
" window, this routine will attempt to get different buffers into the
" windows that will be affected so that windows don't get removed.
function! <SID>Bf_DelWithD()
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('ENTER: Bf_DelWithD() g:Tb_VimBufList =['. g:Tb_VimBufList.'] g:Tb_BufferMap=['.g:Tb_BufferMap.']',10)
endif
" Make sure we are in our window
if bufname('%') != '-TabBar-'
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Bf_DelWithD not called in -TabBar-',1)
endif
return
endif
let l:selected_buf = <SID>Bf_Choosed()
let l:selected_buf = <SID>Map_Get_key( l:selected_buf )
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: l:selected_buf=['.l:selected_buf.']',5)
endif
let l:selected_name = bufname(l:selected_buf +0 )
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: l:selBufName=['. l:selected_name.']',5)
endif
let l:curLine = line('.')
let l:curCol = virtcol('.')
"make the filename an option
if l:selected_name == 'TabBar.DBG' && g:Tb_DBG_LVL > 0
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('EXIT : Bf_DelWithD will not delete the debug window.',1)
endif
return
endif
let l:save_rep = &report
let l:save_sc = &showcmd
let &report = 10000
set noshowcmd
if l:selected_buf != -1 && l:selected_name != ""
" Don't want auto updates while we are processing a delete
" request.
let l:saveTb_AutoUpdt = g:Tb_AutoUpdt
let g:Tb_AutoUpdt = 0
" Save previous window so that if we show a buffer after
" deleting. The show will come up in the correct window.
wincmd p
let l:prevWin = winnr()
let l:prevWinBuf = winbufnr(winnr())
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: l:prevWin='.l:prevWin.' buffer in window: '.l:prevWinBuf,5)
call <SID>DEBUG('Bf_DelWithD: l:selected_name=<'.l:selected_name.'>: l:selected_buf=['.l:selected_buf.']',5)
endif
" If buffer is being displayed in a window then
" move window to a different buffer before
" deleting this one.
let l:winNum = (bufwinnr(l:selected_name) + 0)
" while we have windows that contain our buffer
while l:winNum != -1
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: l:selected_buf='.l:selected_buf.' is being displayed in window: l:winNum='.l:winNum,5)
endif
" move to window that contains our selected buffer
exec l:winNum.' wincmd w'
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: We are now in window: '.winnr().' which contains buffer: '.bufnr('%').' and should contain buffer: '.l:selected_buf,5)
endif
let l:origBuf = bufnr('%')
call <SID>Bf_Cycle(1)
let l:curBuf = bufnr('%')
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: Window now contains buffer: '.bufnr('%').' which should not be: '.l:selected_buf,5)
endif
if l:origBuf == l:curBuf
" we wrapped so we are going to have to delete a buffer
" that is in an open window.
let l:winNum = -1
else
" see if we have anymore windows with our selected buffer
let l:winNum = (bufwinnr(l:selected_name) + 0)
endif
endwhile
" Attempt to restore previous window
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: Restoring previous window to: '.l:prevWin,5)
endif
exec l:prevWin.' wincmd w'
" Try to get back to the -TabBar- window
let l:winNum = bufwinnr(bufnr('-TabBar-'))
if l:winNum != -1
exec l:winNum.' wincmd w'
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: Got to -TabBar- window: '.winnr(),5)
endif
else
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: Unable to get to -TabBar- window',1)
endif
endif
" Delete the buffer selected.
if g:Tb_DBG_LVL > 0
call <SID>DEBUG('Bf_DelWithD: About to delete buffer: '.l:selected_buf,5)
endif
" [displayed_buffer]-- [real_buffer] list
"let l:vimBuf = <SID>Map_Get_key( l:selected_buf )
exec('silent! bd '.l:selected_buf )