|
25 | 25 | --- require('macrothis').delete() |
26 | 26 | --- end, |
27 | 27 | --- 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" |
28 | 42 | --- } |
29 | 43 | --- } |
30 | 44 | --- }, |
@@ -86,9 +100,18 @@ macrothis.save = function() |
86 | 100 | end, |
87 | 101 | }, function(register, _) |
88 | 102 | 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 | + ) |
92 | 115 | end |
93 | 116 | end) |
94 | 117 | end |
@@ -151,6 +174,52 @@ macrothis.delete = function() |
151 | 174 | end) |
152 | 175 | end |
153 | 176 |
|
| 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 | + |
154 | 223 | local generate_register_list = function() |
155 | 224 | local registers_table = { '"', "-", "#", "=", "/", "*", "+", ":", ".", "%" } |
156 | 225 |
|
|
172 | 241 | local default = { |
173 | 242 | datafile = vim.fn.stdpath("data") .. "/macrothis.json", |
174 | 243 | registers = generate_register_list(), |
| 244 | + run_register = "z", -- content of register z is replaced when running a macro |
175 | 245 | } |
176 | 246 | --minidoc_afterlines_end |
177 | 247 |
|
|
0 commit comments