@@ -166,6 +166,47 @@ function M.save_macro(register)
166
166
print (" Macro saved as " .. name )
167
167
end
168
168
169
+ function M .delete_macro ()
170
+ local macros = handle_json_file (" r" )
171
+ if not macros or not macros .macros or # macros .macros == 0 then
172
+ print_error (" No macros found." )
173
+ return
174
+ end
175
+
176
+ local choices = {}
177
+ local name_to_index_map = {}
178
+ for index , macro in ipairs (macros .macros ) do
179
+ if macro .name then
180
+ local display_text = macro .name .. " | " .. string.sub (macro .content , 1 , 150 )
181
+ table.insert (choices , display_text )
182
+ name_to_index_map [display_text ] = index
183
+ end
184
+ end
185
+
186
+ if next (choices ) == nil then
187
+ print_error (" No valid macros to select for deletion." )
188
+ return
189
+ end
190
+
191
+ vim .ui .select (choices , { prompt = " Select a macro to delete:" }, function (choice )
192
+ if not choice then
193
+ print_error (" No macro selected for deletion." )
194
+ return
195
+ end
196
+
197
+ local macro_index = name_to_index_map [choice ]
198
+ if not macro_index then
199
+ print_error (" Selected macro is not valid." )
200
+ return
201
+ end
202
+
203
+ -- Remove the selected macro from the list
204
+ table.remove (macros .macros , macro_index )
205
+ handle_json_file (" w" , macros ) -- Write the updated list back to the JSON file
206
+ print (" Macro deleted: " .. choice :match (" ^[^|]+" ))
207
+ end )
208
+ end
209
+
169
210
-- Select and yank macro from JSON file (Yanks raw or escaped termcodes)
170
211
function M .select_and_yank_macro ()
171
212
local macros = handle_json_file (" r" )
0 commit comments