summaryrefslogtreecommitdiff
path: root/start/indent-blankline-2.20.4/lua/indent_blankline/commands.lua
blob: 263d3325ffc576176e853d033f909a8abd6bc120 (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
local M = {}

M.refresh = function(bang, scroll)
    scroll = scroll or false
    if bang then
        local win = vim.api.nvim_get_current_win()
        vim.cmd(string.format([[noautocmd windo lua require("indent_blankline").refresh(%s)]], tostring(scroll)))
        if vim.api.nvim_win_is_valid(win) then
            vim.api.nvim_set_current_win(win)
        end
    else
        require("indent_blankline").refresh(scroll)
    end
end

M.enable = function(bang)
    if bang then
        vim.g.indent_blankline_enabled = true
        local win = vim.api.nvim_get_current_win()
        vim.cmd [[noautocmd windo lua require("indent_blankline").refresh(false)]]
        vim.api.nvim_set_current_win(win)
    else
        vim.b.indent_blankline_enabled = true
        require("indent_blankline").refresh(false)
    end
end

M.disable = function(bang)
    if bang then
        vim.g.indent_blankline_enabled = false
        local buffers = vim.api.nvim_list_bufs()
        for _, buffer in pairs(buffers) do
            vim.api.nvim_buf_clear_namespace(buffer, vim.g.indent_blankline_namespace, 1, -1)
        end
    else
        vim.b.indent_blankline_enabled = false
        vim.b.__indent_blankline_active = false
        vim.api.nvim_buf_clear_namespace(0, vim.g.indent_blankline_namespace, 1, -1)
    end
end

M.toggle = function(bang)
    if bang then
        if vim.g.indent_blankline_enabled then
            M.disable(bang)
        else
            M.enable(bang)
        end
    else
        if vim.b.__indent_blankline_active then
            M.disable(bang)
        else
            M.enable(bang)
        end
    end
end

return M