From 2b71bd70b805751605208705915fb3be5d9b901c Mon Sep 17 00:00:00 2001 From: Marco Candrian Date: Mon, 21 Jan 2008 12:58:22 +0000 Subject: [PATCH] :macro for playing a macro added --- NEWS | 1 + content/commands.js | 17 ++++++++++++++++- content/completion.js | 14 ++++++++++++++ content/events.js | 9 ++++++--- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 2f46bae7..ac058ec9 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +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 + * :macro for playing a recorded macro * :[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 diff --git a/content/commands.js b/content/commands.js index 44e69e7a..d671011e 100644 --- a/content/commands.js +++ b/content/commands.js @@ -1439,7 +1439,7 @@ vimperator.Commands = function () //{{{ completer: function (filter) { return vimperator.completion.autocommands(filter); } } )); - commandManager.add(new vimperator.Command(["mac[ros]"], + commandManager.add(new vimperator.Command(["macros"], function (arg) { var str = ""; @@ -1472,6 +1472,21 @@ vimperator.Commands = function () //{{{ help: "Delete recorded macros matching a regular expression." } )); + commandManager.add(new vimperator.Command(["mac[ro]"], + function (arg) + { + if (!arg) + vimperator.echoerr("E474: Invalid argument"); + else + vimperator.events.playMacro(arg); + }, + { + usage: ["delmac[ros] [regex]"], + shortHelp: "Delete macros matching a regex", + help: "Delete recorded macros matching a regular expression.", + completer: function (filter) { return vimperator.completion.macros(filter); } + } + )); // 0 args -> list all maps // 1 arg -> list the maps starting with args // 2 args -> map arg1 to arg* diff --git a/content/completion.js b/content/completion.js index cc1d7edc..7e193f74 100644 --- a/content/completion.js +++ b/content/completion.js @@ -186,7 +186,21 @@ vimperator.Completion = function () //{{{ return [0, buildLongestCommonSubstring(mapped, filter)]; }, + macros: function (filter) + { + var macros = []; + var tmp = vimperator.events.getMacros(); + for (var item in tmp) + macros.push([item, tmp[item]]); + if (!filter) + return [0, macros]; + + var mapped = macros.map(function (macro) { + return [[macro[0]], macro[1]]; + }); + return [0, buildLongestCommonSubstring(mapped, filter)]; + }, // filter a list of urls // // may consist of search engines, filenames, bookmarks and history, diff --git a/content/events.js b/content/events.js index 086e76fa..73217052 100644 --- a/content/events.js +++ b/content/events.js @@ -509,7 +509,7 @@ vimperator.Events = function () //{{{ playMacro: function (macro) { - if (!/[a-zA-Z0-9@]/.test(macro)) + if (!/[a-zA-Z0-9@]/.test(macro) && macro.length == 1) { vimperator.echoerr("Register must be [a-z0-9]"); return false; @@ -524,7 +524,10 @@ vimperator.Events = function () //{{{ } else { - lastMacro = macro.toLowerCase(); // XXX: sets last playerd macro, even if it does not yet exist + if (macro.length == 1) + lastMacro = macro.toLowerCase(); // XXX: sets last playerd macro, even if it does not yet exist + else + lastMacro = macro; // e.g. long names are case sensitive } if (macros[lastMacro]) @@ -532,7 +535,7 @@ vimperator.Events = function () //{{{ vimperator.modes.isReplaying = true; BrowserStop(); // make sure the page is stopped before starting to play the macro vimperator.buffer.loaded = 1; // even if not a full page load, assume it did load correctly before starting the macro - vimperator.events.feedkeys(macros[lastMacro], true); // true -> noremap + vimperator.events.feedkeys(macros[lastMacro], true); // true -> noremap vimperator.modes.isReplaying = false; } else