Skip to content

Commit 5fc094c

Browse files
authored
Merge pull request #7 from desdic/dev
Align functions between telescope/non-telescope
2 parents 8baa55f + 63bc5b0 commit 5fc094c

File tree

5 files changed

+109
-8
lines changed

5 files changed

+109
-8
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Works with or without telescope.
2020
{ "<Leader>kks", function() require('macrothis').save() end, desc = "save register" },
2121
{ "<Leader>kkl", function() require('macrothis').load() end, desc = "load register" }
2222
{ "<Leader>kkd", function() require('macrothis').delete() end, desc = "delete register" }
23+
{ "<Leader>kkr", function() require('macrothis').run() end, desc = "run macro" }
24+
{ "<Leader>kkq", function() require('macrothis').quickfix() end, desc = "run macro on all files in quickfix" }
2325
}
2426
},
2527
```

doc/macrothis.txt

+31-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ Using Lazy plugin manager
2929
require('macrothis').delete()
3030
end,
3131
desc = "delete register/macro"
32+
},
33+
{
34+
"<Leader>kkq",
35+
function()
36+
require('macrothis').quickfix()
37+
end,
38+
desc = "run on quickfix list"
39+
},
40+
{
41+
"<Leader>kkr",
42+
function()
43+
require('macrothis').run()
44+
end,
45+
desc = "run macro"
3246
}
3347
}
3448
},
@@ -58,6 +72,22 @@ Delete a macro/register
5872
Usage~
5973
`require('macrothis').delete()`
6074

75+
------------------------------------------------------------------------------
76+
*macrothis.run()*
77+
`macrothis.run`()
78+
Run macro
79+
80+
Usage~
81+
`require('macrothis').run()`
82+
83+
------------------------------------------------------------------------------
84+
*macrothis.quickfix()*
85+
`macrothis.quickfix`()
86+
Run macro on all in quickfix list
87+
88+
Usage~
89+
`require('macrothis').quickfix()`
90+
6191
------------------------------------------------------------------------------
6292
*default*
6393
`default`
@@ -66,6 +96,7 @@ Default options
6696
local default = {
6797
datafile = vim.fn.stdpath("data") .. "/macrothis.json",
6898
registers = generate_register_list(),
99+
run_register = "z", -- content of register z is replaced when running a macro
69100
}
70101
<
71102

@@ -101,7 +132,6 @@ Default telescope options
101132
{ remaining = true },
102133
},
103134
},
104-
run_register = "z", -- content of register z is replaced when running a macro
105135
}
106136
<
107137

lua/macrothis/init.lua

+73-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
--- require('macrothis').delete()
2626
--- end,
2727
--- desc = "delete register/macro"
28+
--- },
29+
--- {
30+
--- "<Leader>kkq",
31+
--- function()
32+
--- require('macrothis').quickfix()
33+
--- end,
34+
--- desc = "run on quickfix list"
35+
--- },
36+
--- {
37+
--- "<Leader>kkr",
38+
--- function()
39+
--- require('macrothis').run()
40+
--- end,
41+
--- desc = "run macro"
2842
--- }
2943
--- }
3044
--- },
@@ -86,9 +100,18 @@ macrothis.save = function()
86100
end,
87101
}, function(register, _)
88102
if register then
89-
local description = vim.fn.input("Enter description: ", "")
90-
utils.store_register(macrothis.opts, register.value, description)
91-
macrothis.opts.last_used = description
103+
vim.ui.input(
104+
{ prompt = "Enter description: " },
105+
function(description)
106+
print(vim.inspect(register))
107+
utils.store_register(
108+
macrothis.opts,
109+
register.label,
110+
description
111+
)
112+
macrothis.opts.last_used = description
113+
end
114+
)
92115
end
93116
end)
94117
end
@@ -151,6 +174,52 @@ macrothis.delete = function()
151174
end)
152175
end
153176

177+
--- Run macro
178+
---
179+
---@usage `require('macrothis').run()`
180+
macrothis.run = function()
181+
local menuelem = macrothis.generate_menu_items()
182+
183+
vim.ui.select(menuelem, {
184+
prompt = "Run on quickfix list",
185+
format_item = function(item)
186+
return ("%s: %s"):format(item.label, item.value)
187+
end,
188+
}, function(description, _)
189+
if description then
190+
utils.run_macro(
191+
macrothis.opts,
192+
macrothis.opts.run_register,
193+
description.label
194+
)
195+
macrothis.opts.last_used = description.label
196+
end
197+
end)
198+
end
199+
200+
--- Run macro on all in quickfix list
201+
---
202+
---@usage `require('macrothis').quickfix()`
203+
macrothis.quickfix = function()
204+
local menuelem = macrothis.generate_menu_items()
205+
206+
vim.ui.select(menuelem, {
207+
prompt = "Run on quickfix list",
208+
format_item = function(item)
209+
return ("%s: %s"):format(item.label, item.value)
210+
end,
211+
}, function(description, _)
212+
if description then
213+
utils.run_macro_on_quickfixlist(
214+
macrothis.opts,
215+
macrothis.opts.run_register,
216+
description.label
217+
)
218+
macrothis.opts.last_used = description.label
219+
end
220+
end)
221+
end
222+
154223
local generate_register_list = function()
155224
local registers_table = { '"', "-", "#", "=", "/", "*", "+", ":", ".", "%" }
156225

@@ -172,6 +241,7 @@ end
172241
local default = {
173242
datafile = vim.fn.stdpath("data") .. "/macrothis.json",
174243
registers = generate_register_list(),
244+
run_register = "z", -- content of register z is replaced when running a macro
175245
}
176246
--minidoc_afterlines_end
177247

lua/macrothis/utils.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ end
5959

6060
utils.run_macro_on_quickfixlist = function(opts, register, description)
6161
utils.load_register(opts, register, description)
62-
vim.cmd(":cdo norm! @" .. register)
62+
vim.cmd(":cfdo norm! @" .. register)
6363
-- Make sure we are back into normal mode after replacement
6464
vim.api.nvim_feedkeys(
6565
vim.api.nvim_replace_termcodes("<ESC>", true, false, true),

lua/telescope/_extensions/macrothis.lua

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ local default_telescope = {
3939
{ remaining = true },
4040
},
4141
},
42-
run_register = "z", -- content of register z is replaced when running a macro
4342
}
4443
--minidoc_afterlines_end
4544

@@ -200,7 +199,7 @@ local run_macro = function(prompt_bufnr)
200199

201200
utils.run_macro(
202201
macrothis.opts,
203-
macrothis.telescope_config.run_register,
202+
macrothis.opts.run_register,
204203
selected_register.value.label
205204
)
206205
end
@@ -212,7 +211,7 @@ local run_macro_on_quickfixlist = function(prompt_bufnr)
212211

213212
utils.run_macro_on_quickfixlist(
214213
macrothis.opts,
215-
macrothis.telescope_config.run_register,
214+
macrothis.opts.run_register,
216215
selected_register.value.label
217216
)
218217
end

0 commit comments

Comments
 (0)