Skip to content

Commit 09ba2e0

Browse files
committed
feat(core): Added a global_attach() functions
refactor(core): Changed `defer_fn()` with `schedule()` Everything is slightly faster refactor(core): Updated default configuration
1 parent 339b0bb commit 09ba2e0

File tree

4 files changed

+119
-97
lines changed

4 files changed

+119
-97
lines changed

lua/bars/statuscolumn.lua

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ end
254254
statuscolumn.detach = function (window)
255255
---|fS
256256

257-
vim.defer_fn(function ()
257+
vim.schedule(function ()
258258
vim.w[window].__scID = nil;
259259

260260
vim.api.nvim_set_option_value(
@@ -283,7 +283,7 @@ statuscolumn.detach = function (window)
283283
);
284284

285285
statuscolumn.state.attached_windows[window] = false;
286-
end, 0);
286+
end);
287287

288288
---|fE
289289
end
@@ -322,41 +322,49 @@ end
322322
statuscolumn.attach = function (window)
323323
---|fS
324324

325-
vim.defer_fn(function ()
326-
if statuscolumn.state.enable == false then
327-
return;
328-
elseif statuscolumn.can_attach(window) == false then
325+
if statuscolumn.state.enable == false then
326+
return;
327+
elseif statuscolumn.can_attach(window) == false then
328+
return;
329+
elseif statuscolumn.state.attached_windows[window] == true then
330+
if vim.wo[window].statuscolumn == "%!v:lua.require('bars.statuscolumn').render()" then
331+
statuscolumn.update_id(window);
329332
return;
330-
elseif statuscolumn.state.attached_windows[window] == true then
331-
if vim.wo[window].statuscolumn == "%!v:lua.require('bars.statuscolumn').render()" then
332-
return;
333-
end
334333
end
334+
end
335335

336-
statuscolumn.update_id(window);
336+
statuscolumn.update_id(window);
337337

338-
vim.w[window].__relativenumber = utils.constant(vim.wo[window].relativenumber);
339-
vim.w[window].__numberwidth = utils.constant(vim.wo[window].numberwidth);
340-
vim.w[window].__statuscolumn = utils.constant(vim.wo[window].statuscolumn);
338+
vim.w[window].__relativenumber = utils.constant(vim.wo[window].relativenumber);
339+
vim.w[window].__numberwidth = utils.constant(vim.wo[window].numberwidth);
340+
vim.w[window].__statuscolumn = utils.constant(vim.wo[window].statuscolumn);
341341

342-
vim.wo[window].statuscolumn = "%!v:lua.require('bars.statuscolumn').render()";
343-
end, 0);
342+
vim.wo[window].statuscolumn = "%!v:lua.require('bars.statuscolumn').render()";
344343

345344
---|fE
346345
end
347346

347+
--- Attaches globally.
348+
statuscolumn.global_attach = function ()
349+
for _, window in ipairs(vim.api.nvim_list_wins()) do
350+
statuscolumn.update_id(window);
351+
end
352+
353+
vim.o.statuscolumn = "%!v:lua.require('bars.statuscolumn').render()";
354+
end
355+
348356
--- Cleans up invalid buffers and recalculates
349357
--- valid buffers config ID.
350358
statuscolumn.clean = function ()
351359
---|fS
352360

353-
vim.defer_fn(function ()
361+
vim.schedule(function ()
354362
for window, _ in pairs(statuscolumn.state.attached_windows) do
355363
if statuscolumn.can_detach(window) then
356364
statuscolumn.detach(window);
357365
end
358366
end
359-
end, 0);
367+
end);
360368

361369
---|fE
362370
end

lua/bars/statusline.lua

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ end
504504
statusline.detach = function (window)
505505
---|fS
506506

507-
vim.defer_fn(function ()
507+
vim.schedule(function ()
508508
vim.w[window].__slID = nil;
509509
vim.api.nvim_set_option_value(
510510
"statusline",
@@ -516,7 +516,7 @@ statusline.detach = function (window)
516516
);
517517

518518
statusline.state.attached_windows[window] = false;
519-
end, 0);
519+
end);
520520

521521
---|fE
522522
end
@@ -554,38 +554,46 @@ end
554554
statusline.attach = function (window)
555555
---|fS
556556

557-
vim.defer_fn(function ()
558-
if statusline.state.enable == false then
559-
return;
560-
elseif statusline.can_attach(window) == false then
557+
if statusline.state.enable == false then
558+
return;
559+
elseif statusline.can_attach(window) == false then
560+
return;
561+
elseif statusline.state.attached_windows[window] == true then
562+
if vim.wo[window].statusline == "%!v:lua.require('bars.statusline').render()" then
563+
statusline.update_id(window);
561564
return;
562-
elseif statusline.state.attached_windows[window] == true then
563-
if vim.wo[window].statusline == "%!v:lua.require('bars.statusline').render()" then
564-
return;
565-
end
566565
end
566+
end
567567

568-
statusline.update_id(window);
568+
statusline.update_id(window);
569569

570-
vim.w[window].__statusline = utils.constant(vim.wo[window].statusline);
571-
vim.wo[window].statusline = "%!v:lua.require('bars.statusline').render()";
572-
end, 0);
570+
vim.w[window].__statusline = utils.constant(vim.wo[window].statusline);
571+
vim.wo[window].statusline = "%!v:lua.require('bars.statusline').render()";
573572

574573
---|fE
575574
end
576575

576+
--- Attaches globally.
577+
statusline.global_attach = function ()
578+
for _, window in ipairs(vim.api.nvim_list_wins()) do
579+
statusline.update_id(window);
580+
end
581+
582+
vim.o.statusline = "%!v:lua.require('bars.statusline').render()";
583+
end
584+
577585
--- Cleans up invalid buffers and recalculates
578586
--- valid buffers config ID.
579587
statusline.clean = function ()
580588
---|fS
581589

582-
vim.defer_fn(function ()
590+
vim.schedule(function ()
583591
for window, _ in pairs(statusline.state.attached_windows) do
584592
if statusline.can_detach(window) then
585593
statusline.detach(window);
586594
end
587595
end
588-
end, 0);
596+
end);
589597

590598
---|fE
591599
end

lua/bars/tabline.lua

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,36 @@ tabline.config = {
1212
{
1313
kind = "tabs",
1414

15+
separator_text = " ",
16+
separator_hl = "Normal",
17+
18+
overflow_text = "",
19+
overflow_hl = "Layer1I",
20+
21+
nav_left_text = " < ",
22+
nav_left_hl = nil,
23+
24+
nav_right_text = " > ",
25+
nav_right_hl = nil,
26+
1527
active = {
16-
padding_left = " ",
17-
padding_right = " ",
28+
padding_left = " ",
29+
padding_right = " ",
30+
31+
win_count = " ┃ 󰨝 %d",
32+
win_count_hl = nil,
33+
34+
icon = "󰛺 ",
1835

19-
hl = "Layer2"
36+
hl = "Color4R"
2037
},
2138
inactive = {
22-
padding_left = " ",
23-
padding_right = " ",
39+
padding_left = " ",
40+
padding_right = " ",
2441

25-
hl = "Layer0"
42+
icon = "󰛻 ",
43+
44+
hl = "Color0B"
2645
}
2746
},
2847
{ kind = "empty", hl = "Normal" },
@@ -47,6 +66,8 @@ tabline.update_id = function ()
4766
local ignore = { "default" };
4867
table.sort(keys);
4968

69+
local ID = "default";
70+
5071
for _, key in ipairs(keys) do
5172
if vim.list_contains(ignore, key) then
5273
goto continue;
@@ -57,15 +78,16 @@ tabline.update_id = function ()
5778
local tmp = tabline.config[key];
5879

5980
if tmp.condition == true then
60-
return key;
81+
ID = key;
6182
elseif pcall(tmp.condition --[[ @as function ]]) and tmp.condition() == true then
62-
return key;
83+
ID = key;
6384
end
6485

6586
::continue::
6687
end
6788

68-
return "default";
89+
vim.g.__tlID = ID;
90+
tabline.state.attached = true;
6991

7092
---|fE
7193
end
@@ -119,13 +141,13 @@ end
119141
tabline.detach = function ()
120142
---|fS
121143

122-
vim.defer_fn(function ()
144+
vim.scheduleefer_fn(function ()
123145
tabline.state.attached = false;
124146
vim.o.tabline = utils.get_const(vim.o.__tabline) or "";
125147

126148
vim.g.__tlID = nil;
127149
vim.g.__tabline = nil;
128-
end, 0);
150+
end);
129151

130152
---|fE
131153
end
@@ -148,32 +170,26 @@ end
148170
tabline.attach = function ()
149171
---|fS
150172

151-
vim.defer_fn(function ()
152-
if tabline.can_attach() == false then
153-
return;
154-
end
155-
156-
local tlID = tabline.update_id();
157-
tabline.state.attached = true;
173+
if tabline.can_attach() == false then
174+
return;
175+
end
158176

159-
vim.g.__tlID = tlID;
160-
vim.g.__tabline = utils.constant(vim.o.tabline);
177+
tabline.update_id();
161178

162-
vim.g.__tabline = utils.constant(vim.o.tabline);
163-
vim.o.tabline = "%!v:lua.require('bars.tabline').render()";
164-
end, 0);
179+
vim.g.__tabline = utils.constant(vim.o.tabline);
180+
vim.o.tabline = "%!v:lua.require('bars.tabline').render()";
165181

166182
---|fE
167183
end
168184

169185
--- Cleans up invalid buffers and recalculates
170186
--- valid buffers config ID.
171187
tabline.clean = function ()
172-
vim.defer_fn(function ()
188+
vim.schedule(function ()
173189
if tabline.can_detach() then
174190
tabline.detach();
175191
end
176-
end, 0);
192+
end);
177193
end
178194

179195
--- Sets up the tabline module.
@@ -183,7 +199,7 @@ tabline.setup = function (config)
183199
tabline.config = vim.tbl_extend("force", tabline.config, config);
184200
end
185201

186-
vim.g.__tlID = tabline.update_id();
202+
tabline.update_id();
187203
end
188204

189205
return tabline;

0 commit comments

Comments
 (0)