From 7982265c98514597861eb99f48651d611aaa46bb Mon Sep 17 00:00:00 2001 From: Marco Candrian Date: Mon, 21 Jan 2008 12:12:26 +0000 Subject: [PATCH] :delmacros regex added --- NEWS | 2 +- content/commands.js | 15 ++++++++++++++- content/events.js | 12 +++++++++++- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index bef6cf72..2f46bae7 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,7 @@ * IMPORTANT: changed 'I' key to Ctrl-Q to also work in textboxes * IMPORTANT: :bmarks! and :history! open the matching items now in a tab, instead of bringing up the bookmarks/history window - * :macros [regex] for listing recorded macros + * :[del]macros [regex] for listing/deleting recorded macros * :set! now lets you change about:config prefs similar to :set * new :command to add user defined commands * new setCustomMode for plugin writers diff --git a/content/commands.js b/content/commands.js index 05511eb2..44e69e7a 100644 --- a/content/commands.js +++ b/content/commands.js @@ -1458,7 +1458,20 @@ vimperator.Commands = function () //{{{ help: "List recorded macros matching the optional regular expression. If no regex is given, list all." } )); - + commandManager.add(new vimperator.Command(["delmac[ros]"], + function (arg) + { + if (!arg) + vimperator.echoerr("E474: Invalid argument"); + else + vimperator.events.delMacros(arg); + }, + { + usage: ["delmac[ros] [regex]"], + shortHelp: "Delete macros matching a regex", + help: "Delete recorded macros matching a regular expression." + } + )); // 0 args -> list all maps // 1 arg -> list the maps starting with args // 2 args -> map arg1 to arg* diff --git a/content/events.js b/content/events.js index 0ecc1a81..086e76fa 100644 --- a/content/events.js +++ b/content/events.js @@ -485,7 +485,6 @@ vimperator.Events = function () //{{{ window.removeEventListener("keydown", this.onKeyDown, true); }, - startRecording: function (macro) { if (!/[a-zA-Z0-9]/.test(macro)) @@ -556,6 +555,17 @@ vimperator.Events = function () //{{{ return filtered; //XXX: returns a real copy, since this is only a 'var ..'? }, + delMacros: function (filter) + { + var re = new RegExp(filter); + + for (var item in macros) + { + if (item.match(re)) + delete macros[item]; + } + }, + // This method pushes keys into the event queue from vimperator // it is similar to vim's feedkeys() method, but cannot cope with // 2 partially feeded strings, you have to feed one parsable string