summaryrefslogtreecommitdiff
path: root/neovim/lua/vimrc/utils.lua
blob: 386efd285d12706509e0a0e598ad73b5821f5cb5 (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
local vim = vim
local cmd = vim.cmd
local M = {}

-- paths {{{
-- }}}
--
-- logging {{{
function M.log_error(msg, source, persist)
    if source then
        msg = "[" .. source .. "] " .. msg
    end
    cmd [[echohl ErrorMsg]]
    if persist then
        cmd("echomsg '" .. msg .. "'")
    else
        cmd("echo '" .. msg .. "'")
    end
    cmd [[echohl Normal]]
end

function M.log_warning(msg, source, persist)
    if source then
        msg = "[" .. source .. "]" .. msg
    end
    msg = string.gsub(msg, "'", '"')
    cmd [[echohl WarningMsg]]
    if persist then
        cmd("echomsg '" .. msg .. "'")
    else
        cmd("echo '" .. msg .. "'")
    end
    cmd [[echohl Normal]]
end
-- }}}

-- tables {{{
function table.filter()
    print"hi"
end

function table.keys(tbl)
    local k = {}
    for key, val in pairs(tbl) do
        table.insert(k, key)
    end
    return k
end

-- }}}

-- string {{{
function string.join(str, join_token)
    local j = ""
    local join = join_token or ""
    if #str == 1 then
        return str[1]
    end
    for i, token in ipairs(str) do
        if i > 1 then
            j = j .. join .. token
        else 
            j = j .. token
        end
    end
    return j
end
-- }}}
return M
-- vim: fdm=marker