-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
167 lines (139 loc) · 4.58 KB
/
init.lua
File metadata and controls
167 lines (139 loc) · 4.58 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
_G.Config = {}
vim.pack.add { 'https://github.com/nvim-mini/mini.misc' }
local misc = require 'mini.misc'
---@alias Config.Callback fun()
---@alias Config.KeymapRhs string|function
---@alias Config.AutocmdCallback fun(ev: vim.api.keyset.create_autocmd.callback_args): boolean?|fun(): boolean?
---@class Config.AutocmdOpts: vim.api.keyset.create_autocmd
---@field callback? nil
---@field command? nil
---@field group? nil
---@class Config.PackChangedEvent: vim.api.keyset.create_autocmd.callback_args
---@field data { spec: { name: string }, kind: string, active: boolean }
---@param f Config.Callback
Config.now = function(f)
misc.safely('now', f)
end
---@param f Config.Callback
Config.later = function(f)
misc.safely('later', f)
end
---@param f Config.Callback
Config.now_if_args = function(f)
return (vim.fn.argc(-1) > 0 and Config.now or Config.later)(f)
end
---@param ev string|string[]
---@param f Config.Callback
Config.on_event = function(ev, f)
misc.safely('event:' .. ev, f)
end
---@param ft string|string[]
---@param f Config.Callback
Config.on_filetype = function(ft, f)
misc.safely('filetype:' .. ft, f)
end
Config.apply_colorscheme = function()
local schemes = vim.g.colorscheme or {}
local scheme = schemes[vim.o.background]
if scheme and scheme ~= '' then vim.cmd.colorscheme(scheme) end
end
Config.lsp_includeexpr = function()
local target = vim.ui._get_urls()[1]
if target and not target:match '^%w+:' then return target end
return vim.v.fname
end
Config.statusline_activity = function()
local winid = vim.g.statusline_winid or vim.api.nvim_get_current_win()
local bufnr = vim.api.nvim_win_get_buf(winid)
local parts = {}
if winid == tonumber(vim.g.actual_curwin or -1) then
local progress = vim.trim(vim.ui.progress_status())
if progress ~= '' then parts[#parts + 1] = progress end
end
if vim.bo[bufnr].busy > 0 then parts[#parts + 1] = '◐' end
if next(vim.diagnostic.count(bufnr)) then parts[#parts + 1] = vim.diagnostic.status(bufnr) end
if #parts == 0 then return '' end
return table.concat(parts, ' ') .. ' '
end
local gr = vim.api.nvim_create_augroup('custom-config', { clear = true })
---@param event string|string[]
---@param callback Config.AutocmdCallback
---@param opts? Config.AutocmdOpts
---@return integer
Config.new_autocmd = function(event, callback, opts)
return vim.api.nvim_create_autocmd(
event,
vim.tbl_extend('force', opts or {}, {
group = gr,
callback = callback,
})
)
end
---@param plugin_name string
---@param kinds string[]
---@param callback Config.Callback
---@param desc string?
Config.on_packchanged = function(plugin_name, kinds, callback, desc)
---@param ev Config.PackChangedEvent
local f = function(ev)
local name, kind = ev.data.spec.name, ev.data.kind
if not (name == plugin_name and vim.tbl_contains(kinds, kind)) then return end
if not ev.data.active then vim.cmd.packadd(plugin_name) end
callback()
end
Config.new_autocmd('PackChanged', f, { desc = desc, pattern = '*' })
end
---@param lhs string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.nmap = function(lhs, rhs, desc)
vim.keymap.set('n', lhs, rhs, { desc = desc })
end
---@param lhs string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.imap = function(lhs, rhs, desc)
vim.keymap.set('i', lhs, rhs, { desc = desc })
end
---@param lhs string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.vmap = function(lhs, rhs, desc)
vim.keymap.set('v', lhs, rhs, { desc = desc })
end
---@param lhs string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.xmap = function(lhs, rhs, desc)
vim.keymap.set('x', lhs, rhs, { desc = desc })
end
---@param lhs string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.smap = function(lhs, rhs, desc)
vim.keymap.set('s', lhs, rhs, { desc = desc })
end
---@param suffix string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.nmap_leader = function(suffix, rhs, desc)
vim.keymap.set('n', '<Leader>' .. suffix, rhs, { desc = desc })
end
---@param suffix string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.imap_leader = function(suffix, rhs, desc)
vim.keymap.set('i', '<Leader>' .. suffix, rhs, { desc = desc })
end
---@param suffix string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.vmap_leader = function(suffix, rhs, desc)
vim.keymap.set('v', '<Leader>' .. suffix, rhs, { desc = desc })
end
---@param suffix string
---@param rhs Config.KeymapRhs
---@param desc string?
Config.xmap_leader = function(suffix, rhs, desc)
vim.keymap.set('x', '<Leader>' .. suffix, rhs, { desc = desc })
end