nanozuki / tabby.nvim

A declarative, highly configurable, and neovim style tabline plugin. Use your nvim tabs as a workspace multiplexer!
MIT License
607 stars 21 forks source link

feature: add symbol in tab when there are not saved changes on file. #125

Closed sergiornelas closed 1 year ago

sergiornelas commented 1 year ago

Hello, would be amazing if the user has an edited non-saved file, then shows a symbol in the respective tab and window. Thanks.

sergiornelas commented 1 year ago

Checking the docs, that requested feature is available. In order to implement this (just for reference):

local modified_symbol = "[x]"

local function buf_modified(buf)
    if vim.bo[buf].modified then
        return modified_symbol
    else
        return ""
    end
end

local function tab_modified(tab)
    local wins = require("tabby.module.api").get_tab_wins(tab)
    for _, x in pairs(wins) do
        if vim.bo[vim.api.nvim_win_get_buf(x)].modified then
            return modified_symbol
        end
    end
    return ""
end

-- ...
    line.wins_in_tab(line.api.get_current_tab()).foreach(function(win)
             return {
            -- ...
            buf_modified(win.buf().id),
                         -- ...
        }
    end),
        -- ...
    line.tabs().foreach(function(tab)
        return {
            -- ...
            tab_modified(tab.id),
                         -- ...
        }
    end),