forked from NormalNvim/NormalNvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.lua
More file actions
316 lines (284 loc) · 10.8 KB
/
Copy pathui.lua
File metadata and controls
316 lines (284 loc) · 10.8 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
--- ### UI toggle functions.
--
-- DESCRIPTION:
-- While you could technically delete this file, we encourage you
-- to keep it as it takes a lot of complexity out of `../4-mappings.lua`.
-- Functions:
-- -> change_number
-- -> set_indent
-- -> toggle_animations
-- -> toggle_autoformat
-- -> toggle_autopairs
-- -> toggle_background
-- -> toggle_buffer_autoformat
-- -> toggle_buffer_inlay_hints
-- -> toggle_buffer_semantic_tokens
-- -> toggle_buffer_syntax
-- -> toggle_codelens
-- -> toggle_coverage_signs
-- -> toggle_cmp
-- -> toggle_conceal
-- -> toggle_diagnostics
-- -> toggle_foldcolumn
-- -> toggle_inlay_hints
-- -> toggle_lsp_signature
-- -> toggle_paste
-- -> toggle_signcolumn
-- -> toggle_spell
-- -> toggle_statusline
-- -> toggle_tabline
-- -> toggle_ui_notifications
-- -> toggle_url_effect
-- -> toggle_wrap
-- -> toggle_zen_mode
local M = {}
local utils = require("base.utils")
local function bool2str(bool) return bool and "on" or "off" end
--- Change the number display modes
function M.change_number()
local number = vim.wo.number -- local to window
local relativenumber = vim.wo.relativenumber -- local to window
if not number and not relativenumber then
vim.wo.number = true
elseif number and not relativenumber then
vim.wo.relativenumber = true
elseif number and relativenumber then
vim.wo.number = false
else -- not number and relativenumber
vim.wo.relativenumber = false
end
utils.notify(string.format("number %s, relativenumber %s", bool2str(vim.wo.number), bool2str(vim.wo.relativenumber)))
end
--- Set the indent and tab related numbers
function M.set_indent()
local input_avail, input = pcall(vim.fn.input, "Set indent value (>0 expandtab, <=0 noexpandtab): ")
if input_avail then
local indent = tonumber(input)
if not indent or indent == 0 then return end
vim.bo.expandtab = (indent > 0) -- local to buffer
indent = math.abs(indent)
vim.bo.tabstop = indent -- local to buffer
vim.bo.softtabstop = indent -- local to buffer
vim.bo.shiftwidth = indent -- local to buffer
utils.notify(string.format("indent=%d %s", indent, vim.bo.expandtab and "expandtab" or "noexpandtab"))
end
end
--- Toggle animations
function M.toggle_animations()
if vim.g.minianimate_disable then
vim.g.minianimate_disable = false
else
vim.g.minianimate_disable = true
end
local state = vim.g.minianimate_disable
utils.notify(string.format("animations %s", bool2str(not state)))
end
--- Toggle auto format
function M.toggle_autoformat()
vim.g.autoformat_enabled = not vim.g.autoformat_enabled
utils.notify(string.format("Global autoformatting %s", bool2str(vim.g.autoformat_enabled)))
end
--- Toggle autopairs
function M.toggle_autopairs()
local ok, autopairs = pcall(require, "nvim-autopairs")
if ok then
if autopairs.state.disabled then
autopairs.enable()
else
autopairs.disable()
end
vim.g.autopairs_enabled = autopairs.state.disabled
utils.notify(string.format("autopairs %s", bool2str(not autopairs.state.disabled)))
else
utils.notify "autopairs not available"
end
end
--- Toggle background="dark"|"light"
function M.toggle_background()
vim.go.background = vim.go.background == "light" and "dark" or "light"
utils.notify(string.format("background=%s", vim.go.background))
end
--- Toggle buffer local auto format
function M.toggle_buffer_autoformat(bufnr)
bufnr = bufnr or 0
local old_val = vim.b[bufnr].autoformat_enabled
if old_val == nil then old_val = vim.g.autoformat_enabled end
vim.b[bufnr].autoformat_enabled = not old_val
utils.notify(string.format("Buffer autoformatting %s", bool2str(vim.b[bufnr].autoformat_enabled)))
end
--- Toggle LSP inlay hints (buffer)
-- @param bufnr? number the buffer to toggle the clients on
function M.toggle_buffer_inlay_hints(bufnr)
bufnr = bufnr or 0
vim.b[bufnr].inlay_hints_enabled = not vim.b[bufnr].inlay_hints_enabled
vim.lsp.inlay_hint.enable(vim.b[bufnr].inlay_hints_enabled, { bufnr = bufnr })
utils.notify(string.format("Buffer inlay hints %s", bool2str(vim.b[bufnr].inlay_hints_enabled)))
end
--- Toggle buffer semantic token highlighting for all language servers that support it
--@param bufnr? number the buffer to toggle the clients on
function M.toggle_buffer_semantic_tokens(bufnr)
bufnr = bufnr or 0
vim.b[bufnr].semantic_tokens_enabled = not vim.b[bufnr].semantic_tokens_enabled
for _, client in ipairs(vim.lsp.get_clients({ bufnr = bufnr })) do
if client.server_capabilities.semanticTokensProvider then
vim.lsp.semantic_tokens[vim.b[bufnr].semantic_tokens_enabled and "start" or "stop"](bufnr, client.id)
utils.notify(string.format("Buffer lsp semantic highlighting %s", bool2str(vim.b[bufnr].semantic_tokens_enabled)))
end
end
end
--- Toggle syntax highlighting and treesitter
function M.toggle_buffer_syntax(bufnr)
-- HACK: this should just be `bufnr = bufnr or 0` but it looks like
-- `vim.treesitter.stop` has a bug with `0` being current.
bufnr = (bufnr and bufnr ~= 0) and bufnr or vim.api.nvim_win_get_buf(0)
local ts_avail, parsers = pcall(require, "nvim-treesitter.parsers")
if vim.bo[bufnr].syntax == "off" then
if ts_avail and parsers.has_parser() then vim.treesitter.start(bufnr) end
vim.bo[bufnr].syntax = "on"
if not vim.b.semantic_tokens_enabled then M.toggle_buffer_semantic_tokens(bufnr, true) end
else
if ts_avail and parsers.has_parser() then vim.treesitter.stop(bufnr) end
vim.bo[bufnr].syntax = "off"
if vim.b.semantic_tokens_enabled then M.toggle_buffer_semantic_tokens(bufnr, true) end
end
utils.notify(string.format("syntax %s", bool2str(vim.bo[bufnr].syntax)))
end
--- Toggle codelens
function M.toggle_codelens()
vim.g.codelens_enabled = not vim.g.codelens_enabled
if not vim.g.codelens_enabled then vim.lsp.codelens.clear() end
utils.notify(string.format("CodeLens %s", bool2str(vim.g.codelens_enabled)))
end
--- Toggle coverage signs
function M.toggle_coverage_signs(bufnr)
bufnr = bufnr or 0
vim.b[bufnr].coverage_signs_enabled = not vim.b[bufnr].coverage_signs_enabled
if vim.b[bufnr].coverage_signs_enabled then
utils.notify("Coverage signs on:" ..
"\n\n- Git signs will be temporary disabled." ..
"\n- Diagnostic signs won't be automatically disabled.")
vim.cmd("Gitsigns toggle_signs")
require("coverage").load(true)
else
utils.notify("Coverage signs off:\n\n- Git signs re-enabled.")
require("coverage").hide()
vim.cmd("Gitsigns toggle_signs")
end
end
--- Toggle cmp entrirely
function M.toggle_cmp()
vim.g.cmp_enabled = not vim.g.cmp_enabled
local ok, _ = pcall(require, "cmp")
utils.notify(ok and string.format("completion %s", bool2str(vim.g.cmp_enabled)) or "completion not available")
end
--- Toggle conceal=2|0
function M.toggle_conceal()
vim.opt.conceallevel = vim.opt.conceallevel:get() == 0 and 2 or 0
utils.notify(string.format("conceal %s", bool2str(vim.opt.conceallevel:get() == 2)))
end
--- Toggle diagnostics
function M.toggle_diagnostics()
vim.g.diagnostics_mode = (vim.g.diagnostics_mode - 1) % 4
vim.diagnostic.config(require("base.utils.lsp").diagnostics[vim.g.diagnostics_mode])
if vim.g.diagnostics_mode == 0 then
utils.notify "diagnostics off"
elseif vim.g.diagnostics_mode == 1 then
utils.notify "only status diagnostics"
elseif vim.g.diagnostics_mode == 2 then
utils.notify "virtual text off"
else
utils.notify "all diagnostics on"
end
end
local last_active_foldcolumn
--- Toggle foldcolumn=0|1
function M.toggle_foldcolumn()
local curr_foldcolumn = vim.wo.foldcolumn
if curr_foldcolumn ~= "0" then last_active_foldcolumn = curr_foldcolumn end
vim.wo.foldcolumn = curr_foldcolumn == "0" and (last_active_foldcolumn or "1") or "0"
utils.notify(string.format("foldcolumn=%s", vim.wo.foldcolumn))
end
--- Toggle LSP inlay hints (global)
-- @param bufnr? number the buffer to toggle the clients on
function M.toggle_inlay_hints(bufnr)
bufnr = bufnr or 0
vim.g.inlay_hints_enabled = not vim.g.inlay_hints_enabled -- flip global state
vim.b.inlay_hints_enabled = not vim.g.inlay_hints_enabled -- sync buffer state
vim.lsp.buf.inlay_hint.enable(vim.g.inlay_hints_enabled, { bufnr = bufnr }) -- apply state
utils.notify(string.format("Global inlay hints %s", bool2str(vim.g.inlay_hints_enabled)))
end
--- Toggle lsp signature
function M.toggle_lsp_signature()
local state = require('lsp_signature').toggle_float_win()
utils.notify(string.format("lsp signature %s", bool2str(state)))
end
--- Toggle paste
function M.toggle_paste()
vim.opt.paste = not vim.opt.paste:get() -- local to window
utils.notify(string.format("paste %s", bool2str(vim.opt.paste:get())))
end
--- Toggle signcolumn="auto"|"no"
function M.toggle_signcolumn()
if vim.wo.signcolumn == "no" then
vim.wo.signcolumn = "yes"
elseif vim.wo.signcolumn == "yes" then
vim.wo.signcolumn = "auto"
else
vim.wo.signcolumn = "no"
end
utils.notify(string.format("signcolumn=%s", vim.wo.signcolumn))
end
--- Toggle spell
function M.toggle_spell()
vim.wo.spell = not vim.wo.spell -- local to window
utils.notify(string.format("spell %s", bool2str(vim.wo.spell)))
end
--- Toggle laststatus=3|2|0
function M.toggle_statusline()
local laststatus = vim.opt.laststatus:get()
local status
if laststatus == 0 then
vim.opt.laststatus = 2
status = "local"
elseif laststatus == 2 then
vim.opt.laststatus = 3
status = "global"
elseif laststatus == 3 then
vim.opt.laststatus = 0
status = "off"
end
utils.notify(string.format("statusline %s", status))
end
--- Toggle showtabline=2|0
function M.toggle_tabline()
vim.opt.showtabline = vim.opt.showtabline:get() == 0 and 2 or 0
utils.notify(string.format("tabline %s", bool2str(vim.opt.showtabline:get() == 2)))
end
--- Toggle notifications for UI toggles
function M.toggle_ui_notifications()
vim.g.notifications_enabled = not vim.g.notifications_enabled
utils.notify(string.format("Notifications %s", bool2str(vim.g.notifications_enabled)))
end
--- Toggle URL/URI syntax highlighting rules
function M.toggle_url_effect()
vim.g.url_effect_enabled = not vim.g.url_effect_enabled
require("base.utils").set_url_effect()
utils.notify(string.format("URL effect %s", bool2str(vim.g.url_effect_enabled)))
end
--- Toggle wrap
function M.toggle_wrap()
vim.wo.wrap = not vim.wo.wrap -- local to window
utils.notify(string.format("wrap %s", bool2str(vim.wo.wrap)))
end
--- Toggle zen mode
function M.toggle_zen_mode(bufnr)
bufnr = bufnr or 0
if not vim.b[bufnr].zen_mode then
vim.b[bufnr].zen_mode = true
else
vim.b[bufnr].zen_mode = false
end
utils.notify(string.format("zen mode %s", bool2str(vim.b[bufnr].zen_mode)))
vim.cmd "ZenMode"
end
return M