R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
132 stars 15 forks source link

Status line indicator #10

Closed jalvesaq closed 4 months ago

jalvesaq commented 5 months ago

Not an issue; just sharing my status line configuration, which includes an R-Nvim indicator. We can improve it and add the code as a suggestion for configuration to the Wiki...

    {
        "nvim-lualine/lualine.nvim",
        config = function()
            local function macro_recording()
                local reg = vim.fn.reg_recording()
                if reg == "" then
                    return ""
                end
                return "[" .. reg .. "]"
            end

            local rstt =
            {
                { "-", "#aaaaaa" }, -- 1: ftplugin/* sourced, but nclientserver not started yet.
                { "S", "#757755" }, -- 2: nclientserver started, but not ready yet.
                { "S", "#117711" }, -- 3: nclientserver is ready.
                { "S", "#ff8833" }, -- 4: nclientserver started the TCP server
                { "S", "#3388ff" }, -- 5: TCP server is ready
                { "R", "#ff8833" }, -- 6: R started, but nvimcom was not loaded yet.
                { "R", "#3388ff" }, -- 7: nvimcom is loaded.
            }

            local rstatus = function ()
                if not vim.g.R_Nvim_status or vim.g.R_Nvim_status == 0 then
                    -- No R file type (R, Quarto, Rmd, Rhelp) opened yet
                    return ""
                end
                return rstt[vim.g.R_Nvim_status][1]
            end

            local rsttcolor = function ()
                if not vim.g.R_Nvim_status or vim.g.R_Nvim_status == 0 then
                    -- No R file type (R, Quarto, Rmd, Rhelp) opened yet
                    return { fg = "#000000" }
                end
                return { fg = rstt[vim.g.R_Nvim_status][2] }
            end

            local selectionCount = function ()
                local m = vim.fn.mode()
                if m == "v" or m == "V" then
                    local c = vim.fn.wordcount()
                    return tostring(c.visual_words) .. " Words, " .. tostring(c.visual_chars) .. " Chars"
                end
                return ""
            end

            require("lualine").setup({
                options = {
                    section_separators = "",
                    component_separators = "",
                    globalstatus = true,
                },
                sections = {
                    lualine_a = { "mode", macro_recording },
                    lualine_b = { {'FugitiveHead', icon = ''}, "diagnostics" },
                    lualine_c = { "filename", "searchcount",  },
                    lualine_x = { selectionCount },
                    lualine_y = { {rstatus, color = rsttcolor }},
                    lualine_z = { "progress", "location" },
                },
                -- extensions = { "nvim-tree" },
            })
        end,
    },
jalvesaq commented 4 months ago

In the Wiki now.