tangled
alpha
login
or
join now
robinwobin.dev
/
artio.nvim
3
fork
atom
minimal extui fuzzy finder for neovim
3
fork
atom
overview
issues
pulls
pipelines
feat(builtins): allow passing props to builtins
robinwobin.dev
3 months ago
9fca634b
fb6f30b5
+132
-98
1 changed file
expand all
collapse all
unified
split
lua
artio
builtins.lua
+132
-98
lua/artio/builtins.lua
···
9
local artio = lzrq("artio")
10
local config = lzrq("artio.config")
11
0
0
0
0
12
local function cmd_callback(o)
13
local src = o.stderr
14
if o.code == 0 then
···
43
44
local findprg = "fd -H -p -t f --color=never"
45
46
-
builtins.files = function()
47
-
local lst = make_cmd(findprg)()
0
0
0
48
49
-
return artio.generic(lst, {
50
-
prompt = "files",
51
-
on_close = function(text, _)
52
-
vim.schedule(function()
53
-
vim.cmd.edit(text)
54
-
end)
55
-
end,
56
-
get_icon = config.get().opts.use_icons and function(item)
57
-
return require("mini.icons").get("file", item.v)
58
-
end or nil,
59
-
preview_item = function(item)
60
-
return vim.fn.bufadd(item)
61
-
end,
62
-
})
0
0
0
63
end
64
65
-
builtins.grep = function()
0
66
local ext = require("vim._extui.shared")
67
local grepcmd = make_cmd(vim.o.grepprg)
68
69
-
return artio.pick({
70
items = {},
71
prompt = "grep",
72
get_items = function(input)
···
107
get_icon = config.get().opts.use_icons and function(item)
108
return require("mini.icons").get("file", item.v[1])
109
end or nil,
110
-
})
111
end
112
113
local function find_oldfiles()
···
119
:totable()
120
end
121
122
-
builtins.oldfiles = function()
0
123
local lst = find_oldfiles()
124
125
-
return artio.generic(lst, {
126
-
prompt = "oldfiles",
127
-
on_close = function(text, _)
128
-
vim.schedule(function()
129
-
vim.cmd.edit(text)
130
-
end)
131
-
end,
132
-
get_icon = config.get().opts.use_icons and function(item)
133
-
return require("mini.icons").get("file", item.v)
134
-
end or nil,
135
-
preview_item = function(item)
136
-
return vim.fn.bufadd(item)
137
-
end,
138
-
})
0
0
0
139
end
140
141
-
builtins.buffergrep = function()
0
142
local win = vim.api.nvim_get_current_win()
143
local buf = vim.api.nvim_win_get_buf(win)
144
local n = vim.api.nvim_buf_line_count(buf)
···
149
150
local pad = #tostring(lst[#lst])
151
152
-
return artio.generic(lst, {
153
-
prompt = "buffergrep",
154
-
on_close = function(row, _)
155
-
vim.schedule(function()
156
-
vim.api.nvim_win_set_cursor(win, { row, 0 })
157
-
end)
158
-
end,
159
-
format_item = function(row)
160
-
return vim.api.nvim_buf_get_lines(buf, row - 1, row, true)[1]
161
-
end,
162
-
preview_item = function(row)
163
-
return buf,
164
-
function(w)
165
-
vim.api.nvim_set_option_value("cursorline", true, { scope = "local", win = w })
166
-
vim.api.nvim_win_set_cursor(w, { row, 0 })
167
-
end
168
-
end,
169
-
get_icon = function(row)
170
-
local v = tostring(row.v)
171
-
return ("%s%s"):format((" "):rep(pad - #v), v)
172
-
end,
173
-
})
0
0
0
174
end
175
176
local function find_helptags()
···
185
end, tags)
186
end
187
188
-
builtins.helptags = function()
0
189
local lst = find_helptags()
190
191
-
return artio.generic(lst, {
192
-
prompt = "helptags",
193
-
on_close = function(text, _)
194
-
vim.schedule(function()
195
-
vim.cmd.help(text)
196
-
end)
197
-
end,
198
-
})
0
0
0
199
end
200
201
local function find_buffers()
···
207
:totable()
208
end
209
210
-
builtins.buffers = function()
0
211
local lst = find_buffers()
212
213
return artio.select(lst, {
···
226
preview_item = function(item)
227
return item
228
end,
229
-
})
230
end
231
232
---@param currentfile string
···
246
--- uses the regular files picker as a base
247
--- - boosts items in the bufferlist
248
--- - proportionally boosts items that match closely to the current file in proximity within the filesystem
249
-
builtins.smart = function()
0
250
local currentfile = vim.api.nvim_buf_get_name(0)
251
currentfile = vim.fs.abspath(currentfile)
252
253
-
local lst = find_files()
0
254
255
local pwd = vim.fn.getcwd()
256
local recentlst = vim
···
261
end)
262
:totable()
263
264
-
return artio.pick({
265
prompt = "smart",
266
items = vim.tbl_keys(vim.iter({ lst, recentlst }):fold({}, function(items, l)
267
for i = 1, #l do
···
298
preview_item = function(item)
299
return vim.fn.bufadd(item)
300
end,
301
-
})
302
end
303
304
-
builtins.colorschemes = function()
0
305
local files = vim.api.nvim_get_runtime_file("colors/*.{vim,lua}", true)
306
local lst = vim.tbl_map(function(f)
307
return vim.fs.basename(f):gsub("%.[^.]+$", "")
308
end, files)
309
310
-
return artio.generic(lst, {
311
-
prompt = "colorschemes",
312
-
on_close = function(text, _)
313
-
vim.schedule(function()
314
-
vim.cmd.colorscheme(text)
315
-
end)
316
-
end,
317
-
})
0
0
0
318
end
319
320
-
builtins.highlights = function()
0
321
local hlout = vim.split(vim.api.nvim_exec2([[ highlight ]], { output = true }).output, "\n", { trimempty = true })
322
323
local maxw = 0
···
335
return t
336
end)
337
338
-
return artio.generic(vim.tbl_keys(hls), {
339
-
prompt = "highlights",
340
-
on_close = function(line, _)
341
-
vim.schedule(function()
342
-
vim.print(line)
343
-
end)
344
-
end,
345
-
format_item = function(hlname)
346
-
return hls[hlname]
347
-
end,
348
-
hl_item = function(hlname)
349
-
return {
350
-
{ { 0, #hlname.v }, hlname.v },
351
-
}
352
-
end,
353
-
})
0
0
0
354
end
355
356
return builtins
···
9
local artio = lzrq("artio")
10
local config = lzrq("artio.config")
11
12
+
local function extend(t1, t2)
13
+
return vim.tbl_deep_extend("force", t1, t2)
14
+
end
15
+
16
local function cmd_callback(o)
17
local src = o.stderr
18
if o.code == 0 then
···
47
48
local findprg = "fd -H -p -t f --color=never"
49
50
+
builtins.files = function(props)
51
+
props = props or {}
52
+
props.findprg = props.findprg or findprg
53
+
54
+
local lst = make_cmd(props.findprg)()
55
56
+
return artio.generic(
57
+
lst,
58
+
extend({
59
+
prompt = "files",
60
+
on_close = function(text, _)
61
+
vim.schedule(function()
62
+
vim.cmd.edit(text)
63
+
end)
64
+
end,
65
+
get_icon = config.get().opts.use_icons and function(item)
66
+
return require("mini.icons").get("file", item.v)
67
+
end or nil,
68
+
preview_item = function(item)
69
+
return vim.fn.bufadd(item)
70
+
end,
71
+
}, props)
72
+
)
73
end
74
75
+
builtins.grep = function(props)
76
+
props = props or {}
77
local ext = require("vim._extui.shared")
78
local grepcmd = make_cmd(vim.o.grepprg)
79
80
+
return artio.pick(extend({
81
items = {},
82
prompt = "grep",
83
get_items = function(input)
···
118
get_icon = config.get().opts.use_icons and function(item)
119
return require("mini.icons").get("file", item.v[1])
120
end or nil,
121
+
}, props))
122
end
123
124
local function find_oldfiles()
···
130
:totable()
131
end
132
133
+
builtins.oldfiles = function(props)
134
+
props = props or {}
135
local lst = find_oldfiles()
136
137
+
return artio.generic(
138
+
lst,
139
+
extend({
140
+
prompt = "oldfiles",
141
+
on_close = function(text, _)
142
+
vim.schedule(function()
143
+
vim.cmd.edit(text)
144
+
end)
145
+
end,
146
+
get_icon = config.get().opts.use_icons and function(item)
147
+
return require("mini.icons").get("file", item.v)
148
+
end or nil,
149
+
preview_item = function(item)
150
+
return vim.fn.bufadd(item)
151
+
end,
152
+
}, props)
153
+
)
154
end
155
156
+
builtins.buffergrep = function(props)
157
+
props = props or {}
158
local win = vim.api.nvim_get_current_win()
159
local buf = vim.api.nvim_win_get_buf(win)
160
local n = vim.api.nvim_buf_line_count(buf)
···
165
166
local pad = #tostring(lst[#lst])
167
168
+
return artio.generic(
169
+
lst,
170
+
extend({
171
+
prompt = "buffergrep",
172
+
on_close = function(row, _)
173
+
vim.schedule(function()
174
+
vim.api.nvim_win_set_cursor(win, { row, 0 })
175
+
end)
176
+
end,
177
+
format_item = function(row)
178
+
return vim.api.nvim_buf_get_lines(buf, row - 1, row, true)[1]
179
+
end,
180
+
preview_item = function(row)
181
+
return buf,
182
+
function(w)
183
+
vim.api.nvim_set_option_value("cursorline", true, { scope = "local", win = w })
184
+
vim.api.nvim_win_set_cursor(w, { row, 0 })
185
+
end
186
+
end,
187
+
get_icon = function(row)
188
+
local v = tostring(row.v)
189
+
return ("%s%s"):format((" "):rep(pad - #v), v)
190
+
end,
191
+
}, props)
192
+
)
193
end
194
195
local function find_helptags()
···
204
end, tags)
205
end
206
207
+
builtins.helptags = function(props)
208
+
props = props or {}
209
local lst = find_helptags()
210
211
+
return artio.generic(
212
+
lst,
213
+
extend({
214
+
prompt = "helptags",
215
+
on_close = function(text, _)
216
+
vim.schedule(function()
217
+
vim.cmd.help(text)
218
+
end)
219
+
end,
220
+
}, props)
221
+
)
222
end
223
224
local function find_buffers()
···
230
:totable()
231
end
232
233
+
builtins.buffers = function(props)
234
+
props = props or {}
235
local lst = find_buffers()
236
237
return artio.select(lst, {
···
250
preview_item = function(item)
251
return item
252
end,
253
+
}, props)
254
end
255
256
---@param currentfile string
···
270
--- uses the regular files picker as a base
271
--- - boosts items in the bufferlist
272
--- - proportionally boosts items that match closely to the current file in proximity within the filesystem
273
+
builtins.smart = function(props)
274
+
props = props or {}
275
local currentfile = vim.api.nvim_buf_get_name(0)
276
currentfile = vim.fs.abspath(currentfile)
277
278
+
props.findprg = props.findprg or findprg
279
+
local lst = make_cmd(props.findprg)()
280
281
local pwd = vim.fn.getcwd()
282
local recentlst = vim
···
287
end)
288
:totable()
289
290
+
return artio.pick(extend({
291
prompt = "smart",
292
items = vim.tbl_keys(vim.iter({ lst, recentlst }):fold({}, function(items, l)
293
for i = 1, #l do
···
324
preview_item = function(item)
325
return vim.fn.bufadd(item)
326
end,
327
+
}, props))
328
end
329
330
+
builtins.colorschemes = function(props)
331
+
props = props or {}
332
local files = vim.api.nvim_get_runtime_file("colors/*.{vim,lua}", true)
333
local lst = vim.tbl_map(function(f)
334
return vim.fs.basename(f):gsub("%.[^.]+$", "")
335
end, files)
336
337
+
return artio.generic(
338
+
lst,
339
+
extend({
340
+
prompt = "colorschemes",
341
+
on_close = function(text, _)
342
+
vim.schedule(function()
343
+
vim.cmd.colorscheme(text)
344
+
end)
345
+
end,
346
+
}, props)
347
+
)
348
end
349
350
+
builtins.highlights = function(props)
351
+
props = props or {}
352
local hlout = vim.split(vim.api.nvim_exec2([[ highlight ]], { output = true }).output, "\n", { trimempty = true })
353
354
local maxw = 0
···
366
return t
367
end)
368
369
+
return artio.generic(
370
+
vim.tbl_keys(hls),
371
+
extend({
372
+
prompt = "highlights",
373
+
on_close = function(line, _)
374
+
vim.schedule(function()
375
+
vim.print(line)
376
+
end)
377
+
end,
378
+
format_item = function(hlname)
379
+
return hls[hlname]
380
+
end,
381
+
hl_item = function(hlname)
382
+
return {
383
+
{ { 0, #hlname.v }, hlname.v },
384
+
}
385
+
end,
386
+
}, props)
387
+
)
388
end
389
390
return builtins