summaryrefslogtreecommitdiff
path: root/plugin/plugins/mini.lua
blob: 92f86c633df38b01727e2b8edb121267db585dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require("mini.notify").setup({
    lsp_progress = { enable = false },
})

local misc = require("mini.misc")
misc.setup_restore_cursor()
misc.setup_termbg_sync()

vim.schedule(function()
    local snippets = require("mini.snippets")
    snippets.setup({
        snippets = {
            snippets.gen_loader.from_lang(),
        },
    })
    local fin_stop = function(args)
        if args.data.tabstop_to == "0" then snippets.session.stop() end
    end
    local au_opts = { pattern = "MiniSnippetsSessionJump", callback = fin_stop }
    vim.api.nvim_create_autocmd("User", au_opts)
end)

vim.schedule(function()
    local hipatterns = require("mini.hipatterns")
    hipatterns.setup({
        highlighters = {
            fixme = { pattern = "FIXME", group = "MiniHipatternsFixme" },
            todo = { pattern = "TODO", group = "MiniHipatternsTodo" },
            note = { pattern = "NOTE", group = "MiniHipatternsNote" },
            hex_color = hipatterns.gen_highlighter.hex_color(),
        },
    })
end)

vim.schedule(function() require("mini.icons").setup() end)

local section_filename = function()
    local st = "%{% &busy > 0 ? '◐ ' : '' %}"
    -- In terminal always use plain name
    if vim.bo.buftype == "terminal" then
        return st .. "%t"
    elseif _G.MiniStatusline.is_truncated(140) then
        -- File name with 'truncate', 'modified', 'readonly' flags
        -- Use relative path if truncated
        return st .. "%f%m%r"
    else
        -- Use fullpath if not truncated
        return st .. "%F%m%r"
    end
end

local section_git = function()
    if _G.MiniStatusline.is_truncated(40) then return "" end
    local summary = vim.b.gitsigns_head
    if summary == nil then return "" end
    return " " .. (summary == "" and "-" or summary)
end

local section_diff = function()
    if _G.MiniStatusline.is_truncated(75) then return "" end
    local summary = vim.b.gitsigns_status
    if summary == nil then return "" end
    return (summary == "" and "-" or summary)
end

local my_diag_status = function(hl_end)
    local diag = vim.diagnostic
    local counts = diag.count(0)
    local signs = { "E", "W", "I", "H" }
    local hl_map = {
        [diag.severity.ERROR] = "DiagSLError",
        [diag.severity.WARN] = "DiagSLWarn",
        [diag.severity.INFO] = "DiagSLInfo",
        [diag.severity.HINT] = "DiagSLHint",
    }
    local result_str = vim.iter(pairs(counts))
        :map(
            function(severity, count)
                return ("%%#%s#%s:%s"):format(
                    hl_map[severity],
                    signs[severity],
                    count
                )
            end
        )
        :join(" ")
    if result_str:len() > 0 then
        result_str = result_str .. "%##%#" .. hl_end .. "#"
    end
    return result_str
end

local section_diagnostics = function()
    if _G.MiniStatusline.is_truncated(75) then return "" end
    if package.loaded["vim.diagnostic"] and #vim.diagnostic.count() ~= 0 then
        return my_diag_status("SLDev")
    end
    return ""
end

vim.schedule(function()
    local statusline = require("mini.statusline")
    statusline.setup({
        content = {
            active = function()
                local git = section_git()
                local diff = section_diff()
                local diagnostics = section_diagnostics()

                local lsp = statusline.section_lsp({ trunc_width = 75 })
                local filename = section_filename()
                local fileinfo = vim.bo.filetype
                local location = "%-6.(%l,%c%V%) %P"
                -- "%{% &ruler ? ( &rulerformat == '' ? '' : &rulerformat ) : '' %}"

                return statusline.combine_groups({
                    { hl = "SLFilename", strings = { filename } },
                    "%=", -- End left alignment
                    { hl = "SLDev", strings = { git, diff, diagnostics, lsp } },
                    "%<", -- Mark general truncate point
                    { hl = "SLFileInfo", strings = { fileinfo } },
                    { hl = "SLLocation", strings = { location } },
                })
            end,
            inactive = nil,
        },
        use_icons = true,
    })
end)