luukvbaal / statuscol.nvim

Status column plugin that provides a configurable 'statuscolumn' and click handlers.
MIT License
529 stars 23 forks source link

git diff/changed lines integration #18

Closed amaanq closed 1 year ago

amaanq commented 1 year ago

Really liking this plugin, but it's conflicting with a current setup I have to show git diffs/changes after the line nr.

Example (look right after the line numbers):

image

Code snippet to add this:

status.lua

local M = {}
_G.Status = M

---@return {name:string, text:string, texthl:string}[]
function M.get_signs()
    local buf = vim.api.nvim_win_get_buf(vim.g.statusline_winid)
    return vim.tbl_map(function(sign)
        return vim.fn.sign_getdefined(sign.name)[1]
    end, vim.fn.sign_getplaced(buf, { group = "*", lnum = vim.v.lnum })[1].signs)
end

function M.column()
    local sign, git_sign
    for _, s in ipairs(M.get_signs()) do
        if s.name:find("GitSign") then
            git_sign = s
        else
            sign = s
        end
    end

    local nu = " "
    local number = vim.api.nvim_win_get_option(vim.g.statusline_winid, "number")
    if number and vim.wo.relativenumber and vim.v.virtnum == 0 then
        nu = vim.v.relnum == 0 and vim.v.lnum or vim.v.relnum
    end
    local components = {
        sign and ("%#" .. sign.texthl .. "#" .. sign.text .. "%*") or " ",
        [[%=]],
        nu .. " ",
        git_sign and ("%#" .. git_sign.texthl .. "#" .. git_sign.text .. "%*") or "  ",
    }
    return table.concat(components, "")
end

if vim.fn.has("nvim-0.9.0") == 1 then
    vim.opt.statuscolumn = [[%!v:lua.Status.column()]]
end

return M

Having this and statuscol pushes this git diff feature to the left of line nrs, like so: image

I understand it's a bit of work to add this, but it'd be really nice to see!

Thanks, Amaan

luukvbaal commented 1 year ago

Hmm, I'm not sure that I get what you're trying to do. Do you want to separate the git signs from the default sign column, or to place all signs in general after the line number?

For the former I think this is covered by https://github.com/luukvbaal/statuscol.nvim/issues/9? In which case thanks for the gist, it might prove useful when I get around to implementing something for it.

But if you just want to place all signs in general after the sign column, you should be able to use to use something like

require("statuscol").setup({setopt = true, order = { "FNSs"})
nyngwang commented 1 year ago
require("statuscol").setup({setopt = true, order = { "FNSs"})

@luukvbaal I tried this but it doesn't work to achieve the first image by OP.

luukvbaal commented 1 year ago

order is deprecated, this plugin now implements a segments config that provides more flexibility. See here for an example: https://github.com/luukvbaal/statuscol.nvim/issues/9#issuecomment-1471982148.

nyngwang commented 1 year ago

@luukvbaal I love this :) Thanks a lot (and I just saw the thread where you made a lot of contributions on merging smoothscroll minutes ago, am using it now)

(I don't mind if you want to use this image in your README)