Skip to content

Conversation

jebaum
Copy link
Contributor

@jebaum jebaum commented Jan 23, 2022

Changed implementation to recalculate the whole contents of t:tabline_framework_buffer_list whenever executing instead of trying to keep track of state. Cleaner, less error prone, and in practice seems to be perfectly performant.

This has worked reliably for me so far in several hours of usage. I've been working on my own version of the diagonal_tiles example config that uses this code to show a list of the buffers open in a tab within the tab bar. As noted in the below diff, still have 2 issues to work out. Will get to tha when I next have a bit of spare time.

diff --git i/lua/tabline_framework/examples/diagonal_tiles.lua w/lua/tabline_framework/examples/diagonal_tiles.lua
index 1707d73..2d96dfc 100644
--- i/lua/tabline_framework/examples/diagonal_tiles.lua
+++ w/lua/tabline_framework/examples/diagonal_tiles.lua
@@ -15,6 +15,8 @@ local colors = {
   fg = '#696969'
 }
 
+local toys = require 'tabline_framework.toys'
+toys.setup_tab_buffers()
 local render = function(f)
   f.add { '  ' }
 
@@ -24,15 +26,30 @@ local render = function(f)
 
     f.add( info.index .. ' ')
 
-    if info.filename then
-      f.add(info.modified and '+')
-      f.add(info.filename)
-      f.add {
-        ' ' .. f.icon(info.filename),
-        fg = info.current and f.icon_color(info.filename) or nil
-      }
-    else
-      f.add(info.modified and '[+]' or '[-]')
+    local current_tab = vim.api.nvim_get_current_tabpage()
+
+    -- TODO:
+    -- 1. need to handle help windows, possibly other unlisted windows?
+    -- when focused, they'll be populated into info.filename or whatever
+    -- but they won't be in the get_tab_buffers list, since they're unlisted buffers
+    -- 2. need to disambiguate if two files are open with the same name by adding components of the path back
+
+    -- info.buf_name is full path to file, info.filename is just the filename (i.e. the tail of the path)
+    for _,bufpath in pairs(toys.get_tab_buffers(info.tab)) do
+        local filename = string.match(bufpath, ".+/(.*)")
+        if info.buf_name and bufpath == info.buf_name and current_tab == info.tab then
+            f.set_fg("#FDB927")
+        end
+        f.add(filename)
+        f.add(info.modified and '+')
+
+        if info.buf_name and bufpath == info.buf_name and current_tab == info.tab then
+          f.set_fg(f.icon_color(filename))
+        end
+        f.add(' ' .. f.icon(filename))
+
+        f.add(' ')
+        f.set_fg(colors.fg)
     end
 
     f.add {

local is_listed = vim.api.nvim_buf_get_option(buf, 'buflisted')
if is_valid and is_listed then
local name = vim.api.nvim_buf_get_name(buf)
table.insert(buffers_in_tab, name)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must return a list of buffers ids (not names) because this function is intended to work as make_bufs input.

@rafcamlet
Copy link
Owner

Hi @jebaum !

Can you provide some examples of problems with previous implementation or benefits of the new one? For me it looks just like an alternative approach.


Your tabline looks nice. 👍

-- 2. need to disambiguate if two files are open with the same name by adding components of the path back
-- info.buf_name is full path to file, info.filename is just the filename (i.e. the tail of the path)

That's a good idea. I need to think about adding some full path shortener helper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants