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