1
+ --- Custom statuscolumn module.
1
2
local statuscolumn = {};
2
3
local components = require (" bars.components.statuscolumn" );
3
4
@@ -8,13 +9,30 @@ local STC = "%!v:lua.require('bars.statuscolumn').render()";
8
9
--- @type statuscolumn.config
9
10
statuscolumn .config = {
10
11
ignore_filetypes = { " blink-cmp-menu" },
11
- ignore_buftypes = { " nofile" , " help" },
12
+ ignore_buftypes = { " help" },
13
+
14
+ condition = function (buffer )
15
+ local ft , bt = vim .bo [buffer ].ft , vim .bo [buffer ].bt ;
16
+
17
+ if bt == " nofile" and ft == " query" then
18
+ --- Buffer for `:InspectTree`
19
+ return true ;
20
+ elseif bt == " nofile" then
21
+ --- Normal nofile buffer.
22
+ return false ;
23
+ else
24
+ return true ;
25
+ end
26
+ end ,
12
27
13
28
default = {
14
29
parts = {
30
+ --- | fS
31
+
15
32
{
16
33
kind = " empty" ,
17
34
width = 1 ,
35
+
18
36
hl = " Normal"
19
37
},
20
38
{
@@ -157,10 +175,14 @@ statuscolumn.config = {
157
175
--- | fE
158
176
end
159
177
},
178
+
179
+ --- | fE
160
180
}
161
181
},
162
182
163
183
query = {
184
+ --- | fS
185
+
164
186
condition = function (buffer )
165
187
return vim .bo [buffer ].ft == " query" and vim .bo [buffer ].bt == " nofile" ;
166
188
end ,
@@ -169,9 +191,11 @@ statuscolumn.config = {
169
191
{
170
192
kind = " empty" ,
171
193
width = 1 ,
172
- hl = " Normal "
194
+ hl = " LineNr "
173
195
},
174
196
}
197
+
198
+ --- | fE
175
199
}
176
200
};
177
201
@@ -274,7 +298,12 @@ statuscolumn.render = function ()
274
298
--- | fE
275
299
end
276
300
301
+ --- Can we detach from {win}?
302
+ --- @param win integer
303
+ --- @return boolean
277
304
statuscolumn .can_detach = function (win )
305
+ --- | fS
306
+
278
307
if vim .api .nvim_win_is_valid (win ) == false then
279
308
return false ;
280
309
end
@@ -300,6 +329,8 @@ statuscolumn.can_detach = function (win)
300
329
return false ;
301
330
end
302
331
end
332
+
333
+ --- | fE
303
334
end
304
335
305
336
--- Detaches from {buffer}.
@@ -357,7 +388,13 @@ statuscolumn.detach = function (window)
357
388
--- | fE
358
389
end
359
390
391
+ --- Can we attach to {win}
392
+ --- @param win integer
393
+ --- @param force ? boolean Forcefully attach (for windows with state ` false` ).
394
+ --- @return boolean
360
395
statuscolumn .can_attach = function (win , force )
396
+ --- | fS
397
+
361
398
if type (win ) ~= " number" or vim .api .nvim_win_is_valid (win ) == false then
362
399
return false ;
363
400
elseif force ~= true and statuscolumn .state .attached_windows [win ] == false then
@@ -387,6 +424,8 @@ statuscolumn.can_attach = function (win, force)
387
424
return true ;
388
425
end
389
426
end
427
+
428
+ --- | fE
390
429
end
391
430
392
431
--- Attaches the statuscolumn module to the windows
@@ -410,6 +449,9 @@ statuscolumn.attach = function (window, force)
410
449
vim .w [window ].__relativenumber = vim .wo [window ].relativenumber ;
411
450
vim .w [window ].__numberwidth = vim .wo [window ].numberwidth ;
412
451
452
+ vim .wo [window ].relativenumber = true ;
453
+ vim .wo [window ].numberwidth = 1 ;
454
+
413
455
--- If the statuscolumn matches the one we set then
414
456
--- this is most likely due to inheriting window properties.
415
457
---
424
466
425
467
--- Attaches globally.
426
468
statuscolumn .global_attach = function ()
469
+ --- | fS
470
+
427
471
if statuscolumn .state .enable == false then
428
472
return ;
429
473
end
@@ -432,8 +476,16 @@ statuscolumn.global_attach = function ()
432
476
statuscolumn .update_id (window );
433
477
end
434
478
479
+ vim .g .__relativenumber = vim .o .relativenumber ;
480
+ vim .g .__numberwidth = vim .o .numberwidth ;
481
+
482
+ vim .o .relativenumber = true ;
483
+ vim .o .numberwidth = 1 ;
484
+
435
485
vim .g .__statuscolumn = vim .o .statuscolumn == STC and " " or vim .o .statuscolumn ;
436
486
vim .o .statuscolumn = STC ;
487
+
488
+ --- | fE
437
489
end
438
490
439
491
--- Cleans up invalid buffers and recalculates
@@ -457,73 +509,99 @@ end
457
509
--- Enables statuscolumn for `window`.
458
510
--- @param window integer
459
511
statuscolumn .enable = function (window )
512
+ --- | fS
513
+
460
514
if type (window ) ~= " number" or statuscolumn .state .attached_windows [window ] == nil then
461
515
return ;
462
516
end
463
517
464
518
statuscolumn .attach (window , true );
519
+
520
+ --- | fE
465
521
end
466
522
467
523
--- Enables *all* attached windows.
468
524
statuscolumn .Enable = function ()
525
+ --- | fS
526
+
469
527
statuscolumn .state .enable = true ;
470
528
471
529
for window , state in pairs (statuscolumn .state .attached_windows ) do
472
530
if state ~= true then
473
531
statuscolumn .enable (window );
474
532
end
475
533
end
534
+
535
+ --- | fE
476
536
end
477
537
478
538
--- Disables statuscolumn for `window`.
479
539
--- @param window integer
480
540
statuscolumn .disable = function (window )
541
+ --- | fS
542
+
481
543
if type (window ) ~= " number" or statuscolumn .state .attached_windows [window ] == nil then
482
544
return ;
483
545
end
484
546
485
547
statuscolumn .detach (window );
548
+
549
+ --- | fE
486
550
end
487
551
488
552
--- Disables *all* attached windows.
489
553
statuscolumn .Disable = function ()
554
+ --- | fS
555
+
490
556
for window , state in pairs (statuscolumn .state .attached_windows ) do
491
557
if state ~= false then
492
558
statuscolumn .disable (window );
493
559
end
494
560
end
495
561
496
562
statuscolumn .state .enable = false ;
563
+
564
+ --- | fE
497
565
end
498
566
499
567
---- ------------------------------------------------------------------
500
568
501
569
--- Toggles state of given window.
502
570
--- @param window integer
503
571
statuscolumn .toggle = function (window )
572
+ --- | fS
573
+
504
574
if type (window ) ~= " number" or statuscolumn .state .attached_windows [window ] == nil then
505
575
return ;
506
576
elseif statuscolumn .state .attached_windows [window ] == true then
507
577
statuscolumn .disable (window );
508
578
else
509
579
statuscolumn .enable (window );
510
580
end
581
+
582
+ --- | fE
511
583
end
512
584
513
585
--- Toggles statuscolumn **globally**.
514
586
statuscolumn .Toggle = function ()
587
+ --- | fS
588
+
515
589
if statuscolumn .state .enable == true then
516
590
statuscolumn .Disable ();
517
591
else
518
592
statuscolumn .Enable ();
519
593
end
594
+
595
+ --- | fE
520
596
end
521
597
522
598
---- ------------------------------------------------------------------
523
599
524
600
--- Sets up the statuscolumn module.
525
601
--- @param config statuscolumn.config | boolean | nil
526
602
statuscolumn .setup = function (config )
603
+ --- | fS
604
+
527
605
if type (config ) == " table" then
528
606
statuscolumn .config = vim .tbl_extend (" force" , statuscolumn .config , config );
529
607
elseif type (config ) == " boolean" then
@@ -533,6 +611,8 @@ statuscolumn.setup = function (config)
533
611
for window , _ in pairs (statuscolumn .state .attached_windows ) do
534
612
vim .w [window ].__scID = statuscolumn .update_id (window );
535
613
end
614
+
615
+ --- | fE
536
616
end
537
617
538
618
return statuscolumn ;
0 commit comments