-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
113 lines (102 loc) · 4.4 KB
/
init.lua
File metadata and controls
113 lines (102 loc) · 4.4 KB
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
if vim.fn.has("nvim-0.11.0") == 0 then
vim.api.nvim_echo({
{ "This configurations requires Neovim >= 0.11.0\n", "ErrorMsg" },
{ "Aborting configuration. You will be left with Vanilla Neovim.\n", "ErrorMsg" },
{ "Press any key to continue.", "MoreMsg" },
}, true, {})
vim.fn.getchar()
return
end
---Remove . from the package.path. This never does anything good.
package.path = package.path:gsub("^%./%?%.lua;", "")
package.cpath = package.cpath:gsub("^%./%?%.so;", "")
-- Fowards compatability:
table.pack = table.pack or function(...) return { n = select("#", ...), ... } end
table.unpack = table.unpack or unpack
--- Wait until after config is loaded before starting notification timer
local _start_notifs_timer ---@type function?
do -- delay notifications till vim.notify was replaced or after 500ms
local notifs, orig = {}, vim.notify
local function temp(...) table.insert(notifs, vim.F.pack_len(...)) end
vim.notify = temp
local timer, check = vim.uv.new_timer(), vim.uv.new_check()
assert(timer)
assert(check)
local function replay()
_ = { timer:stop(), timer:close(), check:stop(), check:close() } -- clean up the timer and check
timer, check = nil, nil
if vim.notify == temp then vim.notify = orig end -- put back the original notify if needed
vim.schedule(function()
for _, notif in ipairs(notifs) do
vim.notify(vim.F.unpack_len(notif))
end
notifs = nil
end)
end
check:start(function()
if vim.notify ~= temp then replay() end
end) -- wait till vim.notify has been replaced
_start_notifs_timer = function()
if not timer then return end -- If this is called after the check has fired, then we're good
timer:start(2000, 0, replay) -- or if it took more than 2 sec, then something went wrong
_start_notifs_timer = nil -- only run this once/gc
end
end
require("config.options") -- This needs to come first!
require("config.lazy") -- bootstrap lazy.nvim and plugins
-- Require all the files in ./config
require("lazy.core.util").lsmod("config", require)
--- Handle regenerating helptags in new VIMRUNTIMEs
local rt = os.getenv("VIMRUNTIME")
if rt and vim.uv.fs_access(rt, "W") then
--- Regen the helptags
vim.cmd.helptags(vim.fs.joinpath(rt, "doc"))
end
---@class nvim_buf_get_keymap.Keymap
---@field abbr 0|1,
---@field buffer 0|1,
---@field desc? string,
---@field expr 0|1,
---@field lhs string,
---@field lhsraw string,
---@field lnum 0|1,
---@field mode? string,
---@field mode_bits integer,
---@field noremap 0|1,
---@field nowait 0|1,
---@field rhs? string,
---@field callback? function,
---@field script 0|1,
---@field scriptversion integer,
---@field sid integer,
---@field silent 0|1,
vim.schedule(function()
---@type nvim_buf_get_keymap.Keymap[]
local keys = vim
.iter({ vim.api.nvim_buf_get_keymap(0, ""), vim.api.nvim_get_keymap("") })
:flatten(1)
:filter(function(k) ---@param k nvim_buf_get_keymap.Keymap
return k.lhs ~= "" and not k.lhs:find("^<Plug>") -- exclude plug mappings
end)
:filter(function(k) ---@param k nvim_buf_get_keymap.Keymap
local has_rhs = k.rhs ~= nil and (k.rhs ~= "" and k.rhs:upper() ~= "<NOP>") -- exclude empty mappings
local has_desc = k.desc ~= nil -- exclude empty descriptions
local has_callback = k.callback ~= nil -- exclude empty callbacks
if not has_rhs and not has_callback then return false end -- if this mapping doesn't do anything, don't show it
return has_desc or has_rhs -- Only show it if it has a description or a rhs (callbacks aren't displayable)
end)
:totable()
local i = math.random(1, #keys)
local k = keys[i]
local ml, mll = vim.g.mapleader or "\\", vim.g.maplocalleader or "\\"
do -- NOTE: Technically, <Leader> can be used anywhwere, but it's convention to put it at the start of the mapping. It's impossible to know whether it was intended to be <Leader> or the content.
local lhs = k.lhs:gsub("^" .. vim.pesc(ml), "<Leader>") -- replace mapleader with <Leader>
if ml ~= mll then -- replace maplocalleader with <LocalLeader>
lhs = lhs:gsub("^" .. vim.pesc(mll), "<LocalLeader>")
end
k.lhs = lhs:gsub(" ", "<Space>") -- replace spaces with <Space>
end
local msg = ("%smap %s"):format(k.mode or "", k.lhs) .. ": " .. (k.desc or k.rhs)
require("utils.notifications").info(msg, { title = "Keymap", timeout = 30 * 1000 })
end)
vim.schedule(_start_notifs_timer) -- start the timer after we're done with everything